Java Code Examples for org.apache.rocketmq.remoting.protocol.RemotingSerializable#fromJson()
The following examples show how to use
org.apache.rocketmq.remoting.protocol.RemotingSerializable#fromJson() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConsumerOffsetManager.java From DDMQ with Apache License 2.0 | 5 votes |
@Override public void decode(String jsonString) { if (jsonString != null) { ConsumerOffsetManager obj = RemotingSerializable.fromJson(jsonString, ConsumerOffsetManager.class); if (obj != null) { ServerUtil.updateMap(this.offsetTable, obj.offsetTable); } } }
Example 2
Source File: TopicStatsTableTest.java From rocketmq with Apache License 2.0 | 5 votes |
@Test public void testFromJson() throws Exception { String json = RemotingSerializable.toJson(topicStatsTable, true); TopicStatsTable fromJson = RemotingSerializable.fromJson(json, TopicStatsTable.class); validateTopicStatsTable(fromJson); }
Example 3
Source File: ConsumerConnectionTest.java From rocketmq with Apache License 2.0 | 5 votes |
@Test public void testFromJson() { ConsumerConnection consumerConnection = new ConsumerConnection(); HashSet<Connection> connections = new HashSet<Connection>(); Connection conn = new Connection(); connections.add(conn); ConcurrentHashMap<String/* Topic */, SubscriptionData> subscriptionTable = new ConcurrentHashMap<String, SubscriptionData>(); SubscriptionData subscriptionData = new SubscriptionData(); subscriptionTable.put("topicA", subscriptionData); ConsumeType consumeType = ConsumeType.CONSUME_ACTIVELY; MessageModel messageModel = MessageModel.CLUSTERING; ConsumeFromWhere consumeFromWhere = ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET; consumerConnection.setConnectionSet(connections); consumerConnection.setSubscriptionTable(subscriptionTable); consumerConnection.setConsumeType(consumeType); consumerConnection.setMessageModel(messageModel); consumerConnection.setConsumeFromWhere(consumeFromWhere); String json = RemotingSerializable.toJson(consumerConnection, true); ConsumerConnection fromJson = RemotingSerializable.fromJson(json, ConsumerConnection.class); assertThat(fromJson.getConsumeType()).isEqualTo(ConsumeType.CONSUME_ACTIVELY); assertThat(fromJson.getMessageModel()).isEqualTo(MessageModel.CLUSTERING); HashSet<Connection> connectionSet = fromJson.getConnectionSet(); assertThat(connectionSet).isInstanceOf(Set.class); SubscriptionData data = fromJson.getSubscriptionTable().get("topicA"); assertThat(data).isExactlyInstanceOf(SubscriptionData.class); }
Example 4
Source File: ResetOffsetBodyTest.java From rocketmq with Apache License 2.0 | 5 votes |
@Test public void testFromJson() throws Exception { ResetOffsetBody rob = new ResetOffsetBody(); Map<MessageQueue, Long> offsetMap = new HashMap<MessageQueue, Long>(); MessageQueue queue = new MessageQueue(); queue.setQueueId(1); queue.setBrokerName("brokerName"); queue.setTopic("topic"); offsetMap.put(queue, 100L); rob.setOffsetTable(offsetMap); String json = RemotingSerializable.toJson(rob, true); ResetOffsetBody fromJson = RemotingSerializable.fromJson(json, ResetOffsetBody.class); assertThat(fromJson.getOffsetTable().get(queue)).isEqualTo(100L); assertThat(fromJson.getOffsetTable().size()).isEqualTo(1); }
Example 5
Source File: ConsumerOffsetManager.java From DDMQ with Apache License 2.0 | 5 votes |
@Override public void decode(String jsonString) { if (jsonString != null) { ConsumerOffsetManager obj = RemotingSerializable.fromJson(jsonString, ConsumerOffsetManager.class); if (obj != null) { ServerUtil.updateMap(this.offsetTable, obj.offsetTable); } } }
Example 6
Source File: SubscriptionGroupManager.java From DDMQ with Apache License 2.0 | 5 votes |
@Override public void decode(String jsonString) { if (jsonString != null) { SubscriptionGroupManager obj = RemotingSerializable.fromJson(jsonString, SubscriptionGroupManager.class); if (obj != null) { ServerUtil.updateMap(this.subscriptionGroupTable, obj.subscriptionGroupTable); this.dataVersion.assignNewOne(obj.dataVersion); this.printLoadDataWhenFirstBoot(obj); } } }
Example 7
Source File: ConsumeStatusTest.java From rocketmq with Apache License 2.0 | 5 votes |
@Test public void testFromJson() throws Exception { ConsumeStatus cs = new ConsumeStatus(); cs.setConsumeFailedTPS(10); cs.setPullRT(100); cs.setPullTPS(1000); String json = RemotingSerializable.toJson(cs, true); ConsumeStatus fromJson = RemotingSerializable.fromJson(json, ConsumeStatus.class); assertThat(fromJson.getPullRT()).isCloseTo(cs.getPullRT(), within(0.0001)); assertThat(fromJson.getPullTPS()).isCloseTo(cs.getPullTPS(), within(0.0001)); assertThat(fromJson.getConsumeFailedTPS()).isCloseTo(cs.getConsumeFailedTPS(), within(0.0001)); }
Example 8
Source File: QueryConsumeTimeSpanBodyTest.java From rocketmq with Apache License 2.0 | 5 votes |
@Test public void testFromJsonRandom() throws Exception { QueryConsumeTimeSpanBody origin = new QueryConsumeTimeSpanBody(); List<QueueTimeSpan> queueTimeSpans = newUniqueConsumeTimeSpanSet(); origin.setConsumeTimeSpanSet(queueTimeSpans); String json = origin.toJson(true); QueryConsumeTimeSpanBody fromJson = RemotingSerializable.fromJson(json, QueryConsumeTimeSpanBody.class); assertThat(fromJson.getConsumeTimeSpanSet().get(0).getMinTimeStamp()).isEqualTo(origin.getConsumeTimeSpanSet().get(0).getMinTimeStamp()); assertThat(fromJson.getConsumeTimeSpanSet().get(0).getMaxTimeStamp()).isEqualTo(origin.getConsumeTimeSpanSet().get(0).getMaxTimeStamp()); assertThat(fromJson.getConsumeTimeSpanSet().get(0).getConsumeTimeStamp()).isEqualTo(origin.getConsumeTimeSpanSet().get(0).getConsumeTimeStamp()); assertThat(fromJson.getConsumeTimeSpanSet().get(0).getDelayTime()).isEqualTo(origin.getConsumeTimeSpanSet().get(0).getDelayTime()); assertThat(fromJson.getConsumeTimeSpanSet().get(0).getMessageQueue().getBrokerName()).isEqualTo(origin.getConsumeTimeSpanSet().get(0).getMessageQueue().getBrokerName()); assertThat(fromJson.getConsumeTimeSpanSet().get(0).getMessageQueue().getTopic()).isEqualTo(origin.getConsumeTimeSpanSet().get(0).getMessageQueue().getTopic()); assertThat(fromJson.getConsumeTimeSpanSet().get(0).getMessageQueue().getQueueId()).isEqualTo(origin.getConsumeTimeSpanSet().get(0).getMessageQueue().getQueueId()); }
Example 9
Source File: ConsumeStatusTest.java From rocketmq-read with Apache License 2.0 | 5 votes |
@Test public void testFromJson() throws Exception { ConsumeStatus cs = new ConsumeStatus(); cs.setConsumeFailedTPS(10); cs.setPullRT(100); cs.setPullTPS(1000); String json = RemotingSerializable.toJson(cs, true); ConsumeStatus fromJson = RemotingSerializable.fromJson(json, ConsumeStatus.class); assertThat(fromJson.getPullRT()).isCloseTo(cs.getPullRT(), within(0.0001)); assertThat(fromJson.getPullTPS()).isCloseTo(cs.getPullTPS(), within(0.0001)); assertThat(fromJson.getConsumeFailedTPS()).isCloseTo(cs.getConsumeFailedTPS(), within(0.0001)); }
Example 10
Source File: ConsumerOffsetManager.java From rocketmq-all-4.1.0-incubating with Apache License 2.0 | 5 votes |
@Override public void decode(String jsonString) { if (jsonString != null) { ConsumerOffsetManager obj = RemotingSerializable.fromJson(jsonString, ConsumerOffsetManager.class); if (obj != null) { this.offsetTable = obj.offsetTable; } } }
Example 11
Source File: ConsumerOffsetManager.java From rocketmq with Apache License 2.0 | 5 votes |
@Override public void decode(String jsonString) { if (jsonString != null) { ConsumerOffsetManager obj = RemotingSerializable.fromJson(jsonString, ConsumerOffsetManager.class); if (obj != null) { this.offsetTable = obj.offsetTable; } } }
Example 12
Source File: TransactionTableDefConfigService.java From rocketmq_trans_message with Apache License 2.0 | 5 votes |
@Override public void decode(String jsonString) { if (jsonString != null && jsonString.length() > 0) { this.tableDefine = RemotingSerializable.fromJson(jsonString, TableDefine.class); } else { this.tableDefine = null; } }
Example 13
Source File: SubscriptionDataTest.java From rocketmq with Apache License 2.0 | 5 votes |
@Test public void testFromJson() throws Exception { SubscriptionData subscriptionData = new SubscriptionData("TOPICA", "*"); subscriptionData.setFilterClassSource("TestFilterClassSource"); subscriptionData.setCodeSet(Sets.newLinkedHashSet(1, 2, 3)); subscriptionData.setTagsSet(Sets.newLinkedHashSet("TAGA", "TAGB", "TAG3")); String json = RemotingSerializable.toJson(subscriptionData, true); SubscriptionData fromJson = RemotingSerializable.fromJson(json, SubscriptionData.class); assertThat(subscriptionData).isEqualTo(fromJson); assertThat(subscriptionData).isEqualByComparingTo(fromJson); assertThat(subscriptionData.getFilterClassSource()).isEqualTo("TestFilterClassSource"); assertThat(fromJson.getFilterClassSource()).isNull(); }
Example 14
Source File: ConsumerOffsetManager.java From rocketmq-4.3.0 with Apache License 2.0 | 5 votes |
@Override public void decode(String jsonString) { if (jsonString != null) { ConsumerOffsetManager obj = RemotingSerializable.fromJson(jsonString, ConsumerOffsetManager.class); if (obj != null) { this.offsetTable = obj.offsetTable; } } }
Example 15
Source File: SubscriptionGroupManager.java From rocketmq-4.3.0 with Apache License 2.0 | 5 votes |
@Override public void decode(String jsonString) { if (jsonString != null) { SubscriptionGroupManager obj = RemotingSerializable.fromJson(jsonString, SubscriptionGroupManager.class); if (obj != null) { this.subscriptionGroupTable.putAll(obj.subscriptionGroupTable); this.dataVersion.assignNewOne(obj.dataVersion); this.printLoadDataWhenFirstBoot(obj); } } }
Example 16
Source File: SubscriptionGroupManager.java From rocketmq_trans_message with Apache License 2.0 | 5 votes |
@Override public void decode(String jsonString) { if (jsonString != null) { SubscriptionGroupManager obj = RemotingSerializable.fromJson(jsonString, SubscriptionGroupManager.class); if (obj != null) { this.subscriptionGroupTable.putAll(obj.subscriptionGroupTable); this.dataVersion.assignNewOne(obj.dataVersion); this.printLoadDataWhenFirstBoot(obj); } } }
Example 17
Source File: SubscriptionGroupManager.java From DDMQ with Apache License 2.0 | 5 votes |
@Override public void decode(String jsonString) { if (jsonString != null) { SubscriptionGroupManager obj = RemotingSerializable.fromJson(jsonString, SubscriptionGroupManager.class); if (obj != null) { ServerUtil.updateMap(this.subscriptionGroupTable, obj.subscriptionGroupTable); this.dataVersion.assignNewOne(obj.dataVersion); this.printLoadDataWhenFirstBoot(obj); } } }
Example 18
Source File: ConsumerFilterManager.java From rocketmq-read with Apache License 2.0 | 4 votes |
@Override public void decode(final String jsonString) { ConsumerFilterManager load = RemotingSerializable.fromJson(jsonString, ConsumerFilterManager.class); if (load != null && load.filterDataByTopic != null) { boolean bloomChanged = false; for (String topic : load.filterDataByTopic.keySet()) { FilterDataMapByTopic dataMapByTopic = load.filterDataByTopic.get(topic); if (dataMapByTopic == null) { continue; } for (String group : dataMapByTopic.getGroupFilterData().keySet()) { ConsumerFilterData filterData = dataMapByTopic.getGroupFilterData().get(group); if (filterData == null) { continue; } try { filterData.setCompiledExpression( FilterFactory.INSTANCE.get(filterData.getExpressionType()).compile(filterData.getExpression()) ); } catch (Exception e) { log.error("load filter data error, " + filterData, e); } // check whether bloom filter is changed // if changed, ignore the bit map calculated before. if (!this.bloomFilter.isValid(filterData.getBloomFilterData())) { bloomChanged = true; log.info("Bloom filter is changed!So ignore all filter data persisted! {}, {}", this.bloomFilter, filterData.getBloomFilterData()); break; } log.info("load exist consumer filter data: {}", filterData); if (filterData.getDeadTime() == 0) { // we think all consumers are dead when load long deadTime = System.currentTimeMillis() - 30 * 1000; filterData.setDeadTime( deadTime <= filterData.getBornTime() ? filterData.getBornTime() : deadTime ); } } } if (!bloomChanged) { this.filterDataByTopic = load.filterDataByTopic; } } }
Example 19
Source File: ConsumerFilterManager.java From rocketmq with Apache License 2.0 | 4 votes |
@Override public void decode(final String jsonString) { ConsumerFilterManager load = RemotingSerializable.fromJson(jsonString, ConsumerFilterManager.class); if (load != null && load.filterDataByTopic != null) { boolean bloomChanged = false; for (String topic : load.filterDataByTopic.keySet()) { FilterDataMapByTopic dataMapByTopic = load.filterDataByTopic.get(topic); if (dataMapByTopic == null) { continue; } for (String group : dataMapByTopic.getGroupFilterData().keySet()) { ConsumerFilterData filterData = dataMapByTopic.getGroupFilterData().get(group); if (filterData == null) { continue; } try { filterData.setCompiledExpression( FilterFactory.INSTANCE.get(filterData.getExpressionType()).compile(filterData.getExpression()) ); } catch (Exception e) { log.error("load filter data error, " + filterData, e); } // check whether bloom filter is changed // if changed, ignore the bit map calculated before. if (!this.bloomFilter.isValid(filterData.getBloomFilterData())) { bloomChanged = true; log.info("Bloom filter is changed!So ignore all filter data persisted! {}, {}", this.bloomFilter, filterData.getBloomFilterData()); break; } log.info("load exist consumer filter data: {}", filterData); if (filterData.getDeadTime() == 0) { // we think all consumers are dead when load long deadTime = System.currentTimeMillis() - 30 * 1000; filterData.setDeadTime( deadTime <= filterData.getBornTime() ? filterData.getBornTime() : deadTime ); } } } if (!bloomChanged) { this.filterDataByTopic = load.filterDataByTopic; } } }
Example 20
Source File: ConsumerFilterManager.java From DDMQ with Apache License 2.0 | 4 votes |
@Override public void decode(final String jsonString) { ConsumerFilterManager load = RemotingSerializable.fromJson(jsonString, ConsumerFilterManager.class); if (load != null && load.filterDataByTopic != null) { boolean bloomChanged = false; for (String topic : load.filterDataByTopic.keySet()) { FilterDataMapByTopic dataMapByTopic = load.filterDataByTopic.get(topic); if (dataMapByTopic == null) { continue; } for (String group : dataMapByTopic.getGroupFilterData().keySet()) { ConsumerFilterData filterData = dataMapByTopic.getGroupFilterData().get(group); if (filterData == null) { continue; } try { filterData.setCompiledExpression( FilterFactory.INSTANCE.get(filterData.getExpressionType()).compile(filterData.getExpression()) ); } catch (Exception e) { log.error("load filter data error, " + filterData, e); } // check whether bloom filter is changed // if changed, ignore the bit map calculated before. if (!this.bloomFilter.isValid(filterData.getBloomFilterData())) { bloomChanged = true; log.info("Bloom filter is changed!So ignore all filter data persisted! {}, {}", this.bloomFilter, filterData.getBloomFilterData()); break; } log.info("load exist consumer filter data: {}", filterData); if (filterData.getDeadTime() == 0) { // we think all consumers are dead when load long deadTime = System.currentTimeMillis() - 30 * 1000; filterData.setDeadTime( deadTime <= filterData.getBornTime() ? filterData.getBornTime() : deadTime ); } } } if (!bloomChanged) { ServerUtil.updateMap(this.filterDataByTopic, load.filterDataByTopic); } } }