From 388ba7a58465245389a3592904b6fc7ef777dc7a Mon Sep 17 00:00:00 2001 From: yukon Date: Wed, 28 Dec 2016 15:42:48 +0800 Subject: [PATCH] ROCKETMQ-18 Reformat all codes. --- broker/pom.xml | 2 +- .../rocketmq/broker/BrokerController.java | 155 ++-- .../broker/BrokerPathConfigHelper.java | 20 +- .../apache/rocketmq/broker/BrokerStartup.java | 41 +- .../broker/client/ClientChannelInfo.java | 32 +- .../client/ClientHousekeepingService.java | 29 +- .../broker/client/ConsumerGroupInfo.java | 73 +- .../client/ConsumerIdsChangeListener.java | 14 +- .../broker/client/ConsumerManager.java | 38 +- .../DefaultConsumerIdsChangeListener.java | 18 +- .../broker/client/ProducerManager.java | 54 +- .../broker/client/net/Broker2Client.java | 96 ++- .../rebalance/RebalanceLockManager.java | 107 ++- .../broker/filtersrv/FilterServerManager.java | 36 +- .../broker/filtersrv/FilterServerUtil.java | 13 +- .../broker/latency/BrokerFastFailure.java | 44 +- .../BrokerFixedThreadPoolExecutor.java | 19 +- .../broker/longpolling/ManyPullRequest.java | 18 +- .../NotifyMessageArrivingListener.java | 15 +- .../broker/longpolling/PullRequest.java | 23 +- .../longpolling/PullRequestHoldService.java | 16 +- .../broker/mqtrace/ConsumeMessageContext.java | 36 +- .../broker/mqtrace/ConsumeMessageHook.java | 14 +- .../broker/mqtrace/SendMessageContext.java | 43 +- .../broker/mqtrace/SendMessageHook.java | 14 +- .../broker/offset/ConsumerOffsetManager.java | 39 +- .../rocketmq/broker/out/BrokerOuterAPI.java | 90 +-- .../broker/pagecache/ManyMessageTransfer.java | 18 +- .../broker/pagecache/OneMessageTransfer.java | 18 +- .../pagecache/QueryMessageTransfer.java | 18 +- .../plugin/AbstractPluginMessageStore.java | 28 +- .../broker/plugin/MessageStoreFactory.java | 21 +- .../plugin/MessageStorePluginContext.java | 17 +- .../AbstractSendMessageProcessor.java | 98 ++- .../processor/AdminBrokerProcessor.java | 237 ++++--- .../processor/ClientManageProcessor.java | 61 +- .../processor/ConsumerManageProcessor.java | 68 +- .../processor/EndTransactionProcessor.java | 50 +- .../processor/ForwardRequestProcessor.java | 17 +- .../processor/PullMessageProcessor.java | 100 ++- .../processor/QueryMessageProcessor.java | 61 +- .../processor/SendMessageProcessor.java | 80 +-- .../broker/slave/SlaveSynchronize.java | 54 +- .../SubscriptionGroupManager.java | 29 +- .../broker/topic/TopicConfigManager.java | 64 +- .../broker/transaction/TransactionRecord.java | 16 +- .../broker/transaction/TransactionStore.java | 20 +- .../jdbc/JDBCTransactionStore.java | 34 +- .../jdbc/JDBCTransactionStoreConfig.java | 20 +- .../rocketmq/broker/BrokerControllerTest.java | 15 +- .../rocketmq/broker/BrokerTestHarness.java | 22 +- .../rocketmq/broker/api/SendMessageTest.java | 23 +- .../offset/ConsumerOffsetManagerTest.java | 15 +- .../broker/topic/TopicConfigManagerTest.java | 19 +- checkstyle/checkstyle.xml | 8 +- client/pom.xml | 2 +- .../apache/rocketmq/client/ClientConfig.java | 35 +- .../org/apache/rocketmq/client/MQAdmin.java | 33 +- .../org/apache/rocketmq/client/MQHelper.java | 42 +- .../apache/rocketmq/client/QueryResult.java | 22 +- .../apache/rocketmq/client/Validators.java | 32 +- .../client/admin/MQAdminExtInner.java | 12 +- .../client/common/ThreadLocalIndex.java | 20 +- .../AllocateMessageQueueStrategy.java | 27 +- .../consumer/DefaultMQPullConsumer.java | 75 +- .../consumer/DefaultMQPushConsumer.java | 81 +-- .../rocketmq/client/consumer/MQConsumer.java | 22 +- .../client/consumer/MQPullConsumer.java | 52 +- .../MQPullConsumerScheduleService.java | 36 +- .../client/consumer/MQPushConsumer.java | 23 +- .../client/consumer/MessageQueueListener.java | 18 +- .../client/consumer/PullCallback.java | 12 +- .../rocketmq/client/consumer/PullResult.java | 30 +- .../rocketmq/client/consumer/PullStatus.java | 12 +- .../client/consumer/PullTaskCallback.java | 13 +- .../client/consumer/PullTaskContext.java | 16 +- .../listener/ConsumeConcurrentlyContext.java | 7 - .../listener/ConsumeConcurrentlyStatus.java | 12 +- .../listener/ConsumeOrderlyContext.java | 19 +- .../listener/ConsumeOrderlyStatus.java | 12 +- .../consumer/listener/ConsumeReturnType.java | 12 +- .../consumer/listener/MessageListener.java | 12 +- .../listener/MessageListenerConcurrently.java | 18 +- .../listener/MessageListenerOrderly.java | 18 +- .../AllocateMessageQueueAveragely.java | 19 +- ...AllocateMessageQueueAveragelyByCircle.java | 15 +- .../AllocateMessageQueueByConfig.java | 19 +- .../AllocateMessageQueueByMachineRoom.java | 21 +- .../consumer/store/LocalFileOffsetStore.java | 51 +- .../store/OffsetSerializeWrapper.java | 20 +- .../client/consumer/store/OffsetStore.java | 23 +- .../client/consumer/store/ReadOffsetType.java | 12 +- .../store/RemoteBrokerOffsetStore.java | 53 +- .../client/exception/MQBrokerException.java | 18 +- .../client/exception/MQClientException.java | 17 +- .../client/hook/CheckForbiddenContext.java | 40 +- .../client/hook/CheckForbiddenHook.java | 14 +- .../client/hook/ConsumeMessageContext.java | 32 +- .../client/hook/ConsumeMessageHook.java | 12 +- .../client/hook/FilterMessageContext.java | 29 +- .../client/hook/FilterMessageHook.java | 13 +- .../client/hook/SendMessageContext.java | 35 +- .../rocketmq/client/hook/SendMessageHook.java | 12 +- .../client/impl/ClientRemotingProcessor.java | 56 +- .../client/impl/CommunicationMode.java | 12 +- .../client/impl/FindBrokerResult.java | 15 +- .../rocketmq/client/impl/MQAdminImpl.java | 114 ++- .../rocketmq/client/impl/MQClientAPIImpl.java | 667 +++++++++--------- .../rocketmq/client/impl/MQClientManager.java | 26 +- .../ConsumeMessageConcurrentlyService.java | 88 +-- .../ConsumeMessageOrderlyService.java | 135 ++-- .../impl/consumer/ConsumeMessageService.java | 31 +- .../consumer/DefaultMQPullConsumerImpl.java | 193 ++--- .../consumer/DefaultMQPushConsumerImpl.java | 261 +++---- .../client/impl/consumer/MQConsumerInner.java | 26 +- .../impl/consumer/MessageQueueLock.java | 19 +- .../client/impl/consumer/ProcessQueue.java | 57 +- .../client/impl/consumer/PullAPIWrapper.java | 84 +-- .../impl/consumer/PullMessageService.java | 37 +- .../client/impl/consumer/PullRequest.java | 23 +- .../client/impl/consumer/PullResultExt.java | 22 +- .../client/impl/consumer/RebalanceImpl.java | 75 +- .../impl/consumer/RebalancePullImpl.java | 22 +- .../impl/consumer/RebalancePushImpl.java | 32 +- .../impl/consumer/RebalanceService.java | 18 +- .../client/impl/factory/MQClientInstance.java | 234 +++--- .../impl/producer/DefaultMQProducerImpl.java | 216 +++--- .../client/impl/producer/MQProducerInner.java | 27 +- .../impl/producer/TopicPublishInfo.java | 17 +- .../latency/LatencyFaultToleranceImpl.java | 52 +- .../client/latency/MQFaultStrategy.java | 7 +- .../rocketmq/client/log/ClientLogger.java | 25 +- .../client/producer/DefaultMQProducer.java | 96 +-- .../producer/LocalTransactionExecuter.java | 13 +- .../producer/LocalTransactionState.java | 12 +- .../rocketmq/client/producer/MQProducer.java | 71 +- .../client/producer/MessageQueueSelector.java | 16 +- .../client/producer/SendCallback.java | 13 +- .../rocketmq/client/producer/SendResult.java | 31 +- .../rocketmq/client/producer/SendStatus.java | 12 +- .../producer/TransactionCheckListener.java | 13 +- .../producer/TransactionMQProducer.java | 27 +- .../producer/TransactionSendResult.java | 15 +- .../selector/SelectMessageQueueByHash.java | 16 +- .../SelectMessageQueueByMachineRoom.java | 21 +- .../selector/SelectMessageQueueByRandoom.java | 19 +- .../client/stat/ConsumerStatsManager.java | 40 +- .../resources/logback_rocketmq_client.xml | 2 +- .../rocketmq/client/ValidatorsTest.java | 13 +- common/pom.xml | 2 +- .../apache/rocketmq/common/BrokerConfig.java | 83 +-- .../common/BrokerConfigSingleton.java | 12 +- .../apache/rocketmq/common/ConfigManager.java | 17 +- .../apache/rocketmq/common/Configuration.java | 27 +- .../rocketmq/common/CountDownLatch2.java | 111 ++- .../apache/rocketmq/common/DataVersion.java | 36 +- .../org/apache/rocketmq/common/MQVersion.java | 2 - .../org/apache/rocketmq/common/MixAll.java | 54 +- .../java/org/apache/rocketmq/common/Pair.java | 17 +- .../apache/rocketmq/common/ServiceState.java | 12 +- .../apache/rocketmq/common/ServiceThread.java | 28 +- .../apache/rocketmq/common/SystemClock.java | 12 +- .../rocketmq/common/ThreadFactoryImpl.java | 15 +- .../apache/rocketmq/common/TopicConfig.java | 68 +- .../rocketmq/common/TopicFilterType.java | 12 +- .../org/apache/rocketmq/common/UtilAll.java | 114 ++- .../rocketmq/common/admin/ConsumeStats.java | 21 +- .../rocketmq/common/admin/OffsetWrapper.java | 18 +- .../rocketmq/common/admin/RollbackStats.java | 24 +- .../rocketmq/common/admin/TopicOffset.java | 18 +- .../common/admin/TopicStatsTable.java | 18 +- .../common/constant/DBMsgConstants.java | 12 +- .../rocketmq/common/constant/LoggerName.java | 12 +- .../rocketmq/common/constant/PermName.java | 12 +- .../common/consumer/ConsumeFromWhere.java | 12 +- .../rocketmq/common/filter/FilterAPI.java | 18 +- .../rocketmq/common/filter/FilterContext.java | 14 +- .../rocketmq/common/filter/MessageFilter.java | 1 - .../rocketmq/common/filter/impl/Op.java | 15 +- .../rocketmq/common/filter/impl/Operand.java | 12 +- .../rocketmq/common/filter/impl/Operator.java | 14 +- .../common/filter/impl/PolishExpr.java | 41 +- .../rocketmq/common/filter/impl/Type.java | 12 +- .../apache/rocketmq/common/help/FAQUrl.java | 49 +- .../rocketmq/common/hook/FilterCheckHook.java | 14 +- .../rocketmq/common/message/Message.java | 48 +- .../common/message/MessageAccessor.java | 24 +- .../common/message/MessageClientExt.java | 34 +- .../common/message/MessageClientIDSetter.java | 16 +- .../rocketmq/common/message/MessageConst.java | 2 - .../common/message/MessageDecoder.java | 71 +- .../rocketmq/common/message/MessageExt.java | 58 +- .../rocketmq/common/message/MessageId.java | 18 +- .../rocketmq/common/message/MessageQueue.java | 27 +- .../common/message/MessageQueueForC.java | 30 +- .../rocketmq/common/message/MessageType.java | 12 +- .../common/namesrv/NamesrvConfig.java | 25 +- .../rocketmq/common/namesrv/NamesrvUtil.java | 12 +- .../common/namesrv/RegisterBrokerResult.java | 19 +- .../common/namesrv/TopAddressing.java | 53 +- .../common/protocol/MQProtosHelper.java | 17 +- .../rocketmq/common/protocol/RequestCode.java | 16 +- .../common/protocol/ResponseCode.java | 17 +- .../common/protocol/body/BrokerStatsData.java | 19 +- .../common/protocol/body/BrokerStatsItem.java | 18 +- .../common/protocol/body/CMResult.java | 12 +- .../common/protocol/body/ClusterInfo.java | 28 +- .../common/protocol/body/Connection.java | 21 +- .../common/protocol/body/ConsumeByWho.java | 26 +- .../body/ConsumeMessageDirectlyResult.java | 28 +- .../protocol/body/ConsumeStatsList.java | 18 +- .../common/protocol/body/ConsumeStatus.java | 24 +- .../protocol/body/ConsumerConnection.java | 31 +- .../body/ConsumerOffsetSerializeWrapper.java | 20 +- .../protocol/body/ConsumerRunningInfo.java | 134 ++-- .../protocol/body/GetConsumerStatusBody.java | 24 +- .../common/protocol/body/GroupList.java | 18 +- .../common/protocol/body/KVTable.java | 18 +- .../protocol/body/LockBatchRequestBody.java | 24 +- .../protocol/body/LockBatchResponseBody.java | 20 +- .../protocol/body/ProcessQueueInfo.java | 54 +- .../protocol/body/ProducerConnection.java | 18 +- .../body/QueryConsumeTimeSpanBody.java | 18 +- .../body/QueryCorrectionOffsetBody.java | 18 +- .../common/protocol/body/QueueTimeSpan.java | 29 +- .../protocol/body/RegisterBrokerBody.java | 20 +- .../common/protocol/body/ResetOffsetBody.java | 18 +- .../protocol/body/ResetOffsetBodyForC.java | 17 +- .../body/SubscriptionGroupWrapper.java | 24 +- .../body/TopicConfigSerializeWrapper.java | 22 +- .../common/protocol/body/TopicList.java | 20 +- .../protocol/body/UnlockBatchRequestBody.java | 24 +- .../CheckTransactionStateRequestHeader.java | 20 +- .../CheckTransactionStateResponseHeader.java | 24 +- .../header/CloneGroupOffsetRequestHeader.java | 24 +- ...umeMessageDirectlyResultRequestHeader.java | 22 +- .../ConsumerSendMsgBackRequestHeader.java | 31 +- .../header/CreateTopicRequestHeader.java | 33 +- .../DeleteSubscriptionGroupRequestHeader.java | 16 +- .../header/DeleteTopicRequestHeader.java | 18 +- .../header/EndTransactionRequestHeader.java | 33 +- .../header/EndTransactionResponseHeader.java | 15 +- .../GetAllTopicConfigResponseHeader.java | 15 +- .../header/GetBrokerConfigResponseHeader.java | 18 +- .../header/GetConsumeStatsInBrokerHeader.java | 13 +- .../header/GetConsumeStatsRequestHeader.java | 18 +- ...etConsumerConnectionListRequestHeader.java | 16 +- .../GetConsumerListByGroupRequestHeader.java | 16 +- .../GetConsumerListByGroupResponseBody.java | 18 +- .../GetConsumerListByGroupResponseHeader.java | 13 +- .../GetConsumerRunningInfoRequestHeader.java | 20 +- .../GetConsumerStatusRequestHeader.java | 20 +- .../GetEarliestMsgStoretimeRequestHeader.java | 20 +- ...GetEarliestMsgStoretimeResponseHeader.java | 18 +- .../header/GetMaxOffsetRequestHeader.java | 20 +- .../header/GetMaxOffsetResponseHeader.java | 18 +- .../header/GetMinOffsetRequestHeader.java | 20 +- .../header/GetMinOffsetResponseHeader.java | 18 +- ...etProducerConnectionListRequestHeader.java | 16 +- .../GetTopicStatsInfoRequestHeader.java | 16 +- .../GetTopicsByClusterRequestHeader.java | 16 +- ...NotifyConsumerIdsChangedRequestHeader.java | 16 +- .../header/PullMessageRequestHeader.java | 36 +- .../header/PullMessageResponseHeader.java | 24 +- .../QueryConsumeTimeSpanRequestHeader.java | 18 +- .../QueryConsumerOffsetRequestHeader.java | 22 +- .../QueryConsumerOffsetResponseHeader.java | 18 +- .../header/QueryCorrectionOffsetHeader.java | 22 +- .../header/QueryMessageRequestHeader.java | 26 +- .../header/QueryMessageResponseHeader.java | 20 +- .../QueryTopicConsumeByWhoRequestHeader.java | 18 +- .../header/ResetOffsetRequestHeader.java | 22 +- .../header/SearchOffsetRequestHeader.java | 22 +- .../header/SearchOffsetResponseHeader.java | 18 +- .../header/SendMessageRequestHeader.java | 40 +- .../header/SendMessageRequestHeaderV2.java | 24 - .../header/SendMessageResponseHeader.java | 22 +- .../header/UnregisterClientRequestHeader.java | 20 +- .../UnregisterClientResponseHeader.java | 13 +- .../UpdateConsumerOffsetRequestHeader.java | 24 +- .../UpdateConsumerOffsetResponseHeader.java | 15 +- .../ViewBrokerStatsDataRequestHeader.java | 18 +- .../header/ViewMessageRequestHeader.java | 18 +- .../header/ViewMessageResponseHeader.java | 15 +- .../RegisterFilterServerRequestHeader.java | 16 +- .../RegisterFilterServerResponseHeader.java | 18 +- ...gisterMessageFilterClassRequestHeader.java | 22 +- .../namesrv/DeleteKVConfigRequestHeader.java | 18 +- .../DeleteTopicInNamesrvRequestHeader.java | 16 +- .../namesrv/GetKVConfigRequestHeader.java | 18 +- .../namesrv/GetKVConfigResponseHeader.java | 16 +- .../GetKVListByNamespaceRequestHeader.java | 16 +- .../namesrv/GetRouteInfoRequestHeader.java | 18 +- .../namesrv/GetRouteInfoResponseHeader.java | 15 +- .../namesrv/PutKVConfigRequestHeader.java | 20 +- .../namesrv/RegisterBrokerRequestHeader.java | 26 +- .../namesrv/RegisterBrokerResponseHeader.java | 18 +- .../RegisterOrderTopicRequestHeader.java | 20 +- .../UnRegisterBrokerRequestHeader.java | 24 +- .../WipeWritePermOfBrokerRequestHeader.java | 16 +- .../WipeWritePermOfBrokerResponseHeader.java | 16 +- .../protocol/heartbeat/ConsumeType.java | 15 +- .../protocol/heartbeat/ConsumerData.java | 35 +- .../protocol/heartbeat/HeartbeatData.java | 27 +- .../protocol/heartbeat/MessageModel.java | 15 +- .../protocol/heartbeat/ProducerData.java | 17 +- .../protocol/heartbeat/SubscriptionData.java | 39 +- .../common/protocol/route/BrokerData.java | 20 +- .../common/protocol/route/QueueData.java | 20 +- .../common/protocol/route/TopicRouteData.java | 27 +- .../protocol/topic/OffsetMovedEvent.java | 24 +- .../common/queue/ConcurrentTreeMap.java | 27 +- .../rocketmq/common/queue/RoundQueue.java | 15 +- .../rocketmq/common/running/RunningStats.java | 12 +- .../common/stats/MomentStatsItem.java | 19 +- .../common/stats/MomentStatsItemSet.java | 11 +- .../rocketmq/common/stats/StatsItem.java | 68 +- .../rocketmq/common/stats/StatsItemSet.java | 14 +- .../rocketmq/common/stats/StatsSnapshot.java | 18 +- .../subscription/SubscriptionGroupConfig.java | 35 +- .../common/sysflag/MessageSysFlag.java | 3 - .../rocketmq/common/sysflag/PullSysFlag.java | 20 +- .../common/sysflag/SubscriptionSysFlag.java | 5 - .../rocketmq/common/sysflag/TopicSysFlag.java | 8 - .../rocketmq/common/utils/ChannelUtil.java | 15 +- .../rocketmq/common/utils/HttpTinyClient.java | 36 +- .../rocketmq/common/utils/IOTinyUtils.java | 42 +- .../apache/rocketmq/common/MixAllTest.java | 18 +- .../rocketmq/common/RemotingUtilTest.java | 13 +- .../apache/rocketmq/common/UtilAllTest.java | 31 +- .../rocketmq/common/filter/FilterAPITest.java | 17 +- .../common/protocol/ConsumeStatusTest.java | 13 +- conf/2m-2s-async/broker-a-s.properties | 1 - conf/2m-2s-async/broker-a.properties | 1 - conf/2m-2s-async/broker-b-s.properties | 1 - conf/2m-2s-async/broker-b.properties | 1 - conf/2m-2s-sync/broker-a-s.properties | 1 - conf/2m-2s-sync/broker-a.properties | 1 - conf/2m-2s-sync/broker-b-s.properties | 1 - conf/2m-2s-sync/broker-b.properties | 1 - conf/2m-noslave/broker-a.properties | 1 - conf/2m-noslave/broker-b.properties | 1 - conf/broker.conf | 14 +- conf/logback_broker.xml | 22 +- conf/logback_filtersrv.xml | 4 +- conf/logback_namesrv.xml | 4 +- conf/logback_tools.xml | 4 +- example/pom.xml | 2 +- .../rocketmq/example/benchmark/Consumer.java | 53 +- .../rocketmq/example/benchmark/Producer.java | 52 +- .../benchmark/TransactionProducer.java | 67 +- .../example/broadcast/PushConsumer.java | 5 +- .../rocketmq/example/filter/Consumer.java | 8 +- .../rocketmq/example/filter/Producer.java | 6 +- .../rocketmq/example/operation/Consumer.java | 21 +- .../rocketmq/example/operation/Producer.java | 27 +- .../example/ordermessage/Consumer.java | 6 +- .../example/ordermessage/Producer.java | 13 +- .../rocketmq/example/quickstart/Consumer.java | 5 +- .../rocketmq/example/quickstart/Producer.java | 4 +- .../example/simple/AsyncProducer.java | 10 +- .../rocketmq/example/simple/CachedQueue.java | 17 +- .../rocketmq/example/simple/Producer.java | 7 +- .../rocketmq/example/simple/PullConsumer.java | 10 +- .../example/simple/PullScheduleService.java | 2 - .../rocketmq/example/simple/PushConsumer.java | 4 +- .../example/simple/RandomAsyncCommit.java | 23 +- .../rocketmq/example/simple/TestProducer.java | 8 +- .../TransactionCheckListenerImpl.java | 5 +- .../transaction/TransactionExecuterImpl.java | 16 +- .../transaction/TransactionProducer.java | 9 +- .../src/main/resources/MessageFilterImpl.java | 15 +- filtersrv/pom.xml | 2 +- .../filtersrv/FilterServerOuterAPI.java | 17 +- .../rocketmq/filtersrv/FiltersrvConfig.java | 41 +- .../filtersrv/FiltersrvController.java | 61 +- .../rocketmq/filtersrv/FiltersrvStartup.java | 34 +- .../rocketmq/filtersrv/filter/DynaCode.java | 177 +++-- .../filter/FilterClassFetchMethod.java | 12 +- .../filtersrv/filter/FilterClassInfo.java | 19 +- .../filtersrv/filter/FilterClassLoader.java | 12 +- .../filtersrv/filter/FilterClassManager.java | 67 +- .../filter/HttpFilterClassFetchMethod.java | 17 +- .../processor/DefaultRequestProcessor.java | 91 ++- .../stats/FilterServerStatsManager.java | 29 +- namesrv/pom.xml | 2 +- .../rocketmq/namesrv/NamesrvController.java | 45 +- .../rocketmq/namesrv/NamesrvStartup.java | 36 +- .../namesrv/kvconfig/KVConfigManager.java | 45 +- .../kvconfig/KVConfigSerializeWrapper.java | 18 +- .../ClusterTestRequestProcessor.java | 25 +- .../processor/DefaultRequestProcessor.java | 154 ++-- .../routeinfo/BrokerHousekeepingService.java | 20 +- .../namesrv/routeinfo/RouteInfoManager.java | 142 ++-- remoting/pom.xml | 2 +- .../remoting/ChannelEventListener.java | 16 +- .../remoting/CommandCustomHeader.java | 13 +- .../rocketmq/remoting/InvokeCallback.java | 13 +- .../org/apache/rocketmq/remoting/RPCHook.java | 4 +- .../rocketmq/remoting/RemotingClient.java | 38 +- .../rocketmq/remoting/RemotingServer.java | 26 +- .../rocketmq/remoting/RemotingService.java | 2 - .../remoting/annotation/CFNullable.java | 12 +- .../apache/rocketmq/remoting/common/Pair.java | 17 +- .../remoting/common/RemotingHelper.java | 41 +- .../remoting/common/RemotingUtil.java | 29 +- .../common/SemaphoreReleaseOnlyOnce.java | 16 +- .../remoting/common/ServiceThread.java | 19 +- .../exception/RemotingCommandException.java | 14 +- .../exception/RemotingConnectException.java | 14 +- .../remoting/exception/RemotingException.java | 14 +- .../RemotingSendRequestException.java | 14 +- .../exception/RemotingTimeoutException.java | 15 +- .../RemotingTooMuchRequestException.java | 13 +- .../remoting/netty/NettyClientConfig.java | 31 +- .../rocketmq/remoting/netty/NettyDecoder.java | 28 +- .../rocketmq/remoting/netty/NettyEncoder.java | 24 +- .../rocketmq/remoting/netty/NettyEvent.java | 18 +- .../remoting/netty/NettyEventType.java | 12 +- .../remoting/netty/NettyRemotingAbstract.java | 85 +-- .../remoting/netty/NettyRemotingClient.java | 111 ++- .../remoting/netty/NettyRemotingServer.java | 120 ++-- .../remoting/netty/NettyRequestProcessor.java | 18 +- .../remoting/netty/NettyServerConfig.java | 36 +- .../remoting/netty/NettySystemConfig.java | 26 +- .../rocketmq/remoting/netty/RequestTask.java | 25 +- .../remoting/netty/ResponseFuture.java | 45 +- .../remoting/protocol/LanguageCode.java | 30 +- .../remoting/protocol/RemotingCommand.java | 73 +- .../protocol/RemotingCommandType.java | 12 +- .../protocol/RemotingSerializable.java | 14 +- .../protocol/RemotingSysResponseCode.java | 12 +- .../protocol/RocketMQSerializable.java | 54 +- .../remoting/protocol/SerializeType.java | 16 +- .../org/apache/rocketmq/remoting/MixTest.java | 15 +- .../rocketmq/remoting/NettyRPCTest.java | 92 ++- .../rocketmq/subclass/TestSubClassAuto.java | 13 +- srvutil/pom.xml | 2 +- .../apache/rocketmq/srvutil/ServerUtil.java | 29 +- store/pom.xml | 2 +- .../store/AllocateMappedFileService.java | 59 +- .../rocketmq/store/AppendMessageCallback.java | 15 +- .../rocketmq/store/AppendMessageResult.java | 42 +- .../rocketmq/store/AppendMessageStatus.java | 12 +- .../org/apache/rocketmq/store/CommitLog.java | 300 ++++---- .../apache/rocketmq/store/ConsumeQueue.java | 78 +- .../rocketmq/store/DefaultMessageFilter.java | 13 +- .../rocketmq/store/DefaultMessageStore.java | 195 ++--- .../rocketmq/store/DispatchRequest.java | 35 +- .../rocketmq/store/GetMessageResult.java | 45 +- .../rocketmq/store/GetMessageStatus.java | 12 +- .../org/apache/rocketmq/store/MappedFile.java | 176 ++--- .../rocketmq/store/MappedFileQueue.java | 82 +-- .../store/MessageArrivingListener.java | 12 +- .../rocketmq/store/MessageExtBrokerInner.java | 17 +- .../apache/rocketmq/store/MessageFilter.java | 13 +- .../apache/rocketmq/store/MessageStore.java | 49 +- .../rocketmq/store/PutMessageResult.java | 21 +- .../rocketmq/store/PutMessageStatus.java | 12 +- .../rocketmq/store/QueryMessageResult.java | 23 +- .../rocketmq/store/ReferenceResource.java | 22 +- .../apache/rocketmq/store/RunningFlags.java | 26 +- .../store/SelectMappedBufferResult.java | 21 +- .../rocketmq/store/StoreCheckpoint.java | 40 +- .../rocketmq/store/StoreStatsService.java | 88 +-- .../org/apache/rocketmq/store/StoreUtil.java | 16 +- .../rocketmq/store/TransientStorePool.java | 15 +- .../rocketmq/store/config/BrokerRole.java | 12 +- .../rocketmq/store/config/FlushDiskType.java | 12 +- .../store/config/MessageStoreConfig.java | 132 +--- .../store/config/StorePathConfigHelper.java | 19 +- .../rocketmq/store/ha/HAConnection.java | 63 +- .../apache/rocketmq/store/ha/HAService.java | 95 +-- .../rocketmq/store/ha/WaitNotifyObject.java | 18 +- .../rocketmq/store/index/IndexFile.java | 72 +- .../rocketmq/store/index/IndexHeader.java | 15 - .../rocketmq/store/index/IndexService.java | 51 +- .../store/index/QueryOffsetResult.java | 19 +- .../schedule/DelayOffsetSerializeWrapper.java | 20 +- .../schedule/ScheduleMessageService.java | 112 ++- .../rocketmq/store/stats/BrokerStats.java | 29 +- .../store/stats/BrokerStatsManager.java | 34 +- .../org/apache/rocketmq/store/util/LibC.java | 15 +- .../store/DefaultMessageStoreTest.java | 34 +- .../rocketmq/store/MappedFileQueueTest.java | 56 +- .../apache/rocketmq/store/MappedFileTest.java | 33 +- .../rocketmq/store/StoreCheckpointTest.java | 20 +- .../rocketmq/store/index/IndexFileTest.java | 25 +- .../store/schedule/ScheduleMessageTest.java | 35 +- store/src/test/resources/logback-test.xml | 24 +- style/copyright/Apache.xml | 9 +- style/copyright/profiles_settings.xml | 84 +-- style/rmq_codeStyle.xml | 204 +++--- tools/pom.xml | 2 +- .../tools/admin/DefaultMQAdminExt.java | 141 ++-- .../tools/admin/DefaultMQAdminExtImpl.java | 212 +++--- .../rocketmq/tools/admin/MQAdminExt.java | 141 ++-- .../tools/admin/api/MessageTrack.java | 21 +- .../rocketmq/tools/admin/api/TrackType.java | 12 +- .../rocketmq/tools/command/CommandUtil.java | 46 +- .../tools/command/MQAdminStartup.java | 72 +- .../rocketmq/tools/command/SubCommand.java | 18 +- .../broker/BrokerConsumeStatsSubCommad.java | 46 +- .../broker/BrokerStatusSubCommand.java | 24 +- .../broker/CleanExpiredCQSubCommand.java | 22 +- .../broker/CleanUnusedTopicCommand.java | 22 +- .../broker/GetBrokerConfigCommand.java | 39 +- .../command/broker/SendMsgStatusCommand.java | 36 +- .../broker/UpdateBrokerConfigSubCommand.java | 29 +- .../cluster/CLusterSendMsgRTCommand.java | 55 +- .../cluster/ClusterListSubCommand.java | 89 ++- .../ConsumerConnectionSubCommand.java | 29 +- .../ProducerConnectionSubCommand.java | 17 +- .../consumer/ConsumerProgressSubCommand.java | 84 +-- .../consumer/ConsumerStatusSubCommand.java | 30 +- .../command/consumer/ConsumerSubCommand.java | 32 +- .../DeleteSubscriptionGroupCommand.java | 35 +- .../consumer/StartMonitoringSubCommand.java | 23 +- .../consumer/UpdateSubGroupSubCommand.java | 29 +- .../message/CheckMsgSendRTCommand.java | 34 +- .../message/DecodeMessageIdCommond.java | 18 +- .../message/PrintMessageByQueueCommand.java | 157 ++--- .../message/PrintMessageSubCommand.java | 76 +- .../message/QueryMsgByIdSubCommand.java | 287 ++++---- .../message/QueryMsgByKeySubCommand.java | 27 +- .../message/QueryMsgByOffsetSubCommand.java | 7 +- .../QueryMsgByUniqueKeySubCommand.java | 177 +++-- .../rocketmq/tools/command/message/Store.java | 56 +- .../namesrv/DeleteKvConfigCommand.java | 22 +- .../namesrv/GetNamesrvConfigCommand.java | 25 +- .../namesrv/UpdateKvConfigCommand.java | 22 +- .../namesrv/UpdateNamesrvConfigCommand.java | 27 +- .../namesrv/WipeWritePermSubCommand.java | 34 +- .../offset/CloneGroupOffsetCommand.java | 23 +- .../offset/GetConsumerStatusCommand.java | 29 +- .../offset/ResetOffsetByTimeCommand.java | 32 +- .../offset/ResetOffsetByTimeOldCommand.java | 80 +-- .../command/stats/StatsAllSubCommand.java | 176 +++-- .../command/topic/AllocateMQSubCommand.java | 20 +- .../command/topic/DeleteTopicSubCommand.java | 70 +- .../tools/command/topic/RebalanceResult.java | 15 +- .../command/topic/TopicClusterSubCommand.java | 12 +- .../command/topic/TopicListSubCommand.java | 34 +- .../command/topic/TopicRouteSubCommand.java | 10 +- .../command/topic/TopicStatusSubCommand.java | 49 +- .../command/topic/UpdateOrderConfCommand.java | 26 +- .../topic/UpdateTopicPermSubCommand.java | 17 +- .../command/topic/UpdateTopicSubCommand.java | 25 +- .../tools/monitor/DefaultMonitorListener.java | 40 +- .../tools/monitor/DeleteMsgsEvent.java | 20 +- .../rocketmq/tools/monitor/FailedMsgs.java | 21 +- .../rocketmq/tools/monitor/MonitorConfig.java | 19 +- .../tools/monitor/MonitorListener.java | 3 +- .../tools/monitor/MonitorService.java | 65 +- .../rocketmq/tools/monitor/UndoneMsgs.java | 27 +- 555 files changed, 8226 insertions(+), 11139 deletions(-) diff --git a/broker/pom.xml b/broker/pom.xml index 09175036..30525e41 100644 --- a/broker/pom.xml +++ b/broker/pom.xml @@ -15,7 +15,7 @@ limitations under the License. --> - org.apache.rocketmq diff --git a/broker/src/main/java/org/apache/rocketmq/broker/BrokerController.java b/broker/src/main/java/org/apache/rocketmq/broker/BrokerController.java index 8e973ac5..501c1c5d 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/BrokerController.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/BrokerController.java @@ -16,7 +16,25 @@ */ package org.apache.rocketmq.broker; -import org.apache.rocketmq.broker.client.*; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; +import org.apache.rocketmq.broker.client.ClientHousekeepingService; +import org.apache.rocketmq.broker.client.ConsumerIdsChangeListener; +import org.apache.rocketmq.broker.client.ConsumerManager; +import org.apache.rocketmq.broker.client.DefaultConsumerIdsChangeListener; +import org.apache.rocketmq.broker.client.ProducerManager; import org.apache.rocketmq.broker.client.net.Broker2Client; import org.apache.rocketmq.broker.client.rebalance.RebalanceLockManager; import org.apache.rocketmq.broker.filtersrv.FilterServerManager; @@ -30,11 +48,21 @@ import org.apache.rocketmq.broker.offset.ConsumerOffsetManager; import org.apache.rocketmq.broker.out.BrokerOuterAPI; import org.apache.rocketmq.broker.plugin.MessageStoreFactory; import org.apache.rocketmq.broker.plugin.MessageStorePluginContext; -import org.apache.rocketmq.broker.processor.*; +import org.apache.rocketmq.broker.processor.AdminBrokerProcessor; +import org.apache.rocketmq.broker.processor.ClientManageProcessor; +import org.apache.rocketmq.broker.processor.ConsumerManageProcessor; +import org.apache.rocketmq.broker.processor.EndTransactionProcessor; +import org.apache.rocketmq.broker.processor.PullMessageProcessor; +import org.apache.rocketmq.broker.processor.QueryMessageProcessor; +import org.apache.rocketmq.broker.processor.SendMessageProcessor; import org.apache.rocketmq.broker.slave.SlaveSynchronize; import org.apache.rocketmq.broker.subscription.SubscriptionGroupManager; import org.apache.rocketmq.broker.topic.TopicConfigManager; -import org.apache.rocketmq.common.*; +import org.apache.rocketmq.common.BrokerConfig; +import org.apache.rocketmq.common.Configuration; +import org.apache.rocketmq.common.ThreadFactoryImpl; +import org.apache.rocketmq.common.TopicConfig; +import org.apache.rocketmq.common.UtilAll; import org.apache.rocketmq.common.constant.LoggerName; import org.apache.rocketmq.common.constant.PermName; import org.apache.rocketmq.common.namesrv.RegisterBrokerResult; @@ -43,7 +71,11 @@ import org.apache.rocketmq.common.protocol.body.TopicConfigSerializeWrapper; import org.apache.rocketmq.common.stats.MomentStatsItem; import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.remoting.RemotingServer; -import org.apache.rocketmq.remoting.netty.*; +import org.apache.rocketmq.remoting.netty.NettyClientConfig; +import org.apache.rocketmq.remoting.netty.NettyRemotingServer; +import org.apache.rocketmq.remoting.netty.NettyRequestProcessor; +import org.apache.rocketmq.remoting.netty.NettyServerConfig; +import org.apache.rocketmq.remoting.netty.RequestTask; import org.apache.rocketmq.store.DefaultMessageStore; import org.apache.rocketmq.store.MessageArrivingListener; import org.apache.rocketmq.store.MessageStore; @@ -54,15 +86,6 @@ import org.apache.rocketmq.store.stats.BrokerStatsManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; -import java.net.InetSocketAddress; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.concurrent.*; - - public class BrokerController { private static final Logger log = LoggerFactory.getLogger(LoggerName.BROKER_LOGGER_NAME); private static final Logger LOG_PROTECTION = LoggerFactory.getLogger(LoggerName.PROTECTION_LOGGER_NAME); @@ -84,7 +107,7 @@ public class BrokerController { private final RebalanceLockManager rebalanceLockManager = new RebalanceLockManager(); private final BrokerOuterAPI brokerOuterAPI; private final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryImpl( - "BrokerControllerScheduledThread")); + "BrokerControllerScheduledThread")); private final SlaveSynchronize slaveSynchronize; private final BlockingQueue sendThreadPoolQueue; private final BlockingQueue pullThreadPoolQueue; @@ -110,10 +133,10 @@ public class BrokerController { private Configuration configuration; public BrokerController(// - final BrokerConfig brokerConfig, // - final NettyServerConfig nettyServerConfig, // - final NettyClientConfig nettyClientConfig, // - final MessageStoreConfig messageStoreConfig // + final BrokerConfig brokerConfig, // + final NettyServerConfig nettyServerConfig, // + final NettyClientConfig nettyClientConfig, // + final MessageStoreConfig messageStoreConfig // ) { this.brokerConfig = brokerConfig; this.nettyServerConfig = nettyServerConfig; @@ -151,9 +174,9 @@ public class BrokerController { this.brokerFastFailure = new BrokerFastFailure(this); this.configuration = new Configuration( - log, - BrokerPathConfigHelper.getBrokerConfigPath(), - this.brokerConfig, this.nettyServerConfig, this.nettyClientConfig, this.messageStoreConfig + log, + BrokerPathConfigHelper.getBrokerConfigPath(), + this.brokerConfig, this.nettyServerConfig, this.nettyClientConfig, this.messageStoreConfig ); } @@ -180,9 +203,9 @@ public class BrokerController { if (result) { try { this.messageStore = - new DefaultMessageStore(this.messageStoreConfig, this.brokerStatsManager, this.messageArrivingListener, - this.brokerConfig); - this.brokerStats = new BrokerStats((DefaultMessageStore) this.messageStore); + new DefaultMessageStore(this.messageStoreConfig, this.brokerStatsManager, this.messageArrivingListener, + this.brokerConfig); + this.brokerStats = new BrokerStats((DefaultMessageStore)this.messageStore); //load plugin MessageStorePluginContext context = new MessageStorePluginContext(messageStoreConfig, brokerStatsManager, messageArrivingListener, brokerConfig); this.messageStore = MessageStoreFactory.build(context, this.messageStore); @@ -196,44 +219,43 @@ public class BrokerController { if (result) { this.remotingServer = new NettyRemotingServer(this.nettyServerConfig, this.clientHousekeepingService); - NettyServerConfig fastConfig = (NettyServerConfig) this.nettyServerConfig.clone(); + NettyServerConfig fastConfig = (NettyServerConfig)this.nettyServerConfig.clone(); fastConfig.setListenPort(nettyServerConfig.getListenPort() - 2); this.fastRemotingServer = new NettyRemotingServer(fastConfig, this.clientHousekeepingService); this.sendMessageExecutor = new BrokerFixedThreadPoolExecutor( - this.brokerConfig.getSendMessageThreadPoolNums(), - this.brokerConfig.getSendMessageThreadPoolNums(), - 1000 * 60, - TimeUnit.MILLISECONDS, - this.sendThreadPoolQueue, - new ThreadFactoryImpl("SendMessageThread_")); + this.brokerConfig.getSendMessageThreadPoolNums(), + this.brokerConfig.getSendMessageThreadPoolNums(), + 1000 * 60, + TimeUnit.MILLISECONDS, + this.sendThreadPoolQueue, + new ThreadFactoryImpl("SendMessageThread_")); this.pullMessageExecutor = new BrokerFixedThreadPoolExecutor( - this.brokerConfig.getPullMessageThreadPoolNums(), - this.brokerConfig.getPullMessageThreadPoolNums(), - 1000 * 60, - TimeUnit.MILLISECONDS, - this.pullThreadPoolQueue, - new ThreadFactoryImpl("PullMessageThread_")); + this.brokerConfig.getPullMessageThreadPoolNums(), + this.brokerConfig.getPullMessageThreadPoolNums(), + 1000 * 60, + TimeUnit.MILLISECONDS, + this.pullThreadPoolQueue, + new ThreadFactoryImpl("PullMessageThread_")); this.adminBrokerExecutor = - Executors.newFixedThreadPool(this.brokerConfig.getAdminBrokerThreadPoolNums(), new ThreadFactoryImpl( - "AdminBrokerThread_")); + Executors.newFixedThreadPool(this.brokerConfig.getAdminBrokerThreadPoolNums(), new ThreadFactoryImpl( + "AdminBrokerThread_")); this.clientManageExecutor = new ThreadPoolExecutor( - this.brokerConfig.getClientManageThreadPoolNums(), - this.brokerConfig.getClientManageThreadPoolNums(), - 1000 * 60, - TimeUnit.MILLISECONDS, - this.clientManagerThreadPoolQueue, - new ThreadFactoryImpl("ClientManageThread_")); + this.brokerConfig.getClientManageThreadPoolNums(), + this.brokerConfig.getClientManageThreadPoolNums(), + 1000 * 60, + TimeUnit.MILLISECONDS, + this.clientManagerThreadPoolQueue, + new ThreadFactoryImpl("ClientManageThread_")); this.consumerManageExecutor = - Executors.newFixedThreadPool(this.brokerConfig.getConsumerManageThreadPoolNums(), new ThreadFactoryImpl( - "ConsumerManageThread_")); + Executors.newFixedThreadPool(this.brokerConfig.getConsumerManageThreadPoolNums(), new ThreadFactoryImpl( + "ConsumerManageThread_")); this.registerProcessor(); - // TODO remove in future final long initialDelay = UtilAll.computNextMorningTimeMillis() - System.currentTimeMillis(); final long period = 1000 * 60 * 60 * 24; @@ -259,7 +281,6 @@ public class BrokerController { } }, 1000 * 10, this.brokerConfig.getFlushConsumerOffsetInterval(), TimeUnit.MILLISECONDS); - this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() { @Override public void run() { @@ -399,7 +420,6 @@ public class BrokerController { this.fastRemotingServer.registerProcessor(RequestCode.UPDATE_CONSUMER_OFFSET, consumerManageProcessor, this.consumerManageExecutor); this.fastRemotingServer.registerProcessor(RequestCode.QUERY_CONSUMER_OFFSET, consumerManageProcessor, this.consumerManageExecutor); - /** * EndTransactionProcessor */ @@ -446,7 +466,8 @@ public class BrokerController { slowTimeMills = this.messageStore.now() - rt.getCreateTimestamp(); } - if (slowTimeMills < 0) slowTimeMills = 0; + if (slowTimeMills < 0) + slowTimeMills = 0; return slowTimeMills; } @@ -577,10 +598,10 @@ public class BrokerController { private void unregisterBrokerAll() { this.brokerOuterAPI.unregisterBrokerAll( - this.brokerConfig.getBrokerClusterName(), - this.getBrokerAddr(), - this.brokerConfig.getBrokerName(), - this.brokerConfig.getBrokerId()); + this.brokerConfig.getBrokerClusterName(), + this.getBrokerAddr(), + this.brokerConfig.getBrokerName(), + this.brokerConfig.getBrokerId()); } public String getBrokerAddr() { @@ -643,27 +664,27 @@ public class BrokerController { TopicConfigSerializeWrapper topicConfigWrapper = this.getTopicConfigManager().buildTopicConfigSerializeWrapper(); if (!PermName.isWriteable(this.getBrokerConfig().getBrokerPermission()) - || !PermName.isReadable(this.getBrokerConfig().getBrokerPermission())) { + || !PermName.isReadable(this.getBrokerConfig().getBrokerPermission())) { ConcurrentHashMap topicConfigTable = new ConcurrentHashMap(); for (TopicConfig topicConfig : topicConfigWrapper.getTopicConfigTable().values()) { TopicConfig tmp = - new TopicConfig(topicConfig.getTopicName(), topicConfig.getReadQueueNums(), topicConfig.getWriteQueueNums(), - this.brokerConfig.getBrokerPermission()); + new TopicConfig(topicConfig.getTopicName(), topicConfig.getReadQueueNums(), topicConfig.getWriteQueueNums(), + this.brokerConfig.getBrokerPermission()); topicConfigTable.put(topicConfig.getTopicName(), tmp); } topicConfigWrapper.setTopicConfigTable(topicConfigTable); } RegisterBrokerResult registerBrokerResult = this.brokerOuterAPI.registerBrokerAll( - this.brokerConfig.getBrokerClusterName(), - this.getBrokerAddr(), - this.brokerConfig.getBrokerName(), - this.brokerConfig.getBrokerId(), - this.getHAServerAddr(), - topicConfigWrapper, - this.filterServerManager.buildNewFilterServerList(), - oneway, - this.brokerConfig.getRegisterBrokerTimeoutMills()); + this.brokerConfig.getBrokerClusterName(), + this.getBrokerAddr(), + this.brokerConfig.getBrokerName(), + this.brokerConfig.getBrokerId(), + this.getHAServerAddr(), + topicConfigWrapper, + this.filterServerManager.buildNewFilterServerList(), + oneway, + this.brokerConfig.getRegisterBrokerTimeoutMills()); if (registerBrokerResult != null) { if (this.updateMasterHAServerAddrPeriodically && registerBrokerResult.getHaServerAddr() != null) { diff --git a/broker/src/main/java/org/apache/rocketmq/broker/BrokerPathConfigHelper.java b/broker/src/main/java/org/apache/rocketmq/broker/BrokerPathConfigHelper.java index dbcd304d..7a46df34 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/BrokerPathConfigHelper.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/BrokerPathConfigHelper.java @@ -6,45 +6,39 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.broker; import java.io.File; - public class BrokerPathConfigHelper { private static String brokerConfigPath = System.getProperty("user.home") + File.separator + "store" - + File.separator + "config" + File.separator + "broker.properties"; - + + File.separator + "config" + File.separator + "broker.properties"; public static String getBrokerConfigPath() { return brokerConfigPath; } - public static void setBrokerConfigPath(String path) { brokerConfigPath = path; } - public static String getTopicConfigPath(final String rootDir) { return rootDir + File.separator + "config" + File.separator + "topics.json"; } - public static String getConsumerOffsetPath(final String rootDir) { return rootDir + File.separator + "config" + File.separator + "consumerOffset.json"; } - public static String getSubscriptionGroupPath(final String rootDir) { return rootDir + File.separator + "config" + File.separator + "subscriptionGroup.json"; } diff --git a/broker/src/main/java/org/apache/rocketmq/broker/BrokerStartup.java b/broker/src/main/java/org/apache/rocketmq/broker/BrokerStartup.java index 86091c45..dfa97c1b 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/BrokerStartup.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/BrokerStartup.java @@ -18,6 +18,15 @@ package org.apache.rocketmq.broker; import ch.qos.logback.classic.LoggerContext; import ch.qos.logback.classic.joran.JoranConfigurator; +import java.io.BufferedInputStream; +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.Properties; +import java.util.concurrent.atomic.AtomicInteger; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.PosixParser; import org.apache.rocketmq.common.BrokerConfig; import org.apache.rocketmq.common.MQVersion; import org.apache.rocketmq.common.MixAll; @@ -30,20 +39,9 @@ import org.apache.rocketmq.remoting.protocol.RemotingCommand; import org.apache.rocketmq.srvutil.ServerUtil; import org.apache.rocketmq.store.config.BrokerRole; import org.apache.rocketmq.store.config.MessageStoreConfig; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.PosixParser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.BufferedInputStream; -import java.io.FileInputStream; -import java.io.InputStream; -import java.util.Properties; -import java.util.concurrent.atomic.AtomicInteger; - - public class BrokerStartup { public static Properties properties = null; public static CommandLine commandLine = null; @@ -58,7 +56,7 @@ public class BrokerStartup { try { controller.start(); String tip = "The broker[" + controller.getBrokerConfig().getBrokerName() + ", " - + controller.getBrokerAddr() + "] boot success. serializeType=" + RemotingCommand.getSerializeTypeConfigInThisServer(); + + controller.getBrokerAddr() + "] boot success. serializeType=" + RemotingCommand.getSerializeTypeConfigInThisServer(); if (null != controller.getBrokerConfig().getNamesrvAddr()) { tip += " and name server is " + controller.getBrokerConfig().getNamesrvAddr(); @@ -89,7 +87,7 @@ public class BrokerStartup { //PackageConflictDetect.detectFastjson(); Options options = ServerUtil.buildCommandlineOptions(new Options()); commandLine = ServerUtil.parseCmdLine("mqbroker", args, buildCommandlineOptions(options), - new PosixParser()); + new PosixParser()); if (null == commandLine) { System.exit(-1); } @@ -142,7 +140,7 @@ public class BrokerStartup { if (null == brokerConfig.getRocketmqHome()) { System.out.printf("Please set the " + MixAll.ROCKETMQ_HOME_ENV - + " variable in your environment to match the location of the RocketMQ installation"); + + " variable in your environment to match the location of the RocketMQ installation"); System.exit(-2); } @@ -157,13 +155,12 @@ public class BrokerStartup { } } catch (Exception e) { System.out.printf( - "The Name Server Address[%s] illegal, please set it as follows, \"127.0.0.1:9876;192.168.0.1:9876\"%n", - namesrvAddr); + "The Name Server Address[%s] illegal, please set it as follows, \"127.0.0.1:9876;192.168.0.1:9876\"%n", + namesrvAddr); System.exit(-3); } } - switch (messageStoreConfig.getBrokerRole()) { case ASYNC_MASTER: case SYNC_MASTER: @@ -181,7 +178,7 @@ public class BrokerStartup { } messageStoreConfig.setHaListenPort(nettyServerConfig.getListenPort() + 1); - LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); + LoggerContext lc = (LoggerContext)LoggerFactory.getILoggerFactory(); JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(lc); lc.reset(); @@ -194,10 +191,10 @@ public class BrokerStartup { MixAll.printObjectProperties(log, messageStoreConfig); final BrokerController controller = new BrokerController(// - brokerConfig, // - nettyServerConfig, // - nettyClientConfig, // - messageStoreConfig); + brokerConfig, // + nettyServerConfig, // + nettyClientConfig, // + messageStoreConfig); // remember all configs to prevent discard controller.getConfiguration().registerConfig(properties); diff --git a/broker/src/main/java/org/apache/rocketmq/broker/client/ClientChannelInfo.java b/broker/src/main/java/org/apache/rocketmq/broker/client/ClientChannelInfo.java index a9945032..24cddb90 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/client/ClientChannelInfo.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/client/ClientChannelInfo.java @@ -6,19 +6,18 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.broker.client; -import org.apache.rocketmq.remoting.protocol.LanguageCode; import io.netty.channel.Channel; - +import org.apache.rocketmq.remoting.protocol.LanguageCode; public class ClientChannelInfo { private final Channel channel; @@ -27,12 +26,10 @@ public class ClientChannelInfo { private final int version; private volatile long lastUpdateTimestamp = System.currentTimeMillis(); - public ClientChannelInfo(Channel channel) { this(channel, null, null, 0); } - public ClientChannelInfo(Channel channel, String clientId, LanguageCode language, int version) { this.channel = channel; this.clientId = clientId; @@ -40,37 +37,30 @@ public class ClientChannelInfo { this.version = version; } - public Channel getChannel() { return channel; } - public String getClientId() { return clientId; } - public LanguageCode getLanguage() { return language; } - public int getVersion() { return version; } - public long getLastUpdateTimestamp() { return lastUpdateTimestamp; } - public void setLastUpdateTimestamp(long lastUpdateTimestamp) { this.lastUpdateTimestamp = lastUpdateTimestamp; } - @Override public int hashCode() { final int prime = 31; @@ -78,12 +68,11 @@ public class ClientChannelInfo { result = prime * result + ((channel == null) ? 0 : channel.hashCode()); result = prime * result + ((clientId == null) ? 0 : clientId.hashCode()); result = prime * result + ((language == null) ? 0 : language.hashCode()); - result = prime * result + (int) (lastUpdateTimestamp ^ (lastUpdateTimestamp >>> 32)); + result = prime * result + (int)(lastUpdateTimestamp ^ (lastUpdateTimestamp >>> 32)); result = prime * result + version; return result; } - @Override public boolean equals(Object obj) { if (this == obj) @@ -92,7 +81,7 @@ public class ClientChannelInfo { return false; if (getClass() != obj.getClass()) return false; - ClientChannelInfo other = (ClientChannelInfo) obj; + ClientChannelInfo other = (ClientChannelInfo)obj; if (channel == null) { if (other.channel != null) return false; @@ -103,10 +92,9 @@ public class ClientChannelInfo { return true; } - @Override public String toString() { return "ClientChannelInfo [channel=" + channel + ", clientId=" + clientId + ", language=" + language - + ", version=" + version + ", lastUpdateTimestamp=" + lastUpdateTimestamp + "]"; + + ", version=" + version + ", lastUpdateTimestamp=" + lastUpdateTimestamp + "]"; } } diff --git a/broker/src/main/java/org/apache/rocketmq/broker/client/ClientHousekeepingService.java b/broker/src/main/java/org/apache/rocketmq/broker/client/ClientHousekeepingService.java index 856ce72c..5d7c0ea5 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/client/ClientHousekeepingService.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/client/ClientHousekeepingService.java @@ -6,42 +6,38 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.broker.client; +import io.netty.channel.Channel; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; import org.apache.rocketmq.broker.BrokerController; import org.apache.rocketmq.common.ThreadFactoryImpl; import org.apache.rocketmq.common.constant.LoggerName; import org.apache.rocketmq.remoting.ChannelEventListener; -import io.netty.channel.Channel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; - - public class ClientHousekeepingService implements ChannelEventListener { private static final Logger log = LoggerFactory.getLogger(LoggerName.BROKER_LOGGER_NAME); private final BrokerController brokerController; private ScheduledExecutorService scheduledExecutorService = Executors - .newSingleThreadScheduledExecutor(new ThreadFactoryImpl("ClientHousekeepingScheduledThread")); - + .newSingleThreadScheduledExecutor(new ThreadFactoryImpl("ClientHousekeepingScheduledThread")); public ClientHousekeepingService(final BrokerController brokerController) { this.brokerController = brokerController; } - public void start() { this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() { @@ -71,7 +67,6 @@ public class ClientHousekeepingService implements ChannelEventListener { } - @Override public void onChannelClose(String remoteAddr, Channel channel) { this.brokerController.getProducerManager().doChannelCloseEvent(remoteAddr, channel); @@ -79,7 +74,6 @@ public class ClientHousekeepingService implements ChannelEventListener { this.brokerController.getFilterServerManager().doChannelCloseEvent(remoteAddr, channel); } - @Override public void onChannelException(String remoteAddr, Channel channel) { this.brokerController.getProducerManager().doChannelCloseEvent(remoteAddr, channel); @@ -87,7 +81,6 @@ public class ClientHousekeepingService implements ChannelEventListener { this.brokerController.getFilterServerManager().doChannelCloseEvent(remoteAddr, channel); } - @Override public void onChannelIdle(String remoteAddr, Channel channel) { this.brokerController.getProducerManager().doChannelCloseEvent(remoteAddr, channel); diff --git a/broker/src/main/java/org/apache/rocketmq/broker/client/ConsumerGroupInfo.java b/broker/src/main/java/org/apache/rocketmq/broker/client/ConsumerGroupInfo.java index d5b056ed..26564678 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/client/ConsumerGroupInfo.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/client/ConsumerGroupInfo.java @@ -16,45 +16,41 @@ */ package org.apache.rocketmq.broker.client; -import org.apache.rocketmq.common.constant.LoggerName; -import org.apache.rocketmq.common.consumer.ConsumeFromWhere; -import org.apache.rocketmq.common.protocol.heartbeat.ConsumeType; -import org.apache.rocketmq.common.protocol.heartbeat.MessageModel; -import org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData; import io.netty.channel.Channel; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; - +import org.apache.rocketmq.common.constant.LoggerName; +import org.apache.rocketmq.common.consumer.ConsumeFromWhere; +import org.apache.rocketmq.common.protocol.heartbeat.ConsumeType; +import org.apache.rocketmq.common.protocol.heartbeat.MessageModel; +import org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class ConsumerGroupInfo { private static final Logger log = LoggerFactory.getLogger(LoggerName.BROKER_LOGGER_NAME); private final String groupName; private final ConcurrentHashMap subscriptionTable = - new ConcurrentHashMap(); + new ConcurrentHashMap(); private final ConcurrentHashMap channelInfoTable = - new ConcurrentHashMap(16); + new ConcurrentHashMap(16); private volatile ConsumeType consumeType; private volatile MessageModel messageModel; private volatile ConsumeFromWhere consumeFromWhere; private volatile long lastUpdateTimestamp = System.currentTimeMillis(); - public ConsumerGroupInfo(String groupName, ConsumeType consumeType, MessageModel messageModel, - ConsumeFromWhere consumeFromWhere) { + ConsumeFromWhere consumeFromWhere) { this.groupName = groupName; this.consumeType = consumeType; this.messageModel = messageModel; this.consumeFromWhere = consumeFromWhere; } - public ClientChannelInfo findChannel(final String clientId) { Iterator> it = this.channelInfoTable.entrySet().iterator(); while (it.hasNext()) { @@ -67,17 +63,14 @@ public class ConsumerGroupInfo { return null; } - public ConcurrentHashMap getSubscriptionTable() { return subscriptionTable; } - public ConcurrentHashMap getChannelInfoTable() { return channelInfoTable; } - public List getAllChannel() { List result = new ArrayList(); @@ -86,7 +79,6 @@ public class ConsumerGroupInfo { return result; } - public List getAllClientId() { List result = new ArrayList(); @@ -101,7 +93,6 @@ public class ConsumerGroupInfo { return result; } - public void unregisterChannel(final ClientChannelInfo clientChannelInfo) { ClientChannelInfo old = this.channelInfoTable.remove(clientChannelInfo.getChannel()); if (old != null) { @@ -109,13 +100,12 @@ public class ConsumerGroupInfo { } } - public boolean doChannelCloseEvent(final String remoteAddr, final Channel channel) { final ClientChannelInfo info = this.channelInfoTable.remove(channel); if (info != null) { log.warn( - "NETTY EVENT: remove not active channel[{}] from ConsumerGroupInfo groupChannelTable, consumer group: {}", - info.toString(), groupName); + "NETTY EVENT: remove not active channel[{}] from ConsumerGroupInfo groupChannelTable, consumer group: {}", + info.toString(), groupName); return true; } @@ -123,7 +113,7 @@ public class ConsumerGroupInfo { } public boolean updateChannel(final ClientChannelInfo infoNew, ConsumeType consumeType, - MessageModel messageModel, ConsumeFromWhere consumeFromWhere) { + MessageModel messageModel, ConsumeFromWhere consumeFromWhere) { boolean updated = false; this.consumeType = consumeType; this.messageModel = messageModel; @@ -134,7 +124,7 @@ public class ConsumerGroupInfo { ClientChannelInfo prev = this.channelInfoTable.put(infoNew.getChannel(), infoNew); if (null == prev) { log.info("new consumer connected, group: {} {} {} channel: {}", this.groupName, consumeType, - messageModel, infoNew.toString()); + messageModel, infoNew.toString()); updated = true; } @@ -142,9 +132,9 @@ public class ConsumerGroupInfo { } else { if (!infoOld.getClientId().equals(infoNew.getClientId())) { log.error("[BUG] consumer channel exist in broker, but clientId not equal. GROUP: {} OLD: {} NEW: {} ", - this.groupName, - infoOld.toString(), - infoNew.toString()); + this.groupName, + infoOld.toString(), + infoNew.toString()); this.channelInfoTable.put(infoNew.getChannel(), infoNew); } } @@ -155,7 +145,6 @@ public class ConsumerGroupInfo { return updated; } - public boolean updateSubscription(final Set subList) { boolean updated = false; @@ -166,15 +155,15 @@ public class ConsumerGroupInfo { if (null == prev) { updated = true; log.info("subscription changed, add new topic, group: {} {}", - this.groupName, - sub.toString()); + this.groupName, + sub.toString()); } } else if (sub.getSubVersion() > old.getSubVersion()) { if (this.consumeType == ConsumeType.CONSUME_PASSIVELY) { log.info("subscription changed, group: {} OLD: {} NEW: {}", - this.groupName, - old.toString(), - sub.toString() + this.groupName, + old.toString(), + sub.toString() ); } @@ -182,7 +171,6 @@ public class ConsumerGroupInfo { } } - Iterator> it = this.subscriptionTable.entrySet().iterator(); while (it.hasNext()) { Entry next = it.next(); @@ -198,9 +186,9 @@ public class ConsumerGroupInfo { if (!exist) { log.warn("subscription changed, group: {} remove topic {} {}", - this.groupName, - oldTopic, - next.getValue().toString() + this.groupName, + oldTopic, + next.getValue().toString() ); it.remove(); @@ -213,57 +201,46 @@ public class ConsumerGroupInfo { return updated; } - public Set getSubscribeTopics() { return subscriptionTable.keySet(); } - public SubscriptionData findSubscriptionData(final String topic) { return this.subscriptionTable.get(topic); } - public ConsumeType getConsumeType() { return consumeType; } - public void setConsumeType(ConsumeType consumeType) { this.consumeType = consumeType; } - public MessageModel getMessageModel() { return messageModel; } - public void setMessageModel(MessageModel messageModel) { this.messageModel = messageModel; } - public String getGroupName() { return groupName; } - public long getLastUpdateTimestamp() { return lastUpdateTimestamp; } - public void setLastUpdateTimestamp(long lastUpdateTimestamp) { this.lastUpdateTimestamp = lastUpdateTimestamp; } - public ConsumeFromWhere getConsumeFromWhere() { return consumeFromWhere; } - public void setConsumeFromWhere(ConsumeFromWhere consumeFromWhere) { this.consumeFromWhere = consumeFromWhere; } diff --git a/broker/src/main/java/org/apache/rocketmq/broker/client/ConsumerIdsChangeListener.java b/broker/src/main/java/org/apache/rocketmq/broker/client/ConsumerIdsChangeListener.java index 368582a5..fbec010d 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/client/ConsumerIdsChangeListener.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/client/ConsumerIdsChangeListener.java @@ -6,21 +6,19 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.broker.client; import io.netty.channel.Channel; - import java.util.List; - public interface ConsumerIdsChangeListener { void consumerIdsChanged(final String group, final List channels); } diff --git a/broker/src/main/java/org/apache/rocketmq/broker/client/ConsumerManager.java b/broker/src/main/java/org/apache/rocketmq/broker/client/ConsumerManager.java index 95ed478c..fd4fb88b 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/client/ConsumerManager.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/client/ConsumerManager.java @@ -16,6 +16,12 @@ */ package org.apache.rocketmq.broker.client; +import io.netty.channel.Channel; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import org.apache.rocketmq.common.constant.LoggerName; import org.apache.rocketmq.common.consumer.ConsumeFromWhere; import org.apache.rocketmq.common.protocol.heartbeat.ConsumeType; @@ -23,22 +29,14 @@ import org.apache.rocketmq.common.protocol.heartbeat.MessageModel; import org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData; import org.apache.rocketmq.remoting.common.RemotingHelper; import org.apache.rocketmq.remoting.common.RemotingUtil; -import io.netty.channel.Channel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map.Entry; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - - public class ConsumerManager { private static final Logger log = LoggerFactory.getLogger(LoggerName.BROKER_LOGGER_NAME); private static final long CHANNEL_EXPIRED_TIMEOUT = 1000 * 120; private final ConcurrentHashMap consumerTable = - new ConcurrentHashMap(1024); + new ConcurrentHashMap(1024); private final ConsumerIdsChangeListener consumerIdsChangeListener; public ConsumerManager(final ConsumerIdsChangeListener consumerIdsChangeListener) { @@ -86,7 +84,7 @@ public class ConsumerManager { ConsumerGroupInfo remove = this.consumerTable.remove(next.getKey()); if (remove != null) { log.info("unregister consumer ok, no any connection, and remove consumer group, {}", - next.getKey()); + next.getKey()); } } @@ -96,8 +94,8 @@ public class ConsumerManager { } public boolean registerConsumer(final String group, final ClientChannelInfo clientChannelInfo, - ConsumeType consumeType, MessageModel messageModel, ConsumeFromWhere consumeFromWhere, - final Set subList, boolean isNotifyConsumerIdsChangedEnable) { + ConsumeType consumeType, MessageModel messageModel, ConsumeFromWhere consumeFromWhere, + final Set subList, boolean isNotifyConsumerIdsChangedEnable) { ConsumerGroupInfo consumerGroupInfo = this.consumerTable.get(group); if (null == consumerGroupInfo) { @@ -107,8 +105,8 @@ public class ConsumerManager { } boolean r1 = - consumerGroupInfo.updateChannel(clientChannelInfo, consumeType, messageModel, - consumeFromWhere); + consumerGroupInfo.updateChannel(clientChannelInfo, consumeType, messageModel, + consumeFromWhere); boolean r2 = consumerGroupInfo.updateSubscription(subList); if (r1 || r2) { @@ -143,7 +141,7 @@ public class ConsumerManager { String group = next.getKey(); ConsumerGroupInfo consumerGroupInfo = next.getValue(); ConcurrentHashMap channelInfoTable = - consumerGroupInfo.getChannelInfoTable(); + consumerGroupInfo.getChannelInfoTable(); Iterator> itChannel = channelInfoTable.entrySet().iterator(); while (itChannel.hasNext()) { @@ -152,8 +150,8 @@ public class ConsumerManager { long diff = System.currentTimeMillis() - clientChannelInfo.getLastUpdateTimestamp(); if (diff > CHANNEL_EXPIRED_TIMEOUT) { log.warn( - "SCAN: remove expired channel from ConsumerManager consumerTable. channel={}, consumerGroup={}", - RemotingHelper.parseChannelRemoteAddr(clientChannelInfo.getChannel()), group); + "SCAN: remove expired channel from ConsumerManager consumerTable. channel={}, consumerGroup={}", + RemotingHelper.parseChannelRemoteAddr(clientChannelInfo.getChannel()), group); RemotingUtil.closeChannel(clientChannelInfo.getChannel()); itChannel.remove(); } @@ -161,8 +159,8 @@ public class ConsumerManager { if (channelInfoTable.isEmpty()) { log.warn( - "SCAN: remove expired channel from ConsumerManager consumerTable, all clear, consumerGroup={}", - group); + "SCAN: remove expired channel from ConsumerManager consumerTable, all clear, consumerGroup={}", + group); it.remove(); } } @@ -174,7 +172,7 @@ public class ConsumerManager { while (it.hasNext()) { Entry entry = it.next(); ConcurrentHashMap subscriptionTable = - entry.getValue().getSubscriptionTable(); + entry.getValue().getSubscriptionTable(); if (subscriptionTable.containsKey(topic)) { groups.add(entry.getKey()); } diff --git a/broker/src/main/java/org/apache/rocketmq/broker/client/DefaultConsumerIdsChangeListener.java b/broker/src/main/java/org/apache/rocketmq/broker/client/DefaultConsumerIdsChangeListener.java index b60fcb39..93f73b81 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/client/DefaultConsumerIdsChangeListener.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/client/DefaultConsumerIdsChangeListener.java @@ -6,31 +6,27 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.broker.client; -import org.apache.rocketmq.broker.BrokerController; import io.netty.channel.Channel; - import java.util.List; - +import org.apache.rocketmq.broker.BrokerController; public class DefaultConsumerIdsChangeListener implements ConsumerIdsChangeListener { private final BrokerController brokerController; - public DefaultConsumerIdsChangeListener(BrokerController brokerController) { this.brokerController = brokerController; } - @Override public void consumerIdsChanged(String group, List channels) { if (channels != null && brokerController.getBrokerConfig().isNotifyConsumerIdsChangedEnable()) { diff --git a/broker/src/main/java/org/apache/rocketmq/broker/client/ProducerManager.java b/broker/src/main/java/org/apache/rocketmq/broker/client/ProducerManager.java index 0f9954bd..3047faf1 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/client/ProducerManager.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/client/ProducerManager.java @@ -6,23 +6,17 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.broker.client; -import org.apache.rocketmq.common.constant.LoggerName; -import org.apache.rocketmq.remoting.common.RemotingHelper; -import org.apache.rocketmq.remoting.common.RemotingUtil; import io.netty.channel.Channel; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -30,7 +24,11 @@ import java.util.Map.Entry; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; - +import org.apache.rocketmq.common.constant.LoggerName; +import org.apache.rocketmq.remoting.common.RemotingHelper; +import org.apache.rocketmq.remoting.common.RemotingUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class ProducerManager { private static final Logger log = LoggerFactory.getLogger(LoggerName.BROKER_LOGGER_NAME); @@ -38,16 +36,14 @@ public class ProducerManager { private static final long CHANNEL_EXPIRED_TIMEOUT = 1000 * 120; private final Lock groupChannelLock = new ReentrantLock(); private final HashMap> groupChannelTable = - new HashMap>(); - + new HashMap>(); public ProducerManager() { } - public HashMap> getGroupChannelTable() { HashMap> newGroupChannelTable = - new HashMap>(); + new HashMap>(); try { if (this.groupChannelLock.tryLock(LOCK_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) { try { @@ -62,13 +58,12 @@ public class ProducerManager { return newGroupChannelTable; } - public void scanNotActiveChannel() { try { if (this.groupChannelLock.tryLock(LOCK_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) { try { for (final Map.Entry> entry : this.groupChannelTable - .entrySet()) { + .entrySet()) { final String group = entry.getKey(); final HashMap chlMap = entry.getValue(); @@ -82,8 +77,8 @@ public class ProducerManager { if (diff > CHANNEL_EXPIRED_TIMEOUT) { it.remove(); log.warn( - "SCAN: remove expired channel[{}] from ProducerManager groupChannelTable, producer group name: {}", - RemotingHelper.parseChannelRemoteAddr(info.getChannel()), group); + "SCAN: remove expired channel[{}] from ProducerManager groupChannelTable, producer group name: {}", + RemotingHelper.parseChannelRemoteAddr(info.getChannel()), group); RemotingUtil.closeChannel(info.getChannel()); } } @@ -99,23 +94,22 @@ public class ProducerManager { } } - public void doChannelCloseEvent(final String remoteAddr, final Channel channel) { if (channel != null) { try { if (this.groupChannelLock.tryLock(LOCK_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) { try { for (final Map.Entry> entry : this.groupChannelTable - .entrySet()) { + .entrySet()) { final String group = entry.getKey(); final HashMap clientChannelInfoTable = - entry.getValue(); + entry.getValue(); final ClientChannelInfo clientChannelInfo = - clientChannelInfoTable.remove(channel); + clientChannelInfoTable.remove(channel); if (clientChannelInfo != null) { log.info( - "NETTY EVENT: remove channel[{}][{}] from ProducerManager groupChannelTable, producer group: {}", - clientChannelInfo.toString(), remoteAddr, group); + "NETTY EVENT: remove channel[{}][{}] from ProducerManager groupChannelTable, producer group: {}", + clientChannelInfo.toString(), remoteAddr, group); } } @@ -131,7 +125,6 @@ public class ProducerManager { } } - public void registerProducer(final String group, final ClientChannelInfo clientChannelInfo) { try { ClientChannelInfo clientChannelInfoFound = null; @@ -148,7 +141,7 @@ public class ProducerManager { if (null == clientChannelInfoFound) { channelTable.put(clientChannelInfo.getChannel(), clientChannelInfo); log.info("new producer connected, group: {} channel: {}", group, - clientChannelInfo.toString()); + clientChannelInfo.toString()); } } finally { this.groupChannelLock.unlock(); @@ -165,7 +158,6 @@ public class ProducerManager { } } - public void unregisterProducer(final String group, final ClientChannelInfo clientChannelInfo) { try { if (this.groupChannelLock.tryLock(LOCK_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) { @@ -175,7 +167,7 @@ public class ProducerManager { ClientChannelInfo old = channelTable.remove(clientChannelInfo.getChannel()); if (old != null) { log.info("unregister a producer[{}] from groupChannelTable {}", group, - clientChannelInfo.toString()); + clientChannelInfo.toString()); } if (channelTable.isEmpty()) { diff --git a/broker/src/main/java/org/apache/rocketmq/broker/client/net/Broker2Client.java b/broker/src/main/java/org/apache/rocketmq/broker/client/net/Broker2Client.java index 40eff81f..f6d7955e 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/client/net/Broker2Client.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/client/net/Broker2Client.java @@ -16,6 +16,16 @@ */ package org.apache.rocketmq.broker.client.net; +import io.netty.channel.Channel; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelFutureListener; +import io.netty.channel.FileRegion; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; import org.apache.rocketmq.broker.BrokerController; import org.apache.rocketmq.broker.client.ClientChannelInfo; import org.apache.rocketmq.broker.client.ConsumerGroupInfo; @@ -40,21 +50,9 @@ import org.apache.rocketmq.remoting.exception.RemotingSendRequestException; import org.apache.rocketmq.remoting.exception.RemotingTimeoutException; import org.apache.rocketmq.remoting.protocol.RemotingCommand; import org.apache.rocketmq.store.SelectMappedBufferResult; -import io.netty.channel.Channel; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelFutureListener; -import io.netty.channel.FileRegion; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.concurrent.ConcurrentHashMap; - - public class Broker2Client { private static final Logger log = LoggerFactory.getLogger(LoggerName.BROKER_LOGGER_NAME); private final BrokerController brokerController; @@ -64,17 +62,17 @@ public class Broker2Client { } public void checkProducerTransactionState( - final Channel channel, - final CheckTransactionStateRequestHeader requestHeader, - final SelectMappedBufferResult selectMappedBufferResult) { + final Channel channel, + final CheckTransactionStateRequestHeader requestHeader, + final SelectMappedBufferResult selectMappedBufferResult) { RemotingCommand request = - RemotingCommand.createRequestCommand(RequestCode.CHECK_TRANSACTION_STATE, requestHeader); + RemotingCommand.createRequestCommand(RequestCode.CHECK_TRANSACTION_STATE, requestHeader); request.markOnewayRPC(); try { FileRegion fileRegion = - new OneMessageTransfer(request.encodeHeader(selectMappedBufferResult.getSize()), - selectMappedBufferResult); + new OneMessageTransfer(request.encodeHeader(selectMappedBufferResult.getSize()), + selectMappedBufferResult); channel.writeAndFlush(fileRegion).addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { @@ -91,14 +89,14 @@ public class Broker2Client { } public RemotingCommand callClient(final Channel channel, - final RemotingCommand request + final RemotingCommand request ) throws RemotingSendRequestException, RemotingTimeoutException, InterruptedException { return this.brokerController.getRemotingServer().invokeSync(channel, request, 10000); } public void notifyConsumerIdsChanged( - final Channel channel, - final String consumerGroup) { + final Channel channel, + final String consumerGroup) { if (null == consumerGroup) { log.error("notifyConsumerIdsChanged consumerGroup is null"); return; @@ -107,7 +105,7 @@ public class Broker2Client { NotifyConsumerIdsChangedRequestHeader requestHeader = new NotifyConsumerIdsChangedRequestHeader(); requestHeader.setConsumerGroup(consumerGroup); RemotingCommand request = - RemotingCommand.createRequestCommand(RequestCode.NOTIFY_CONSUMER_IDS_CHANGED, requestHeader); + RemotingCommand.createRequestCommand(RequestCode.NOTIFY_CONSUMER_IDS_CHANGED, requestHeader); try { this.brokerController.getRemotingServer().invokeOneway(channel, request, 10); @@ -121,7 +119,7 @@ public class Broker2Client { } public RemotingCommand resetOffset(String topic, String group, long timeStamp, boolean isForce, - boolean isC) { + boolean isC) { final RemotingCommand response = RemotingCommand.createResponseCommand(null); TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(topic); @@ -141,7 +139,7 @@ public class Broker2Client { mq.setQueueId(i); long consumerOffset = - this.brokerController.getConsumerOffsetManager().queryOffset(group, topic, i); + this.brokerController.getConsumerOffsetManager().queryOffset(group, topic, i); if (-1 == consumerOffset) { response.setCode(ResponseCode.SYSTEM_ERROR); response.setRemark(String.format("THe consumer group <%s> not exist", group)); @@ -173,7 +171,7 @@ public class Broker2Client { requestHeader.setGroup(group); requestHeader.setTimestamp(timeStamp); RemotingCommand request = - RemotingCommand.createRequestCommand(RequestCode.RESET_CONSUMER_CLIENT_OFFSET, requestHeader); + RemotingCommand.createRequestCommand(RequestCode.RESET_CONSUMER_CLIENT_OFFSET, requestHeader); if (isC) { // c++ language ResetOffsetBodyForC body = new ResetOffsetBodyForC(); @@ -188,37 +186,37 @@ public class Broker2Client { } ConsumerGroupInfo consumerGroupInfo = - this.brokerController.getConsumerManager().getConsumerGroupInfo(group); + this.brokerController.getConsumerManager().getConsumerGroupInfo(group); if (consumerGroupInfo != null && !consumerGroupInfo.getAllChannel().isEmpty()) { ConcurrentHashMap channelInfoTable = - consumerGroupInfo.getChannelInfoTable(); + consumerGroupInfo.getChannelInfoTable(); for (Map.Entry entry : channelInfoTable.entrySet()) { int version = entry.getValue().getVersion(); if (version >= MQVersion.Version.V3_0_7_SNAPSHOT.ordinal()) { try { this.brokerController.getRemotingServer().invokeOneway(entry.getKey(), request, 5000); log.info("[reset-offset] reset offset success. topic={}, group={}, clientId={}", - topic, group, entry.getValue().getClientId()); + topic, group, entry.getValue().getClientId()); } catch (Exception e) { log.error("[reset-offset] reset offset exception. topic={}, group={}", - new Object[]{topic, group}, e); + new Object[] {topic, group}, e); } } else { response.setCode(ResponseCode.SYSTEM_ERROR); response.setRemark("the client does not support this feature. version=" - + MQVersion.getVersionDesc(version)); + + MQVersion.getVersionDesc(version)); log.warn("[reset-offset] the client does not support this feature. version={}", - RemotingHelper.parseChannelRemoteAddr(entry.getKey()), MQVersion.getVersionDesc(version)); + RemotingHelper.parseChannelRemoteAddr(entry.getKey()), MQVersion.getVersionDesc(version)); return response; } } } else { String errorInfo = - String.format("Consumer not online, so can not reset offset, Group: %s Topic: %s Timestamp: %d", - requestHeader.getGroup(), - requestHeader.getTopic(), - requestHeader.getTimestamp()); + String.format("Consumer not online, so can not reset offset, Group: %s Topic: %s Timestamp: %d", + requestHeader.getGroup(), + requestHeader.getTopic(), + requestHeader.getTimestamp()); log.error(errorInfo); response.setCode(ResponseCode.CONSUMER_NOT_ONLINE); response.setRemark(errorInfo); @@ -236,7 +234,7 @@ public class Broker2Client { for (Entry entry : table.entrySet()) { MessageQueue mq = entry.getKey(); MessageQueueForC tmp = - new MessageQueueForC(mq.getTopic(), mq.getBrokerName(), mq.getQueueId(), entry.getValue()); + new MessageQueueForC(mq.getTopic(), mq.getBrokerName(), mq.getQueueId(), entry.getValue()); list.add(tmp); } return list; @@ -249,13 +247,13 @@ public class Broker2Client { requestHeader.setTopic(topic); requestHeader.setGroup(group); RemotingCommand request = - RemotingCommand.createRequestCommand(RequestCode.GET_CONSUMER_STATUS_FROM_CLIENT, - requestHeader); + RemotingCommand.createRequestCommand(RequestCode.GET_CONSUMER_STATUS_FROM_CLIENT, + requestHeader); Map> consumerStatusTable = - new HashMap>(); + new HashMap>(); ConcurrentHashMap channelInfoTable = - this.brokerController.getConsumerManager().getConsumerGroupInfo(group).getChannelInfoTable(); + this.brokerController.getConsumerManager().getConsumerGroupInfo(group).getChannelInfoTable(); if (null == channelInfoTable || channelInfoTable.isEmpty()) { result.setCode(ResponseCode.SYSTEM_ERROR); result.setRemark(String.format("No Any Consumer online in the consumer group: [%s]", group)); @@ -268,26 +266,26 @@ public class Broker2Client { if (version < MQVersion.Version.V3_0_7_SNAPSHOT.ordinal()) { result.setCode(ResponseCode.SYSTEM_ERROR); result.setRemark("the client does not support this feature. version=" - + MQVersion.getVersionDesc(version)); + + MQVersion.getVersionDesc(version)); log.warn("[get-consumer-status] the client does not support this feature. version={}", - RemotingHelper.parseChannelRemoteAddr(entry.getKey()), MQVersion.getVersionDesc(version)); + RemotingHelper.parseChannelRemoteAddr(entry.getKey()), MQVersion.getVersionDesc(version)); return result; } else if (UtilAll.isBlank(originClientId) || originClientId.equals(clientId)) { try { RemotingCommand response = - this.brokerController.getRemotingServer().invokeSync(entry.getKey(), request, 5000); + this.brokerController.getRemotingServer().invokeSync(entry.getKey(), request, 5000); assert response != null; switch (response.getCode()) { case ResponseCode.SUCCESS: { if (response.getBody() != null) { GetConsumerStatusBody body = - GetConsumerStatusBody.decode(response.getBody(), - GetConsumerStatusBody.class); + GetConsumerStatusBody.decode(response.getBody(), + GetConsumerStatusBody.class); consumerStatusTable.put(clientId, body.getMessageQueueTable()); log.info( - "[get-consumer-status] get consumer status success. topic={}, group={}, channelRemoteAddr={}", - topic, group, clientId); + "[get-consumer-status] get consumer status success. topic={}, group={}, channelRemoteAddr={}", + topic, group, clientId); } } default: @@ -295,8 +293,8 @@ public class Broker2Client { } } catch (Exception e) { log.error( - "[get-consumer-status] get consumer status exception. topic={}, group={}, offset={}", - new Object[]{topic, group}, e); + "[get-consumer-status] get consumer status exception. topic={}, group={}, offset={}", + new Object[] {topic, group}, e); } if (!UtilAll.isBlank(originClientId) && originClientId.equals(clientId)) { diff --git a/broker/src/main/java/org/apache/rocketmq/broker/client/rebalance/RebalanceLockManager.java b/broker/src/main/java/org/apache/rocketmq/broker/client/rebalance/RebalanceLockManager.java index 82ca0144..88c044a0 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/client/rebalance/RebalanceLockManager.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/client/rebalance/RebalanceLockManager.java @@ -16,25 +16,23 @@ */ package org.apache.rocketmq.broker.client.rebalance; -import org.apache.rocketmq.common.constant.LoggerName; -import org.apache.rocketmq.common.message.MessageQueue; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.util.HashSet; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; - +import org.apache.rocketmq.common.constant.LoggerName; +import org.apache.rocketmq.common.message.MessageQueue; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class RebalanceLockManager { private static final Logger log = LoggerFactory.getLogger(LoggerName.REBALANCE_LOCK_LOGGER_NAME); private final static long REBALANCE_LOCK_MAX_LIVE_TIME = Long.parseLong(System.getProperty( - "rocketmq.broker.rebalance.lockMaxLiveTime", "60000")); + "rocketmq.broker.rebalance.lockMaxLiveTime", "60000")); private final Lock lock = new ReentrantLock(); private final ConcurrentHashMap> mqLockTable = - new ConcurrentHashMap>(1024); + new ConcurrentHashMap>(1024); public boolean tryLock(final String group, final MessageQueue mq, final String clientId) { @@ -54,9 +52,9 @@ public class RebalanceLockManager { lockEntry.setClientId(clientId); groupValue.put(mq, lockEntry); log.info("tryLock, message queue not locked, I got it. Group: {} NewClientId: {} {}", // - group, // - clientId, // - mq); + group, // + clientId, // + mq); } if (lockEntry.isLocked(clientId)) { @@ -66,26 +64,24 @@ public class RebalanceLockManager { String oldClientId = lockEntry.getClientId(); - if (lockEntry.isExpired()) { lockEntry.setClientId(clientId); lockEntry.setLastUpdateTimestamp(System.currentTimeMillis()); log.warn( - "tryLock, message queue lock expired, I got it. Group: {} OldClientId: {} NewClientId: {} {}", // - group, // - oldClientId, // - clientId, // - mq); - return true; - } - - - log.warn( - "tryLock, message queue locked by other client. Group: {} OtherClientId: {} NewClientId: {} {}", // + "tryLock, message queue lock expired, I got it. Group: {} OldClientId: {} NewClientId: {} {}", // group, // oldClientId, // clientId, // mq); + return true; + } + + log.warn( + "tryLock, message queue locked by other client. Group: {} OtherClientId: {} NewClientId: {} {}", // + group, // + oldClientId, // + clientId, // + mq); return false; } finally { this.lock.unlock(); @@ -118,11 +114,10 @@ public class RebalanceLockManager { } public Set tryLockBatch(final String group, final Set mqs, - final String clientId) { + final String clientId) { Set lockedMqs = new HashSet(mqs.size()); Set notLockedMqs = new HashSet(mqs.size()); - for (MessageQueue mq : mqs) { if (this.isLocked(group, mq, clientId)) { lockedMqs.add(mq); @@ -141,7 +136,6 @@ public class RebalanceLockManager { this.mqLockTable.put(group, groupValue); } - for (MessageQueue mq : notLockedMqs) { LockEntry lockEntry = groupValue.get(mq); if (null == lockEntry) { @@ -149,13 +143,12 @@ public class RebalanceLockManager { lockEntry.setClientId(clientId); groupValue.put(mq, lockEntry); log.info( - "tryLockBatch, message queue not locked, I got it. Group: {} NewClientId: {} {}", // - group, // - clientId, // - mq); + "tryLockBatch, message queue not locked, I got it. Group: {} NewClientId: {} {}", // + group, // + clientId, // + mq); } - if (lockEntry.isLocked(clientId)) { lockEntry.setLastUpdateTimestamp(System.currentTimeMillis()); lockedMqs.add(mq); @@ -164,27 +157,25 @@ public class RebalanceLockManager { String oldClientId = lockEntry.getClientId(); - if (lockEntry.isExpired()) { lockEntry.setClientId(clientId); lockEntry.setLastUpdateTimestamp(System.currentTimeMillis()); log.warn( - "tryLockBatch, message queue lock expired, I got it. Group: {} OldClientId: {} NewClientId: {} {}", // - group, // - oldClientId, // - clientId, // - mq); + "tryLockBatch, message queue lock expired, I got it. Group: {} OldClientId: {} NewClientId: {} {}", // + group, // + oldClientId, // + clientId, // + mq); lockedMqs.add(mq); continue; } - log.warn( - "tryLockBatch, message queue locked by other client. Group: {} OtherClientId: {} NewClientId: {} {}", // - group, // - oldClientId, // - clientId, // - mq); + "tryLockBatch, message queue locked by other client. Group: {} OtherClientId: {} NewClientId: {} {}", // + group, // + oldClientId, // + clientId, // + mq); } } finally { this.lock.unlock(); @@ -209,27 +200,27 @@ public class RebalanceLockManager { if (lockEntry.getClientId().equals(clientId)) { groupValue.remove(mq); log.info("unlockBatch, Group: {} {} {}", - group, - mq, - clientId); + group, + mq, + clientId); } else { log.warn("unlockBatch, but mq locked by other client: {}, Group: {} {} {}", - lockEntry.getClientId(), - group, - mq, - clientId); - } - } else { - log.warn("unlockBatch, but mq not locked, Group: {} {} {}", + lockEntry.getClientId(), group, mq, clientId); + } + } else { + log.warn("unlockBatch, but mq not locked, Group: {} {} {}", + group, + mq, + clientId); } } } else { log.warn("unlockBatch, group not exist, Group: {} {}", - group, - clientId); + group, + clientId); } } finally { this.lock.unlock(); @@ -243,22 +234,18 @@ public class RebalanceLockManager { private String clientId; private volatile long lastUpdateTimestamp = System.currentTimeMillis(); - public String getClientId() { return clientId; } - public void setClientId(String clientId) { this.clientId = clientId; } - public long getLastUpdateTimestamp() { return lastUpdateTimestamp; } - public void setLastUpdateTimestamp(long lastUpdateTimestamp) { this.lastUpdateTimestamp = lastUpdateTimestamp; } @@ -270,7 +257,7 @@ public class RebalanceLockManager { public boolean isExpired() { boolean expired = - (System.currentTimeMillis() - this.lastUpdateTimestamp) > REBALANCE_LOCK_MAX_LIVE_TIME; + (System.currentTimeMillis() - this.lastUpdateTimestamp) > REBALANCE_LOCK_MAX_LIVE_TIME; return expired; } diff --git a/broker/src/main/java/org/apache/rocketmq/broker/filtersrv/FilterServerManager.java b/broker/src/main/java/org/apache/rocketmq/broker/filtersrv/FilterServerManager.java index 5b86d990..c1b67ae4 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/filtersrv/FilterServerManager.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/filtersrv/FilterServerManager.java @@ -17,15 +17,7 @@ package org.apache.rocketmq.broker.filtersrv; -import org.apache.rocketmq.broker.BrokerController; -import org.apache.rocketmq.broker.BrokerStartup; -import org.apache.rocketmq.common.ThreadFactoryImpl; -import org.apache.rocketmq.common.constant.LoggerName; -import org.apache.rocketmq.remoting.common.RemotingUtil; import io.netty.channel.Channel; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -34,18 +26,24 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; - +import org.apache.rocketmq.broker.BrokerController; +import org.apache.rocketmq.broker.BrokerStartup; +import org.apache.rocketmq.common.ThreadFactoryImpl; +import org.apache.rocketmq.common.constant.LoggerName; +import org.apache.rocketmq.remoting.common.RemotingUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class FilterServerManager { public static final long FILTER_SERVER_MAX_IDLE_TIME_MILLS = 30000; private static final Logger log = LoggerFactory.getLogger(LoggerName.BROKER_LOGGER_NAME); private final ConcurrentHashMap filterServerTable = - new ConcurrentHashMap(16); + new ConcurrentHashMap(16); private final BrokerController brokerController; private ScheduledExecutorService scheduledExecutorService = Executors - .newSingleThreadScheduledExecutor(new ThreadFactoryImpl("FilterServerManagerScheduledThread")); + .newSingleThreadScheduledExecutor(new ThreadFactoryImpl("FilterServerManagerScheduledThread")); public FilterServerManager(final BrokerController brokerController) { this.brokerController = brokerController; @@ -67,7 +65,7 @@ public class FilterServerManager { public void createFilterServer() { int more = - this.brokerController.getBrokerConfig().getFilterServerNums() - this.filterServerTable.size(); + this.brokerController.getBrokerConfig().getFilterServerNums() - this.filterServerTable.size(); String cmd = this.buildStartCommand(); for (int i = 0; i < more; i++) { FilterServerUtil.callShell(cmd, log); @@ -86,12 +84,12 @@ public class FilterServerManager { if (RemotingUtil.isWindowsPlatform()) { return String.format("start /b %s\\bin\\mqfiltersrv.exe %s", - this.brokerController.getBrokerConfig().getRocketmqHome(), - config); + this.brokerController.getBrokerConfig().getRocketmqHome(), + config); } else { return String.format("sh %s/bin/startfsrv.sh %s", - this.brokerController.getBrokerConfig().getRocketmqHome(), - config); + this.brokerController.getBrokerConfig().getRocketmqHome(), + config); } } @@ -134,7 +132,7 @@ public class FilterServerManager { FilterServerInfo old = this.filterServerTable.remove(channel); if (old != null) { log.warn("The Filter Server<{}> connection<{}> closed, remove it", old.getFilterServerAddr(), - remoteAddr); + remoteAddr); } } @@ -152,22 +150,18 @@ public class FilterServerManager { private String filterServerAddr; private long lastUpdateTimestamp; - public String getFilterServerAddr() { return filterServerAddr; } - public void setFilterServerAddr(String filterServerAddr) { this.filterServerAddr = filterServerAddr; } - public long getLastUpdateTimestamp() { return lastUpdateTimestamp; } - public void setLastUpdateTimestamp(long lastUpdateTimestamp) { this.lastUpdateTimestamp = lastUpdateTimestamp; } diff --git a/broker/src/main/java/org/apache/rocketmq/broker/filtersrv/FilterServerUtil.java b/broker/src/main/java/org/apache/rocketmq/broker/filtersrv/FilterServerUtil.java index de4cc374..9edfbe4c 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/filtersrv/FilterServerUtil.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/filtersrv/FilterServerUtil.java @@ -6,20 +6,19 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.broker.filtersrv; import org.slf4j.Logger; - public class FilterServerUtil { public static void callShell(final String shellString, final Logger log) { Process process = null; diff --git a/broker/src/main/java/org/apache/rocketmq/broker/latency/BrokerFastFailure.java b/broker/src/main/java/org/apache/rocketmq/broker/latency/BrokerFastFailure.java index 5359368a..f616e338 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/latency/BrokerFastFailure.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/latency/BrokerFastFailure.java @@ -6,16 +6,19 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.broker.latency; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; import org.apache.rocketmq.broker.BrokerController; import org.apache.rocketmq.common.ThreadFactoryImpl; import org.apache.rocketmq.common.constant.LoggerName; @@ -24,21 +27,27 @@ import org.apache.rocketmq.remoting.protocol.RemotingSysResponseCode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; - - public class BrokerFastFailure { private static final Logger log = LoggerFactory.getLogger(LoggerName.BROKER_LOGGER_NAME); private final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryImpl( - "BrokerFastFailureScheduledThread")); + "BrokerFastFailureScheduledThread")); private final BrokerController brokerController; public BrokerFastFailure(final BrokerController brokerController) { this.brokerController = brokerController; } + public static RequestTask castRunnable(final Runnable runnable) { + try { + FutureTaskExt object = (FutureTaskExt)runnable; + return (RequestTask)object.getRunnable(); + } catch (Throwable e) { + log.error(String.format("castRunnable exception, %s", runnable.getClass().getName()), e); + } + + return null; + } + public void start() { this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() { @Override @@ -95,17 +104,6 @@ public class BrokerFastFailure { } } - public static RequestTask castRunnable(final Runnable runnable) { - try { - FutureTaskExt object = (FutureTaskExt) runnable; - return (RequestTask) object.getRunnable(); - } catch (Throwable e) { - log.error(String.format("castRunnable exception, %s", runnable.getClass().getName()), e); - } - - return null; - } - public void shutdown() { this.scheduledExecutorService.shutdown(); } diff --git a/broker/src/main/java/org/apache/rocketmq/broker/latency/BrokerFixedThreadPoolExecutor.java b/broker/src/main/java/org/apache/rocketmq/broker/latency/BrokerFixedThreadPoolExecutor.java index 8c4c5e87..5a4ad2d6 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/latency/BrokerFixedThreadPoolExecutor.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/latency/BrokerFixedThreadPoolExecutor.java @@ -17,22 +17,31 @@ package org.apache.rocketmq.broker.latency; -import java.util.concurrent.*; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.RejectedExecutionHandler; +import java.util.concurrent.RunnableFuture; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; public class BrokerFixedThreadPoolExecutor extends ThreadPoolExecutor { - public BrokerFixedThreadPoolExecutor(final int corePoolSize, final int maximumPoolSize, final long keepAliveTime, final TimeUnit unit, final BlockingQueue workQueue) { + public BrokerFixedThreadPoolExecutor(final int corePoolSize, final int maximumPoolSize, final long keepAliveTime, final TimeUnit unit, + final BlockingQueue workQueue) { super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue); } - public BrokerFixedThreadPoolExecutor(final int corePoolSize, final int maximumPoolSize, final long keepAliveTime, final TimeUnit unit, final BlockingQueue workQueue, final ThreadFactory threadFactory) { + public BrokerFixedThreadPoolExecutor(final int corePoolSize, final int maximumPoolSize, final long keepAliveTime, final TimeUnit unit, + final BlockingQueue workQueue, final ThreadFactory threadFactory) { super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory); } - public BrokerFixedThreadPoolExecutor(final int corePoolSize, final int maximumPoolSize, final long keepAliveTime, final TimeUnit unit, final BlockingQueue workQueue, final RejectedExecutionHandler handler) { + public BrokerFixedThreadPoolExecutor(final int corePoolSize, final int maximumPoolSize, final long keepAliveTime, final TimeUnit unit, + final BlockingQueue workQueue, final RejectedExecutionHandler handler) { super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, handler); } - public BrokerFixedThreadPoolExecutor(final int corePoolSize, final int maximumPoolSize, final long keepAliveTime, final TimeUnit unit, final BlockingQueue workQueue, final ThreadFactory threadFactory, final RejectedExecutionHandler handler) { + public BrokerFixedThreadPoolExecutor(final int corePoolSize, final int maximumPoolSize, final long keepAliveTime, final TimeUnit unit, + final BlockingQueue workQueue, final ThreadFactory threadFactory, final RejectedExecutionHandler handler) { super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, handler); } diff --git a/broker/src/main/java/org/apache/rocketmq/broker/longpolling/ManyPullRequest.java b/broker/src/main/java/org/apache/rocketmq/broker/longpolling/ManyPullRequest.java index e261b408..0ee02ad6 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/longpolling/ManyPullRequest.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/longpolling/ManyPullRequest.java @@ -6,37 +6,33 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.broker.longpolling; import java.util.ArrayList; import java.util.List; - public class ManyPullRequest { private final ArrayList pullRequestList = new ArrayList(); - public synchronized void addPullRequest(final PullRequest pullRequest) { this.pullRequestList.add(pullRequest); } - public synchronized void addPullRequest(final List many) { this.pullRequestList.addAll(many); } - public synchronized List cloneListAndClear() { if (!this.pullRequestList.isEmpty()) { - List result = (ArrayList) this.pullRequestList.clone(); + List result = (ArrayList)this.pullRequestList.clone(); this.pullRequestList.clear(); return result; } diff --git a/broker/src/main/java/org/apache/rocketmq/broker/longpolling/NotifyMessageArrivingListener.java b/broker/src/main/java/org/apache/rocketmq/broker/longpolling/NotifyMessageArrivingListener.java index f953c1ed..97e54f90 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/longpolling/NotifyMessageArrivingListener.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/longpolling/NotifyMessageArrivingListener.java @@ -6,29 +6,26 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.broker.longpolling; import org.apache.rocketmq.store.MessageArrivingListener; - public class NotifyMessageArrivingListener implements MessageArrivingListener { private final PullRequestHoldService pullRequestHoldService; - public NotifyMessageArrivingListener(final PullRequestHoldService pullRequestHoldService) { this.pullRequestHoldService = pullRequestHoldService; } - @Override public void arriving(String topic, int queueId, long logicOffset, long tagsCode) { this.pullRequestHoldService.notifyMessageArriving(topic, queueId, logicOffset, tagsCode); diff --git a/broker/src/main/java/org/apache/rocketmq/broker/longpolling/PullRequest.java b/broker/src/main/java/org/apache/rocketmq/broker/longpolling/PullRequest.java index 40716f89..1cceec87 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/longpolling/PullRequest.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/longpolling/PullRequest.java @@ -6,20 +6,19 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.broker.longpolling; +import io.netty.channel.Channel; import org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData; import org.apache.rocketmq.remoting.protocol.RemotingCommand; -import io.netty.channel.Channel; - public class PullRequest { private final RemotingCommand requestCommand; @@ -29,9 +28,8 @@ public class PullRequest { private final long pullFromThisOffset; private final SubscriptionData subscriptionData; - public PullRequest(RemotingCommand requestCommand, Channel clientChannel, long timeoutMillis, long suspendTimestamp, - long pullFromThisOffset, SubscriptionData subscriptionData) { + long pullFromThisOffset, SubscriptionData subscriptionData) { this.requestCommand = requestCommand; this.clientChannel = clientChannel; this.timeoutMillis = timeoutMillis; @@ -40,27 +38,22 @@ public class PullRequest { this.subscriptionData = subscriptionData; } - public RemotingCommand getRequestCommand() { return requestCommand; } - public Channel getClientChannel() { return clientChannel; } - public long getTimeoutMillis() { return timeoutMillis; } - public long getSuspendTimestamp() { return suspendTimestamp; } - public long getPullFromThisOffset() { return pullFromThisOffset; } diff --git a/broker/src/main/java/org/apache/rocketmq/broker/longpolling/PullRequestHoldService.java b/broker/src/main/java/org/apache/rocketmq/broker/longpolling/PullRequestHoldService.java index 51826645..0e5be9bb 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/longpolling/PullRequestHoldService.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/longpolling/PullRequestHoldService.java @@ -16,6 +16,9 @@ */ package org.apache.rocketmq.broker.longpolling; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; import org.apache.rocketmq.broker.BrokerController; import org.apache.rocketmq.common.ServiceThread; import org.apache.rocketmq.common.SystemClock; @@ -25,11 +28,6 @@ import org.apache.rocketmq.store.MessageFilter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.ConcurrentHashMap; - - public class PullRequestHoldService extends ServiceThread { private static final Logger log = LoggerFactory.getLogger(LoggerName.BROKER_LOGGER_NAME); private static final String TOPIC_QUEUEID_SEPARATOR = "@"; @@ -37,8 +35,7 @@ public class PullRequestHoldService extends ServiceThread { private final SystemClock systemClock = new SystemClock(); private final MessageFilter messageFilter = new DefaultMessageFilter(); private ConcurrentHashMap pullRequestTable = - new ConcurrentHashMap(1024); - + new ConcurrentHashMap(1024); public PullRequestHoldService(final BrokerController brokerController) { this.brokerController = brokerController; @@ -135,7 +132,7 @@ public class PullRequestHoldService extends ServiceThread { if (this.messageFilter.isMessageMatched(request.getSubscriptionData(), tmp)) { try { this.brokerController.getPullMessageProcessor().excuteRequestWhenWakeup(request.getClientChannel(), - request.getRequestCommand()); + request.getRequestCommand()); } catch (Throwable e) { log.error("execute request when wakeup failed.", e); } @@ -146,14 +143,13 @@ public class PullRequestHoldService extends ServiceThread { if (System.currentTimeMillis() >= (request.getSuspendTimestamp() + request.getTimeoutMillis())) { try { this.brokerController.getPullMessageProcessor().excuteRequestWhenWakeup(request.getClientChannel(), - request.getRequestCommand()); + request.getRequestCommand()); } catch (Throwable e) { log.error("execute request when wakeup failed.", e); } continue; } - replayList.add(request); } diff --git a/broker/src/main/java/org/apache/rocketmq/broker/mqtrace/ConsumeMessageContext.java b/broker/src/main/java/org/apache/rocketmq/broker/mqtrace/ConsumeMessageContext.java index 3a167fa7..cc2f218d 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/mqtrace/ConsumeMessageContext.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/mqtrace/ConsumeMessageContext.java @@ -6,20 +6,18 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.broker.mqtrace; -import org.apache.rocketmq.store.stats.BrokerStatsManager; - import java.util.Map; - +import org.apache.rocketmq.store.stats.BrokerStatsManager; public class ConsumeMessageContext { private String consumerGroup; @@ -38,102 +36,82 @@ public class ConsumeMessageContext { private int commercialRcvTimes; private int commercialRcvSize; - public String getConsumerGroup() { return consumerGroup; } - public void setConsumerGroup(String consumerGroup) { this.consumerGroup = consumerGroup; } - public String getTopic() { return topic; } - public void setTopic(String topic) { this.topic = topic; } - public Integer getQueueId() { return queueId; } - public void setQueueId(Integer queueId) { this.queueId = queueId; } - public String getClientHost() { return clientHost; } - public void setClientHost(String clientHost) { this.clientHost = clientHost; } - public String getStoreHost() { return storeHost; } - public void setStoreHost(String storeHost) { this.storeHost = storeHost; } - public Map getMessageIds() { return messageIds; } - public void setMessageIds(Map messageIds) { this.messageIds = messageIds; } - public boolean isSuccess() { return success; } - public void setSuccess(boolean success) { this.success = success; } - public String getStatus() { return status; } - public void setStatus(String status) { this.status = status; } - public Object getMqTraceContext() { return mqTraceContext; } - public void setMqTraceContext(Object mqTraceContext) { this.mqTraceContext = mqTraceContext; } - public int getBodyLength() { return bodyLength; } - public void setBodyLength(int bodyLength) { this.bodyLength = bodyLength; } diff --git a/broker/src/main/java/org/apache/rocketmq/broker/mqtrace/ConsumeMessageHook.java b/broker/src/main/java/org/apache/rocketmq/broker/mqtrace/ConsumeMessageHook.java index c4b7f368..7e724a0d 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/mqtrace/ConsumeMessageHook.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/mqtrace/ConsumeMessageHook.java @@ -6,22 +6,20 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.broker.mqtrace; public interface ConsumeMessageHook { String hookName(); - void consumeMessageBefore(final ConsumeMessageContext context); - void consumeMessageAfter(final ConsumeMessageContext context); } diff --git a/broker/src/main/java/org/apache/rocketmq/broker/mqtrace/SendMessageContext.java b/broker/src/main/java/org/apache/rocketmq/broker/mqtrace/SendMessageContext.java index ca8121d8..8ad79193 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/mqtrace/SendMessageContext.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/mqtrace/SendMessageContext.java @@ -6,22 +6,20 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.broker.mqtrace; +import java.util.Properties; import org.apache.rocketmq.common.message.MessageType; import org.apache.rocketmq.store.stats.BrokerStatsManager; -import java.util.Properties; - - public class SendMessageContext { private String producerGroup; private String topic; @@ -92,137 +90,110 @@ public class SendMessageContext { return producerGroup; } - public void setProducerGroup(String producerGroup) { this.producerGroup = producerGroup; } - public String getTopic() { return topic; } - public void setTopic(String topic) { this.topic = topic; } - public String getMsgId() { return msgId; } - public void setMsgId(String msgId) { this.msgId = msgId; } - public String getOriginMsgId() { return originMsgId; } - public void setOriginMsgId(String originMsgId) { this.originMsgId = originMsgId; } - public Integer getQueueId() { return queueId; } - public void setQueueId(Integer queueId) { this.queueId = queueId; } - public Long getQueueOffset() { return queueOffset; } - public void setQueueOffset(Long queueOffset) { this.queueOffset = queueOffset; } - public String getBrokerAddr() { return brokerAddr; } - public void setBrokerAddr(String brokerAddr) { this.brokerAddr = brokerAddr; } - public String getBornHost() { return bornHost; } - public void setBornHost(String bornHost) { this.bornHost = bornHost; } - public int getBodyLength() { return bodyLength; } - public void setBodyLength(int bodyLength) { this.bodyLength = bodyLength; } - public int getCode() { return code; } - public void setCode(int code) { this.code = code; } - public String getErrorMsg() { return errorMsg; } - public void setErrorMsg(String errorMsg) { this.errorMsg = errorMsg; } - public String getMsgProps() { return msgProps; } - public void setMsgProps(String msgProps) { this.msgProps = msgProps; } - public Object getMqTraceContext() { return mqTraceContext; } - public void setMqTraceContext(Object mqTraceContext) { this.mqTraceContext = mqTraceContext; } - public Properties getExtProps() { return extProps; } - public void setExtProps(Properties extProps) { this.extProps = extProps; } diff --git a/broker/src/main/java/org/apache/rocketmq/broker/mqtrace/SendMessageHook.java b/broker/src/main/java/org/apache/rocketmq/broker/mqtrace/SendMessageHook.java index 84cbdcbd..a84d8992 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/mqtrace/SendMessageHook.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/mqtrace/SendMessageHook.java @@ -6,22 +6,20 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.broker.mqtrace; public interface SendMessageHook { public String hookName(); - public void sendMessageBefore(final SendMessageContext context); - public void sendMessageAfter(final SendMessageContext context); } diff --git a/broker/src/main/java/org/apache/rocketmq/broker/offset/ConsumerOffsetManager.java b/broker/src/main/java/org/apache/rocketmq/broker/offset/ConsumerOffsetManager.java index 06ceb36d..9346067c 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/offset/ConsumerOffsetManager.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/offset/ConsumerOffsetManager.java @@ -6,16 +6,23 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.broker.offset; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import org.apache.rocketmq.broker.BrokerController; import org.apache.rocketmq.broker.BrokerPathConfigHelper; import org.apache.rocketmq.common.ConfigManager; @@ -25,30 +32,22 @@ import org.apache.rocketmq.remoting.protocol.RemotingSerializable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.*; -import java.util.Map.Entry; -import java.util.concurrent.ConcurrentHashMap; - - public class ConsumerOffsetManager extends ConfigManager { private static final Logger log = LoggerFactory.getLogger(LoggerName.BROKER_LOGGER_NAME); private static final String TOPIC_GROUP_SEPARATOR = "@"; private ConcurrentHashMap> offsetTable = - new ConcurrentHashMap>(512); + new ConcurrentHashMap>(512); private transient BrokerController brokerController; - public ConsumerOffsetManager() { } - public ConsumerOffsetManager(BrokerController brokerController) { this.brokerController = brokerController; } - public void scanUnsubscribedTopic() { Iterator>> it = this.offsetTable.entrySet().iterator(); while (it.hasNext()) { @@ -60,7 +59,7 @@ public class ConsumerOffsetManager extends ConfigManager { String group = arrays[1]; if (null == brokerController.getConsumerManager().findSubscriptionData(group, topic) - && this.offsetBehindMuchThanData(topic, next.getValue())) { + && this.offsetBehindMuchThanData(topic, next.getValue())) { it.remove(); log.warn("remove topic offset, {}", topicAtGroup); } @@ -68,7 +67,6 @@ public class ConsumerOffsetManager extends ConfigManager { } } - private boolean offsetBehindMuchThanData(final String topic, ConcurrentHashMap table) { Iterator> it = table.entrySet().iterator(); boolean result = !table.isEmpty(); @@ -83,7 +81,6 @@ public class ConsumerOffsetManager extends ConfigManager { return result; } - public Set whichTopicByConsumer(final String group) { Set topics = new HashSet(); @@ -102,7 +99,6 @@ public class ConsumerOffsetManager extends ConfigManager { return topics; } - public Set whichGroupByTopic(final String topic) { Set groups = new HashSet(); @@ -121,7 +117,6 @@ public class ConsumerOffsetManager extends ConfigManager { return groups; } - public void commitOffset(final String clientHost, final String group, final String topic, final int queueId, final long offset) { // topic@group String key = topic + TOPIC_GROUP_SEPARATOR + group; @@ -182,12 +177,10 @@ public class ConsumerOffsetManager extends ConfigManager { return offsetTable; } - public void setOffsetTable(ConcurrentHashMap> offsetTable) { this.offsetTable = offsetTable; } - public Map queryMinOffsetInAllGroup(final String topic, final String filterGroups) { Map queueMinOffset = new HashMap(); @@ -224,14 +217,12 @@ public class ConsumerOffsetManager extends ConfigManager { return queueMinOffset; } - public Map queryOffset(final String group, final String topic) { // topic@group String key = topic + TOPIC_GROUP_SEPARATOR + group; return this.offsetTable.get(key); } - public void cloneOffset(final String srcGroup, final String destGroup, final String topic) { ConcurrentHashMap offsets = this.offsetTable.get(topic + TOPIC_GROUP_SEPARATOR + srcGroup); if (offsets != null) { diff --git a/broker/src/main/java/org/apache/rocketmq/broker/out/BrokerOuterAPI.java b/broker/src/main/java/org/apache/rocketmq/broker/out/BrokerOuterAPI.java index 3d969c46..25b333a9 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/out/BrokerOuterAPI.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/out/BrokerOuterAPI.java @@ -16,6 +16,9 @@ */ package org.apache.rocketmq.broker.out; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.List; import org.apache.rocketmq.client.exception.MQBrokerException; import org.apache.rocketmq.common.MixAll; import org.apache.rocketmq.common.constant.LoggerName; @@ -23,24 +26,27 @@ import org.apache.rocketmq.common.namesrv.RegisterBrokerResult; import org.apache.rocketmq.common.namesrv.TopAddressing; import org.apache.rocketmq.common.protocol.RequestCode; import org.apache.rocketmq.common.protocol.ResponseCode; -import org.apache.rocketmq.common.protocol.body.*; +import org.apache.rocketmq.common.protocol.body.ConsumerOffsetSerializeWrapper; +import org.apache.rocketmq.common.protocol.body.KVTable; +import org.apache.rocketmq.common.protocol.body.RegisterBrokerBody; +import org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper; +import org.apache.rocketmq.common.protocol.body.TopicConfigSerializeWrapper; import org.apache.rocketmq.common.protocol.header.namesrv.RegisterBrokerRequestHeader; import org.apache.rocketmq.common.protocol.header.namesrv.RegisterBrokerResponseHeader; import org.apache.rocketmq.common.protocol.header.namesrv.UnRegisterBrokerRequestHeader; import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.remoting.RemotingClient; -import org.apache.rocketmq.remoting.exception.*; +import org.apache.rocketmq.remoting.exception.RemotingCommandException; +import org.apache.rocketmq.remoting.exception.RemotingConnectException; +import org.apache.rocketmq.remoting.exception.RemotingSendRequestException; +import org.apache.rocketmq.remoting.exception.RemotingTimeoutException; +import org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException; import org.apache.rocketmq.remoting.netty.NettyClientConfig; import org.apache.rocketmq.remoting.netty.NettyRemotingClient; import org.apache.rocketmq.remoting.protocol.RemotingCommand; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.List; - - public class BrokerOuterAPI { private static final Logger log = LoggerFactory.getLogger(LoggerName.BROKER_LOGGER_NAME); private final RemotingClient remotingClient; @@ -92,15 +98,15 @@ public class BrokerOuterAPI { } public RegisterBrokerResult registerBrokerAll( - final String clusterName, - final String brokerAddr, - final String brokerName, - final long brokerId, - final String haServerAddr, - final TopicConfigSerializeWrapper topicConfigWrapper, - final List filterServerList, - final boolean oneway, - final int timeoutMills) { + final String clusterName, + final String brokerAddr, + final String brokerName, + final long brokerId, + final String haServerAddr, + final TopicConfigSerializeWrapper topicConfigWrapper, + final List filterServerList, + final boolean oneway, + final int timeoutMills) { RegisterBrokerResult registerBrokerResult = null; List nameServerAddressList = this.remotingClient.getNameServerAddressList(); @@ -108,7 +114,7 @@ public class BrokerOuterAPI { for (String namesrvAddr : nameServerAddressList) { try { RegisterBrokerResult result = this.registerBroker(namesrvAddr, clusterName, brokerAddr, brokerName, brokerId, - haServerAddr, topicConfigWrapper, filterServerList, oneway, timeoutMills); + haServerAddr, topicConfigWrapper, filterServerList, oneway, timeoutMills); if (result != null) { registerBrokerResult = result; } @@ -124,18 +130,18 @@ public class BrokerOuterAPI { } private RegisterBrokerResult registerBroker( - final String namesrvAddr, - final String clusterName, - final String brokerAddr, - final String brokerName, - final long brokerId, - final String haServerAddr, - final TopicConfigSerializeWrapper topicConfigWrapper, - final List filterServerList, - final boolean oneway, - final int timeoutMills + final String namesrvAddr, + final String clusterName, + final String brokerAddr, + final String brokerName, + final long brokerId, + final String haServerAddr, + final TopicConfigSerializeWrapper topicConfigWrapper, + final List filterServerList, + final boolean oneway, + final int timeoutMills ) throws RemotingCommandException, MQBrokerException, RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, - InterruptedException { + InterruptedException { RegisterBrokerRequestHeader requestHeader = new RegisterBrokerRequestHeader(); requestHeader.setBrokerAddr(brokerAddr); requestHeader.setBrokerId(brokerId); @@ -163,7 +169,7 @@ public class BrokerOuterAPI { switch (response.getCode()) { case ResponseCode.SUCCESS: { RegisterBrokerResponseHeader responseHeader = - (RegisterBrokerResponseHeader) response.decodeCommandCustomHeader(RegisterBrokerResponseHeader.class); + (RegisterBrokerResponseHeader)response.decodeCommandCustomHeader(RegisterBrokerResponseHeader.class); RegisterBrokerResult result = new RegisterBrokerResult(); result.setMasterAddr(responseHeader.getMasterAddr()); result.setHaServerAddr(responseHeader.getHaServerAddr()); @@ -181,10 +187,10 @@ public class BrokerOuterAPI { } public void unregisterBrokerAll( - final String clusterName, - final String brokerAddr, - final String brokerName, - final long brokerId + final String clusterName, + final String brokerAddr, + final String brokerName, + final long brokerId ) { List nameServerAddressList = this.remotingClient.getNameServerAddressList(); if (nameServerAddressList != null) { @@ -200,11 +206,11 @@ public class BrokerOuterAPI { } public void unregisterBroker( - final String namesrvAddr, - final String clusterName, - final String brokerAddr, - final String brokerName, - final long brokerId + final String namesrvAddr, + final String clusterName, + final String brokerAddr, + final String brokerName, + final long brokerId ) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQBrokerException { UnRegisterBrokerRequestHeader requestHeader = new UnRegisterBrokerRequestHeader(); requestHeader.setBrokerAddr(brokerAddr); @@ -227,7 +233,7 @@ public class BrokerOuterAPI { } public TopicConfigSerializeWrapper getAllTopicConfig(final String addr) throws RemotingConnectException, RemotingSendRequestException, - RemotingTimeoutException, InterruptedException, MQBrokerException { + RemotingTimeoutException, InterruptedException, MQBrokerException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_TOPIC_CONFIG, null); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(true, addr), request, 3000); @@ -244,7 +250,7 @@ public class BrokerOuterAPI { } public ConsumerOffsetSerializeWrapper getAllConsumerOffset(final String addr) throws InterruptedException, RemotingTimeoutException, - RemotingSendRequestException, RemotingConnectException, MQBrokerException { + RemotingSendRequestException, RemotingConnectException, MQBrokerException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_CONSUMER_OFFSET, null); RemotingCommand response = this.remotingClient.invokeSync(addr, request, 3000); assert response != null; @@ -260,7 +266,7 @@ public class BrokerOuterAPI { } public String getAllDelayOffset(final String addr) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, - RemotingConnectException, MQBrokerException, UnsupportedEncodingException { + RemotingConnectException, MQBrokerException, UnsupportedEncodingException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_DELAY_OFFSET, null); RemotingCommand response = this.remotingClient.invokeSync(addr, request, 3000); assert response != null; @@ -276,7 +282,7 @@ public class BrokerOuterAPI { } public SubscriptionGroupWrapper getAllSubscriptionGroupConfig(final String addr) throws InterruptedException, RemotingTimeoutException, - RemotingSendRequestException, RemotingConnectException, MQBrokerException { + RemotingSendRequestException, RemotingConnectException, MQBrokerException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_SUBSCRIPTIONGROUP_CONFIG, null); RemotingCommand response = this.remotingClient.invokeSync(addr, request, 3000); assert response != null; diff --git a/broker/src/main/java/org/apache/rocketmq/broker/pagecache/ManyMessageTransfer.java b/broker/src/main/java/org/apache/rocketmq/broker/pagecache/ManyMessageTransfer.java index e4c30451..1b1d5bb5 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/pagecache/ManyMessageTransfer.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/pagecache/ManyMessageTransfer.java @@ -6,38 +6,34 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.broker.pagecache; -import org.apache.rocketmq.store.GetMessageResult; import io.netty.channel.FileRegion; import io.netty.util.AbstractReferenceCounted; - import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.WritableByteChannel; import java.util.List; - +import org.apache.rocketmq.store.GetMessageResult; public class ManyMessageTransfer extends AbstractReferenceCounted implements FileRegion { private final ByteBuffer byteBufferHeader; private final GetMessageResult getMessageResult; private long transfered; // the bytes which was transfered already - public ManyMessageTransfer(ByteBuffer byteBufferHeader, GetMessageResult getMessageResult) { this.byteBufferHeader = byteBufferHeader; this.getMessageResult = getMessageResult; } - @Override public long position() { int pos = byteBufferHeader.position(); diff --git a/broker/src/main/java/org/apache/rocketmq/broker/pagecache/OneMessageTransfer.java b/broker/src/main/java/org/apache/rocketmq/broker/pagecache/OneMessageTransfer.java index 3f00ecea..b4cf0da2 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/pagecache/OneMessageTransfer.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/pagecache/OneMessageTransfer.java @@ -6,37 +6,33 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.broker.pagecache; -import org.apache.rocketmq.store.SelectMappedBufferResult; import io.netty.channel.FileRegion; import io.netty.util.AbstractReferenceCounted; - import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.WritableByteChannel; - +import org.apache.rocketmq.store.SelectMappedBufferResult; public class OneMessageTransfer extends AbstractReferenceCounted implements FileRegion { private final ByteBuffer byteBufferHeader; private final SelectMappedBufferResult selectMappedBufferResult; private long transfered; // the bytes which was transfered already - public OneMessageTransfer(ByteBuffer byteBufferHeader, SelectMappedBufferResult selectMappedBufferResult) { this.byteBufferHeader = byteBufferHeader; this.selectMappedBufferResult = selectMappedBufferResult; } - @Override public long position() { return this.byteBufferHeader.position() + this.selectMappedBufferResult.getByteBuffer().position(); diff --git a/broker/src/main/java/org/apache/rocketmq/broker/pagecache/QueryMessageTransfer.java b/broker/src/main/java/org/apache/rocketmq/broker/pagecache/QueryMessageTransfer.java index 146770a4..2971b6c8 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/pagecache/QueryMessageTransfer.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/pagecache/QueryMessageTransfer.java @@ -6,38 +6,34 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.broker.pagecache; -import org.apache.rocketmq.store.QueryMessageResult; import io.netty.channel.FileRegion; import io.netty.util.AbstractReferenceCounted; - import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.WritableByteChannel; import java.util.List; - +import org.apache.rocketmq.store.QueryMessageResult; public class QueryMessageTransfer extends AbstractReferenceCounted implements FileRegion { private final ByteBuffer byteBufferHeader; private final QueryMessageResult queryMessageResult; private long transfered; // the bytes which was transfered already - public QueryMessageTransfer(ByteBuffer byteBufferHeader, QueryMessageResult queryMessageResult) { this.byteBufferHeader = byteBufferHeader; this.queryMessageResult = queryMessageResult; } - @Override public long position() { int pos = byteBufferHeader.position(); diff --git a/broker/src/main/java/org/apache/rocketmq/broker/plugin/AbstractPluginMessageStore.java b/broker/src/main/java/org/apache/rocketmq/broker/plugin/AbstractPluginMessageStore.java index 601e2f3b..bac941d4 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/plugin/AbstractPluginMessageStore.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/plugin/AbstractPluginMessageStore.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ /** @@ -20,12 +20,16 @@ */ package org.apache.rocketmq.broker.plugin; -import org.apache.rocketmq.common.message.MessageExt; -import org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData; -import org.apache.rocketmq.store.*; - import java.util.HashMap; import java.util.Set; +import org.apache.rocketmq.common.message.MessageExt; +import org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData; +import org.apache.rocketmq.store.GetMessageResult; +import org.apache.rocketmq.store.MessageExtBrokerInner; +import org.apache.rocketmq.store.MessageStore; +import org.apache.rocketmq.store.PutMessageResult; +import org.apache.rocketmq.store.QueryMessageResult; +import org.apache.rocketmq.store.SelectMappedBufferResult; public abstract class AbstractPluginMessageStore implements MessageStore { protected MessageStore next = null; @@ -83,7 +87,7 @@ public abstract class AbstractPluginMessageStore implements MessageStore { @Override public GetMessageResult getMessage(String group, String topic, int queueId, long offset, - int maxMsgNums, SubscriptionData subscriptionData) { + int maxMsgNums, SubscriptionData subscriptionData) { return next.getMessage(group, topic, queueId, offset, maxMsgNums, subscriptionData); } @@ -174,7 +178,7 @@ public abstract class AbstractPluginMessageStore implements MessageStore { @Override public QueryMessageResult queryMessage(String topic, String key, int maxNum, long begin, - long end) { + long end) { return next.queryMessage(topic, key, maxNum, begin, end); } diff --git a/broker/src/main/java/org/apache/rocketmq/broker/plugin/MessageStoreFactory.java b/broker/src/main/java/org/apache/rocketmq/broker/plugin/MessageStoreFactory.java index 42793ae5..294bf8c2 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/plugin/MessageStoreFactory.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/plugin/MessageStoreFactory.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ /** @@ -20,14 +20,13 @@ */ package org.apache.rocketmq.broker.plugin; -import org.apache.rocketmq.store.MessageStore; - import java.io.IOException; import java.lang.reflect.Constructor; +import org.apache.rocketmq.store.MessageStore; public final class MessageStoreFactory { public final static MessageStore build(MessageStorePluginContext context, MessageStore messageStore) - throws IOException { + throws IOException { String plugin = context.getBrokerConfig().getMessageStorePlugIn(); if (plugin != null && plugin.trim().length() != 0) { String[] pluginClasses = plugin.split(","); @@ -35,12 +34,12 @@ public final class MessageStoreFactory { String pluginClass = pluginClasses[i]; try { @SuppressWarnings("unchecked") - Class clazz = (Class) Class.forName(pluginClass); + Class clazz = (Class)Class.forName(pluginClass); Constructor construct = clazz.getConstructor(MessageStorePluginContext.class, MessageStore.class); messageStore = construct.newInstance(context, messageStore); } catch (Throwable e) { throw new RuntimeException(String.format( - "Initialize plugin's class %s not found!", pluginClass), e); + "Initialize plugin's class %s not found!", pluginClass), e); } } } diff --git a/broker/src/main/java/org/apache/rocketmq/broker/plugin/MessageStorePluginContext.java b/broker/src/main/java/org/apache/rocketmq/broker/plugin/MessageStorePluginContext.java index 32af4025..fcab1e67 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/plugin/MessageStorePluginContext.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/plugin/MessageStorePluginContext.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ /** @@ -32,8 +32,8 @@ public class MessageStorePluginContext { private BrokerConfig brokerConfig; public MessageStorePluginContext(MessageStoreConfig messageStoreConfig, - BrokerStatsManager brokerStatsManager, MessageArrivingListener messageArrivingListener, - BrokerConfig brokerConfig) { + BrokerStatsManager brokerStatsManager, MessageArrivingListener messageArrivingListener, + BrokerConfig brokerConfig) { super(); this.messageStoreConfig = messageStoreConfig; this.brokerStatsManager = brokerStatsManager; @@ -57,5 +57,4 @@ public class MessageStorePluginContext { return brokerConfig; } - } diff --git a/broker/src/main/java/org/apache/rocketmq/broker/processor/AbstractSendMessageProcessor.java b/broker/src/main/java/org/apache/rocketmq/broker/processor/AbstractSendMessageProcessor.java index f04e86ca..75e57667 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/processor/AbstractSendMessageProcessor.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/processor/AbstractSendMessageProcessor.java @@ -6,16 +6,22 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.broker.processor; +import io.netty.channel.ChannelHandlerContext; +import java.net.InetSocketAddress; +import java.net.SocketAddress; +import java.util.List; +import java.util.Map; +import java.util.Random; import org.apache.rocketmq.broker.BrokerController; import org.apache.rocketmq.broker.mqtrace.SendMessageContext; import org.apache.rocketmq.broker.mqtrace.SendMessageHook; @@ -42,17 +48,9 @@ import org.apache.rocketmq.remoting.exception.RemotingCommandException; import org.apache.rocketmq.remoting.netty.NettyRequestProcessor; import org.apache.rocketmq.remoting.protocol.RemotingCommand; import org.apache.rocketmq.store.MessageExtBrokerInner; -import io.netty.channel.ChannelHandlerContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.util.List; -import java.util.Map; -import java.util.Random; - - public abstract class AbstractSendMessageProcessor implements NettyRequestProcessor { protected static final Logger log = LoggerFactory.getLogger(LoggerName.BROKER_LOGGER_NAME); @@ -62,16 +60,15 @@ public abstract class AbstractSendMessageProcessor implements NettyRequestProces protected final SocketAddress storeHost; private List sendMessageHookList; - public AbstractSendMessageProcessor(final BrokerController brokerController) { this.brokerController = brokerController; this.storeHost = - new InetSocketAddress(brokerController.getBrokerConfig().getBrokerIP1(), brokerController - .getNettyServerConfig().getListenPort()); + new InetSocketAddress(brokerController.getBrokerConfig().getBrokerIP1(), brokerController + .getNettyServerConfig().getListenPort()); } protected SendMessageContext buildMsgContext(ChannelHandlerContext ctx, - SendMessageRequestHeader requestHeader) { + SendMessageRequestHeader requestHeader) { if (!this.hasSendMessageHook()) { return null; } @@ -91,7 +88,6 @@ public abstract class AbstractSendMessageProcessor implements NettyRequestProces properties.put(MessageConst.PROPERTY_TRACE_SWITCH, String.valueOf(this.brokerController.getBrokerConfig().isTraceOn())); requestHeader.setProperties(MessageDecoder.messageProperties2String(properties)); - if (uniqueKey == null) { uniqueKey = ""; } @@ -104,7 +100,7 @@ public abstract class AbstractSendMessageProcessor implements NettyRequestProces } protected MessageExtBrokerInner buildInnerMsg(final ChannelHandlerContext ctx, - final SendMessageRequestHeader requestHeader, final byte[] body, TopicConfig topicConfig) { + final SendMessageRequestHeader requestHeader, final byte[] body, TopicConfig topicConfig) { int queueIdInt = requestHeader.getQueueId(); if (queueIdInt < 0) { queueIdInt = Math.abs(this.random.nextInt() % 99999999) % topicConfig.getWriteQueueNums(); @@ -120,10 +116,10 @@ public abstract class AbstractSendMessageProcessor implements NettyRequestProces msgInner.setBody(body); msgInner.setFlag(requestHeader.getFlag()); MessageAccessor.setProperties(msgInner, - MessageDecoder.string2messageProperties(requestHeader.getProperties())); + MessageDecoder.string2messageProperties(requestHeader.getProperties())); msgInner.setPropertiesString(requestHeader.getProperties()); msgInner.setTagsCode(MessageExtBrokerInner.tagsString2tagsCode(topicConfig.getTopicFilterType(), - msgInner.getTags())); + msgInner.getTags())); msgInner.setQueueId(queueIdInt); msgInner.setSysFlag(sysFlag); @@ -131,7 +127,7 @@ public abstract class AbstractSendMessageProcessor implements NettyRequestProces msgInner.setBornHost(ctx.channel().remoteAddress()); msgInner.setStoreHost(this.getStoreHost()); msgInner.setReconsumeTimes(requestHeader.getReconsumeTimes() == null ? 0 : requestHeader - .getReconsumeTimes()); + .getReconsumeTimes()); return msgInner; } @@ -140,8 +136,8 @@ public abstract class AbstractSendMessageProcessor implements NettyRequestProces } protected RemotingCommand msgContentCheck(final ChannelHandlerContext ctx, - final SendMessageRequestHeader requestHeader, RemotingCommand request, - final RemotingCommand response) { + final SendMessageRequestHeader requestHeader, RemotingCommand request, + final RemotingCommand response) { if (requestHeader.getTopic().length() > Byte.MAX_VALUE) { log.warn("putMessage message topic length too long " + requestHeader.getTopic().length()); response.setCode(ResponseCode.MESSAGE_ILLEGAL); @@ -149,13 +145,13 @@ public abstract class AbstractSendMessageProcessor implements NettyRequestProces } if (requestHeader.getProperties() != null && requestHeader.getProperties().length() > Short.MAX_VALUE) { log.warn("putMessage message properties length too long " - + requestHeader.getProperties().length()); + + requestHeader.getProperties().length()); response.setCode(ResponseCode.MESSAGE_ILLEGAL); return response; } if (request.getBody().length > DBMsgConstants.MAX_BODY_SIZE) { log.warn(" topic {} msg body size {} from {}", requestHeader.getTopic(), - request.getBody().length, ChannelUtil.getRemoteIp(ctx.channel())); + request.getBody().length, ChannelUtil.getRemoteIp(ctx.channel())); response.setRemark("msg body must be less 64KB"); response.setCode(ResponseCode.MESSAGE_ILLEGAL); return response; @@ -164,12 +160,12 @@ public abstract class AbstractSendMessageProcessor implements NettyRequestProces } protected RemotingCommand msgCheck(final ChannelHandlerContext ctx, - final SendMessageRequestHeader requestHeader, final RemotingCommand response) { + final SendMessageRequestHeader requestHeader, final RemotingCommand response) { if (!PermName.isWriteable(this.brokerController.getBrokerConfig().getBrokerPermission()) - && this.brokerController.getTopicConfigManager().isOrderTopic(requestHeader.getTopic())) { + && this.brokerController.getTopicConfigManager().isOrderTopic(requestHeader.getTopic())) { response.setCode(ResponseCode.NO_PERMISSION); response.setRemark("the broker[" + this.brokerController.getBrokerConfig().getBrokerIP1() - + "] sending message is forbidden"); + + "] sending message is forbidden"); return response; } if (!this.brokerController.getTopicConfigManager().isTopicCanSendMessage(requestHeader.getTopic())) { @@ -181,7 +177,7 @@ public abstract class AbstractSendMessageProcessor implements NettyRequestProces } TopicConfig topicConfig = - this.brokerController.getTopicConfigManager().selectTopicConfig(requestHeader.getTopic()); + this.brokerController.getTopicConfigManager().selectTopicConfig(requestHeader.getTopic()); if (null == topicConfig) { int topicSysFlag = 0; if (requestHeader.isUnitMode()) { @@ -193,26 +189,26 @@ public abstract class AbstractSendMessageProcessor implements NettyRequestProces } log.warn("the topic " + requestHeader.getTopic() + " not exist, producer: " - + ctx.channel().remoteAddress()); + + ctx.channel().remoteAddress()); topicConfig = this.brokerController.getTopicConfigManager().createTopicInSendMessageMethod(// - requestHeader.getTopic(), // - requestHeader.getDefaultTopic(), // - RemotingHelper.parseChannelRemoteAddr(ctx.channel()), // - requestHeader.getDefaultTopicQueueNums(), topicSysFlag); + requestHeader.getTopic(), // + requestHeader.getDefaultTopic(), // + RemotingHelper.parseChannelRemoteAddr(ctx.channel()), // + requestHeader.getDefaultTopicQueueNums(), topicSysFlag); if (null == topicConfig) { if (requestHeader.getTopic().startsWith(MixAll.RETRY_GROUP_TOPIC_PREFIX)) { topicConfig = - this.brokerController.getTopicConfigManager().createTopicInSendMessageBackMethod( - requestHeader.getTopic(), 1, PermName.PERM_WRITE | PermName.PERM_READ, - topicSysFlag); + this.brokerController.getTopicConfigManager().createTopicInSendMessageBackMethod( + requestHeader.getTopic(), 1, PermName.PERM_WRITE | PermName.PERM_READ, + topicSysFlag); } } if (null == topicConfig) { response.setCode(ResponseCode.TOPIC_NOT_EXIST); response.setRemark("topic[" + requestHeader.getTopic() + "] not exist, apply first please!" - + FAQUrl.suggestTodo(FAQUrl.APPLY_TOPIC_URL)); + + FAQUrl.suggestTodo(FAQUrl.APPLY_TOPIC_URL)); return response; } } @@ -221,9 +217,9 @@ public abstract class AbstractSendMessageProcessor implements NettyRequestProces int idValid = Math.max(topicConfig.getWriteQueueNums(), topicConfig.getReadQueueNums()); if (queueIdInt >= idValid) { String errorInfo = String.format("request queueId[%d] is illagal, %s Producer: %s", - queueIdInt, - topicConfig.toString(), - RemotingHelper.parseChannelRemoteAddr(ctx.channel())); + queueIdInt, + topicConfig.toString(), + RemotingHelper.parseChannelRemoteAddr(ctx.channel())); log.warn(errorInfo); response.setCode(ResponseCode.SYSTEM_ERROR); @@ -239,7 +235,7 @@ public abstract class AbstractSendMessageProcessor implements NettyRequestProces } protected void doResponse(ChannelHandlerContext ctx, RemotingCommand request, - final RemotingCommand response) { + final RemotingCommand response) { if (!request.isOnewayRPC()) { try { ctx.writeAndFlush(response); @@ -252,7 +248,7 @@ public abstract class AbstractSendMessageProcessor implements NettyRequestProces } public void executeSendMessageHookBefore(final ChannelHandlerContext ctx, final RemotingCommand request, - SendMessageContext context) { + SendMessageContext context) { if (hasSendMessageHook()) { for (SendMessageHook hook : this.sendMessageHookList) { try { @@ -280,20 +276,20 @@ public abstract class AbstractSendMessageProcessor implements NettyRequestProces } protected SendMessageRequestHeader parseRequestHeader(RemotingCommand request) - throws RemotingCommandException { + throws RemotingCommandException { SendMessageRequestHeaderV2 requestHeaderV2 = null; SendMessageRequestHeader requestHeader = null; switch (request.getCode()) { case RequestCode.SEND_MESSAGE_V2: requestHeaderV2 = - (SendMessageRequestHeaderV2) request - .decodeCommandCustomHeader(SendMessageRequestHeaderV2.class); + (SendMessageRequestHeaderV2)request + .decodeCommandCustomHeader(SendMessageRequestHeaderV2.class); case RequestCode.SEND_MESSAGE: if (null == requestHeaderV2) { requestHeader = - (SendMessageRequestHeader) request - .decodeCommandCustomHeader(SendMessageRequestHeader.class); + (SendMessageRequestHeader)request + .decodeCommandCustomHeader(SendMessageRequestHeader.class); } else { requestHeader = SendMessageRequestHeaderV2.createSendMessageRequestHeaderV1(requestHeaderV2); } @@ -309,7 +305,7 @@ public abstract class AbstractSendMessageProcessor implements NettyRequestProces try { if (response != null) { final SendMessageResponseHeader responseHeader = - (SendMessageResponseHeader) response.readCustomHeader(); + (SendMessageResponseHeader)response.readCustomHeader(); context.setMsgId(responseHeader.getMsgId()); context.setQueueId(responseHeader.getQueueId()); context.setQueueOffset(responseHeader.getQueueOffset()); diff --git a/broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java b/broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java index d2d4bc71..722bec22 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java @@ -16,6 +16,19 @@ */ package org.apache.rocketmq.broker.processor; +import io.netty.channel.Channel; +import io.netty.channel.ChannelHandlerContext; +import java.io.UnsupportedEncodingException; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import org.apache.rocketmq.broker.BrokerController; import org.apache.rocketmq.broker.client.ClientChannelInfo; import org.apache.rocketmq.broker.client.ConsumerGroupInfo; @@ -33,8 +46,48 @@ import org.apache.rocketmq.common.message.MessageId; import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.common.protocol.RequestCode; import org.apache.rocketmq.common.protocol.ResponseCode; -import org.apache.rocketmq.common.protocol.body.*; -import org.apache.rocketmq.common.protocol.header.*; +import org.apache.rocketmq.common.protocol.body.BrokerStatsData; +import org.apache.rocketmq.common.protocol.body.BrokerStatsItem; +import org.apache.rocketmq.common.protocol.body.Connection; +import org.apache.rocketmq.common.protocol.body.ConsumeStatsList; +import org.apache.rocketmq.common.protocol.body.ConsumerConnection; +import org.apache.rocketmq.common.protocol.body.GroupList; +import org.apache.rocketmq.common.protocol.body.KVTable; +import org.apache.rocketmq.common.protocol.body.LockBatchRequestBody; +import org.apache.rocketmq.common.protocol.body.LockBatchResponseBody; +import org.apache.rocketmq.common.protocol.body.ProducerConnection; +import org.apache.rocketmq.common.protocol.body.QueryConsumeTimeSpanBody; +import org.apache.rocketmq.common.protocol.body.QueryCorrectionOffsetBody; +import org.apache.rocketmq.common.protocol.body.QueueTimeSpan; +import org.apache.rocketmq.common.protocol.body.TopicList; +import org.apache.rocketmq.common.protocol.body.UnlockBatchRequestBody; +import org.apache.rocketmq.common.protocol.header.CloneGroupOffsetRequestHeader; +import org.apache.rocketmq.common.protocol.header.ConsumeMessageDirectlyResultRequestHeader; +import org.apache.rocketmq.common.protocol.header.CreateTopicRequestHeader; +import org.apache.rocketmq.common.protocol.header.DeleteSubscriptionGroupRequestHeader; +import org.apache.rocketmq.common.protocol.header.DeleteTopicRequestHeader; +import org.apache.rocketmq.common.protocol.header.GetAllTopicConfigResponseHeader; +import org.apache.rocketmq.common.protocol.header.GetBrokerConfigResponseHeader; +import org.apache.rocketmq.common.protocol.header.GetConsumeStatsInBrokerHeader; +import org.apache.rocketmq.common.protocol.header.GetConsumeStatsRequestHeader; +import org.apache.rocketmq.common.protocol.header.GetConsumerConnectionListRequestHeader; +import org.apache.rocketmq.common.protocol.header.GetConsumerRunningInfoRequestHeader; +import org.apache.rocketmq.common.protocol.header.GetConsumerStatusRequestHeader; +import org.apache.rocketmq.common.protocol.header.GetEarliestMsgStoretimeRequestHeader; +import org.apache.rocketmq.common.protocol.header.GetEarliestMsgStoretimeResponseHeader; +import org.apache.rocketmq.common.protocol.header.GetMaxOffsetRequestHeader; +import org.apache.rocketmq.common.protocol.header.GetMaxOffsetResponseHeader; +import org.apache.rocketmq.common.protocol.header.GetMinOffsetRequestHeader; +import org.apache.rocketmq.common.protocol.header.GetMinOffsetResponseHeader; +import org.apache.rocketmq.common.protocol.header.GetProducerConnectionListRequestHeader; +import org.apache.rocketmq.common.protocol.header.GetTopicStatsInfoRequestHeader; +import org.apache.rocketmq.common.protocol.header.QueryConsumeTimeSpanRequestHeader; +import org.apache.rocketmq.common.protocol.header.QueryCorrectionOffsetHeader; +import org.apache.rocketmq.common.protocol.header.QueryTopicConsumeByWhoRequestHeader; +import org.apache.rocketmq.common.protocol.header.ResetOffsetRequestHeader; +import org.apache.rocketmq.common.protocol.header.SearchOffsetRequestHeader; +import org.apache.rocketmq.common.protocol.header.SearchOffsetResponseHeader; +import org.apache.rocketmq.common.protocol.header.ViewBrokerStatsDataRequestHeader; import org.apache.rocketmq.common.protocol.header.filtersrv.RegisterFilterServerRequestHeader; import org.apache.rocketmq.common.protocol.header.filtersrv.RegisterFilterServerResponseHeader; import org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData; @@ -50,17 +103,9 @@ import org.apache.rocketmq.remoting.protocol.RemotingCommand; import org.apache.rocketmq.remoting.protocol.RemotingSerializable; import org.apache.rocketmq.store.DefaultMessageStore; import org.apache.rocketmq.store.SelectMappedBufferResult; -import io.netty.channel.Channel; -import io.netty.channel.ChannelHandlerContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.UnsupportedEncodingException; -import java.net.UnknownHostException; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; - - public class AdminBrokerProcessor implements NettyRequestProcessor { private static final Logger log = LoggerFactory.getLogger(LoggerName.BROKER_LOGGER_NAME); private final BrokerController brokerController; @@ -157,10 +202,9 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { private RemotingCommand updateAndCreateTopic(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final CreateTopicRequestHeader requestHeader = - (CreateTopicRequestHeader) request.decodeCommandCustomHeader(CreateTopicRequestHeader.class); + (CreateTopicRequestHeader)request.decodeCommandCustomHeader(CreateTopicRequestHeader.class); log.info("updateAndCreateTopic called by {}", RemotingHelper.parseChannelRemoteAddr(ctx.channel())); - if (requestHeader.getTopic().equals(this.brokerController.getBrokerConfig().getBrokerClusterName())) { String errorMsg = "the topic[" + requestHeader.getTopic() + "] is conflict with system reserved words."; log.warn(errorMsg); @@ -193,13 +237,13 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { private RemotingCommand deleteTopic(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); DeleteTopicRequestHeader requestHeader = - (DeleteTopicRequestHeader) request.decodeCommandCustomHeader(DeleteTopicRequestHeader.class); + (DeleteTopicRequestHeader)request.decodeCommandCustomHeader(DeleteTopicRequestHeader.class); log.info("deleteTopic called by {}", RemotingHelper.parseChannelRemoteAddr(ctx.channel())); this.brokerController.getTopicConfigManager().deleteTopicConfig(requestHeader.getTopic()); this.brokerController.getMessageStore() - .cleanUnusedTopic(this.brokerController.getTopicConfigManager().getTopicConfigTable().keySet()); + .cleanUnusedTopic(this.brokerController.getTopicConfigManager().getTopicConfigTable().keySet()); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); @@ -274,7 +318,7 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { private RemotingCommand getBrokerConfig(ChannelHandlerContext ctx, RemotingCommand request) { final RemotingCommand response = RemotingCommand.createResponseCommand(GetBrokerConfigResponseHeader.class); - final GetBrokerConfigResponseHeader responseHeader = (GetBrokerConfigResponseHeader) response.readCustomHeader(); + final GetBrokerConfigResponseHeader responseHeader = (GetBrokerConfigResponseHeader)response.readCustomHeader(); String content = this.brokerController.getConfiguration().getAllConfigsFormatString(); if (content != null && content.length() > 0) { @@ -298,12 +342,12 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { private RemotingCommand searchOffsetByTimestamp(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(SearchOffsetResponseHeader.class); - final SearchOffsetResponseHeader responseHeader = (SearchOffsetResponseHeader) response.readCustomHeader(); + final SearchOffsetResponseHeader responseHeader = (SearchOffsetResponseHeader)response.readCustomHeader(); final SearchOffsetRequestHeader requestHeader = - (SearchOffsetRequestHeader) request.decodeCommandCustomHeader(SearchOffsetRequestHeader.class); + (SearchOffsetRequestHeader)request.decodeCommandCustomHeader(SearchOffsetRequestHeader.class); long offset = this.brokerController.getMessageStore().getOffsetInQueueByTime(requestHeader.getTopic(), requestHeader.getQueueId(), - requestHeader.getTimestamp()); + requestHeader.getTimestamp()); responseHeader.setOffset(offset); @@ -314,9 +358,9 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { private RemotingCommand getMaxOffset(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(GetMaxOffsetResponseHeader.class); - final GetMaxOffsetResponseHeader responseHeader = (GetMaxOffsetResponseHeader) response.readCustomHeader(); + final GetMaxOffsetResponseHeader responseHeader = (GetMaxOffsetResponseHeader)response.readCustomHeader(); final GetMaxOffsetRequestHeader requestHeader = - (GetMaxOffsetRequestHeader) request.decodeCommandCustomHeader(GetMaxOffsetRequestHeader.class); + (GetMaxOffsetRequestHeader)request.decodeCommandCustomHeader(GetMaxOffsetRequestHeader.class); long offset = this.brokerController.getMessageStore().getMaxOffsetInQuque(requestHeader.getTopic(), requestHeader.getQueueId()); @@ -329,9 +373,9 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { private RemotingCommand getMinOffset(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(GetMinOffsetResponseHeader.class); - final GetMinOffsetResponseHeader responseHeader = (GetMinOffsetResponseHeader) response.readCustomHeader(); + final GetMinOffsetResponseHeader responseHeader = (GetMinOffsetResponseHeader)response.readCustomHeader(); final GetMinOffsetRequestHeader requestHeader = - (GetMinOffsetRequestHeader) request.decodeCommandCustomHeader(GetMinOffsetRequestHeader.class); + (GetMinOffsetRequestHeader)request.decodeCommandCustomHeader(GetMinOffsetRequestHeader.class); long offset = this.brokerController.getMessageStore().getMinOffsetInQuque(requestHeader.getTopic(), requestHeader.getQueueId()); @@ -343,12 +387,12 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { private RemotingCommand getEarliestMsgStoretime(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(GetEarliestMsgStoretimeResponseHeader.class); - final GetEarliestMsgStoretimeResponseHeader responseHeader = (GetEarliestMsgStoretimeResponseHeader) response.readCustomHeader(); + final GetEarliestMsgStoretimeResponseHeader responseHeader = (GetEarliestMsgStoretimeResponseHeader)response.readCustomHeader(); final GetEarliestMsgStoretimeRequestHeader requestHeader = - (GetEarliestMsgStoretimeRequestHeader) request.decodeCommandCustomHeader(GetEarliestMsgStoretimeRequestHeader.class); + (GetEarliestMsgStoretimeRequestHeader)request.decodeCommandCustomHeader(GetEarliestMsgStoretimeRequestHeader.class); long timestamp = - this.brokerController.getMessageStore().getEarliestMessageTime(requestHeader.getTopic(), requestHeader.getQueueId()); + this.brokerController.getMessageStore().getEarliestMessageTime(requestHeader.getTopic(), requestHeader.getQueueId()); responseHeader.setTimestamp(timestamp); response.setCode(ResponseCode.SUCCESS); @@ -375,9 +419,9 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { LockBatchRequestBody requestBody = LockBatchRequestBody.decode(request.getBody(), LockBatchRequestBody.class); Set lockOKMQSet = this.brokerController.getRebalanceLockManager().tryLockBatch(// - requestBody.getConsumerGroup(), // - requestBody.getMqSet(), // - requestBody.getClientId()); + requestBody.getConsumerGroup(), // + requestBody.getMqSet(), // + requestBody.getClientId()); LockBatchResponseBody responseBody = new LockBatchResponseBody(); responseBody.setLockOKMQSet(lockOKMQSet); @@ -393,9 +437,9 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { UnlockBatchRequestBody requestBody = UnlockBatchRequestBody.decode(request.getBody(), UnlockBatchRequestBody.class); this.brokerController.getRebalanceLockManager().unlockBatch(// - requestBody.getConsumerGroup(), // - requestBody.getMqSet(), // - requestBody.getClientId()); + requestBody.getConsumerGroup(), // + requestBody.getMqSet(), // + requestBody.getClientId()); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); @@ -403,7 +447,7 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { } private RemotingCommand updateAndCreateSubscriptionGroup(ChannelHandlerContext ctx, RemotingCommand request) - throws RemotingCommandException { + throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); log.info("updateAndCreateSubscriptionGroup called by {}", RemotingHelper.parseChannelRemoteAddr(ctx.channel())); @@ -447,7 +491,7 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { private RemotingCommand deleteSubscriptionGroup(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); DeleteSubscriptionGroupRequestHeader requestHeader = - (DeleteSubscriptionGroupRequestHeader) request.decodeCommandCustomHeader(DeleteSubscriptionGroupRequestHeader.class); + (DeleteSubscriptionGroupRequestHeader)request.decodeCommandCustomHeader(DeleteSubscriptionGroupRequestHeader.class); log.info("deleteSubscriptionGroup called by {}", RemotingHelper.parseChannelRemoteAddr(ctx.channel())); @@ -461,7 +505,7 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { private RemotingCommand getTopicStatsInfo(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetTopicStatsInfoRequestHeader requestHeader = - (GetTopicStatsInfoRequestHeader) request.decodeCommandCustomHeader(GetTopicStatsInfoRequestHeader.class); + (GetTopicStatsInfoRequestHeader)request.decodeCommandCustomHeader(GetTopicStatsInfoRequestHeader.class); final String topic = requestHeader.getTopic(); TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(topic); @@ -509,10 +553,10 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { private RemotingCommand getConsumerConnectionList(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetConsumerConnectionListRequestHeader requestHeader = - (GetConsumerConnectionListRequestHeader) request.decodeCommandCustomHeader(GetConsumerConnectionListRequestHeader.class); + (GetConsumerConnectionListRequestHeader)request.decodeCommandCustomHeader(GetConsumerConnectionListRequestHeader.class); ConsumerGroupInfo consumerGroupInfo = - this.brokerController.getConsumerManager().getConsumerGroupInfo(requestHeader.getConsumerGroup()); + this.brokerController.getConsumerManager().getConsumerGroupInfo(requestHeader.getConsumerGroup()); if (consumerGroupInfo != null) { ConsumerConnection bodydata = new ConsumerConnection(); bodydata.setConsumeFromWhere(consumerGroupInfo.getConsumeFromWhere()); @@ -548,11 +592,11 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { private RemotingCommand getProducerConnectionList(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetProducerConnectionListRequestHeader requestHeader = - (GetProducerConnectionListRequestHeader) request.decodeCommandCustomHeader(GetProducerConnectionListRequestHeader.class); + (GetProducerConnectionListRequestHeader)request.decodeCommandCustomHeader(GetProducerConnectionListRequestHeader.class); ProducerConnection bodydata = new ProducerConnection(); HashMap channelInfoHashMap = - this.brokerController.getProducerManager().getGroupChannelTable().get(requestHeader.getProducerGroup()); + this.brokerController.getProducerManager().getGroupChannelTable().get(requestHeader.getProducerGroup()); if (channelInfoHashMap != null) { Iterator> it = channelInfoHashMap.entrySet().iterator(); while (it.hasNext()) { @@ -581,7 +625,7 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { private RemotingCommand getConsumeStats(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetConsumeStatsRequestHeader requestHeader = - (GetConsumeStatsRequestHeader) request.decodeCommandCustomHeader(GetConsumeStatsRequestHeader.class); + (GetConsumeStatsRequestHeader)request.decodeCommandCustomHeader(GetConsumeStatsRequestHeader.class); ConsumeStats consumeStats = new ConsumeStats(); @@ -604,10 +648,10 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { */ { SubscriptionData findSubscriptionData = - this.brokerController.getConsumerManager().findSubscriptionData(requestHeader.getConsumerGroup(), topic); + this.brokerController.getConsumerManager().findSubscriptionData(requestHeader.getConsumerGroup(), topic); if (null == findSubscriptionData // - && this.brokerController.getConsumerManager().findSubscriptionDataCount(requestHeader.getConsumerGroup()) > 0) { + && this.brokerController.getConsumerManager().findSubscriptionDataCount(requestHeader.getConsumerGroup()) > 0) { log.warn("consumeStats, the consumer group[{}], topic[{}] not exist", requestHeader.getConsumerGroup(), topic); continue; } @@ -626,16 +670,15 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { brokerOffset = 0; long consumerOffset = this.brokerController.getConsumerOffsetManager().queryOffset(// - requestHeader.getConsumerGroup(), // - topic, // - i); + requestHeader.getConsumerGroup(), // + topic, // + i); if (consumerOffset < 0) consumerOffset = 0; offsetWrapper.setBrokerOffset(brokerOffset); offsetWrapper.setConsumerOffset(consumerOffset); - long timeOffset = consumerOffset - 1; if (timeOffset >= 0) { long lastTimestamp = this.brokerController.getMessageStore().getMessageStoreTimeStamp(topic, i, timeOffset); @@ -690,7 +733,7 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { private RemotingCommand getAllDelayOffset(ChannelHandlerContext ctx, RemotingCommand request) { final RemotingCommand response = RemotingCommand.createResponseCommand(null); - String content = ((DefaultMessageStore) this.brokerController.getMessageStore()).getScheduleMessageService().encode(); + String content = ((DefaultMessageStore)this.brokerController.getMessageStore()).getScheduleMessageService().encode(); if (content != null && content.length() > 0) { try { response.setBody(content.getBytes(MixAll.DEFAULT_CHARSET)); @@ -716,10 +759,10 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { public RemotingCommand resetOffset(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final ResetOffsetRequestHeader requestHeader = - (ResetOffsetRequestHeader) request.decodeCommandCustomHeader(ResetOffsetRequestHeader.class); + (ResetOffsetRequestHeader)request.decodeCommandCustomHeader(ResetOffsetRequestHeader.class); log.info("[reset-offset] reset offset started by {}. topic={}, group={}, timestamp={}, isForce={}", - RemotingHelper.parseChannelRemoteAddr(ctx.channel()), requestHeader.getTopic(), requestHeader.getGroup(), - requestHeader.getTimestamp(), requestHeader.isForce()); + RemotingHelper.parseChannelRemoteAddr(ctx.channel()), requestHeader.getTopic(), requestHeader.getGroup(), + requestHeader.getTimestamp(), requestHeader.isForce()); boolean isC = false; LanguageCode language = request.getLanguage(); switch (language) { @@ -728,25 +771,24 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { break; } return this.brokerController.getBroker2Client().resetOffset(requestHeader.getTopic(), requestHeader.getGroup(), - requestHeader.getTimestamp(), requestHeader.isForce(), isC); + requestHeader.getTimestamp(), requestHeader.isForce(), isC); } public RemotingCommand getConsumerStatus(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final GetConsumerStatusRequestHeader requestHeader = - (GetConsumerStatusRequestHeader) request.decodeCommandCustomHeader(GetConsumerStatusRequestHeader.class); + (GetConsumerStatusRequestHeader)request.decodeCommandCustomHeader(GetConsumerStatusRequestHeader.class); log.info("[get-consumer-status] get consumer status by {}. topic={}, group={}", - RemotingHelper.parseChannelRemoteAddr(ctx.channel()), requestHeader.getTopic(), requestHeader.getGroup()); + RemotingHelper.parseChannelRemoteAddr(ctx.channel()), requestHeader.getTopic(), requestHeader.getGroup()); return this.brokerController.getBroker2Client().getConsumeStatus(requestHeader.getTopic(), requestHeader.getGroup(), - requestHeader.getClientAddr()); + requestHeader.getClientAddr()); } private RemotingCommand queryTopicConsumeByWho(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); QueryTopicConsumeByWhoRequestHeader requestHeader = - (QueryTopicConsumeByWhoRequestHeader) request.decodeCommandCustomHeader(QueryTopicConsumeByWhoRequestHeader.class); - + (QueryTopicConsumeByWhoRequestHeader)request.decodeCommandCustomHeader(QueryTopicConsumeByWhoRequestHeader.class); HashSet groups = this.brokerController.getConsumerManager().queryTopicConsumeByWho(requestHeader.getTopic()); @@ -767,9 +809,9 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { private RemotingCommand registerFilterServer(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(RegisterFilterServerResponseHeader.class); - final RegisterFilterServerResponseHeader responseHeader = (RegisterFilterServerResponseHeader) response.readCustomHeader(); + final RegisterFilterServerResponseHeader responseHeader = (RegisterFilterServerResponseHeader)response.readCustomHeader(); final RegisterFilterServerRequestHeader requestHeader = - (RegisterFilterServerRequestHeader) request.decodeCommandCustomHeader(RegisterFilterServerRequestHeader.class); + (RegisterFilterServerRequestHeader)request.decodeCommandCustomHeader(RegisterFilterServerRequestHeader.class); this.brokerController.getFilterServerManager().registerFilterServer(ctx.channel(), requestHeader.getFilterServerAddr()); @@ -784,7 +826,7 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { private RemotingCommand queryConsumeTimeSpan(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); QueryConsumeTimeSpanRequestHeader requestHeader = - (QueryConsumeTimeSpanRequestHeader) request.decodeCommandCustomHeader(QueryConsumeTimeSpanRequestHeader.class); + (QueryConsumeTimeSpanRequestHeader)request.decodeCommandCustomHeader(QueryConsumeTimeSpanRequestHeader.class); final String topic = requestHeader.getTopic(); TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(topic); @@ -812,7 +854,7 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { long consumeTime; long consumerOffset = this.brokerController.getConsumerOffsetManager().queryOffset( - requestHeader.getGroup(), topic, i); + requestHeader.getGroup(), topic, i); if (consumerOffset > 0) { consumeTime = this.brokerController.getMessageStore().getMessageStoreTimeStamp(topic, i, consumerOffset - 1); } else { @@ -837,7 +879,7 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { } private RemotingCommand getSystemTopicListFromBroker(ChannelHandlerContext ctx, RemotingCommand request) - throws RemotingCommandException { + throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); Set topics = this.brokerController.getTopicConfigManager().getSystemTopic(); @@ -874,28 +916,28 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { */ private RemotingCommand getConsumerRunningInfo(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final GetConsumerRunningInfoRequestHeader requestHeader = - (GetConsumerRunningInfoRequestHeader) request.decodeCommandCustomHeader(GetConsumerRunningInfoRequestHeader.class); + (GetConsumerRunningInfoRequestHeader)request.decodeCommandCustomHeader(GetConsumerRunningInfoRequestHeader.class); return this.callConsumer(RequestCode.GET_CONSUMER_RUNNING_INFO, request, requestHeader.getConsumerGroup(), - requestHeader.getClientId()); + requestHeader.getClientId()); } private RemotingCommand queryCorrectionOffset(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); QueryCorrectionOffsetHeader requestHeader = - (QueryCorrectionOffsetHeader) request.decodeCommandCustomHeader(QueryCorrectionOffsetHeader.class); + (QueryCorrectionOffsetHeader)request.decodeCommandCustomHeader(QueryCorrectionOffsetHeader.class); Map correctionOffset = this.brokerController.getConsumerOffsetManager() - .queryMinOffsetInAllGroup(requestHeader.getTopic(), requestHeader.getFilterGroups()); + .queryMinOffsetInAllGroup(requestHeader.getTopic(), requestHeader.getFilterGroups()); Map compareOffset = - this.brokerController.getConsumerOffsetManager().queryOffset(requestHeader.getTopic(), requestHeader.getCompareGroup()); + this.brokerController.getConsumerOffsetManager().queryOffset(requestHeader.getTopic(), requestHeader.getCompareGroup()); if (compareOffset != null && !compareOffset.isEmpty()) { for (Map.Entry entry : compareOffset.entrySet()) { Integer queueId = entry.getKey(); correctionOffset.put(queueId, - correctionOffset.get(queueId) > entry.getValue() ? Long.MAX_VALUE : correctionOffset.get(queueId)); + correctionOffset.get(queueId) > entry.getValue() ? Long.MAX_VALUE : correctionOffset.get(queueId)); } } @@ -908,8 +950,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { } private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { - final ConsumeMessageDirectlyResultRequestHeader requestHeader = (ConsumeMessageDirectlyResultRequestHeader) request - .decodeCommandCustomHeader(ConsumeMessageDirectlyResultRequestHeader.class); + final ConsumeMessageDirectlyResultRequestHeader requestHeader = (ConsumeMessageDirectlyResultRequestHeader)request + .decodeCommandCustomHeader(ConsumeMessageDirectlyResultRequestHeader.class); request.getExtFields().put("brokerName", this.brokerController.getBrokerConfig().getBrokerName()); SelectMappedBufferResult selectMappedBufferResult = null; @@ -928,13 +970,13 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { } return this.callConsumer(RequestCode.CONSUME_MESSAGE_DIRECTLY, request, requestHeader.getConsumerGroup(), - requestHeader.getClientId()); + requestHeader.getClientId()); } private RemotingCommand cloneGroupOffset(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); CloneGroupOffsetRequestHeader requestHeader = - (CloneGroupOffsetRequestHeader) request.decodeCommandCustomHeader(CloneGroupOffsetRequestHeader.class); + (CloneGroupOffsetRequestHeader)request.decodeCommandCustomHeader(CloneGroupOffsetRequestHeader.class); Set topics; if (UtilAll.isBlank(requestHeader.getTopic())) { @@ -957,16 +999,16 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { if (!requestHeader.isOffline()) { SubscriptionData findSubscriptionData = - this.brokerController.getConsumerManager().findSubscriptionData(requestHeader.getSrcGroup(), topic); + this.brokerController.getConsumerManager().findSubscriptionData(requestHeader.getSrcGroup(), topic); if (this.brokerController.getConsumerManager().findSubscriptionDataCount(requestHeader.getSrcGroup()) > 0 - && findSubscriptionData == null) { + && findSubscriptionData == null) { log.warn("[cloneGroupOffset], the consumer group[{}], topic[{}] not exist", requestHeader.getSrcGroup(), topic); continue; } } this.brokerController.getConsumerOffsetManager().cloneOffset(requestHeader.getSrcGroup(), requestHeader.getDestGroup(), - requestHeader.getTopic()); + requestHeader.getTopic()); } response.setCode(ResponseCode.SUCCESS); @@ -976,9 +1018,9 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { private RemotingCommand ViewBrokerStatsData(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final ViewBrokerStatsDataRequestHeader requestHeader = - (ViewBrokerStatsDataRequestHeader) request.decodeCommandCustomHeader(ViewBrokerStatsDataRequestHeader.class); + (ViewBrokerStatsDataRequestHeader)request.decodeCommandCustomHeader(ViewBrokerStatsDataRequestHeader.class); final RemotingCommand response = RemotingCommand.createResponseCommand(null); - DefaultMessageStore messageStore = (DefaultMessageStore) this.brokerController.getMessageStore(); + DefaultMessageStore messageStore = (DefaultMessageStore)this.brokerController.getMessageStore(); StatsItem statsItem = messageStore.getBrokerStatsManager().getStatsItem(requestHeader.getStatsName(), requestHeader.getStatsKey()); if (null == statsItem) { @@ -998,7 +1040,6 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { brokerStatsData.setStatsMinute(it); } - { BrokerStatsItem it = new BrokerStatsItem(); StatsSnapshot ss = statsItem.getStatsDataInHour(); @@ -1008,7 +1049,6 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { brokerStatsData.setStatsHour(it); } - { BrokerStatsItem it = new BrokerStatsItem(); StatsSnapshot ss = statsItem.getStatsDataInDay(); @@ -1025,16 +1065,16 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { } private RemotingCommand fetchAllConsumeStatsInBroker(ChannelHandlerContext ctx, RemotingCommand request) - throws RemotingCommandException { + throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); GetConsumeStatsInBrokerHeader requestHeader = - (GetConsumeStatsInBrokerHeader) request.decodeCommandCustomHeader(GetConsumeStatsInBrokerHeader.class); + (GetConsumeStatsInBrokerHeader)request.decodeCommandCustomHeader(GetConsumeStatsInBrokerHeader.class); boolean isOrder = requestHeader.isOrder(); ConcurrentHashMap subscriptionGroups = - brokerController.getSubscriptionGroupManager().getSubscriptionGroupTable(); + brokerController.getSubscriptionGroupManager().getSubscriptionGroupTable(); List>> brokerConsumeStatsList = - new ArrayList>>(); + new ArrayList>>(); long totalDiff = 0L; @@ -1060,7 +1100,7 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { SubscriptionData findSubscriptionData = this.brokerController.getConsumerManager().findSubscriptionData(group, topic); if (null == findSubscriptionData // - && this.brokerController.getConsumerManager().findSubscriptionDataCount(group) > 0) { + && this.brokerController.getConsumerManager().findSubscriptionDataCount(group) > 0) { log.warn("consumeStats, the consumer group[{}], topic[{}] not exist", group, topic); continue; } @@ -1076,16 +1116,15 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { if (brokerOffset < 0) brokerOffset = 0; long consumerOffset = this.brokerController.getConsumerOffsetManager().queryOffset(// - group, // - topic, // - i); + group, // + topic, // + i); if (consumerOffset < 0) consumerOffset = 0; offsetWrapper.setBrokerOffset(brokerOffset); offsetWrapper.setConsumerOffset(consumerOffset); - long timeOffset = consumerOffset - 1; if (timeOffset >= 0) { long lastTimestamp = this.brokerController.getMessageStore().getMessageStoreTimeStamp(topic, i, timeOffset); @@ -1120,23 +1159,23 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { runtimeInfo.put("brokerVersion", String.valueOf(MQVersion.CURRENT_VERSION)); runtimeInfo.put("msgPutTotalYesterdayMorning", - String.valueOf(this.brokerController.getBrokerStats().getMsgPutTotalYesterdayMorning())); + String.valueOf(this.brokerController.getBrokerStats().getMsgPutTotalYesterdayMorning())); runtimeInfo.put("msgPutTotalTodayMorning", String.valueOf(this.brokerController.getBrokerStats().getMsgPutTotalTodayMorning())); runtimeInfo.put("msgPutTotalTodayNow", String.valueOf(this.brokerController.getBrokerStats().getMsgPutTotalTodayNow())); runtimeInfo.put("msgGetTotalYesterdayMorning", - String.valueOf(this.brokerController.getBrokerStats().getMsgGetTotalYesterdayMorning())); + String.valueOf(this.brokerController.getBrokerStats().getMsgGetTotalYesterdayMorning())); runtimeInfo.put("msgGetTotalTodayMorning", String.valueOf(this.brokerController.getBrokerStats().getMsgGetTotalTodayMorning())); runtimeInfo.put("msgGetTotalTodayNow", String.valueOf(this.brokerController.getBrokerStats().getMsgGetTotalTodayNow())); runtimeInfo.put("sendThreadPoolQueueSize", String.valueOf(this.brokerController.getSendThreadPoolQueue().size())); runtimeInfo.put("sendThreadPoolQueueCapacity", - String.valueOf(this.brokerController.getBrokerConfig().getSendThreadPoolQueueCapacity())); + String.valueOf(this.brokerController.getBrokerConfig().getSendThreadPoolQueueCapacity())); runtimeInfo.put("pullThreadPoolQueueSize", String.valueOf(this.brokerController.getPullThreadPoolQueue().size())); runtimeInfo.put("pullThreadPoolQueueCapacity", - String.valueOf(this.brokerController.getBrokerConfig().getPullThreadPoolQueueCapacity())); + String.valueOf(this.brokerController.getBrokerConfig().getPullThreadPoolQueueCapacity())); runtimeInfo.put("dispatchBehindBytes", String.valueOf(this.brokerController.getMessageStore().dispatchBehindBytes())); runtimeInfo.put("pageCacheLockTimeMills", String.valueOf(this.brokerController.getMessageStore().lockTimeMills())); @@ -1146,7 +1185,7 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { runtimeInfo.put("earliestMessageTimeStamp", String.valueOf(this.brokerController.getMessageStore().getEarliestMessageTime())); runtimeInfo.put("startAcceptSendRequestTimeStamp", String.valueOf(this.brokerController.getBrokerConfig().getStartAcceptSendRequestTimeStamp())); if (this.brokerController.getMessageStore() instanceof DefaultMessageStore) { - DefaultMessageStore defaultMessageStore = (DefaultMessageStore) this.brokerController.getMessageStore(); + DefaultMessageStore defaultMessageStore = (DefaultMessageStore)this.brokerController.getMessageStore(); runtimeInfo.put("remainTransientStoreBufferNumbs", String.valueOf(defaultMessageStore.remainTransientStoreBufferNumbs())); if (defaultMessageStore.getMessageStoreConfig().isTransientStorePoolEnable()) { runtimeInfo.put("remainHowManyDataToCommit", MixAll.humanReadableByteCount(defaultMessageStore.getCommitLog().remainHowManyDataToCommit(), false)); @@ -1163,10 +1202,10 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { } private RemotingCommand callConsumer(// - final int requestCode, // - final RemotingCommand request, // - final String consumerGroup, // - final String clientId) throws RemotingCommandException { + final int requestCode, // + final RemotingCommand request, // + final String consumerGroup, // + final String clientId) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); ClientChannelInfo clientChannelInfo = this.brokerController.getConsumerManager().findChannel(consumerGroup, clientId); @@ -1179,8 +1218,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { if (clientChannelInfo.getVersion() < MQVersion.Version.V3_1_8_SNAPSHOT.ordinal()) { response.setCode(ResponseCode.SYSTEM_ERROR); response.setRemark(String.format("The Consumer <%s> Version <%s> too low to finish, please upgrade it to V3_1_8_SNAPSHOT", // - clientId, // - MQVersion.getVersionDesc(clientChannelInfo.getVersion()))); + clientId, // + MQVersion.getVersionDesc(clientChannelInfo.getVersion()))); return response; } @@ -1193,12 +1232,12 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { } catch (RemotingTimeoutException e) { response.setCode(ResponseCode.CONSUME_MSG_TIMEOUT); response - .setRemark(String.format("consumer <%s> <%s> Timeout: %s", consumerGroup, clientId, RemotingHelper.exceptionSimpleDesc(e))); + .setRemark(String.format("consumer <%s> <%s> Timeout: %s", consumerGroup, clientId, RemotingHelper.exceptionSimpleDesc(e))); return response; } catch (Exception e) { response.setCode(ResponseCode.SYSTEM_ERROR); response.setRemark( - String.format("invoke consumer <%s> <%s> Exception: %s", consumerGroup, clientId, RemotingHelper.exceptionSimpleDesc(e))); + String.format("invoke consumer <%s> <%s> Exception: %s", consumerGroup, clientId, RemotingHelper.exceptionSimpleDesc(e))); return response; } } diff --git a/broker/src/main/java/org/apache/rocketmq/broker/processor/ClientManageProcessor.java b/broker/src/main/java/org/apache/rocketmq/broker/processor/ClientManageProcessor.java index 62de995f..717afaf3 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/processor/ClientManageProcessor.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/processor/ClientManageProcessor.java @@ -16,6 +16,7 @@ */ package org.apache.rocketmq.broker.processor; +import io.netty.channel.ChannelHandlerContext; import org.apache.rocketmq.broker.BrokerController; import org.apache.rocketmq.broker.client.ClientChannelInfo; import org.apache.rocketmq.common.MixAll; @@ -34,11 +35,9 @@ import org.apache.rocketmq.remoting.common.RemotingHelper; import org.apache.rocketmq.remoting.exception.RemotingCommandException; import org.apache.rocketmq.remoting.netty.NettyRequestProcessor; import org.apache.rocketmq.remoting.protocol.RemotingCommand; -import io.netty.channel.ChannelHandlerContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - public class ClientManageProcessor implements NettyRequestProcessor { private static final Logger log = LoggerFactory.getLogger(LoggerName.BROKER_LOGGER_NAME); private final BrokerController brokerController; @@ -49,7 +48,7 @@ public class ClientManageProcessor implements NettyRequestProcessor { @Override public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) - throws RemotingCommandException { + throws RemotingCommandException { switch (request.getCode()) { case RequestCode.HEART_BEAT: return this.heartBeat(ctx, request); @@ -70,16 +69,16 @@ public class ClientManageProcessor implements NettyRequestProcessor { RemotingCommand response = RemotingCommand.createResponseCommand(null); HeartbeatData heartbeatData = HeartbeatData.decode(request.getBody(), HeartbeatData.class); ClientChannelInfo clientChannelInfo = new ClientChannelInfo( - ctx.channel(), - heartbeatData.getClientID(), - request.getLanguage(), - request.getVersion() + ctx.channel(), + heartbeatData.getClientID(), + request.getLanguage(), + request.getVersion() ); for (ConsumerData data : heartbeatData.getConsumerDataSet()) { SubscriptionGroupConfig subscriptionGroupConfig = - this.brokerController.getSubscriptionGroupManager().findSubscriptionGroupConfig( - data.getGroupName()); + this.brokerController.getSubscriptionGroupManager().findSubscriptionGroupConfig( + data.getGroupName()); boolean isNotifyConsumerIdsChangedEnable = true; if (null != subscriptionGroupConfig) { isNotifyConsumerIdsChangedEnable = subscriptionGroupConfig.isNotifyConsumerIdsChangedEnable(); @@ -89,32 +88,32 @@ public class ClientManageProcessor implements NettyRequestProcessor { } String newTopic = MixAll.getRetryTopic(data.getGroupName()); this.brokerController.getTopicConfigManager().createTopicInSendMessageBackMethod( - newTopic, - subscriptionGroupConfig.getRetryQueueNums(), - PermName.PERM_WRITE | PermName.PERM_READ, topicSysFlag); + newTopic, + subscriptionGroupConfig.getRetryQueueNums(), + PermName.PERM_WRITE | PermName.PERM_READ, topicSysFlag); } boolean changed = this.brokerController.getConsumerManager().registerConsumer( - data.getGroupName(), - clientChannelInfo, - data.getConsumeType(), - data.getMessageModel(), - data.getConsumeFromWhere(), - data.getSubscriptionDataSet(), - isNotifyConsumerIdsChangedEnable + data.getGroupName(), + clientChannelInfo, + data.getConsumeType(), + data.getMessageModel(), + data.getConsumeFromWhere(), + data.getSubscriptionDataSet(), + isNotifyConsumerIdsChangedEnable ); if (changed) { log.info("registerConsumer info changed {} {}", - data.toString(), - RemotingHelper.parseChannelRemoteAddr(ctx.channel()) + data.toString(), + RemotingHelper.parseChannelRemoteAddr(ctx.channel()) ); } } for (ProducerData data : heartbeatData.getProducerDataSet()) { this.brokerController.getProducerManager().registerProducer(data.getGroupName(), - clientChannelInfo); + clientChannelInfo); } response.setCode(ResponseCode.SUCCESS); response.setRemark(null); @@ -122,18 +121,18 @@ public class ClientManageProcessor implements NettyRequestProcessor { } public RemotingCommand unregisterClient(ChannelHandlerContext ctx, RemotingCommand request) - throws RemotingCommandException { + throws RemotingCommandException { final RemotingCommand response = - RemotingCommand.createResponseCommand(UnregisterClientResponseHeader.class); + RemotingCommand.createResponseCommand(UnregisterClientResponseHeader.class); final UnregisterClientRequestHeader requestHeader = - (UnregisterClientRequestHeader) request - .decodeCommandCustomHeader(UnregisterClientRequestHeader.class); + (UnregisterClientRequestHeader)request + .decodeCommandCustomHeader(UnregisterClientRequestHeader.class); ClientChannelInfo clientChannelInfo = new ClientChannelInfo( - ctx.channel(), - requestHeader.getClientID(), - request.getLanguage(), - request.getVersion()); + ctx.channel(), + requestHeader.getClientID(), + request.getLanguage(), + request.getVersion()); { final String group = requestHeader.getProducerGroup(); if (group != null) { @@ -145,7 +144,7 @@ public class ClientManageProcessor implements NettyRequestProcessor { final String group = requestHeader.getConsumerGroup(); if (group != null) { SubscriptionGroupConfig subscriptionGroupConfig = - this.brokerController.getSubscriptionGroupManager().findSubscriptionGroupConfig(group); + this.brokerController.getSubscriptionGroupManager().findSubscriptionGroupConfig(group); boolean isNotifyConsumerIdsChangedEnable = true; if (null != subscriptionGroupConfig) { isNotifyConsumerIdsChangedEnable = subscriptionGroupConfig.isNotifyConsumerIdsChangedEnable(); diff --git a/broker/src/main/java/org/apache/rocketmq/broker/processor/ConsumerManageProcessor.java b/broker/src/main/java/org/apache/rocketmq/broker/processor/ConsumerManageProcessor.java index c0c43e01..d2e6d7d0 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/processor/ConsumerManageProcessor.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/processor/ConsumerManageProcessor.java @@ -16,36 +16,39 @@ */ package org.apache.rocketmq.broker.processor; +import io.netty.channel.ChannelHandlerContext; +import java.util.List; import org.apache.rocketmq.broker.BrokerController; import org.apache.rocketmq.broker.client.ConsumerGroupInfo; import org.apache.rocketmq.common.constant.LoggerName; import org.apache.rocketmq.common.protocol.RequestCode; import org.apache.rocketmq.common.protocol.ResponseCode; +import org.apache.rocketmq.common.protocol.header.GetConsumerListByGroupRequestHeader; +import org.apache.rocketmq.common.protocol.header.GetConsumerListByGroupResponseBody; +import org.apache.rocketmq.common.protocol.header.GetConsumerListByGroupResponseHeader; +import org.apache.rocketmq.common.protocol.header.QueryConsumerOffsetRequestHeader; +import org.apache.rocketmq.common.protocol.header.QueryConsumerOffsetResponseHeader; +import org.apache.rocketmq.common.protocol.header.UpdateConsumerOffsetRequestHeader; +import org.apache.rocketmq.common.protocol.header.UpdateConsumerOffsetResponseHeader; import org.apache.rocketmq.remoting.common.RemotingHelper; import org.apache.rocketmq.remoting.exception.RemotingCommandException; import org.apache.rocketmq.remoting.netty.NettyRequestProcessor; import org.apache.rocketmq.remoting.protocol.RemotingCommand; -import io.netty.channel.ChannelHandlerContext; -import org.apache.rocketmq.common.protocol.header.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.List; - - public class ConsumerManageProcessor implements NettyRequestProcessor { private static final Logger log = LoggerFactory.getLogger(LoggerName.BROKER_LOGGER_NAME); private final BrokerController brokerController; - public ConsumerManageProcessor(final BrokerController brokerController) { this.brokerController = brokerController; } @Override public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) - throws RemotingCommandException { + throws RemotingCommandException { switch (request.getCode()) { case RequestCode.GET_CONSUMER_LIST_BY_GROUP: return this.getConsumerListByGroup(ctx, request); @@ -64,18 +67,17 @@ public class ConsumerManageProcessor implements NettyRequestProcessor { return false; } - public RemotingCommand getConsumerListByGroup(ChannelHandlerContext ctx, RemotingCommand request) - throws RemotingCommandException { + throws RemotingCommandException { final RemotingCommand response = - RemotingCommand.createResponseCommand(GetConsumerListByGroupResponseHeader.class); + RemotingCommand.createResponseCommand(GetConsumerListByGroupResponseHeader.class); final GetConsumerListByGroupRequestHeader requestHeader = - (GetConsumerListByGroupRequestHeader) request - .decodeCommandCustomHeader(GetConsumerListByGroupRequestHeader.class); + (GetConsumerListByGroupRequestHeader)request + .decodeCommandCustomHeader(GetConsumerListByGroupRequestHeader.class); ConsumerGroupInfo consumerGroupInfo = - this.brokerController.getConsumerManager().getConsumerGroupInfo( - requestHeader.getConsumerGroup()); + this.brokerController.getConsumerManager().getConsumerGroupInfo( + requestHeader.getConsumerGroup()); if (consumerGroupInfo != null) { List clientIds = consumerGroupInfo.getAllClientId(); if (!clientIds.isEmpty()) { @@ -87,11 +89,11 @@ public class ConsumerManageProcessor implements NettyRequestProcessor { return response; } else { log.warn("getAllClientId failed, {} {}", requestHeader.getConsumerGroup(), - RemotingHelper.parseChannelRemoteAddr(ctx.channel())); + RemotingHelper.parseChannelRemoteAddr(ctx.channel())); } } else { log.warn("getConsumerGroupInfo failed, {} {}", requestHeader.getConsumerGroup(), - RemotingHelper.parseChannelRemoteAddr(ctx.channel())); + RemotingHelper.parseChannelRemoteAddr(ctx.channel())); } response.setCode(ResponseCode.SYSTEM_ERROR); @@ -100,34 +102,32 @@ public class ConsumerManageProcessor implements NettyRequestProcessor { } private RemotingCommand updateConsumerOffset(ChannelHandlerContext ctx, RemotingCommand request) - throws RemotingCommandException { + throws RemotingCommandException { final RemotingCommand response = - RemotingCommand.createResponseCommand(UpdateConsumerOffsetResponseHeader.class); + RemotingCommand.createResponseCommand(UpdateConsumerOffsetResponseHeader.class); final UpdateConsumerOffsetRequestHeader requestHeader = - (UpdateConsumerOffsetRequestHeader) request - .decodeCommandCustomHeader(UpdateConsumerOffsetRequestHeader.class); + (UpdateConsumerOffsetRequestHeader)request + .decodeCommandCustomHeader(UpdateConsumerOffsetRequestHeader.class); this.brokerController.getConsumerOffsetManager().commitOffset(RemotingHelper.parseChannelRemoteAddr(ctx.channel()), requestHeader.getConsumerGroup(), - requestHeader.getTopic(), requestHeader.getQueueId(), requestHeader.getCommitOffset()); + requestHeader.getTopic(), requestHeader.getQueueId(), requestHeader.getCommitOffset()); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; } - private RemotingCommand queryConsumerOffset(ChannelHandlerContext ctx, RemotingCommand request) - throws RemotingCommandException { + throws RemotingCommandException { final RemotingCommand response = - RemotingCommand.createResponseCommand(QueryConsumerOffsetResponseHeader.class); + RemotingCommand.createResponseCommand(QueryConsumerOffsetResponseHeader.class); final QueryConsumerOffsetResponseHeader responseHeader = - (QueryConsumerOffsetResponseHeader) response.readCustomHeader(); + (QueryConsumerOffsetResponseHeader)response.readCustomHeader(); final QueryConsumerOffsetRequestHeader requestHeader = - (QueryConsumerOffsetRequestHeader) request - .decodeCommandCustomHeader(QueryConsumerOffsetRequestHeader.class); + (QueryConsumerOffsetRequestHeader)request + .decodeCommandCustomHeader(QueryConsumerOffsetRequestHeader.class); long offset = - this.brokerController.getConsumerOffsetManager().queryOffset( - requestHeader.getConsumerGroup(), requestHeader.getTopic(), requestHeader.getQueueId()); - + this.brokerController.getConsumerOffsetManager().queryOffset( + requestHeader.getConsumerGroup(), requestHeader.getTopic(), requestHeader.getQueueId()); if (offset >= 0) { responseHeader.setOffset(offset); @@ -135,11 +135,11 @@ public class ConsumerManageProcessor implements NettyRequestProcessor { response.setRemark(null); } else { long minOffset = - this.brokerController.getMessageStore().getMinOffsetInQuque(requestHeader.getTopic(), - requestHeader.getQueueId()); + this.brokerController.getMessageStore().getMinOffsetInQuque(requestHeader.getTopic(), + requestHeader.getQueueId()); if (minOffset <= 0 - && !this.brokerController.getMessageStore().checkInDiskByConsumeOffset( - requestHeader.getTopic(), requestHeader.getQueueId(), 0)) { + && !this.brokerController.getMessageStore().checkInDiskByConsumeOffset( + requestHeader.getTopic(), requestHeader.getQueueId(), 0)) { responseHeader.setOffset(0L); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); diff --git a/broker/src/main/java/org/apache/rocketmq/broker/processor/EndTransactionProcessor.java b/broker/src/main/java/org/apache/rocketmq/broker/processor/EndTransactionProcessor.java index c493c705..6a34a69c 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/processor/EndTransactionProcessor.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/processor/EndTransactionProcessor.java @@ -16,6 +16,7 @@ */ package org.apache.rocketmq.broker.processor; +import io.netty.channel.ChannelHandlerContext; import org.apache.rocketmq.broker.BrokerController; import org.apache.rocketmq.common.TopicFilterType; import org.apache.rocketmq.common.constant.LoggerName; @@ -33,11 +34,9 @@ import org.apache.rocketmq.remoting.protocol.RemotingCommand; import org.apache.rocketmq.store.MessageExtBrokerInner; import org.apache.rocketmq.store.MessageStore; import org.apache.rocketmq.store.PutMessageResult; -import io.netty.channel.ChannelHandlerContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - public class EndTransactionProcessor implements NettyRequestProcessor { private static final Logger LOGGER = LoggerFactory.getLogger(LoggerName.TRANSACTION_LOGGER_NAME); private final BrokerController brokerController; @@ -50,36 +49,35 @@ public class EndTransactionProcessor implements NettyRequestProcessor { public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final EndTransactionRequestHeader requestHeader = - (EndTransactionRequestHeader) request.decodeCommandCustomHeader(EndTransactionRequestHeader.class); - + (EndTransactionRequestHeader)request.decodeCommandCustomHeader(EndTransactionRequestHeader.class); if (requestHeader.getFromTransactionCheck()) { switch (requestHeader.getCommitOrRollback()) { case MessageSysFlag.TRANSACTION_NOT_TYPE: { LOGGER.warn("check producer[{}] transaction state, but it's pending status." - + "RequestHeader: {} Remark: {}", - RemotingHelper.parseChannelRemoteAddr(ctx.channel()), - requestHeader.toString(), - request.getRemark()); + + "RequestHeader: {} Remark: {}", + RemotingHelper.parseChannelRemoteAddr(ctx.channel()), + requestHeader.toString(), + request.getRemark()); return null; } case MessageSysFlag.TRANSACTION_COMMIT_TYPE: { LOGGER.warn("check producer[{}] transaction state, the producer commit the message." - + "RequestHeader: {} Remark: {}", - RemotingHelper.parseChannelRemoteAddr(ctx.channel()), - requestHeader.toString(), - request.getRemark()); + + "RequestHeader: {} Remark: {}", + RemotingHelper.parseChannelRemoteAddr(ctx.channel()), + requestHeader.toString(), + request.getRemark()); break; } case MessageSysFlag.TRANSACTION_ROLLBACK_TYPE: { LOGGER.warn("check producer[{}] transaction state, the producer rollback the message." - + "RequestHeader: {} Remark: {}", - RemotingHelper.parseChannelRemoteAddr(ctx.channel()), - requestHeader.toString(), - request.getRemark()); + + "RequestHeader: {} Remark: {}", + RemotingHelper.parseChannelRemoteAddr(ctx.channel()), + requestHeader.toString(), + request.getRemark()); break; } default: @@ -89,10 +87,10 @@ public class EndTransactionProcessor implements NettyRequestProcessor { switch (requestHeader.getCommitOrRollback()) { case MessageSysFlag.TRANSACTION_NOT_TYPE: { LOGGER.warn("the producer[{}] end transaction in sending message, and it's pending status." - + "RequestHeader: {} Remark: {}", - RemotingHelper.parseChannelRemoteAddr(ctx.channel()), - requestHeader.toString(), - request.getRemark()); + + "RequestHeader: {} Remark: {}", + RemotingHelper.parseChannelRemoteAddr(ctx.channel()), + requestHeader.toString(), + request.getRemark()); return null; } @@ -102,10 +100,10 @@ public class EndTransactionProcessor implements NettyRequestProcessor { case MessageSysFlag.TRANSACTION_ROLLBACK_TYPE: { LOGGER.warn("the producer[{}] end transaction in sending message, rollback the message." - + "RequestHeader: {} Remark: {}", - RemotingHelper.parseChannelRemoteAddr(ctx.channel()), - requestHeader.toString(), - request.getRemark()); + + "RequestHeader: {} Remark: {}", + RemotingHelper.parseChannelRemoteAddr(ctx.channel()), + requestHeader.toString(), + request.getRemark()); break; } default: @@ -210,8 +208,8 @@ public class EndTransactionProcessor implements NettyRequestProcessor { MessageAccessor.setProperties(msgInner, msgExt.getProperties()); TopicFilterType topicFilterType = - (msgInner.getSysFlag() & MessageSysFlag.MULTI_TAGS_FLAG) == MessageSysFlag.MULTI_TAGS_FLAG ? TopicFilterType.MULTI_TAG - : TopicFilterType.SINGLE_TAG; + (msgInner.getSysFlag() & MessageSysFlag.MULTI_TAGS_FLAG) == MessageSysFlag.MULTI_TAGS_FLAG ? TopicFilterType.MULTI_TAG + : TopicFilterType.SINGLE_TAG; long tagsCodeValue = MessageExtBrokerInner.tagsString2tagsCode(topicFilterType, msgInner.getTags()); msgInner.setTagsCode(tagsCodeValue); msgInner.setPropertiesString(MessageDecoder.messageProperties2String(msgExt.getProperties())); diff --git a/broker/src/main/java/org/apache/rocketmq/broker/processor/ForwardRequestProcessor.java b/broker/src/main/java/org/apache/rocketmq/broker/processor/ForwardRequestProcessor.java index 67e55a45..2a6482cd 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/processor/ForwardRequestProcessor.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/processor/ForwardRequestProcessor.java @@ -6,36 +6,33 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.broker.processor; +import io.netty.channel.ChannelHandlerContext; import org.apache.rocketmq.broker.BrokerController; import org.apache.rocketmq.common.constant.LoggerName; import org.apache.rocketmq.remoting.netty.NettyRequestProcessor; import org.apache.rocketmq.remoting.protocol.RemotingCommand; -import io.netty.channel.ChannelHandlerContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - public class ForwardRequestProcessor implements NettyRequestProcessor { private static final Logger log = LoggerFactory.getLogger(LoggerName.BROKER_LOGGER_NAME); private final BrokerController brokerController; - public ForwardRequestProcessor(final BrokerController brokerController) { this.brokerController = brokerController; } - @Override public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) { return null; diff --git a/broker/src/main/java/org/apache/rocketmq/broker/processor/PullMessageProcessor.java b/broker/src/main/java/org/apache/rocketmq/broker/processor/PullMessageProcessor.java index 041037f4..7169b9c9 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/processor/PullMessageProcessor.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/processor/PullMessageProcessor.java @@ -16,6 +16,13 @@ */ package org.apache.rocketmq.broker.processor; +import io.netty.channel.Channel; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelFutureListener; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.FileRegion; +import java.nio.ByteBuffer; +import java.util.List; import org.apache.rocketmq.broker.BrokerController; import org.apache.rocketmq.broker.client.ConsumerGroupInfo; import org.apache.rocketmq.broker.longpolling.PullRequest; @@ -49,14 +56,9 @@ import org.apache.rocketmq.store.MessageExtBrokerInner; import org.apache.rocketmq.store.PutMessageResult; import org.apache.rocketmq.store.config.BrokerRole; import org.apache.rocketmq.store.stats.BrokerStatsManager; -import io.netty.channel.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.nio.ByteBuffer; -import java.util.List; - - public class PullMessageProcessor implements NettyRequestProcessor { private static final Logger LOG = LoggerFactory.getLogger(LoggerName.BROKER_LOGGER_NAME); private final BrokerController brokerController; @@ -77,12 +79,11 @@ public class PullMessageProcessor implements NettyRequestProcessor { } private RemotingCommand processRequest(final Channel channel, RemotingCommand request, boolean brokerAllowSuspend) - throws RemotingCommandException { + throws RemotingCommandException { RemotingCommand response = RemotingCommand.createResponseCommand(PullMessageResponseHeader.class); - final PullMessageResponseHeader responseHeader = (PullMessageResponseHeader) response.readCustomHeader(); + final PullMessageResponseHeader responseHeader = (PullMessageResponseHeader)response.readCustomHeader(); final PullMessageRequestHeader requestHeader = - (PullMessageRequestHeader) request.decodeCommandCustomHeader(PullMessageRequestHeader.class); - + (PullMessageRequestHeader)request.decodeCommandCustomHeader(PullMessageRequestHeader.class); response.setOpaque(request.getOpaque()); @@ -90,24 +91,21 @@ public class PullMessageProcessor implements NettyRequestProcessor { LOG.debug("receive PullMessage request command, " + request); } - if (!PermName.isReadable(this.brokerController.getBrokerConfig().getBrokerPermission())) { response.setCode(ResponseCode.NO_PERMISSION); response.setRemark("the broker[" + this.brokerController.getBrokerConfig().getBrokerIP1() + "] pulling message is forbidden"); return response; } - SubscriptionGroupConfig subscriptionGroupConfig = - this.brokerController.getSubscriptionGroupManager().findSubscriptionGroupConfig(requestHeader.getConsumerGroup()); + this.brokerController.getSubscriptionGroupManager().findSubscriptionGroupConfig(requestHeader.getConsumerGroup()); if (null == subscriptionGroupConfig) { response.setCode(ResponseCode.SUBSCRIPTION_GROUP_NOT_EXIST); response.setRemark("subscription group not exist, " + requestHeader.getConsumerGroup() + " " - + FAQUrl.suggestTodo(FAQUrl.SUBSCRIPTION_GROUP_NOT_EXIST)); + + FAQUrl.suggestTodo(FAQUrl.SUBSCRIPTION_GROUP_NOT_EXIST)); return response; } - if (!subscriptionGroupConfig.isConsumeEnable()) { response.setCode(ResponseCode.NO_PERMISSION); response.setRemark("subscription group no permission, " + requestHeader.getConsumerGroup()); @@ -120,49 +118,45 @@ public class PullMessageProcessor implements NettyRequestProcessor { final long suspendTimeoutMillisLong = hasSuspendFlag ? requestHeader.getSuspendTimeoutMillis() : 0; - TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(requestHeader.getTopic()); if (null == topicConfig) { LOG.error("the topic " + requestHeader.getTopic() + " not exist, consumer: " + RemotingHelper.parseChannelRemoteAddr(channel)); response.setCode(ResponseCode.TOPIC_NOT_EXIST); response.setRemark( - "topic[" + requestHeader.getTopic() + "] not exist, apply first please!" + FAQUrl.suggestTodo(FAQUrl.APPLY_TOPIC_URL)); + "topic[" + requestHeader.getTopic() + "] not exist, apply first please!" + FAQUrl.suggestTodo(FAQUrl.APPLY_TOPIC_URL)); return response; } - if (!PermName.isReadable(topicConfig.getPerm())) { response.setCode(ResponseCode.NO_PERMISSION); response.setRemark("the topic[" + requestHeader.getTopic() + "] pulling message is forbidden"); return response; } - if (requestHeader.getQueueId() < 0 || requestHeader.getQueueId() >= topicConfig.getReadQueueNums()) { String errorInfo = "queueId[" + requestHeader.getQueueId() + "] is illagal,Topic :" + requestHeader.getTopic() - + " topicConfig.readQueueNums: " + topicConfig.getReadQueueNums() + " consumer: " + channel.remoteAddress(); + + " topicConfig.readQueueNums: " + topicConfig.getReadQueueNums() + " consumer: " + channel.remoteAddress(); LOG.warn(errorInfo); response.setCode(ResponseCode.SYSTEM_ERROR); response.setRemark(errorInfo); return response; } - SubscriptionData subscriptionData = null; if (hasSubscriptionFlag) { try { subscriptionData = FilterAPI.buildSubscriptionData(requestHeader.getConsumerGroup(), requestHeader.getTopic(), - requestHeader.getSubscription()); + requestHeader.getSubscription()); } catch (Exception e) { LOG.warn("parse the consumer's subscription[{}] failed, group: {}", requestHeader.getSubscription(), // - requestHeader.getConsumerGroup()); + requestHeader.getConsumerGroup()); response.setCode(ResponseCode.SUBSCRIPTION_PARSE_FAILED); response.setRemark("parse the consumer's subscription failed"); return response; } } else { ConsumerGroupInfo consumerGroupInfo = - this.brokerController.getConsumerManager().getConsumerGroupInfo(requestHeader.getConsumerGroup()); + this.brokerController.getConsumerManager().getConsumerGroupInfo(requestHeader.getConsumerGroup()); if (null == consumerGroupInfo) { LOG.warn("the consumer's group info not exist, group: {}", requestHeader.getConsumerGroup()); response.setCode(ResponseCode.SUBSCRIPTION_NOT_EXIST); @@ -171,7 +165,7 @@ public class PullMessageProcessor implements NettyRequestProcessor { } if (!subscriptionGroupConfig.isConsumeBroadcastEnable() // - && consumerGroupInfo.getMessageModel() == MessageModel.BROADCASTING) { + && consumerGroupInfo.getMessageModel() == MessageModel.BROADCASTING) { response.setCode(ResponseCode.NO_PERMISSION); response.setRemark("the consumer group[" + requestHeader.getConsumerGroup() + "] can not consume by broadcast way"); return response; @@ -185,10 +179,9 @@ public class PullMessageProcessor implements NettyRequestProcessor { return response; } - if (subscriptionData.getSubVersion() < requestHeader.getSubVersion()) { LOG.warn("the broker's subscription is not latest, group: {} {}", requestHeader.getConsumerGroup(), - subscriptionData.getSubString()); + subscriptionData.getSubString()); response.setCode(ResponseCode.SUBSCRIPTION_NOT_LATEST); response.setRemark("the consumer's subscription not latest"); return response; @@ -196,15 +189,14 @@ public class PullMessageProcessor implements NettyRequestProcessor { } final GetMessageResult getMessageResult = - this.brokerController.getMessageStore().getMessage(requestHeader.getConsumerGroup(), requestHeader.getTopic(), - requestHeader.getQueueId(), requestHeader.getQueueOffset(), requestHeader.getMaxMsgNums(), subscriptionData); + this.brokerController.getMessageStore().getMessage(requestHeader.getConsumerGroup(), requestHeader.getTopic(), + requestHeader.getQueueId(), requestHeader.getQueueOffset(), requestHeader.getMaxMsgNums(), subscriptionData); if (getMessageResult != null) { response.setRemark(getMessageResult.getStatus().name()); responseHeader.setNextBeginOffset(getMessageResult.getNextBeginOffset()); responseHeader.setMinOffset(getMessageResult.getMinOffset()); responseHeader.setMaxOffset(getMessageResult.getMaxOffset()); - if (getMessageResult.isSuggestPullingFromSlave()) { responseHeader.setSuggestWhichBrokerId(subscriptionGroupConfig.getWhichBrokerWhenConsumeSlowly()); } else { @@ -250,11 +242,11 @@ public class PullMessageProcessor implements NettyRequestProcessor { // XXX: warn and notify me LOG.info("the broker store no queue data, fix the request offset {} to {}, Topic: {} QueueId: {} Consumer Group: {}", // - requestHeader.getQueueOffset(), // - getMessageResult.getNextBeginOffset(), // - requestHeader.getTopic(), // - requestHeader.getQueueId(), // - requestHeader.getConsumerGroup()// + requestHeader.getQueueOffset(), // + getMessageResult.getNextBeginOffset(), // + requestHeader.getTopic(), // + requestHeader.getQueueId(), // + requestHeader.getConsumerGroup()// ); } else { response.setCode(ResponseCode.PULL_NOT_FOUND); @@ -270,7 +262,7 @@ public class PullMessageProcessor implements NettyRequestProcessor { response.setCode(ResponseCode.PULL_OFFSET_MOVED); // XXX: warn and notify me LOG.info("the request offset: " + requestHeader.getQueueOffset() + " over flow badly, broker max offset: " - + getMessageResult.getMaxOffset() + ", consumer: " + channel.remoteAddress()); + + getMessageResult.getMaxOffset() + ", consumer: " + channel.remoteAddress()); break; case OFFSET_OVERFLOW_ONE: response.setCode(ResponseCode.PULL_NOT_FOUND); @@ -278,8 +270,8 @@ public class PullMessageProcessor implements NettyRequestProcessor { case OFFSET_TOO_SMALL: response.setCode(ResponseCode.PULL_OFFSET_MOVED); LOG.info("the request offset too small. group={}, topic={}, requestOffset={}, brokerMinOffset={}, clientIp={}", - requestHeader.getConsumerGroup(), requestHeader.getTopic(), requestHeader.getQueueOffset(), - getMessageResult.getMinOffset(), channel.remoteAddress()); + requestHeader.getConsumerGroup(), requestHeader.getTopic(), requestHeader.getQueueOffset(), + getMessageResult.getMinOffset(), channel.remoteAddress()); break; default: assert false; @@ -308,7 +300,6 @@ public class PullMessageProcessor implements NettyRequestProcessor { case ResponseCode.PULL_NOT_FOUND: if (!brokerAllowSuspend) { - context.setCommercialRcvStats(BrokerStatsManager.StatsType.RCV_EPOLLS); context.setCommercialRcvTimes(1); context.setCommercialOwner(owner); @@ -333,23 +324,23 @@ public class PullMessageProcessor implements NettyRequestProcessor { case ResponseCode.SUCCESS: this.brokerController.getBrokerStatsManager().incGroupGetNums(requestHeader.getConsumerGroup(), requestHeader.getTopic(), - getMessageResult.getMessageCount()); + getMessageResult.getMessageCount()); this.brokerController.getBrokerStatsManager().incGroupGetSize(requestHeader.getConsumerGroup(), requestHeader.getTopic(), - getMessageResult.getBufferTotalSize()); + getMessageResult.getBufferTotalSize()); this.brokerController.getBrokerStatsManager().incBrokerGetNums(getMessageResult.getMessageCount()); if (this.brokerController.getBrokerConfig().isTransferMsgByHeap()) { final long beginTimeMills = this.brokerController.getMessageStore().now(); final byte[] r = this.readGetMessageResult(getMessageResult, requestHeader.getConsumerGroup(), requestHeader.getTopic(), requestHeader.getQueueId()); this.brokerController.getBrokerStatsManager().incGroupGetLatency(requestHeader.getConsumerGroup(), - requestHeader.getTopic(), requestHeader.getQueueId(), - (int) (this.brokerController.getMessageStore().now() - beginTimeMills)); + requestHeader.getTopic(), requestHeader.getQueueId(), + (int)(this.brokerController.getMessageStore().now() - beginTimeMills)); response.setBody(r); } else { try { FileRegion fileRegion = - new ManyMessageTransfer(response.encodeHeader(getMessageResult.getBufferTotalSize()), getMessageResult); + new ManyMessageTransfer(response.encodeHeader(getMessageResult.getBufferTotalSize()), getMessageResult); channel.writeAndFlush(fileRegion).addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { @@ -379,18 +370,17 @@ public class PullMessageProcessor implements NettyRequestProcessor { long offset = requestHeader.getQueueOffset(); int queueId = requestHeader.getQueueId(); PullRequest pullRequest = new PullRequest(request, channel, pollingTimeMills, - this.brokerController.getMessageStore().now(), offset, subscriptionData); + this.brokerController.getMessageStore().now(), offset, subscriptionData); this.brokerController.getPullRequestHoldService().suspendPullRequest(topic, queueId, pullRequest); response = null; break; } - case ResponseCode.PULL_RETRY_IMMEDIATELY: break; case ResponseCode.PULL_OFFSET_MOVED: if (this.brokerController.getMessageStoreConfig().getBrokerRole() != BrokerRole.SLAVE - || this.brokerController.getMessageStoreConfig().isOffsetCheckInSlave()) { + || this.brokerController.getMessageStoreConfig().isOffsetCheckInSlave()) { MessageQueue mq = new MessageQueue(); mq.setTopic(requestHeader.getTopic()); mq.setQueueId(requestHeader.getQueueId()); @@ -403,15 +393,15 @@ public class PullMessageProcessor implements NettyRequestProcessor { event.setOffsetNew(getMessageResult.getNextBeginOffset()); this.generateOffsetMovedEvent(event); LOG.warn( - "PULL_OFFSET_MOVED:correction offset. topic={}, groupId={}, requestOffset={}, newOffset={}, suggestBrokerId={}", - requestHeader.getTopic(), requestHeader.getConsumerGroup(), event.getOffsetRequest(), event.getOffsetNew(), - responseHeader.getSuggestWhichBrokerId()); + "PULL_OFFSET_MOVED:correction offset. topic={}, groupId={}, requestOffset={}, newOffset={}, suggestBrokerId={}", + requestHeader.getTopic(), requestHeader.getConsumerGroup(), event.getOffsetRequest(), event.getOffsetNew(), + responseHeader.getSuggestWhichBrokerId()); } else { responseHeader.setSuggestWhichBrokerId(subscriptionGroupConfig.getBrokerId()); response.setCode(ResponseCode.PULL_RETRY_IMMEDIATELY); LOG.warn("PULL_OFFSET_MOVED:none correction. topic={}, groupId={}, requestOffset={}, suggestBrokerId={}", - requestHeader.getTopic(), requestHeader.getConsumerGroup(), requestHeader.getQueueOffset(), - responseHeader.getSuggestWhichBrokerId()); + requestHeader.getTopic(), requestHeader.getConsumerGroup(), requestHeader.getQueueOffset(), + responseHeader.getSuggestWhichBrokerId()); } break; @@ -423,19 +413,17 @@ public class PullMessageProcessor implements NettyRequestProcessor { response.setRemark("store getMessage return null"); } - boolean storeOffsetEnable = brokerAllowSuspend; storeOffsetEnable = storeOffsetEnable && hasCommitOffsetFlag; storeOffsetEnable = storeOffsetEnable - && this.brokerController.getMessageStoreConfig().getBrokerRole() != BrokerRole.SLAVE; + && this.brokerController.getMessageStoreConfig().getBrokerRole() != BrokerRole.SLAVE; if (storeOffsetEnable) { this.brokerController.getConsumerOffsetManager().commitOffset(RemotingHelper.parseChannelRemoteAddr(channel), - requestHeader.getConsumerGroup(), requestHeader.getTopic(), requestHeader.getQueueId(), requestHeader.getCommitOffset()); + requestHeader.getConsumerGroup(), requestHeader.getTopic(), requestHeader.getQueueId(), requestHeader.getCommitOffset()); } return response; } - public boolean hasConsumeMessageHook() { return consumeMessageHookList != null && !this.consumeMessageHookList.isEmpty(); } @@ -512,7 +500,7 @@ public class PullMessageProcessor implements NettyRequestProcessor { public void operationComplete(ChannelFuture future) throws Exception { if (!future.isSuccess()) { LOG.error("processRequestWrapper response to " + future.channel().remoteAddress() + " failed", - future.cause()); + future.cause()); LOG.error(request.toString()); LOG.error(response.toString()); } diff --git a/broker/src/main/java/org/apache/rocketmq/broker/processor/QueryMessageProcessor.java b/broker/src/main/java/org/apache/rocketmq/broker/processor/QueryMessageProcessor.java index 0b6b7752..04f206f0 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/processor/QueryMessageProcessor.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/processor/QueryMessageProcessor.java @@ -6,16 +6,20 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.broker.processor; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelFutureListener; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.FileRegion; import org.apache.rocketmq.broker.BrokerController; import org.apache.rocketmq.broker.pagecache.OneMessageTransfer; import org.apache.rocketmq.broker.pagecache.QueryMessageTransfer; @@ -31,28 +35,21 @@ import org.apache.rocketmq.remoting.netty.NettyRequestProcessor; import org.apache.rocketmq.remoting.protocol.RemotingCommand; import org.apache.rocketmq.store.QueryMessageResult; import org.apache.rocketmq.store.SelectMappedBufferResult; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelFutureListener; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.FileRegion; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - public class QueryMessageProcessor implements NettyRequestProcessor { private static final Logger log = LoggerFactory.getLogger(LoggerName.BROKER_LOGGER_NAME); private final BrokerController brokerController; - public QueryMessageProcessor(final BrokerController brokerController) { this.brokerController = brokerController; } - @Override public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) - throws RemotingCommandException { + throws RemotingCommandException { switch (request.getCode()) { case RequestCode.QUERY_MESSAGE: return this.queryMessage(ctx, request); @@ -70,44 +67,40 @@ public class QueryMessageProcessor implements NettyRequestProcessor { return false; } - public RemotingCommand queryMessage(ChannelHandlerContext ctx, RemotingCommand request) - throws RemotingCommandException { + throws RemotingCommandException { final RemotingCommand response = - RemotingCommand.createResponseCommand(QueryMessageResponseHeader.class); + RemotingCommand.createResponseCommand(QueryMessageResponseHeader.class); final QueryMessageResponseHeader responseHeader = - (QueryMessageResponseHeader) response.readCustomHeader(); + (QueryMessageResponseHeader)response.readCustomHeader(); final QueryMessageRequestHeader requestHeader = - (QueryMessageRequestHeader) request - .decodeCommandCustomHeader(QueryMessageRequestHeader.class); - + (QueryMessageRequestHeader)request + .decodeCommandCustomHeader(QueryMessageRequestHeader.class); response.setOpaque(request.getOpaque()); - String isUniqueKey = request.getExtFields().get(MixAll.UNIQUE_MSG_QUERY_FLAG); if (isUniqueKey != null && isUniqueKey.equals("true")) { requestHeader.setMaxNum(this.brokerController.getMessageStoreConfig().getDefaultQueryMaxNum()); } final QueryMessageResult queryMessageResult = - this.brokerController.getMessageStore().queryMessage(requestHeader.getTopic(), - requestHeader.getKey(), requestHeader.getMaxNum(), requestHeader.getBeginTimestamp(), - requestHeader.getEndTimestamp()); + this.brokerController.getMessageStore().queryMessage(requestHeader.getTopic(), + requestHeader.getKey(), requestHeader.getMaxNum(), requestHeader.getBeginTimestamp(), + requestHeader.getEndTimestamp()); assert queryMessageResult != null; responseHeader.setIndexLastUpdatePhyoffset(queryMessageResult.getIndexLastUpdatePhyoffset()); responseHeader.setIndexLastUpdateTimestamp(queryMessageResult.getIndexLastUpdateTimestamp()); - if (queryMessageResult.getBufferTotalSize() > 0) { response.setCode(ResponseCode.SUCCESS); response.setRemark(null); try { FileRegion fileRegion = - new QueryMessageTransfer(response.encodeHeader(queryMessageResult - .getBufferTotalSize()), queryMessageResult); + new QueryMessageTransfer(response.encodeHeader(queryMessageResult + .getBufferTotalSize()), queryMessageResult); ctx.channel().writeAndFlush(fileRegion).addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { @@ -130,26 +123,24 @@ public class QueryMessageProcessor implements NettyRequestProcessor { return response; } - public RemotingCommand viewMessageById(ChannelHandlerContext ctx, RemotingCommand request) - throws RemotingCommandException { + throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final ViewMessageRequestHeader requestHeader = - (ViewMessageRequestHeader) request.decodeCommandCustomHeader(ViewMessageRequestHeader.class); - + (ViewMessageRequestHeader)request.decodeCommandCustomHeader(ViewMessageRequestHeader.class); response.setOpaque(request.getOpaque()); final SelectMappedBufferResult selectMappedBufferResult = - this.brokerController.getMessageStore().selectOneMessageByOffset(requestHeader.getOffset()); + this.brokerController.getMessageStore().selectOneMessageByOffset(requestHeader.getOffset()); if (selectMappedBufferResult != null) { response.setCode(ResponseCode.SUCCESS); response.setRemark(null); try { FileRegion fileRegion = - new OneMessageTransfer(response.encodeHeader(selectMappedBufferResult.getSize()), - selectMappedBufferResult); + new OneMessageTransfer(response.encodeHeader(selectMappedBufferResult.getSize()), + selectMappedBufferResult); ctx.channel().writeAndFlush(fileRegion).addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { diff --git a/broker/src/main/java/org/apache/rocketmq/broker/processor/SendMessageProcessor.java b/broker/src/main/java/org/apache/rocketmq/broker/processor/SendMessageProcessor.java index 6002df2b..1b952051 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/processor/SendMessageProcessor.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/processor/SendMessageProcessor.java @@ -17,11 +17,17 @@ package org.apache.rocketmq.broker.processor; import io.netty.channel.ChannelHandlerContext; +import java.net.SocketAddress; +import java.util.List; import org.apache.rocketmq.broker.BrokerController; import org.apache.rocketmq.broker.mqtrace.ConsumeMessageContext; import org.apache.rocketmq.broker.mqtrace.ConsumeMessageHook; import org.apache.rocketmq.broker.mqtrace.SendMessageContext; -import org.apache.rocketmq.common.*; +import org.apache.rocketmq.common.MQVersion; +import org.apache.rocketmq.common.MixAll; +import org.apache.rocketmq.common.TopicConfig; +import org.apache.rocketmq.common.TopicFilterType; +import org.apache.rocketmq.common.UtilAll; import org.apache.rocketmq.common.constant.PermName; import org.apache.rocketmq.common.help.FAQUrl; import org.apache.rocketmq.common.message.MessageAccessor; @@ -44,10 +50,6 @@ import org.apache.rocketmq.store.PutMessageResult; import org.apache.rocketmq.store.config.StorePathConfigHelper; import org.apache.rocketmq.store.stats.BrokerStatsManager; -import java.net.SocketAddress; -import java.util.List; - - public class SendMessageProcessor extends AbstractSendMessageProcessor implements NettyRequestProcessor { private List consumeMessageHookList; @@ -80,14 +82,14 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement @Override public boolean rejectRequest() { return this.brokerController.getMessageStore().isOSPageCacheBusy() || - this.brokerController.getMessageStore().isTransientStorePoolDeficient(); + this.brokerController.getMessageStore().isTransientStorePoolDeficient(); } private RemotingCommand consumerSendMsgBack(final ChannelHandlerContext ctx, final RemotingCommand request) - throws RemotingCommandException { + throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final ConsumerSendMsgBackRequestHeader requestHeader = - (ConsumerSendMsgBackRequestHeader) request.decodeCommandCustomHeader(ConsumerSendMsgBackRequestHeader.class); + (ConsumerSendMsgBackRequestHeader)request.decodeCommandCustomHeader(ConsumerSendMsgBackRequestHeader.class); if (this.hasConsumeMessageHook() && !UtilAll.isBlank(requestHeader.getOriginMsgId())) { @@ -101,24 +103,21 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement this.executeConsumeMessageHookAfter(context); } - SubscriptionGroupConfig subscriptionGroupConfig = - this.brokerController.getSubscriptionGroupManager().findSubscriptionGroupConfig(requestHeader.getGroup()); + this.brokerController.getSubscriptionGroupManager().findSubscriptionGroupConfig(requestHeader.getGroup()); if (null == subscriptionGroupConfig) { response.setCode(ResponseCode.SUBSCRIPTION_GROUP_NOT_EXIST); response.setRemark("subscription group not exist, " + requestHeader.getGroup() + " " - + FAQUrl.suggestTodo(FAQUrl.SUBSCRIPTION_GROUP_NOT_EXIST)); + + FAQUrl.suggestTodo(FAQUrl.SUBSCRIPTION_GROUP_NOT_EXIST)); return response; } - if (!PermName.isWriteable(this.brokerController.getBrokerConfig().getBrokerPermission())) { response.setCode(ResponseCode.NO_PERMISSION); response.setRemark("the broker[" + this.brokerController.getBrokerConfig().getBrokerIP1() + "] sending message is forbidden"); return response; } - if (subscriptionGroupConfig.getRetryQueueNums() <= 0) { response.setCode(ResponseCode.SUCCESS); response.setRemark(null); @@ -128,24 +127,21 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement String newTopic = MixAll.getRetryTopic(requestHeader.getGroup()); int queueIdInt = Math.abs(this.random.nextInt() % 99999999) % subscriptionGroupConfig.getRetryQueueNums(); - int topicSysFlag = 0; if (requestHeader.isUnitMode()) { topicSysFlag = TopicSysFlag.buildSysFlag(false, true); } - TopicConfig topicConfig = this.brokerController.getTopicConfigManager().createTopicInSendMessageBackMethod(// - newTopic, // - subscriptionGroupConfig.getRetryQueueNums(), // - PermName.PERM_WRITE | PermName.PERM_READ, topicSysFlag); + newTopic, // + subscriptionGroupConfig.getRetryQueueNums(), // + PermName.PERM_WRITE | PermName.PERM_READ, topicSysFlag); if (null == topicConfig) { response.setCode(ResponseCode.SYSTEM_ERROR); response.setRemark("topic[" + newTopic + "] not exist"); return response; } - if (!PermName.isWriteable(topicConfig.getPerm())) { response.setCode(ResponseCode.NO_PERMISSION); response.setRemark(String.format("the topic[%s] sending message is forbidden", newTopic)); @@ -159,31 +155,27 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement return response; } - final String retryTopic = msgExt.getProperty(MessageConst.PROPERTY_RETRY_TOPIC); if (null == retryTopic) { MessageAccessor.putProperty(msgExt, MessageConst.PROPERTY_RETRY_TOPIC, msgExt.getTopic()); } msgExt.setWaitStoreMsgOK(false); - int delayLevel = requestHeader.getDelayLevel(); - int maxReconsumeTimes = subscriptionGroupConfig.getRetryMaxTimes(); if (request.getVersion() >= MQVersion.Version.V3_4_9.ordinal()) { maxReconsumeTimes = requestHeader.getMaxReconsumeTimes(); } - if (msgExt.getReconsumeTimes() >= maxReconsumeTimes// - || delayLevel < 0) { + || delayLevel < 0) { newTopic = MixAll.getDLQTopic(requestHeader.getGroup()); queueIdInt = Math.abs(this.random.nextInt() % 99999999) % DLQ_NUMS_PER_GROUP; topicConfig = this.brokerController.getTopicConfigManager().createTopicInSendMessageBackMethod(newTopic, // - DLQ_NUMS_PER_GROUP, // - PermName.PERM_WRITE, 0 + DLQ_NUMS_PER_GROUP, // + PermName.PERM_WRITE, 0 ); if (null == topicConfig) { response.setCode(ResponseCode.SYSTEM_ERROR); @@ -247,13 +239,12 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement } private RemotingCommand sendMessage(final ChannelHandlerContext ctx, // - final RemotingCommand request, // - final SendMessageContext sendMessageContext, // - final SendMessageRequestHeader requestHeader) throws RemotingCommandException { + final RemotingCommand request, // + final SendMessageContext sendMessageContext, // + final SendMessageRequestHeader requestHeader) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(SendMessageResponseHeader.class); - final SendMessageResponseHeader responseHeader = (SendMessageResponseHeader) response.readCustomHeader(); - + final SendMessageResponseHeader responseHeader = (SendMessageResponseHeader)response.readCustomHeader(); response.setOpaque(request.getOpaque()); @@ -296,15 +287,14 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement if (null != newTopic && newTopic.startsWith(MixAll.RETRY_GROUP_TOPIC_PREFIX)) { String groupName = newTopic.substring(MixAll.RETRY_GROUP_TOPIC_PREFIX.length()); SubscriptionGroupConfig subscriptionGroupConfig = - this.brokerController.getSubscriptionGroupManager().findSubscriptionGroupConfig(groupName); + this.brokerController.getSubscriptionGroupManager().findSubscriptionGroupConfig(groupName); if (null == subscriptionGroupConfig) { response.setCode(ResponseCode.SUBSCRIPTION_GROUP_NOT_EXIST); response.setRemark( - "subscription group not exist, " + groupName + " " + FAQUrl.suggestTodo(FAQUrl.SUBSCRIPTION_GROUP_NOT_EXIST)); + "subscription group not exist, " + groupName + " " + FAQUrl.suggestTodo(FAQUrl.SUBSCRIPTION_GROUP_NOT_EXIST)); return response; } - int maxReconsumeTimes = subscriptionGroupConfig.getRetryMaxTimes(); if (request.getVersion() >= MQVersion.Version.V3_4_9.ordinal()) { maxReconsumeTimes = requestHeader.getMaxReconsumeTimes(); @@ -314,8 +304,8 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement newTopic = MixAll.getDLQTopic(groupName); queueIdInt = Math.abs(this.random.nextInt() % 99999999) % DLQ_NUMS_PER_GROUP; topicConfig = this.brokerController.getTopicConfigManager().createTopicInSendMessageBackMethod(newTopic, // - DLQ_NUMS_PER_GROUP, // - PermName.PERM_WRITE, 0 + DLQ_NUMS_PER_GROUP, // + PermName.PERM_WRITE, 0 ); if (null == topicConfig) { response.setCode(ResponseCode.SYSTEM_ERROR); @@ -344,7 +334,7 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement if (traFlag != null) { response.setCode(ResponseCode.NO_PERMISSION); response.setRemark( - "the broker[" + this.brokerController.getBrokerConfig().getBrokerIP1() + "] sending transaction message is forbidden"); + "the broker[" + this.brokerController.getBrokerConfig().getBrokerIP1() + "] sending transaction message is forbidden"); return response; } } @@ -381,12 +371,12 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement case PROPERTIES_SIZE_EXCEEDED: response.setCode(ResponseCode.MESSAGE_ILLEGAL); response.setRemark( - "the message is illegal, maybe msg body or properties length not matched. msg body length limit 128k, msg properties length limit 32k."); + "the message is illegal, maybe msg body or properties length not matched. msg body length limit 128k, msg properties length limit 32k."); break; case SERVICE_NOT_AVAILABLE: response.setCode(ResponseCode.SERVICE_NOT_AVAILABLE); response.setRemark( - "service not available now, maybe disk full, " + diskUtil() + ", maybe your broker machine memory too small."); + "service not available now, maybe disk full, " + diskUtil() + ", maybe your broker machine memory too small."); break; case OS_PAGECACHE_BUSY: response.setCode(ResponseCode.SYSTEM_ERROR); @@ -407,7 +397,7 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement this.brokerController.getBrokerStatsManager().incTopicPutNums(msgInner.getTopic()); this.brokerController.getBrokerStatsManager().incTopicPutSize(msgInner.getTopic(), - putMessageResult.getAppendMessageResult().getWroteBytes()); + putMessageResult.getAppendMessageResult().getWroteBytes()); this.brokerController.getBrokerStatsManager().incBrokerPutNums(); response.setRemark(null); @@ -416,10 +406,8 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement responseHeader.setQueueId(queueIdInt); responseHeader.setQueueOffset(putMessageResult.getAppendMessageResult().getLogicsOffset()); - doResponse(ctx, request, response); - if (hasSendMessageHook()) { sendMessageContext.setMsgId(responseHeader.getMsgId()); sendMessageContext.setQueueId(responseHeader.getQueueId()); @@ -427,7 +415,7 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement int commercialBaseCount = brokerController.getBrokerConfig().getCommercialBaseCount(); int wroteSize = putMessageResult.getAppendMessageResult().getWroteBytes(); - int incValue = (int) Math.ceil(wroteSize / BrokerStatsManager.SIZE_PER_COUNT) * commercialBaseCount; + int incValue = (int)Math.ceil(wroteSize / BrokerStatsManager.SIZE_PER_COUNT) * commercialBaseCount; sendMessageContext.setCommercialSendStats(BrokerStatsManager.StatsType.SEND_SUCCESS); sendMessageContext.setCommercialSendTimes(incValue); @@ -438,7 +426,7 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement } else { if (hasSendMessageHook()) { int wroteSize = request.getBody().length; - int incValue = (int) Math.ceil(wroteSize / BrokerStatsManager.SIZE_PER_COUNT); + int incValue = (int)Math.ceil(wroteSize / BrokerStatsManager.SIZE_PER_COUNT); sendMessageContext.setCommercialSendStats(BrokerStatsManager.StatsType.SEND_FAILURE); sendMessageContext.setCommercialSendTimes(incValue); @@ -479,11 +467,11 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement double physicRatio = UtilAll.getDiskPartitionSpaceUsedPercent(storePathPhysic); String storePathLogis = - StorePathConfigHelper.getStorePathConsumeQueue(this.brokerController.getMessageStoreConfig().getStorePathRootDir()); + StorePathConfigHelper.getStorePathConsumeQueue(this.brokerController.getMessageStoreConfig().getStorePathRootDir()); double logisRatio = UtilAll.getDiskPartitionSpaceUsedPercent(storePathLogis); String storePathIndex = - StorePathConfigHelper.getStorePathIndex(this.brokerController.getMessageStoreConfig().getStorePathRootDir()); + StorePathConfigHelper.getStorePathIndex(this.brokerController.getMessageStoreConfig().getStorePathRootDir()); double indexRatio = UtilAll.getDiskPartitionSpaceUsedPercent(storePathIndex); return String.format("CL: %5.2f CQ: %5.2f INDEX: %5.2f", physicRatio, logisRatio, indexRatio); diff --git a/broker/src/main/java/org/apache/rocketmq/broker/slave/SlaveSynchronize.java b/broker/src/main/java/org/apache/rocketmq/broker/slave/SlaveSynchronize.java index 2db23175..2545f1f5 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/slave/SlaveSynchronize.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/slave/SlaveSynchronize.java @@ -6,16 +6,17 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.broker.slave; +import java.io.IOException; import org.apache.rocketmq.broker.BrokerController; import org.apache.rocketmq.broker.subscription.SubscriptionGroupManager; import org.apache.rocketmq.common.MixAll; @@ -27,30 +28,23 @@ import org.apache.rocketmq.store.config.StorePathConfigHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; - - public class SlaveSynchronize { private static final Logger log = LoggerFactory.getLogger(LoggerName.BROKER_LOGGER_NAME); private final BrokerController brokerController; private volatile String masterAddr = null; - public SlaveSynchronize(BrokerController brokerController) { this.brokerController = brokerController; } - public String getMasterAddr() { return masterAddr; } - public void setMasterAddr(String masterAddr) { this.masterAddr = masterAddr; } - public void syncAll() { this.syncTopicConfig(); this.syncConsumerOffset(); @@ -58,21 +52,20 @@ public class SlaveSynchronize { this.syncSubscriptionGroupConfig(); } - private void syncTopicConfig() { String masterAddrBak = this.masterAddr; if (masterAddrBak != null) { try { TopicConfigSerializeWrapper topicWrapper = - this.brokerController.getBrokerOuterAPI().getAllTopicConfig(masterAddrBak); + this.brokerController.getBrokerOuterAPI().getAllTopicConfig(masterAddrBak); if (!this.brokerController.getTopicConfigManager().getDataVersion() - .equals(topicWrapper.getDataVersion())) { + .equals(topicWrapper.getDataVersion())) { this.brokerController.getTopicConfigManager().getDataVersion() - .assignNewOne(topicWrapper.getDataVersion()); + .assignNewOne(topicWrapper.getDataVersion()); this.brokerController.getTopicConfigManager().getTopicConfigTable().clear(); this.brokerController.getTopicConfigManager().getTopicConfigTable() - .putAll(topicWrapper.getTopicConfigTable()); + .putAll(topicWrapper.getTopicConfigTable()); this.brokerController.getTopicConfigManager().persist(); log.info("update slave topic config from master, {}", masterAddrBak); @@ -83,15 +76,14 @@ public class SlaveSynchronize { } } - private void syncConsumerOffset() { String masterAddrBak = this.masterAddr; if (masterAddrBak != null) { try { ConsumerOffsetSerializeWrapper offsetWrapper = - this.brokerController.getBrokerOuterAPI().getAllConsumerOffset(masterAddrBak); + this.brokerController.getBrokerOuterAPI().getAllConsumerOffset(masterAddrBak); this.brokerController.getConsumerOffsetManager().getOffsetTable() - .putAll(offsetWrapper.getOffsetTable()); + .putAll(offsetWrapper.getOffsetTable()); this.brokerController.getConsumerOffsetManager().persist(); log.info("update slave consumer offset from master, {}", masterAddrBak); } catch (Exception e) { @@ -100,18 +92,17 @@ public class SlaveSynchronize { } } - private void syncDelayOffset() { String masterAddrBak = this.masterAddr; if (masterAddrBak != null) { try { String delayOffset = - this.brokerController.getBrokerOuterAPI().getAllDelayOffset(masterAddrBak); + this.brokerController.getBrokerOuterAPI().getAllDelayOffset(masterAddrBak); if (delayOffset != null) { String fileName = - StorePathConfigHelper.getDelayOffsetStorePath(this.brokerController - .getMessageStoreConfig().getStorePathRootDir()); + StorePathConfigHelper.getDelayOffsetStorePath(this.brokerController + .getMessageStoreConfig().getStorePathRootDir()); try { MixAll.string2File(delayOffset, fileName); } catch (IOException e) { @@ -125,24 +116,23 @@ public class SlaveSynchronize { } } - private void syncSubscriptionGroupConfig() { String masterAddrBak = this.masterAddr; if (masterAddrBak != null) { try { SubscriptionGroupWrapper subscriptionWrapper = - this.brokerController.getBrokerOuterAPI() - .getAllSubscriptionGroupConfig(masterAddrBak); + this.brokerController.getBrokerOuterAPI() + .getAllSubscriptionGroupConfig(masterAddrBak); if (!this.brokerController.getSubscriptionGroupManager().getDataVersion() - .equals(subscriptionWrapper.getDataVersion())) { + .equals(subscriptionWrapper.getDataVersion())) { SubscriptionGroupManager subscriptionGroupManager = - this.brokerController.getSubscriptionGroupManager(); + this.brokerController.getSubscriptionGroupManager(); subscriptionGroupManager.getDataVersion().assignNewOne( - subscriptionWrapper.getDataVersion()); + subscriptionWrapper.getDataVersion()); subscriptionGroupManager.getSubscriptionGroupTable().clear(); subscriptionGroupManager.getSubscriptionGroupTable().putAll( - subscriptionWrapper.getSubscriptionGroupTable()); + subscriptionWrapper.getSubscriptionGroupTable()); subscriptionGroupManager.persist(); log.info("update slave Subscription Group from master, {}", masterAddrBak); } diff --git a/broker/src/main/java/org/apache/rocketmq/broker/subscription/SubscriptionGroupManager.java b/broker/src/main/java/org/apache/rocketmq/broker/subscription/SubscriptionGroupManager.java index 7865bc74..f77249a5 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/subscription/SubscriptionGroupManager.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/subscription/SubscriptionGroupManager.java @@ -16,6 +16,10 @@ */ package org.apache.rocketmq.broker.subscription; +import java.io.File; +import java.util.Iterator; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; import org.apache.rocketmq.broker.BrokerController; import org.apache.rocketmq.broker.BrokerPathConfigHelper; import org.apache.rocketmq.common.ConfigManager; @@ -27,25 +31,23 @@ import org.apache.rocketmq.remoting.protocol.RemotingSerializable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.util.Iterator; -import java.util.Map.Entry; -import java.util.concurrent.ConcurrentHashMap; - - public class SubscriptionGroupManager extends ConfigManager { private static final Logger log = LoggerFactory.getLogger(LoggerName.BROKER_LOGGER_NAME); private final ConcurrentHashMap subscriptionGroupTable = - new ConcurrentHashMap(1024); + new ConcurrentHashMap(1024); private final DataVersion dataVersion = new DataVersion(); private transient BrokerController brokerController; - public SubscriptionGroupManager() { this.init(); } + public SubscriptionGroupManager(BrokerController brokerController) { + this.brokerController = brokerController; + this.init(); + } + private void init() { { SubscriptionGroupConfig subscriptionGroupConfig = new SubscriptionGroupConfig(); @@ -94,13 +96,6 @@ public class SubscriptionGroupManager extends ConfigManager { } } - - public SubscriptionGroupManager(BrokerController brokerController) { - this.brokerController = brokerController; - this.init(); - } - - public void updateSubscriptionGroupConfig(final SubscriptionGroupConfig config) { SubscriptionGroupConfig old = this.subscriptionGroupTable.put(config.getGroupName(), config); if (old != null) { @@ -122,7 +117,6 @@ public class SubscriptionGroupManager extends ConfigManager { } } - public SubscriptionGroupConfig findSubscriptionGroupConfig(final String group) { SubscriptionGroupConfig subscriptionGroupConfig = this.subscriptionGroupTable.get(group); if (null == subscriptionGroupConfig) { @@ -141,7 +135,6 @@ public class SubscriptionGroupManager extends ConfigManager { return subscriptionGroupConfig; } - @Override public String encode() { return this.encode(false); @@ -181,12 +174,10 @@ public class SubscriptionGroupManager extends ConfigManager { return subscriptionGroupTable; } - public DataVersion getDataVersion() { return dataVersion; } - public void deleteSubscriptionGroupConfig(final String groupName) { SubscriptionGroupConfig old = this.subscriptionGroupTable.remove(groupName); if (old != null) { diff --git a/broker/src/main/java/org/apache/rocketmq/broker/topic/TopicConfigManager.java b/broker/src/main/java/org/apache/rocketmq/broker/topic/TopicConfigManager.java index 9e143324..e826d246 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/topic/TopicConfigManager.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/topic/TopicConfigManager.java @@ -16,6 +16,16 @@ */ package org.apache.rocketmq.broker.topic; +import java.io.File; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; import org.apache.rocketmq.broker.BrokerController; import org.apache.rocketmq.broker.BrokerPathConfigHelper; import org.apache.rocketmq.common.ConfigManager; @@ -30,34 +40,20 @@ import org.apache.rocketmq.common.sysflag.TopicSysFlag; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; - - public class TopicConfigManager extends ConfigManager { private static final Logger LOG = LoggerFactory.getLogger(LoggerName.BROKER_LOGGER_NAME); private static final long LOCK_TIMEOUT_MILLIS = 3000; private transient final Lock lockTopicConfigTable = new ReentrantLock(); private final ConcurrentHashMap topicConfigTable = - new ConcurrentHashMap(1024); + new ConcurrentHashMap(1024); private final DataVersion dataVersion = new DataVersion(); private final Set systemTopicList = new HashSet(); private transient BrokerController brokerController; - public TopicConfigManager() { } - public TopicConfigManager(BrokerController brokerController) { this.brokerController = brokerController; { @@ -76,9 +72,9 @@ public class TopicConfigManager extends ConfigManager { TopicConfig topicConfig = new TopicConfig(topic); this.systemTopicList.add(topic); topicConfig.setReadQueueNums(this.brokerController.getBrokerConfig() - .getDefaultTopicQueueNums()); + .getDefaultTopicQueueNums()); topicConfig.setWriteQueueNums(this.brokerController.getBrokerConfig() - .getDefaultTopicQueueNums()); + .getDefaultTopicQueueNums()); int perm = PermName.PERM_INHERIT | PermName.PERM_READ | PermName.PERM_WRITE; topicConfig.setPerm(perm); this.topicConfigTable.put(topicConfig.getTopicName(), topicConfig); @@ -130,29 +126,24 @@ public class TopicConfigManager extends ConfigManager { } } - public boolean isSystemTopic(final String topic) { return this.systemTopicList.contains(topic); } - public Set getSystemTopic() { return this.systemTopicList; } - public boolean isTopicCanSendMessage(final String topic) { return !topic.equals(MixAll.DEFAULT_TOPIC); } - public TopicConfig selectTopicConfig(final String topic) { return this.topicConfigTable.get(topic); } - public TopicConfig createTopicInSendMessageMethod(final String topic, final String defaultTopic, - final String remoteAddress, final int clientDefaultTopicQueueNums, final int topicSysFlag) { + final String remoteAddress, final int clientDefaultTopicQueueNums, final int topicSysFlag) { TopicConfig topicConfig = null; boolean createNew = false; @@ -175,8 +166,8 @@ public class TopicConfigManager extends ConfigManager { topicConfig = new TopicConfig(topic); int queueNums = - clientDefaultTopicQueueNums > defaultTopicConfig.getWriteQueueNums() ? defaultTopicConfig - .getWriteQueueNums() : clientDefaultTopicQueueNums; + clientDefaultTopicQueueNums > defaultTopicConfig.getWriteQueueNums() ? defaultTopicConfig + .getWriteQueueNums() : clientDefaultTopicQueueNums; if (queueNums < 0) { queueNums = 0; @@ -191,17 +182,17 @@ public class TopicConfigManager extends ConfigManager { topicConfig.setTopicFilterType(defaultTopicConfig.getTopicFilterType()); } else { LOG.warn("create new topic failed, because the default topic[" + defaultTopic - + "] no perm, " + defaultTopicConfig.getPerm() + " producer: " - + remoteAddress); + + "] no perm, " + defaultTopicConfig.getPerm() + " producer: " + + remoteAddress); } } else { LOG.warn("create new topic failed, because the default topic[" + defaultTopic - + "] not exist." + " producer: " + remoteAddress); + + "] not exist." + " producer: " + remoteAddress); } if (topicConfig != null) { LOG.info("create new topic by default topic[" + defaultTopic + "], " + topicConfig - + " producer: " + remoteAddress); + + " producer: " + remoteAddress); this.topicConfigTable.put(topic, topicConfig); @@ -227,10 +218,10 @@ public class TopicConfigManager extends ConfigManager { } public TopicConfig createTopicInSendMessageBackMethod( - final String topic, - final int clientDefaultTopicQueueNums, - final int perm, - final int topicSysFlag) { + final String topic, + final int clientDefaultTopicQueueNums, + final int perm, + final int topicSysFlag) { TopicConfig topicConfig = this.topicConfigTable.get(topic); if (topicConfig != null) return topicConfig; @@ -282,7 +273,7 @@ public class TopicConfigManager extends ConfigManager { } LOG.info("update topic sys flag. oldTopicSysFlag={}, newTopicSysFlag", oldTopicSysFlag, - topicConfig.getTopicSysFlag()); + topicConfig.getTopicSysFlag()); this.topicConfigTable.put(topic, topicConfig); @@ -302,7 +293,7 @@ public class TopicConfigManager extends ConfigManager { } LOG.info("update topic sys flag. oldTopicSysFlag={}, newTopicSysFlag", oldTopicSysFlag, - topicConfig.getTopicSysFlag()); + topicConfig.getTopicSysFlag()); this.topicConfigTable.put(topic, topicConfig); @@ -326,7 +317,6 @@ public class TopicConfigManager extends ConfigManager { this.persist(); } - public void updateOrderTopicConfig(final KVTable orderKVTableFromNs) { if (orderKVTableFromNs != null && orderKVTableFromNs.getTable() != null) { @@ -403,7 +393,7 @@ public class TopicConfigManager extends ConfigManager { public void decode(String jsonString) { if (jsonString != null) { TopicConfigSerializeWrapper topicConfigSerializeWrapper = - TopicConfigSerializeWrapper.fromJson(jsonString, TopicConfigSerializeWrapper.class); + TopicConfigSerializeWrapper.fromJson(jsonString, TopicConfigSerializeWrapper.class); if (topicConfigSerializeWrapper != null) { this.topicConfigTable.putAll(topicConfigSerializeWrapper.getTopicConfigTable()); this.dataVersion.assignNewOne(topicConfigSerializeWrapper.getDataVersion()); diff --git a/broker/src/main/java/org/apache/rocketmq/broker/transaction/TransactionRecord.java b/broker/src/main/java/org/apache/rocketmq/broker/transaction/TransactionRecord.java index 68256d91..830a0c5f 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/transaction/TransactionRecord.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/transaction/TransactionRecord.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.broker.transaction; @@ -22,22 +22,18 @@ public class TransactionRecord { private long offset; private String producerGroup; - public long getOffset() { return offset; } - public void setOffset(long offset) { this.offset = offset; } - public String getProducerGroup() { return producerGroup; } - public void setProducerGroup(String producerGroup) { this.producerGroup = producerGroup; } diff --git a/broker/src/main/java/org/apache/rocketmq/broker/transaction/TransactionStore.java b/broker/src/main/java/org/apache/rocketmq/broker/transaction/TransactionStore.java index d6e897ac..f9b56d58 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/transaction/TransactionStore.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/transaction/TransactionStore.java @@ -6,41 +6,33 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.broker.transaction; import java.util.List; - public interface TransactionStore { boolean open(); - void close(); - boolean put(final List trs); - void remove(final List pks); - List traverse(final long pk, final int nums); - long totalRecords(); - long minPK(); - long maxPK(); } diff --git a/broker/src/main/java/org/apache/rocketmq/broker/transaction/jdbc/JDBCTransactionStore.java b/broker/src/main/java/org/apache/rocketmq/broker/transaction/jdbc/JDBCTransactionStore.java index 4bf73d24..240e1414 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/transaction/jdbc/JDBCTransactionStore.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/transaction/jdbc/JDBCTransactionStore.java @@ -6,17 +6,27 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.broker.transaction.jdbc; +import java.net.URL; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.List; +import java.util.Properties; +import java.util.concurrent.atomic.AtomicLong; import org.apache.rocketmq.broker.transaction.TransactionRecord; import org.apache.rocketmq.broker.transaction.TransactionStore; import org.apache.rocketmq.common.MixAll; @@ -24,13 +34,6 @@ import org.apache.rocketmq.common.constant.LoggerName; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.net.URL; -import java.sql.*; -import java.util.List; -import java.util.Properties; -import java.util.concurrent.atomic.AtomicLong; - - public class JDBCTransactionStore implements TransactionStore { private static final Logger log = LoggerFactory.getLogger(LoggerName.TRANSACTION_LOGGER_NAME); private final JDBCTransactionStoreConfig jdbcTransactionStoreConfig; @@ -50,11 +53,10 @@ public class JDBCTransactionStore implements TransactionStore { try { this.connection = - DriverManager.getConnection(this.jdbcTransactionStoreConfig.getJdbcURL(), props); + DriverManager.getConnection(this.jdbcTransactionStoreConfig.getJdbcURL(), props); this.connection.setAutoCommit(false); - if (!this.computeTotalRecords()) { return this.createDB(); } @@ -72,7 +74,7 @@ public class JDBCTransactionStore implements TransactionStore { try { Class.forName(this.jdbcTransactionStoreConfig.getJdbcDriverClass()).newInstance(); log.info("Loaded the appropriate driver, {}", - this.jdbcTransactionStoreConfig.getJdbcDriverClass()); + this.jdbcTransactionStoreConfig.getJdbcDriverClass()); return true; } catch (Exception e) { log.info("Loaded the appropriate driver Exception", e); diff --git a/broker/src/main/java/org/apache/rocketmq/broker/transaction/jdbc/JDBCTransactionStoreConfig.java b/broker/src/main/java/org/apache/rocketmq/broker/transaction/jdbc/JDBCTransactionStoreConfig.java index 57893293..86c1ec8e 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/transaction/jdbc/JDBCTransactionStoreConfig.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/transaction/jdbc/JDBCTransactionStoreConfig.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.broker.transaction.jdbc; @@ -23,42 +23,34 @@ public class JDBCTransactionStoreConfig { private String jdbcUser = "xxx"; private String jdbcPassword = "xxx"; - public String getJdbcDriverClass() { return jdbcDriverClass; } - public void setJdbcDriverClass(String jdbcDriverClass) { this.jdbcDriverClass = jdbcDriverClass; } - public String getJdbcURL() { return jdbcURL; } - public void setJdbcURL(String jdbcURL) { this.jdbcURL = jdbcURL; } - public String getJdbcUser() { return jdbcUser; } - public void setJdbcUser(String jdbcUser) { this.jdbcUser = jdbcUser; } - public String getJdbcPassword() { return jdbcPassword; } - public void setJdbcPassword(String jdbcPassword) { this.jdbcPassword = jdbcPassword; } diff --git a/broker/src/test/java/org/apache/rocketmq/broker/BrokerControllerTest.java b/broker/src/test/java/org/apache/rocketmq/broker/BrokerControllerTest.java index 6e7b9b09..f7675c21 100644 --- a/broker/src/test/java/org/apache/rocketmq/broker/BrokerControllerTest.java +++ b/broker/src/test/java/org/apache/rocketmq/broker/BrokerControllerTest.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.broker; @@ -27,9 +27,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class BrokerControllerTest { - protected Logger logger = LoggerFactory.getLogger(BrokerControllerTest.class); - private static final int RESTART_NUM = 3; + protected Logger logger = LoggerFactory.getLogger(BrokerControllerTest.class); /** * Tests if the controller can be properly stopped and started. diff --git a/broker/src/test/java/org/apache/rocketmq/broker/BrokerTestHarness.java b/broker/src/test/java/org/apache/rocketmq/broker/BrokerTestHarness.java index 4fd7a5b0..5e944d8e 100644 --- a/broker/src/test/java/org/apache/rocketmq/broker/BrokerTestHarness.java +++ b/broker/src/test/java/org/apache/rocketmq/broker/BrokerTestHarness.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: SendMessageTest.java 1831 2013-05-16 01:39:51Z vintagewang@apache.org $ */ /** @@ -20,6 +22,8 @@ */ package org.apache.rocketmq.broker; +import java.io.File; +import java.util.Random; import org.apache.rocketmq.common.BrokerConfig; import org.apache.rocketmq.remoting.netty.NettyClientConfig; import org.apache.rocketmq.remoting.netty.NettyServerConfig; @@ -30,15 +34,11 @@ import org.junit.Before; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.util.Random; - public class BrokerTestHarness { + public final String BROKER_NAME = "TestBrokerName"; protected BrokerController brokerController = null; - protected Random random = new Random(); - public final String BROKER_NAME = "TestBrokerName"; protected String brokerAddr = ""; protected Logger logger = LoggerFactory.getLogger(BrokerTestHarness.class); protected BrokerConfig brokerConfig = new BrokerConfig(); diff --git a/broker/src/test/java/org/apache/rocketmq/broker/api/SendMessageTest.java b/broker/src/test/java/org/apache/rocketmq/broker/api/SendMessageTest.java index 0ff589dd..38d885e5 100644 --- a/broker/src/test/java/org/apache/rocketmq/broker/api/SendMessageTest.java +++ b/broker/src/test/java/org/apache/rocketmq/broker/api/SendMessageTest.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: SendMessageTest.java 1831 2013-05-16 01:39:51Z vintagewang@apache.org $ */ /** @@ -36,10 +38,9 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.*; - +import static org.junit.Assert.assertEquals; -public class SendMessageTest extends BrokerTestHarness{ +public class SendMessageTest extends BrokerTestHarness { MQClientAPIImpl client = new MQClientAPIImpl(new NettyClientConfig(), null, null, new ClientConfig()); String topic = "UnitTestTopic"; @@ -60,7 +61,7 @@ public class SendMessageTest extends BrokerTestHarness{ } @Test - public void testSendSingle() throws Exception{ + public void testSendSingle() throws Exception { Message msg = new Message(topic, "TAG1 TAG2", "100200300", "body".getBytes()); SendMessageRequestHeader requestHeader = new SendMessageRequestHeader(); requestHeader.setProducerGroup("abc"); @@ -74,7 +75,7 @@ public class SendMessageTest extends BrokerTestHarness{ requestHeader.setProperties(MessageDecoder.messageProperties2String(msg.getProperties())); SendResult result = client.sendMessage(brokerAddr, BROKER_NAME, msg, requestHeader, 1000 * 5, - CommunicationMode.SYNC, new SendMessageContext(), null); + CommunicationMode.SYNC, new SendMessageContext(), null); assertEquals(result.getSendStatus(), SendStatus.SEND_OK); } } diff --git a/broker/src/test/java/org/apache/rocketmq/broker/offset/ConsumerOffsetManagerTest.java b/broker/src/test/java/org/apache/rocketmq/broker/offset/ConsumerOffsetManagerTest.java index d6be5fb7..89813fc6 100644 --- a/broker/src/test/java/org/apache/rocketmq/broker/offset/ConsumerOffsetManagerTest.java +++ b/broker/src/test/java/org/apache/rocketmq/broker/offset/ConsumerOffsetManagerTest.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: ConsumerOffsetManagerTest.java 1831 2013-05-16 01:39:51Z vintagewang@apache.org $ */ /** @@ -25,7 +27,6 @@ import org.junit.Test; import static org.junit.Assert.assertEquals; - public class ConsumerOffsetManagerTest extends BrokerTestHarness { @Test diff --git a/broker/src/test/java/org/apache/rocketmq/broker/topic/TopicConfigManagerTest.java b/broker/src/test/java/org/apache/rocketmq/broker/topic/TopicConfigManagerTest.java index ab9ab6f4..2f85dbc2 100644 --- a/broker/src/test/java/org/apache/rocketmq/broker/topic/TopicConfigManagerTest.java +++ b/broker/src/test/java/org/apache/rocketmq/broker/topic/TopicConfigManagerTest.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: TopicConfigManagerTest.java 1831 2013-05-16 01:39:51Z vintagewang@apache.org $ */ /** @@ -25,8 +27,9 @@ import org.apache.rocketmq.common.MixAll; import org.apache.rocketmq.common.TopicConfig; import org.junit.Test; -import static org.junit.Assert.*; - +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; public class TopicConfigManagerTest extends BrokerTestHarness { @Test diff --git a/checkstyle/checkstyle.xml b/checkstyle/checkstyle.xml index e4a8c362..0d22d7d3 100644 --- a/checkstyle/checkstyle.xml +++ b/checkstyle/checkstyle.xml @@ -1,7 +1,7 @@ + "-//Puppy Crawl//DTD Check Configuration 1.3//EN" + "http://www.puppycrawl.com/dtds/configuration_1_3.dtd"> - org.apache.rocketmq diff --git a/client/src/main/java/org/apache/rocketmq/client/ClientConfig.java b/client/src/main/java/org/apache/rocketmq/client/ClientConfig.java index 8afca136..9c7a0cdc 100644 --- a/client/src/main/java/org/apache/rocketmq/client/ClientConfig.java +++ b/client/src/main/java/org/apache/rocketmq/client/ClientConfig.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client; @@ -20,7 +20,6 @@ import org.apache.rocketmq.common.MixAll; import org.apache.rocketmq.common.UtilAll; import org.apache.rocketmq.remoting.common.RemotingUtil; - /** * Client Common configuration * @@ -123,78 +122,64 @@ public class ClientConfig { return clientCallbackExecutorThreads; } - public void setClientCallbackExecutorThreads(int clientCallbackExecutorThreads) { this.clientCallbackExecutorThreads = clientCallbackExecutorThreads; } - public int getPollNameServerInteval() { return pollNameServerInteval; } - public void setPollNameServerInteval(int pollNameServerInteval) { this.pollNameServerInteval = pollNameServerInteval; } - public int getHeartbeatBrokerInterval() { return heartbeatBrokerInterval; } - public void setHeartbeatBrokerInterval(int heartbeatBrokerInterval) { this.heartbeatBrokerInterval = heartbeatBrokerInterval; } - public int getPersistConsumerOffsetInterval() { return persistConsumerOffsetInterval; } - public void setPersistConsumerOffsetInterval(int persistConsumerOffsetInterval) { this.persistConsumerOffsetInterval = persistConsumerOffsetInterval; } - public String getUnitName() { return unitName; } - public void setUnitName(String unitName) { this.unitName = unitName; } - public boolean isUnitMode() { return unitMode; } - public void setUnitMode(boolean unitMode) { this.unitMode = unitMode; } - public boolean isVipChannelEnabled() { return vipChannelEnabled; } - public void setVipChannelEnabled(final boolean vipChannelEnabled) { this.vipChannelEnabled = vipChannelEnabled; } - @Override public String toString() { return "ClientConfig [namesrvAddr=" + namesrvAddr + ", clientIP=" + clientIP + ", instanceName=" + instanceName - + ", clientCallbackExecutorThreads=" + clientCallbackExecutorThreads + ", pollNameServerInteval=" + pollNameServerInteval - + ", heartbeatBrokerInterval=" + heartbeatBrokerInterval + ", persistConsumerOffsetInterval=" - + persistConsumerOffsetInterval + ", unitMode=" + unitMode + ", unitName=" + unitName + ", vipChannelEnabled=" - + vipChannelEnabled + "]"; + + ", clientCallbackExecutorThreads=" + clientCallbackExecutorThreads + ", pollNameServerInteval=" + pollNameServerInteval + + ", heartbeatBrokerInterval=" + heartbeatBrokerInterval + ", persistConsumerOffsetInterval=" + + persistConsumerOffsetInterval + ", unitMode=" + unitMode + ", unitName=" + unitName + ", vipChannelEnabled=" + + vipChannelEnabled + "]"; } } diff --git a/client/src/main/java/org/apache/rocketmq/client/MQAdmin.java b/client/src/main/java/org/apache/rocketmq/client/MQAdmin.java index 65968558..76975206 100644 --- a/client/src/main/java/org/apache/rocketmq/client/MQAdmin.java +++ b/client/src/main/java/org/apache/rocketmq/client/MQAdmin.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client; @@ -22,7 +22,6 @@ import org.apache.rocketmq.common.message.MessageExt; import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.remoting.exception.RemotingException; - /** * Base interface for MQ management * @@ -41,8 +40,7 @@ public interface MQAdmin { * @throws MQClientException */ void createTopic(final String key, final String newTopic, final int queueNum) - throws MQClientException; - + throws MQClientException; /** * Creates an topic @@ -59,8 +57,7 @@ public interface MQAdmin { * @throws MQClientException */ void createTopic(String key, String newTopic, int queueNum, int topicSysFlag) - throws MQClientException; - + throws MQClientException; /** * Gets the message queue offset according to some time in milliseconds
@@ -77,7 +74,6 @@ public interface MQAdmin { */ long searchOffset(final MessageQueue mq, final long timestamp) throws MQClientException; - /** * Gets the max offset * @@ -90,7 +86,6 @@ public interface MQAdmin { */ long maxOffset(final MessageQueue mq) throws MQClientException; - /** * Gets the minimum offset * @@ -103,7 +98,6 @@ public interface MQAdmin { */ long minOffset(final MessageQueue mq) throws MQClientException; - /** * Gets the earliest stored message time * @@ -116,7 +110,6 @@ public interface MQAdmin { */ long earliestMsgStoreTime(final MessageQueue mq) throws MQClientException; - /** * Query message according tto message id * @@ -131,8 +124,7 @@ public interface MQAdmin { * @throws MQClientException */ MessageExt viewMessage(final String offsetMsgId) throws RemotingException, MQBrokerException, - InterruptedException, MQClientException; - + InterruptedException, MQClientException; /** * Query messages @@ -154,8 +146,8 @@ public interface MQAdmin { * @throws InterruptedException */ QueryResult queryMessage(final String topic, final String key, final int maxNum, final long begin, - final long end) throws MQClientException, InterruptedException; - + final long end) throws MQClientException, InterruptedException; + /** * @param topic @@ -166,7 +158,6 @@ public interface MQAdmin { * @throws InterruptedException * @throws MQClientException */ - MessageExt viewMessage(String topic, String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException; + MessageExt viewMessage(String topic, String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException; - } \ No newline at end of file diff --git a/client/src/main/java/org/apache/rocketmq/client/MQHelper.java b/client/src/main/java/org/apache/rocketmq/client/MQHelper.java index b4ddb080..937e8464 100644 --- a/client/src/main/java/org/apache/rocketmq/client/MQHelper.java +++ b/client/src/main/java/org/apache/rocketmq/client/MQHelper.java @@ -16,47 +16,39 @@ */ package org.apache.rocketmq.client; +import java.util.Set; +import java.util.TreeSet; import org.apache.rocketmq.client.consumer.DefaultMQPullConsumer; import org.apache.rocketmq.client.log.ClientLogger; import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.common.protocol.heartbeat.MessageModel; import org.slf4j.Logger; -import java.util.Set; -import java.util.TreeSet; - - public class MQHelper { public static void resetOffsetByTimestamp( - final MessageModel messageModel, - final String consumerGroup, - final String topic, - final long timestamp) throws Exception { + final MessageModel messageModel, + final String consumerGroup, + final String topic, + final long timestamp) throws Exception { resetOffsetByTimestamp(messageModel, "DEFAULT", consumerGroup, topic, timestamp); } /** * Reset consumer topic offset according to time * - * @param messageModel - * which model - * @param instanceName - * which instance - * @param consumerGroup - * consumer group - * @param topic - * topic - * @param timestamp - * time - * + * @param messageModel which model + * @param instanceName which instance + * @param consumerGroup consumer group + * @param topic topic + * @param timestamp time * @throws Exception */ public static void resetOffsetByTimestamp( - final MessageModel messageModel, - final String instanceName, - final String consumerGroup, - final String topic, - final long timestamp) throws Exception { + final MessageModel messageModel, + final String instanceName, + final String consumerGroup, + final String topic, + final long timestamp) throws Exception { final Logger log = ClientLogger.getLog(); DefaultMQPullConsumer consumer = new DefaultMQPullConsumer(consumerGroup); @@ -74,7 +66,7 @@ public class MQHelper { if (offset >= 0) { consumer.updateConsumeOffset(mq, offset); log.info("resetOffsetByTimestamp updateConsumeOffset success, {} {} {}", - consumerGroup, offset, mq); + consumerGroup, offset, mq); } } } diff --git a/client/src/main/java/org/apache/rocketmq/client/QueryResult.java b/client/src/main/java/org/apache/rocketmq/client/QueryResult.java index af3649b5..7b1cc015 100644 --- a/client/src/main/java/org/apache/rocketmq/client/QueryResult.java +++ b/client/src/main/java/org/apache/rocketmq/client/QueryResult.java @@ -6,45 +6,39 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client; -import org.apache.rocketmq.common.message.MessageExt; - import java.util.List; - +import org.apache.rocketmq.common.message.MessageExt; public class QueryResult { private final long indexLastUpdateTimestamp; private final List messageList; - public QueryResult(long indexLastUpdateTimestamp, List messageList) { this.indexLastUpdateTimestamp = indexLastUpdateTimestamp; this.messageList = messageList; } - public long getIndexLastUpdateTimestamp() { return indexLastUpdateTimestamp; } - public List getMessageList() { return messageList; } - @Override public String toString() { return "QueryResult [indexLastUpdateTimestamp=" + indexLastUpdateTimestamp + ", messageList=" - + messageList + "]"; + + messageList + "]"; } } diff --git a/client/src/main/java/org/apache/rocketmq/client/Validators.java b/client/src/main/java/org/apache/rocketmq/client/Validators.java index 92fc53ba..fa9e4e60 100644 --- a/client/src/main/java/org/apache/rocketmq/client/Validators.java +++ b/client/src/main/java/org/apache/rocketmq/client/Validators.java @@ -6,17 +6,19 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.client.producer.DefaultMQProducer; import org.apache.rocketmq.common.MixAll; @@ -24,10 +26,6 @@ import org.apache.rocketmq.common.UtilAll; import org.apache.rocketmq.common.message.Message; import org.apache.rocketmq.common.protocol.ResponseCode; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - - /** * Common Validator * @@ -65,8 +63,8 @@ public class Validators { } if (!regularExpressionMatcher(group, PATTERN)) { throw new MQClientException(String.format( - "the specified group[%s] contains illegal characters, allowing only %s", group, - VALID_PATTERN_STR), null); + "the specified group[%s] contains illegal characters, allowing only %s", group, + VALID_PATTERN_STR), null); } if (group.length() > CHARACTER_MAX_LENGTH) { throw new MQClientException("the specified group is longer than group max length 255.", null); @@ -97,7 +95,7 @@ public class Validators { * @throws MQClientException */ public static void checkMessage(Message msg, DefaultMQProducer defaultMQProducer) - throws MQClientException { + throws MQClientException { if (null == msg) { throw new MQClientException(ResponseCode.MESSAGE_ILLEGAL, "the message is null"); } @@ -114,7 +112,7 @@ public class Validators { if (msg.getBody().length > defaultMQProducer.getMaxMessageSize()) { throw new MQClientException(ResponseCode.MESSAGE_ILLEGAL, - "the message body size over max value, MAX: " + defaultMQProducer.getMaxMessageSize()); + "the message body size over max value, MAX: " + defaultMQProducer.getMaxMessageSize()); } } @@ -132,8 +130,8 @@ public class Validators { if (!regularExpressionMatcher(topic, PATTERN)) { throw new MQClientException(String.format( - "the specified topic[%s] contains illegal characters, allowing only %s", topic, - VALID_PATTERN_STR), null); + "the specified topic[%s] contains illegal characters, allowing only %s", topic, + VALID_PATTERN_STR), null); } if (topic.length() > CHARACTER_MAX_LENGTH) { @@ -143,7 +141,7 @@ public class Validators { //whether the same with system reserved keyword if (topic.equals(MixAll.DEFAULT_TOPIC)) { throw new MQClientException( - String.format("the topic[%s] is conflict with default topic.", topic), null); + String.format("the topic[%s] is conflict with default topic.", topic), null); } } } diff --git a/client/src/main/java/org/apache/rocketmq/client/admin/MQAdminExtInner.java b/client/src/main/java/org/apache/rocketmq/client/admin/MQAdminExtInner.java index bc4ca6c4..913d4f25 100644 --- a/client/src/main/java/org/apache/rocketmq/client/admin/MQAdminExtInner.java +++ b/client/src/main/java/org/apache/rocketmq/client/admin/MQAdminExtInner.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.admin; diff --git a/client/src/main/java/org/apache/rocketmq/client/common/ThreadLocalIndex.java b/client/src/main/java/org/apache/rocketmq/client/common/ThreadLocalIndex.java index 360cfdf6..391f1d1f 100644 --- a/client/src/main/java/org/apache/rocketmq/client/common/ThreadLocalIndex.java +++ b/client/src/main/java/org/apache/rocketmq/client/common/ThreadLocalIndex.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.common; @@ -22,6 +22,7 @@ import java.util.Random; public class ThreadLocalIndex { private final ThreadLocal threadLocalIndex = new ThreadLocal(); private final Random random = new Random(); + public ThreadLocalIndex(int value) { } @@ -30,7 +31,8 @@ public class ThreadLocalIndex { Integer index = this.threadLocalIndex.get(); if (null == index) { index = Math.abs(random.nextInt()); - if (index < 0) index = 0; + if (index < 0) + index = 0; this.threadLocalIndex.set(index); } @@ -45,7 +47,7 @@ public class ThreadLocalIndex { @Override public String toString() { return "ThreadLocalIndex{" + - "threadLocalIndex=" + threadLocalIndex.get() + - '}'; + "threadLocalIndex=" + threadLocalIndex.get() + + '}'; } } diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/AllocateMessageQueueStrategy.java b/client/src/main/java/org/apache/rocketmq/client/consumer/AllocateMessageQueueStrategy.java index 81a71e4b..ca692d3f 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/AllocateMessageQueueStrategy.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/AllocateMessageQueueStrategy.java @@ -16,39 +16,30 @@ */ package org.apache.rocketmq.client.consumer; -import org.apache.rocketmq.common.message.MessageQueue; - import java.util.List; - +import org.apache.rocketmq.common.message.MessageQueue; /** * Strategy Algorithm for message allocating between consumers - * */ public interface AllocateMessageQueueStrategy { /** * Allocating by consumer id * - * @param consumerGroup - * current consumer group - * @param currentCID - * current consumer id - * @param mqAll - * message queue set in current topic - * @param cidAll - * consumer set in current consumer group - * + * @param consumerGroup current consumer group + * @param currentCID current consumer id + * @param mqAll message queue set in current topic + * @param cidAll consumer set in current consumer group * @return The allocate result of given strategy */ List allocate( - final String consumerGroup, - final String currentCID, - final List mqAll, - final List cidAll + final String consumerGroup, + final String currentCID, + final List mqAll, + final List cidAll ); - /** * Algorithm name * diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/DefaultMQPullConsumer.java b/client/src/main/java/org/apache/rocketmq/client/consumer/DefaultMQPullConsumer.java index 156b3d0a..8eb1258f 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/DefaultMQPullConsumer.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/DefaultMQPullConsumer.java @@ -6,16 +6,18 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.consumer; +import java.util.HashSet; +import java.util.Set; import org.apache.rocketmq.client.ClientConfig; import org.apache.rocketmq.client.QueryResult; import org.apache.rocketmq.client.consumer.rebalance.AllocateMessageQueueAveragely; @@ -31,10 +33,6 @@ import org.apache.rocketmq.common.protocol.heartbeat.MessageModel; import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.remoting.exception.RemotingException; -import java.util.HashSet; -import java.util.Set; - - /** * Default pulling consumer * @@ -88,23 +86,19 @@ public class DefaultMQPullConsumer extends ClientConfig implements MQPullConsume private int maxReconsumeTimes = 16; - public DefaultMQPullConsumer() { this(MixAll.DEFAULT_CONSUMER_GROUP, null); } - public DefaultMQPullConsumer(final String consumerGroup, RPCHook rpcHook) { this.consumerGroup = consumerGroup; defaultMQPullConsumerImpl = new DefaultMQPullConsumerImpl(this, rpcHook); } - public DefaultMQPullConsumer(final String consumerGroup) { this(consumerGroup, null); } - public DefaultMQPullConsumer(RPCHook rpcHook) { this(MixAll.DEFAULT_CONSUMER_GROUP, rpcHook); } @@ -114,141 +108,116 @@ public class DefaultMQPullConsumer extends ClientConfig implements MQPullConsume createTopic(key, newTopic, queueNum, 0); } - @Override public void createTopic(String key, String newTopic, int queueNum, int topicSysFlag) throws MQClientException { this.defaultMQPullConsumerImpl.createTopic(key, newTopic, queueNum, topicSysFlag); } - @Override public long searchOffset(MessageQueue mq, long timestamp) throws MQClientException { return this.defaultMQPullConsumerImpl.searchOffset(mq, timestamp); } - @Override public long maxOffset(MessageQueue mq) throws MQClientException { return this.defaultMQPullConsumerImpl.maxOffset(mq); } - @Override public long minOffset(MessageQueue mq) throws MQClientException { return this.defaultMQPullConsumerImpl.minOffset(mq); } - @Override public long earliestMsgStoreTime(MessageQueue mq) throws MQClientException { return this.defaultMQPullConsumerImpl.earliestMsgStoreTime(mq); } - @Override public MessageExt viewMessage(String offsetMsgId) throws RemotingException, MQBrokerException, - InterruptedException, MQClientException { + InterruptedException, MQClientException { return this.defaultMQPullConsumerImpl.viewMessage(offsetMsgId); } - @Override public QueryResult queryMessage(String topic, String key, int maxNum, long begin, long end) - throws MQClientException, InterruptedException { + throws MQClientException, InterruptedException { return this.defaultMQPullConsumerImpl.queryMessage(topic, key, maxNum, begin, end); } - public AllocateMessageQueueStrategy getAllocateMessageQueueStrategy() { return allocateMessageQueueStrategy; } - public void setAllocateMessageQueueStrategy(AllocateMessageQueueStrategy allocateMessageQueueStrategy) { this.allocateMessageQueueStrategy = allocateMessageQueueStrategy; } - public long getBrokerSuspendMaxTimeMillis() { return brokerSuspendMaxTimeMillis; } - public void setBrokerSuspendMaxTimeMillis(long brokerSuspendMaxTimeMillis) { this.brokerSuspendMaxTimeMillis = brokerSuspendMaxTimeMillis; } - public String getConsumerGroup() { return consumerGroup; } - public void setConsumerGroup(String consumerGroup) { this.consumerGroup = consumerGroup; } - public long getConsumerPullTimeoutMillis() { return consumerPullTimeoutMillis; } - public void setConsumerPullTimeoutMillis(long consumerPullTimeoutMillis) { this.consumerPullTimeoutMillis = consumerPullTimeoutMillis; } - public long getConsumerTimeoutMillisWhenSuspend() { return consumerTimeoutMillisWhenSuspend; } - public void setConsumerTimeoutMillisWhenSuspend(long consumerTimeoutMillisWhenSuspend) { this.consumerTimeoutMillisWhenSuspend = consumerTimeoutMillisWhenSuspend; } - public MessageModel getMessageModel() { return messageModel; } - public void setMessageModel(MessageModel messageModel) { this.messageModel = messageModel; } - public MessageQueueListener getMessageQueueListener() { return messageQueueListener; } - public void setMessageQueueListener(MessageQueueListener messageQueueListener) { this.messageQueueListener = messageQueueListener; } - public Set getRegisterTopics() { return registerTopics; } - public void setRegisterTopics(Set registerTopics) { this.registerTopics = registerTopics; } - @Override public void sendMessageBack(MessageExt msg, int delayLevel) - throws RemotingException, MQBrokerException, InterruptedException, MQClientException { + throws RemotingException, MQBrokerException, InterruptedException, MQClientException { this.defaultMQPullConsumerImpl.sendMessageBack(msg, delayLevel, null); } - @Override public void sendMessageBack(MessageExt msg, int delayLevel, String brokerName) - throws RemotingException, MQBrokerException, InterruptedException, MQClientException { + throws RemotingException, MQBrokerException, InterruptedException, MQClientException { this.defaultMQPullConsumerImpl.sendMessageBack(msg, delayLevel, brokerName); } @@ -279,37 +248,37 @@ public class DefaultMQPullConsumer extends ClientConfig implements MQPullConsume @Override public PullResult pull(MessageQueue mq, String subExpression, long offset, int maxNums) - throws MQClientException, RemotingException, MQBrokerException, InterruptedException { + throws MQClientException, RemotingException, MQBrokerException, InterruptedException { return this.defaultMQPullConsumerImpl.pull(mq, subExpression, offset, maxNums); } @Override public PullResult pull(MessageQueue mq, String subExpression, long offset, int maxNums, long timeout) - throws MQClientException, RemotingException, MQBrokerException, InterruptedException { + throws MQClientException, RemotingException, MQBrokerException, InterruptedException { return this.defaultMQPullConsumerImpl.pull(mq, subExpression, offset, maxNums, timeout); } @Override public void pull(MessageQueue mq, String subExpression, long offset, int maxNums, PullCallback pullCallback) - throws MQClientException, RemotingException, InterruptedException { + throws MQClientException, RemotingException, InterruptedException { this.defaultMQPullConsumerImpl.pull(mq, subExpression, offset, maxNums, pullCallback); } @Override public void pull(MessageQueue mq, String subExpression, long offset, int maxNums, PullCallback pullCallback, long timeout) - throws MQClientException, RemotingException, InterruptedException { + throws MQClientException, RemotingException, InterruptedException { this.defaultMQPullConsumerImpl.pull(mq, subExpression, offset, maxNums, pullCallback, timeout); } @Override public PullResult pullBlockIfNotFound(MessageQueue mq, String subExpression, long offset, int maxNums) - throws MQClientException, RemotingException, MQBrokerException, InterruptedException { + throws MQClientException, RemotingException, MQBrokerException, InterruptedException { return this.defaultMQPullConsumerImpl.pullBlockIfNotFound(mq, subExpression, offset, maxNums); } @Override public void pullBlockIfNotFound(MessageQueue mq, String subExpression, long offset, int maxNums, PullCallback pullCallback) - throws MQClientException, RemotingException, InterruptedException { + throws MQClientException, RemotingException, InterruptedException { this.defaultMQPullConsumerImpl.pullBlockIfNotFound(mq, subExpression, offset, maxNums, pullCallback); } @@ -341,7 +310,7 @@ public class DefaultMQPullConsumer extends ClientConfig implements MQPullConsume @Override public void sendMessageBack(MessageExt msg, int delayLevel, String brokerName, String consumerGroup) - throws RemotingException, MQBrokerException, InterruptedException, MQClientException { + throws RemotingException, MQBrokerException, InterruptedException, MQClientException { this.defaultMQPullConsumerImpl.sendMessageBack(msg, delayLevel, brokerName, consumerGroup); } @@ -349,32 +318,26 @@ public class DefaultMQPullConsumer extends ClientConfig implements MQPullConsume return offsetStore; } - public void setOffsetStore(OffsetStore offsetStore) { this.offsetStore = offsetStore; } - public DefaultMQPullConsumerImpl getDefaultMQPullConsumerImpl() { return defaultMQPullConsumerImpl; } - public boolean isUnitMode() { return unitMode; } - public void setUnitMode(boolean isUnitMode) { this.unitMode = isUnitMode; } - public int getMaxReconsumeTimes() { return maxReconsumeTimes; } - public void setMaxReconsumeTimes(final int maxReconsumeTimes) { this.maxReconsumeTimes = maxReconsumeTimes; } diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/DefaultMQPushConsumer.java b/client/src/main/java/org/apache/rocketmq/client/consumer/DefaultMQPushConsumer.java index 228e075b..fcb3e646 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/DefaultMQPushConsumer.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/DefaultMQPushConsumer.java @@ -16,6 +16,9 @@ */ package org.apache.rocketmq.client.consumer; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; import org.apache.rocketmq.client.ClientConfig; import org.apache.rocketmq.client.QueryResult; import org.apache.rocketmq.client.consumer.listener.MessageListener; @@ -36,14 +39,8 @@ import org.apache.rocketmq.common.protocol.heartbeat.MessageModel; import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.remoting.exception.RemotingException; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - - /** * Wrapped push consumer.in fact,it works as remarkable as the pull consumer - * */ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsumer { protected final transient DefaultMQPushConsumerImpl defaultMQPushConsumerImpl; @@ -133,24 +130,20 @@ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsume private long suspendCurrentQueueTimeMillis = 1000; private long consumeTimeout = 15; - public DefaultMQPushConsumer() { this(MixAll.DEFAULT_CONSUMER_GROUP, null, new AllocateMessageQueueAveragely()); } - public DefaultMQPushConsumer(final String consumerGroup, RPCHook rpcHook, AllocateMessageQueueStrategy allocateMessageQueueStrategy) { this.consumerGroup = consumerGroup; this.allocateMessageQueueStrategy = allocateMessageQueueStrategy; defaultMQPushConsumerImpl = new DefaultMQPushConsumerImpl(this, rpcHook); } - public DefaultMQPushConsumer(RPCHook rpcHook) { this(MixAll.DEFAULT_CONSUMER_GROUP, rpcHook, new AllocateMessageQueueAveragely()); } - public DefaultMQPushConsumer(final String consumerGroup) { this(consumerGroup, null, new AllocateMessageQueueAveragely()); } @@ -160,46 +153,39 @@ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsume createTopic(key, newTopic, queueNum, 0); } - @Override public void createTopic(String key, String newTopic, int queueNum, int topicSysFlag) throws MQClientException { this.defaultMQPushConsumerImpl.createTopic(key, newTopic, queueNum, topicSysFlag); } - @Override public long searchOffset(MessageQueue mq, long timestamp) throws MQClientException { return this.defaultMQPushConsumerImpl.searchOffset(mq, timestamp); } - @Override public long maxOffset(MessageQueue mq) throws MQClientException { return this.defaultMQPushConsumerImpl.maxOffset(mq); } - @Override public long minOffset(MessageQueue mq) throws MQClientException { return this.defaultMQPushConsumerImpl.minOffset(mq); } - @Override public long earliestMsgStoreTime(MessageQueue mq) throws MQClientException { return this.defaultMQPushConsumerImpl.earliestMsgStoreTime(mq); } - @Override public MessageExt viewMessage(String offsetMsgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { return this.defaultMQPushConsumerImpl.viewMessage(offsetMsgId); } - @Override public QueryResult queryMessage(String topic, String key, int maxNum, long begin, long end) - throws MQClientException, InterruptedException { + throws MQClientException, InterruptedException { return this.defaultMQPushConsumerImpl.queryMessage(topic, key, maxNum, begin, end); } @@ -218,169 +204,137 @@ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsume return allocateMessageQueueStrategy; } - public void setAllocateMessageQueueStrategy(AllocateMessageQueueStrategy allocateMessageQueueStrategy) { this.allocateMessageQueueStrategy = allocateMessageQueueStrategy; } - public int getConsumeConcurrentlyMaxSpan() { return consumeConcurrentlyMaxSpan; } - public void setConsumeConcurrentlyMaxSpan(int consumeConcurrentlyMaxSpan) { this.consumeConcurrentlyMaxSpan = consumeConcurrentlyMaxSpan; } - public ConsumeFromWhere getConsumeFromWhere() { return consumeFromWhere; } - public void setConsumeFromWhere(ConsumeFromWhere consumeFromWhere) { this.consumeFromWhere = consumeFromWhere; } - public int getConsumeMessageBatchMaxSize() { return consumeMessageBatchMaxSize; } - public void setConsumeMessageBatchMaxSize(int consumeMessageBatchMaxSize) { this.consumeMessageBatchMaxSize = consumeMessageBatchMaxSize; } - public String getConsumerGroup() { return consumerGroup; } - public void setConsumerGroup(String consumerGroup) { this.consumerGroup = consumerGroup; } - public int getConsumeThreadMax() { return consumeThreadMax; } - public void setConsumeThreadMax(int consumeThreadMax) { this.consumeThreadMax = consumeThreadMax; } - public int getConsumeThreadMin() { return consumeThreadMin; } - public void setConsumeThreadMin(int consumeThreadMin) { this.consumeThreadMin = consumeThreadMin; } - public DefaultMQPushConsumerImpl getDefaultMQPushConsumerImpl() { return defaultMQPushConsumerImpl; } - public MessageListener getMessageListener() { return messageListener; } - public void setMessageListener(MessageListener messageListener) { this.messageListener = messageListener; } - public MessageModel getMessageModel() { return messageModel; } - public void setMessageModel(MessageModel messageModel) { this.messageModel = messageModel; } - public int getPullBatchSize() { return pullBatchSize; } - public void setPullBatchSize(int pullBatchSize) { this.pullBatchSize = pullBatchSize; } - public long getPullInterval() { return pullInterval; } - public void setPullInterval(long pullInterval) { this.pullInterval = pullInterval; } - public int getPullThresholdForQueue() { return pullThresholdForQueue; } - public void setPullThresholdForQueue(int pullThresholdForQueue) { this.pullThresholdForQueue = pullThresholdForQueue; } - public Map getSubscription() { return subscription; } - public void setSubscription(Map subscription) { this.subscription = subscription; } - @Override public void sendMessageBack(MessageExt msg, int delayLevel) - throws RemotingException, MQBrokerException, InterruptedException, MQClientException { + throws RemotingException, MQBrokerException, InterruptedException, MQClientException { this.defaultMQPushConsumerImpl.sendMessageBack(msg, delayLevel, null); } - @Override public void sendMessageBack(MessageExt msg, int delayLevel, String brokerName) - throws RemotingException, MQBrokerException, InterruptedException, MQClientException { + throws RemotingException, MQBrokerException, InterruptedException, MQClientException { this.defaultMQPushConsumerImpl.sendMessageBack(msg, delayLevel, brokerName); } - @Override public Set fetchSubscribeMessageQueues(String topic) throws MQClientException { return this.defaultMQPushConsumerImpl.fetchSubscribeMessageQueues(topic); } - @Override public void start() throws MQClientException { this.defaultMQPushConsumerImpl.start(); } - @Override public void shutdown() { this.defaultMQPushConsumerImpl.shutdown(); } - @Override @Deprecated public void registerMessageListener(MessageListener messageListener) { @@ -388,127 +342,104 @@ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsume this.defaultMQPushConsumerImpl.registerMessageListener(messageListener); } - @Override public void registerMessageListener(MessageListenerConcurrently messageListener) { this.messageListener = messageListener; this.defaultMQPushConsumerImpl.registerMessageListener(messageListener); } - @Override public void registerMessageListener(MessageListenerOrderly messageListener) { this.messageListener = messageListener; this.defaultMQPushConsumerImpl.registerMessageListener(messageListener); } - @Override public void subscribe(String topic, String subExpression) throws MQClientException { this.defaultMQPushConsumerImpl.subscribe(topic, subExpression); } - @Override public void subscribe(String topic, String fullClassName, String filterClassSource) throws MQClientException { this.defaultMQPushConsumerImpl.subscribe(topic, fullClassName, filterClassSource); } - @Override public void unsubscribe(String topic) { this.defaultMQPushConsumerImpl.unsubscribe(topic); } - @Override public void updateCorePoolSize(int corePoolSize) { this.defaultMQPushConsumerImpl.updateCorePoolSize(corePoolSize); } - @Override public void suspend() { this.defaultMQPushConsumerImpl.suspend(); } - @Override public void resume() { this.defaultMQPushConsumerImpl.resume(); } - public OffsetStore getOffsetStore() { return offsetStore; } - public void setOffsetStore(OffsetStore offsetStore) { this.offsetStore = offsetStore; } - public String getConsumeTimestamp() { return consumeTimestamp; } - public void setConsumeTimestamp(String consumeTimestamp) { this.consumeTimestamp = consumeTimestamp; } - public boolean isPostSubscriptionWhenPull() { return postSubscriptionWhenPull; } - public void setPostSubscriptionWhenPull(boolean postSubscriptionWhenPull) { this.postSubscriptionWhenPull = postSubscriptionWhenPull; } - public boolean isUnitMode() { return unitMode; } - public void setUnitMode(boolean isUnitMode) { this.unitMode = isUnitMode; } - public long getAdjustThreadPoolNumsThreshold() { return adjustThreadPoolNumsThreshold; } - public void setAdjustThreadPoolNumsThreshold(long adjustThreadPoolNumsThreshold) { this.adjustThreadPoolNumsThreshold = adjustThreadPoolNumsThreshold; } - public int getMaxReconsumeTimes() { return maxReconsumeTimes; } - public void setMaxReconsumeTimes(final int maxReconsumeTimes) { this.maxReconsumeTimes = maxReconsumeTimes; } - public long getSuspendCurrentQueueTimeMillis() { return suspendCurrentQueueTimeMillis; } - public void setSuspendCurrentQueueTimeMillis(final long suspendCurrentQueueTimeMillis) { this.suspendCurrentQueueTimeMillis = suspendCurrentQueueTimeMillis; } - public long getConsumeTimeout() { return consumeTimeout; } diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/MQConsumer.java b/client/src/main/java/org/apache/rocketmq/client/consumer/MQConsumer.java index 9d9c72b7..343a0a25 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/MQConsumer.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/MQConsumer.java @@ -6,16 +6,17 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.consumer; +import java.util.Set; import org.apache.rocketmq.client.MQAdmin; import org.apache.rocketmq.client.exception.MQBrokerException; import org.apache.rocketmq.client.exception.MQClientException; @@ -23,9 +24,6 @@ import org.apache.rocketmq.common.message.MessageExt; import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.remoting.exception.RemotingException; -import java.util.Set; - - /** * Message queue consumer interface * @@ -44,8 +42,7 @@ public interface MQConsumer extends MQAdmin { */ @Deprecated void sendMessageBack(final MessageExt msg, final int delayLevel) throws RemotingException, - MQBrokerException, InterruptedException, MQClientException; - + MQBrokerException, InterruptedException, MQClientException; /** * If consuming failure,message will be send back to the broker,and delay consuming some time @@ -60,8 +57,7 @@ public interface MQConsumer extends MQAdmin { * @throws MQClientException */ void sendMessageBack(final MessageExt msg, final int delayLevel, final String brokerName) - throws RemotingException, MQBrokerException, InterruptedException, MQClientException; - + throws RemotingException, MQBrokerException, InterruptedException, MQClientException; /** * Fetch message queues from consumer cache according to the topic diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/MQPullConsumer.java b/client/src/main/java/org/apache/rocketmq/client/consumer/MQPullConsumer.java index 2335e3db..d199f8aa 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/MQPullConsumer.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/MQPullConsumer.java @@ -6,25 +6,23 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.consumer; +import java.util.Set; import org.apache.rocketmq.client.exception.MQBrokerException; import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.common.message.MessageExt; import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.remoting.exception.RemotingException; -import java.util.Set; - - /** * Pulling consumer interface * @@ -37,13 +35,11 @@ public interface MQPullConsumer extends MQConsumer { */ void start() throws MQClientException; - /** * Shutdown the consumer */ void shutdown(); - /** * Register the message queue listener * @@ -52,7 +48,6 @@ public interface MQPullConsumer extends MQConsumer { */ void registerMessageQueueListener(final String topic, final MessageQueueListener listener); - /** * Pulling the messages,not blocking * @@ -74,9 +69,8 @@ public interface MQPullConsumer extends MQConsumer { * @throws RemotingException */ PullResult pull(final MessageQueue mq, final String subExpression, final long offset, - final int maxNums) throws MQClientException, RemotingException, MQBrokerException, - InterruptedException; - + final int maxNums) throws MQClientException, RemotingException, MQBrokerException, + InterruptedException; /** * Pulling the messages in the specified timeout @@ -95,9 +89,8 @@ public interface MQPullConsumer extends MQConsumer { * @throws InterruptedException */ PullResult pull(final MessageQueue mq, final String subExpression, final long offset, - final int maxNums, final long timeout) throws MQClientException, RemotingException, - MQBrokerException, InterruptedException; - + final int maxNums, final long timeout) throws MQClientException, RemotingException, + MQBrokerException, InterruptedException; /** * Pulling the messages in a async. way @@ -113,8 +106,8 @@ public interface MQPullConsumer extends MQConsumer { * @throws InterruptedException */ void pull(final MessageQueue mq, final String subExpression, final long offset, final int maxNums, - final PullCallback pullCallback) throws MQClientException, RemotingException, - InterruptedException; + final PullCallback pullCallback) throws MQClientException, RemotingException, + InterruptedException; /** * Pulling the messages in a async. way @@ -131,9 +124,8 @@ public interface MQPullConsumer extends MQConsumer { * @throws InterruptedException */ void pull(final MessageQueue mq, final String subExpression, final long offset, final int maxNums, - final PullCallback pullCallback, long timeout) throws MQClientException, RemotingException, - InterruptedException; - + final PullCallback pullCallback, long timeout) throws MQClientException, RemotingException, + InterruptedException; /** * Pulling the messages,if no message arrival,blocking some time @@ -151,9 +143,8 @@ public interface MQPullConsumer extends MQConsumer { * @throws InterruptedException */ PullResult pullBlockIfNotFound(final MessageQueue mq, final String subExpression, - final long offset, final int maxNums) throws MQClientException, RemotingException, - MQBrokerException, InterruptedException; - + final long offset, final int maxNums) throws MQClientException, RemotingException, + MQBrokerException, InterruptedException; /** * Pulling the messages through callback function,if no message arrival,blocking. @@ -169,9 +160,8 @@ public interface MQPullConsumer extends MQConsumer { * @throws InterruptedException */ void pullBlockIfNotFound(final MessageQueue mq, final String subExpression, final long offset, - final int maxNums, final PullCallback pullCallback) throws MQClientException, RemotingException, - InterruptedException; - + final int maxNums, final PullCallback pullCallback) throws MQClientException, RemotingException, + InterruptedException; /** * Update the offset @@ -183,7 +173,6 @@ public interface MQPullConsumer extends MQConsumer { */ void updateConsumeOffset(final MessageQueue mq, final long offset) throws MQClientException; - /** * Fetch the offset * @@ -196,7 +185,6 @@ public interface MQPullConsumer extends MQConsumer { */ long fetchConsumeOffset(final MessageQueue mq, final boolean fromStore) throws MQClientException; - /** * Fetch the message queues according to the topic * @@ -224,5 +212,5 @@ public interface MQPullConsumer extends MQConsumer { * @throws MQClientException */ void sendMessageBack(MessageExt msg, int delayLevel, String brokerName, String consumerGroup) - throws RemotingException, MQBrokerException, InterruptedException, MQClientException; + throws RemotingException, MQBrokerException, InterruptedException, MQClientException; } diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/MQPullConsumerScheduleService.java b/client/src/main/java/org/apache/rocketmq/client/consumer/MQPullConsumerScheduleService.java index da8ffb56..ec747e20 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/MQPullConsumerScheduleService.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/MQPullConsumerScheduleService.java @@ -16,34 +16,31 @@ */ package org.apache.rocketmq.client.consumer; -import org.apache.rocketmq.client.exception.MQClientException; -import org.apache.rocketmq.client.log.ClientLogger; -import org.apache.rocketmq.common.ThreadFactoryImpl; -import org.apache.rocketmq.common.message.MessageQueue; -import org.apache.rocketmq.common.protocol.heartbeat.MessageModel; -import org.slf4j.Logger; - import java.util.Iterator; import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; - +import org.apache.rocketmq.client.exception.MQClientException; +import org.apache.rocketmq.client.log.ClientLogger; +import org.apache.rocketmq.common.ThreadFactoryImpl; +import org.apache.rocketmq.common.message.MessageQueue; +import org.apache.rocketmq.common.protocol.heartbeat.MessageModel; +import org.slf4j.Logger; /** * Schedule service for pull consumer - * */ public class MQPullConsumerScheduleService { private final Logger log = ClientLogger.getLog(); private final MessageQueueListener messageQueueListener = new MessageQueueListenerImpl(); private final ConcurrentHashMap taskTable = - new ConcurrentHashMap(); + new ConcurrentHashMap(); private DefaultMQPullConsumer defaultMQPullConsumer; private int pullThreadNums = 20; private ConcurrentHashMap callbackTable = - new ConcurrentHashMap(); + new ConcurrentHashMap(); private ScheduledThreadPoolExecutor scheduledThreadPoolExecutor; public MQPullConsumerScheduleService(final String consumerGroup) { @@ -76,8 +73,8 @@ public class MQPullConsumerScheduleService { public void start() throws MQClientException { final String group = this.defaultMQPullConsumer.getConsumerGroup(); this.scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor( - this.pullThreadNums, - new ThreadFactoryImpl("PullMsgThread-" + group) + this.pullThreadNums, + new ThreadFactoryImpl("PullMsgThread-" + group) ); this.defaultMQPullConsumer.setMessageQueueListener(this.messageQueueListener); @@ -85,7 +82,7 @@ public class MQPullConsumerScheduleService { this.defaultMQPullConsumer.start(); log.info("MQPullConsumerScheduleService start OK, {} {}", - this.defaultMQPullConsumer.getConsumerGroup(), this.callbackTable); + this.defaultMQPullConsumer.getConsumerGroup(), this.callbackTable); } public void registerPullTaskCallback(final String topic, final PullTaskCallback callback) { @@ -139,7 +136,7 @@ public class MQPullConsumerScheduleService { @Override public void messageQueueChanged(String topic, Set mqAll, Set mqDivided) { MessageModel messageModel = - MQPullConsumerScheduleService.this.defaultMQPullConsumer.getMessageModel(); + MQPullConsumerScheduleService.this.defaultMQPullConsumer.getMessageModel(); switch (messageModel) { case BROADCASTING: MQPullConsumerScheduleService.this.putTask(topic, mqAll); @@ -157,18 +154,16 @@ public class MQPullConsumerScheduleService { private final MessageQueue messageQueue; private volatile boolean cancelled = false; - public PullTaskImpl(final MessageQueue messageQueue) { this.messageQueue = messageQueue; } - @Override public void run() { String topic = this.messageQueue.getTopic(); if (!this.isCancelled()) { PullTaskCallback pullTaskCallback = - MQPullConsumerScheduleService.this.callbackTable.get(topic); + MQPullConsumerScheduleService.this.callbackTable.get(topic); if (pullTaskCallback != null) { final PullTaskContext context = new PullTaskContext(); context.setPullConsumer(MQPullConsumerScheduleService.this.defaultMQPullConsumer); @@ -181,7 +176,7 @@ public class MQPullConsumerScheduleService { if (!this.isCancelled()) { MQPullConsumerScheduleService.this.scheduledThreadPoolExecutor.schedule(this, - context.getPullNextDelayTimeMillis(), TimeUnit.MILLISECONDS); + context.getPullNextDelayTimeMillis(), TimeUnit.MILLISECONDS); } else { log.warn("The Pull Task is cancelled after doPullTask, {}", messageQueue); } @@ -193,17 +188,14 @@ public class MQPullConsumerScheduleService { } } - public boolean isCancelled() { return cancelled; } - public void setCancelled(boolean cancelled) { this.cancelled = cancelled; } - public MessageQueue getMessageQueue() { return messageQueue; } diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/MQPushConsumer.java b/client/src/main/java/org/apache/rocketmq/client/consumer/MQPushConsumer.java index b04956c8..1b969bdf 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/MQPushConsumer.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/MQPushConsumer.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.consumer; @@ -21,7 +21,6 @@ import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently; import org.apache.rocketmq.client.consumer.listener.MessageListenerOrderly; import org.apache.rocketmq.client.exception.MQClientException; - /** * Push consumer * @@ -34,13 +33,11 @@ public interface MQPushConsumer extends MQConsumer { */ void start() throws MQClientException; - /** * Shutdown the consumer */ void shutdown(); - /** * Register the message listener * @@ -49,13 +46,10 @@ public interface MQPushConsumer extends MQConsumer { @Deprecated void registerMessageListener(MessageListener messageListener); - void registerMessageListener(final MessageListenerConcurrently messageListener); - void registerMessageListener(final MessageListenerOrderly messageListener); - /** * Subscribe some topic * @@ -69,7 +63,6 @@ public interface MQPushConsumer extends MQConsumer { */ void subscribe(final String topic, final String subExpression) throws MQClientException; - /** * Subscribe some topic * @@ -85,7 +78,6 @@ public interface MQPushConsumer extends MQConsumer { */ void subscribe(final String topic, final String fullClassName, final String filterClassSource) throws MQClientException; - /** * Unsubscribe consumption some topic * @@ -94,7 +86,6 @@ public interface MQPushConsumer extends MQConsumer { */ void unsubscribe(final String topic); - /** * Update the consumer thread pool size Dynamically * @@ -102,13 +93,11 @@ public interface MQPushConsumer extends MQConsumer { */ void updateCorePoolSize(int corePoolSize); - /** * Suspend the consumption */ void suspend(); - /** * Resume the consumption */ diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/MessageQueueListener.java b/client/src/main/java/org/apache/rocketmq/client/consumer/MessageQueueListener.java index 7a083483..0cc2dc47 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/MessageQueueListener.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/MessageQueueListener.java @@ -6,20 +6,18 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.consumer; -import org.apache.rocketmq.common.message.MessageQueue; - import java.util.Set; - +import org.apache.rocketmq.common.message.MessageQueue; /** * A MessageQueueListener is implemented by the application and may be specified when a message queue changed @@ -35,5 +33,5 @@ public interface MessageQueueListener { * collection of queues,assigned to the current consumer */ void messageQueueChanged(final String topic, final Set mqAll, - final Set mqDivided); + final Set mqDivided); } diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/PullCallback.java b/client/src/main/java/org/apache/rocketmq/client/consumer/PullCallback.java index cf554c47..06e47d95 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/PullCallback.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/PullCallback.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.consumer; diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/PullResult.java b/client/src/main/java/org/apache/rocketmq/client/consumer/PullResult.java index 1cb23cea..e494f748 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/PullResult.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/PullResult.java @@ -6,20 +6,18 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.consumer; -import org.apache.rocketmq.common.message.MessageExt; - import java.util.List; - +import org.apache.rocketmq.common.message.MessageExt; public class PullResult { private final PullStatus pullStatus; @@ -28,9 +26,8 @@ public class PullResult { private final long maxOffset; private List msgFoundList; - public PullResult(PullStatus pullStatus, long nextBeginOffset, long minOffset, long maxOffset, - List msgFoundList) { + List msgFoundList) { super(); this.pullStatus = pullStatus; this.nextBeginOffset = nextBeginOffset; @@ -39,41 +36,34 @@ public class PullResult { this.msgFoundList = msgFoundList; } - public PullStatus getPullStatus() { return pullStatus; } - public long getNextBeginOffset() { return nextBeginOffset; } - public long getMinOffset() { return minOffset; } - public long getMaxOffset() { return maxOffset; } - public List getMsgFoundList() { return msgFoundList; } - public void setMsgFoundList(List msgFoundList) { this.msgFoundList = msgFoundList; } - @Override public String toString() { return "PullResult [pullStatus=" + pullStatus + ", nextBeginOffset=" + nextBeginOffset - + ", minOffset=" + minOffset + ", maxOffset=" + maxOffset + ", msgFoundList=" - + (msgFoundList == null ? 0 : msgFoundList.size()) + "]"; + + ", minOffset=" + minOffset + ", maxOffset=" + maxOffset + ", msgFoundList=" + + (msgFoundList == null ? 0 : msgFoundList.size()) + "]"; } } diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/PullStatus.java b/client/src/main/java/org/apache/rocketmq/client/consumer/PullStatus.java index b2a3c8c7..a400d90f 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/PullStatus.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/PullStatus.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.consumer; diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/PullTaskCallback.java b/client/src/main/java/org/apache/rocketmq/client/consumer/PullTaskCallback.java index dc74bcab..bc9a867c 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/PullTaskCallback.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/PullTaskCallback.java @@ -6,19 +6,18 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.consumer; import org.apache.rocketmq.common.message.MessageQueue; - public interface PullTaskCallback { void doPullTask(final MessageQueue mq, final PullTaskContext context); } diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/PullTaskContext.java b/client/src/main/java/org/apache/rocketmq/client/consumer/PullTaskContext.java index ba66a1f3..f0114ae8 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/PullTaskContext.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/PullTaskContext.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.consumer; @@ -22,22 +22,18 @@ public class PullTaskContext { private MQPullConsumer pullConsumer; - public int getPullNextDelayTimeMillis() { return pullNextDelayTimeMillis; } - public void setPullNextDelayTimeMillis(int pullNextDelayTimeMillis) { this.pullNextDelayTimeMillis = pullNextDelayTimeMillis; } - public MQPullConsumer getPullConsumer() { return pullConsumer; } - public void setPullConsumer(MQPullConsumer pullConsumer) { this.pullConsumer = pullConsumer; } diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/listener/ConsumeConcurrentlyContext.java b/client/src/main/java/org/apache/rocketmq/client/consumer/listener/ConsumeConcurrentlyContext.java index 981ceaf5..40ac6c18 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/listener/ConsumeConcurrentlyContext.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/listener/ConsumeConcurrentlyContext.java @@ -18,10 +18,8 @@ package org.apache.rocketmq.client.consumer.listener; import org.apache.rocketmq.common.message.MessageQueue; - /** * Consumer concurrent consumption context - * */ public class ConsumeConcurrentlyContext { private final MessageQueue messageQueue; @@ -38,27 +36,22 @@ public class ConsumeConcurrentlyContext { this.messageQueue = messageQueue; } - public int getDelayLevelWhenNextConsume() { return delayLevelWhenNextConsume; } - public void setDelayLevelWhenNextConsume(int delayLevelWhenNextConsume) { this.delayLevelWhenNextConsume = delayLevelWhenNextConsume; } - public MessageQueue getMessageQueue() { return messageQueue; } - public int getAckIndex() { return ackIndex; } - public void setAckIndex(int ackIndex) { this.ackIndex = ackIndex; } diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/listener/ConsumeConcurrentlyStatus.java b/client/src/main/java/org/apache/rocketmq/client/consumer/listener/ConsumeConcurrentlyStatus.java index cd666993..08308429 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/listener/ConsumeConcurrentlyStatus.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/listener/ConsumeConcurrentlyStatus.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.consumer.listener; diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/listener/ConsumeOrderlyContext.java b/client/src/main/java/org/apache/rocketmq/client/consumer/listener/ConsumeOrderlyContext.java index 3c1ef3de..405781b4 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/listener/ConsumeOrderlyContext.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/listener/ConsumeOrderlyContext.java @@ -6,19 +6,18 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.consumer.listener; import org.apache.rocketmq.common.message.MessageQueue; - /** * Consumer Orderly consumption context * @@ -28,32 +27,26 @@ public class ConsumeOrderlyContext { private boolean autoCommit = true; private long suspendCurrentQueueTimeMillis = -1; - public ConsumeOrderlyContext(MessageQueue messageQueue) { this.messageQueue = messageQueue; } - public boolean isAutoCommit() { return autoCommit; } - public void setAutoCommit(boolean autoCommit) { this.autoCommit = autoCommit; } - public MessageQueue getMessageQueue() { return messageQueue; } - public long getSuspendCurrentQueueTimeMillis() { return suspendCurrentQueueTimeMillis; } - public void setSuspendCurrentQueueTimeMillis(long suspendCurrentQueueTimeMillis) { this.suspendCurrentQueueTimeMillis = suspendCurrentQueueTimeMillis; } diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/listener/ConsumeOrderlyStatus.java b/client/src/main/java/org/apache/rocketmq/client/consumer/listener/ConsumeOrderlyStatus.java index 2e55d89f..0c6c6e67 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/listener/ConsumeOrderlyStatus.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/listener/ConsumeOrderlyStatus.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.consumer.listener; diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/listener/ConsumeReturnType.java b/client/src/main/java/org/apache/rocketmq/client/consumer/listener/ConsumeReturnType.java index 99083b4c..5de4deda 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/listener/ConsumeReturnType.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/listener/ConsumeReturnType.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.consumer.listener; diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/listener/MessageListener.java b/client/src/main/java/org/apache/rocketmq/client/consumer/listener/MessageListener.java index 5d05452a..2a9e5c95 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/listener/MessageListener.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/listener/MessageListener.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.consumer.listener; diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/listener/MessageListenerConcurrently.java b/client/src/main/java/org/apache/rocketmq/client/consumer/listener/MessageListenerConcurrently.java index 1c59ef74..c0831573 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/listener/MessageListenerConcurrently.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/listener/MessageListenerConcurrently.java @@ -6,20 +6,18 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.consumer.listener; -import org.apache.rocketmq.common.message.MessageExt; - import java.util.List; - +import org.apache.rocketmq.common.message.MessageExt; /** * A MessageListenerConcurrently object is used to receive asynchronously delivered messages concurrently @@ -37,5 +35,5 @@ public interface MessageListenerConcurrently extends MessageListener { * @return The consume status */ ConsumeConcurrentlyStatus consumeMessage(final List msgs, - final ConsumeConcurrentlyContext context); + final ConsumeConcurrentlyContext context); } diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/listener/MessageListenerOrderly.java b/client/src/main/java/org/apache/rocketmq/client/consumer/listener/MessageListenerOrderly.java index 5de976fb..57a553a6 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/listener/MessageListenerOrderly.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/listener/MessageListenerOrderly.java @@ -6,20 +6,18 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.consumer.listener; -import org.apache.rocketmq.common.message.MessageExt; - import java.util.List; - +import org.apache.rocketmq.common.message.MessageExt; /** * A MessageListenerConcurrently object is used to receive asynchronously delivered messages orderly.one queue,one thread @@ -37,5 +35,5 @@ public interface MessageListenerOrderly extends MessageListener { * @return The consume status */ ConsumeOrderlyStatus consumeMessage(final List msgs, - final ConsumeOrderlyContext context); + final ConsumeOrderlyContext context); } diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueAveragely.java b/client/src/main/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueAveragely.java index 218f659f..256c639c 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueAveragely.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueAveragely.java @@ -16,25 +16,22 @@ */ package org.apache.rocketmq.client.consumer.rebalance; +import java.util.ArrayList; +import java.util.List; import org.apache.rocketmq.client.consumer.AllocateMessageQueueStrategy; import org.apache.rocketmq.client.log.ClientLogger; import org.apache.rocketmq.common.message.MessageQueue; import org.slf4j.Logger; -import java.util.ArrayList; -import java.util.List; - - /** * Average Hashing queue algorithm - * */ public class AllocateMessageQueueAveragely implements AllocateMessageQueueStrategy { private final Logger log = ClientLogger.getLog(); @Override public List allocate(String consumerGroup, String currentCID, List mqAll, - List cidAll) { + List cidAll) { if (currentCID == null || currentCID.length() < 1) { throw new IllegalArgumentException("currentCID is empty"); } @@ -48,17 +45,17 @@ public class AllocateMessageQueueAveragely implements AllocateMessageQueueStrate List result = new ArrayList(); if (!cidAll.contains(currentCID)) { log.info("[BUG] ConsumerGroup: {} The consumerId: {} not in cidAll: {}", - consumerGroup, - currentCID, - cidAll); + consumerGroup, + currentCID, + cidAll); return result; } int index = cidAll.indexOf(currentCID); int mod = mqAll.size() % cidAll.size(); int averageSize = - mqAll.size() <= cidAll.size() ? 1 : (mod > 0 && index < mod ? mqAll.size() / cidAll.size() - + 1 : mqAll.size() / cidAll.size()); + mqAll.size() <= cidAll.size() ? 1 : (mod > 0 && index < mod ? mqAll.size() / cidAll.size() + + 1 : mqAll.size() / cidAll.size()); int startIndex = (mod > 0 && index < mod) ? index * averageSize : index * averageSize + mod; int range = Math.min(averageSize, mqAll.size() - startIndex); for (int i = 0; i < range; i++) { diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueAveragelyByCircle.java b/client/src/main/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueAveragelyByCircle.java index d612d4f4..5df5cd2f 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueAveragelyByCircle.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueAveragelyByCircle.java @@ -16,25 +16,22 @@ */ package org.apache.rocketmq.client.consumer.rebalance; +import java.util.ArrayList; +import java.util.List; import org.apache.rocketmq.client.consumer.AllocateMessageQueueStrategy; import org.apache.rocketmq.client.log.ClientLogger; import org.apache.rocketmq.common.message.MessageQueue; import org.slf4j.Logger; -import java.util.ArrayList; -import java.util.List; - - /** * Cycle average Hashing queue algorithm - * */ public class AllocateMessageQueueAveragelyByCircle implements AllocateMessageQueueStrategy { private final Logger log = ClientLogger.getLog(); @Override public List allocate(String consumerGroup, String currentCID, List mqAll, - List cidAll) { + List cidAll) { if (currentCID == null || currentCID.length() < 1) { throw new IllegalArgumentException("currentCID is empty"); } @@ -48,9 +45,9 @@ public class AllocateMessageQueueAveragelyByCircle implements AllocateMessageQue List result = new ArrayList(); if (!cidAll.contains(currentCID)) { log.info("[BUG] ConsumerGroup: {} The consumerId: {} not in cidAll: {}", - consumerGroup, - currentCID, - cidAll); + consumerGroup, + currentCID, + cidAll); return result; } diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueByConfig.java b/client/src/main/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueByConfig.java index c8fe2d11..387822d6 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueByConfig.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueByConfig.java @@ -6,28 +6,26 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.consumer.rebalance; +import java.util.List; import org.apache.rocketmq.client.consumer.AllocateMessageQueueStrategy; import org.apache.rocketmq.common.message.MessageQueue; -import java.util.List; - - public class AllocateMessageQueueByConfig implements AllocateMessageQueueStrategy { private List messageQueueList; @Override public List allocate(String consumerGroup, String currentCID, List mqAll, - List cidAll) { + List cidAll) { return this.messageQueueList; } @@ -40,7 +38,6 @@ public class AllocateMessageQueueByConfig implements AllocateMessageQueueStrateg return messageQueueList; } - public void setMessageQueueList(List messageQueueList) { this.messageQueueList = messageQueueList; } diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueByMachineRoom.java b/client/src/main/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueByMachineRoom.java index adfc124b..a154f89a 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueByMachineRoom.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueByMachineRoom.java @@ -6,23 +6,21 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.consumer.rebalance; -import org.apache.rocketmq.client.consumer.AllocateMessageQueueStrategy; -import org.apache.rocketmq.common.message.MessageQueue; - import java.util.ArrayList; import java.util.List; import java.util.Set; - +import org.apache.rocketmq.client.consumer.AllocateMessageQueueStrategy; +import org.apache.rocketmq.common.message.MessageQueue; /** * Computer room Hashing queue algorithm, such as Alipay logic room @@ -32,7 +30,7 @@ public class AllocateMessageQueueByMachineRoom implements AllocateMessageQueueSt @Override public List allocate(String consumerGroup, String currentCID, List mqAll, - List cidAll) { + List cidAll) { List result = new ArrayList(); int currentIndex = cidAll.indexOf(currentCID); if (currentIndex < 0) { @@ -68,7 +66,6 @@ public class AllocateMessageQueueByMachineRoom implements AllocateMessageQueueSt return consumeridcs; } - public void setConsumeridcs(Set consumeridcs) { this.consumeridcs = consumeridcs; } diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/store/LocalFileOffsetStore.java b/client/src/main/java/org/apache/rocketmq/client/consumer/store/LocalFileOffsetStore.java index bdaeb580..053ade2f 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/store/LocalFileOffsetStore.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/store/LocalFileOffsetStore.java @@ -16,6 +16,13 @@ */ package org.apache.rocketmq.client.consumer.store; +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicLong; import org.apache.rocketmq.client.exception.MQBrokerException; import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.client.impl.factory.MQClientInstance; @@ -27,41 +34,29 @@ import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.remoting.exception.RemotingException; import org.slf4j.Logger; -import java.io.File; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicLong; - - /** * Local storage implementation - * */ public class LocalFileOffsetStore implements OffsetStore { public final static String LOCAL_OFFSET_STORE_DIR = System.getProperty( - "rocketmq.client.localOffsetStoreDir", - System.getProperty("user.home") + File.separator + ".rocketmq_offsets"); + "rocketmq.client.localOffsetStoreDir", + System.getProperty("user.home") + File.separator + ".rocketmq_offsets"); private final static Logger log = ClientLogger.getLog(); private final MQClientInstance mQClientFactory; private final String groupName; private final String storePath; private ConcurrentHashMap offsetTable = - new ConcurrentHashMap(); - + new ConcurrentHashMap(); public LocalFileOffsetStore(MQClientInstance mQClientFactory, String groupName) { this.mQClientFactory = mQClientFactory; this.groupName = groupName; this.storePath = LOCAL_OFFSET_STORE_DIR + File.separator + // - this.mQClientFactory.getClientId() + File.separator + // - this.groupName + File.separator + // - "offsets.json"; + this.mQClientFactory.getClientId() + File.separator + // + this.groupName + File.separator + // + "offsets.json"; } - @Override public void load() throws MQClientException { OffsetSerializeWrapper offsetSerializeWrapper = this.readLocalOffset(); @@ -71,14 +66,13 @@ public class LocalFileOffsetStore implements OffsetStore { for (MessageQueue mq : offsetSerializeWrapper.getOffsetTable().keySet()) { AtomicLong offset = offsetSerializeWrapper.getOffsetTable().get(mq); log.info("load consumer's offset, {} {} {}", - this.groupName, - mq, - offset.get()); + this.groupName, + mq, + offset.get()); } } } - @Override public void updateOffset(MessageQueue mq, long offset, boolean increaseOnly) { if (mq != null) { @@ -97,7 +91,6 @@ public class LocalFileOffsetStore implements OffsetStore { } } - @Override public long readOffset(final MessageQueue mq, final ReadOffsetType type) { if (mq != null) { @@ -134,7 +127,6 @@ public class LocalFileOffsetStore implements OffsetStore { return -1; } - @Override public void persistAll(Set mqs) { if (null == mqs || mqs.isEmpty()) @@ -158,7 +150,6 @@ public class LocalFileOffsetStore implements OffsetStore { } } - @Override public void persist(MessageQueue mq) { } @@ -170,7 +161,7 @@ public class LocalFileOffsetStore implements OffsetStore { @Override public void updateConsumeOffsetToBroker(final MessageQueue mq, final long offset, final boolean isOneway) - throws RemotingException, MQBrokerException, InterruptedException, MQClientException { + throws RemotingException, MQBrokerException, InterruptedException, MQClientException { } @@ -196,7 +187,7 @@ public class LocalFileOffsetStore implements OffsetStore { OffsetSerializeWrapper offsetSerializeWrapper = null; try { offsetSerializeWrapper = - OffsetSerializeWrapper.fromJson(content, OffsetSerializeWrapper.class); + OffsetSerializeWrapper.fromJson(content, OffsetSerializeWrapper.class); } catch (Exception e) { log.warn("readLocalOffset Exception, and try to correct", e); return this.readLocalOffsetBak(); @@ -212,12 +203,12 @@ public class LocalFileOffsetStore implements OffsetStore { OffsetSerializeWrapper offsetSerializeWrapper = null; try { offsetSerializeWrapper = - OffsetSerializeWrapper.fromJson(content, OffsetSerializeWrapper.class); + OffsetSerializeWrapper.fromJson(content, OffsetSerializeWrapper.class); } catch (Exception e) { log.warn("readLocalOffset Exception", e); throw new MQClientException("readLocalOffset Exception, maybe fastjson version too low" // - + FAQUrl.suggestTodo(FAQUrl.LOAD_JSON_EXCEPTION), // - e); + + FAQUrl.suggestTodo(FAQUrl.LOAD_JSON_EXCEPTION), // + e); } return offsetSerializeWrapper; } diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/store/OffsetSerializeWrapper.java b/client/src/main/java/org/apache/rocketmq/client/consumer/store/OffsetSerializeWrapper.java index a9fadf2a..4954f6f5 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/store/OffsetSerializeWrapper.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/store/OffsetSerializeWrapper.java @@ -6,22 +6,20 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.consumer.store; -import org.apache.rocketmq.common.message.MessageQueue; -import org.apache.rocketmq.remoting.protocol.RemotingSerializable; - import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicLong; - +import org.apache.rocketmq.common.message.MessageQueue; +import org.apache.rocketmq.remoting.protocol.RemotingSerializable; /** * Wrapper class for offset serialization @@ -29,7 +27,7 @@ import java.util.concurrent.atomic.AtomicLong; */ public class OffsetSerializeWrapper extends RemotingSerializable { private ConcurrentHashMap offsetTable = - new ConcurrentHashMap(); + new ConcurrentHashMap(); public ConcurrentHashMap getOffsetTable() { return offsetTable; diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/store/OffsetStore.java b/client/src/main/java/org/apache/rocketmq/client/consumer/store/OffsetStore.java index 334f0a10..592796f6 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/store/OffsetStore.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/store/OffsetStore.java @@ -6,25 +6,23 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.consumer.store; +import java.util.Map; +import java.util.Set; import org.apache.rocketmq.client.exception.MQBrokerException; import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.remoting.exception.RemotingException; -import java.util.Map; -import java.util.Set; - - /** * Offset store interface * @@ -37,7 +35,6 @@ public interface OffsetStore { */ void load() throws MQClientException; - /** * Update the offset,store it in memory * @@ -91,6 +88,6 @@ public interface OffsetStore { * @param offset * @param isOneway */ - void updateConsumeOffsetToBroker(MessageQueue mq, long offset, boolean isOneway) throws RemotingException, - MQBrokerException, InterruptedException, MQClientException; + void updateConsumeOffsetToBroker(MessageQueue mq, long offset, boolean isOneway) throws RemotingException, + MQBrokerException, InterruptedException, MQClientException; } diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/store/ReadOffsetType.java b/client/src/main/java/org/apache/rocketmq/client/consumer/store/ReadOffsetType.java index c2ee9b7a..da167658 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/store/ReadOffsetType.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/store/ReadOffsetType.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.consumer.store; diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/store/RemoteBrokerOffsetStore.java b/client/src/main/java/org/apache/rocketmq/client/consumer/store/RemoteBrokerOffsetStore.java index 4adc18c2..32ef8777 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/store/RemoteBrokerOffsetStore.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/store/RemoteBrokerOffsetStore.java @@ -16,6 +16,12 @@ */ package org.apache.rocketmq.client.consumer.store; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicLong; import org.apache.rocketmq.client.exception.MQBrokerException; import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.client.impl.FindBrokerResult; @@ -29,37 +35,25 @@ import org.apache.rocketmq.common.protocol.header.UpdateConsumerOffsetRequestHea import org.apache.rocketmq.remoting.exception.RemotingException; import org.slf4j.Logger; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicLong; - - /** * Remote storage implementation - * */ public class RemoteBrokerOffsetStore implements OffsetStore { private final static Logger log = ClientLogger.getLog(); private final MQClientInstance mQClientFactory; private final String groupName; private ConcurrentHashMap offsetTable = - new ConcurrentHashMap(); - + new ConcurrentHashMap(); public RemoteBrokerOffsetStore(MQClientInstance mQClientFactory, String groupName) { this.mQClientFactory = mQClientFactory; this.groupName = groupName; } - @Override public void load() { } - @Override public void updateOffset(MessageQueue mq, long offset, boolean increaseOnly) { if (mq != null) { @@ -78,7 +72,6 @@ public class RemoteBrokerOffsetStore implements OffsetStore { } } - @Override public long readOffset(final MessageQueue mq, final ReadOffsetType type) { if (mq != null) { @@ -117,7 +110,6 @@ public class RemoteBrokerOffsetStore implements OffsetStore { return -1; } - @Override public void persistAll(Set mqs) { if (null == mqs || mqs.isEmpty()) @@ -133,10 +125,10 @@ public class RemoteBrokerOffsetStore implements OffsetStore { try { this.updateConsumeOffsetToBroker(mq, offset.get()); log.info("[persistAll] Group: {} ClientId: {} updateConsumeOffsetToBroker {} {}", - this.groupName, - this.mQClientFactory.getClientId(), - mq, - offset.get()); + this.groupName, + this.mQClientFactory.getClientId(), + mq, + offset.get()); } catch (Exception e) { log.error("updateConsumeOffsetToBroker exception, " + mq.toString(), e); } @@ -155,7 +147,6 @@ public class RemoteBrokerOffsetStore implements OffsetStore { } } - @Override public void persist(MessageQueue mq) { AtomicLong offset = this.offsetTable.get(mq); @@ -163,10 +154,10 @@ public class RemoteBrokerOffsetStore implements OffsetStore { try { this.updateConsumeOffsetToBroker(mq, offset.get()); log.info("[persist] Group: {} ClientId: {} updateConsumeOffsetToBroker {} {}", - this.groupName, - this.mQClientFactory.getClientId(), - mq, - offset.get()); + this.groupName, + this.mQClientFactory.getClientId(), + mq, + offset.get()); } catch (Exception e) { log.error("updateConsumeOffsetToBroker exception, " + mq.toString(), e); } @@ -177,7 +168,7 @@ public class RemoteBrokerOffsetStore implements OffsetStore { if (mq != null) { this.offsetTable.remove(mq); log.info("remove unnecessary messageQueue offset. group={}, mq={}, offsetTableSize={}", this.groupName, mq, - offsetTable.size()); + offsetTable.size()); } } @@ -199,7 +190,7 @@ public class RemoteBrokerOffsetStore implements OffsetStore { * here need to be optimized. */ private void updateConsumeOffsetToBroker(MessageQueue mq, long offset) throws RemotingException, - MQBrokerException, InterruptedException, MQClientException { + MQBrokerException, InterruptedException, MQClientException { updateConsumeOffsetToBroker(mq, offset, true); } @@ -209,7 +200,7 @@ public class RemoteBrokerOffsetStore implements OffsetStore { */ @Override public void updateConsumeOffsetToBroker(MessageQueue mq, long offset, boolean isOneway) throws RemotingException, - MQBrokerException, InterruptedException, MQClientException { + MQBrokerException, InterruptedException, MQClientException { FindBrokerResult findBrokerResult = this.mQClientFactory.findBrokerAddressInAdmin(mq.getBrokerName()); if (null == findBrokerResult) { // TODO Here may be heavily overhead for Name Server,need tuning @@ -226,10 +217,10 @@ public class RemoteBrokerOffsetStore implements OffsetStore { if (isOneway) { this.mQClientFactory.getMQClientAPIImpl().updateConsumerOffsetOneway( - findBrokerResult.getBrokerAddr(), requestHeader, 1000 * 5); + findBrokerResult.getBrokerAddr(), requestHeader, 1000 * 5); } else { this.mQClientFactory.getMQClientAPIImpl().updateConsumerOffset( - findBrokerResult.getBrokerAddr(), requestHeader, 1000 * 5); + findBrokerResult.getBrokerAddr(), requestHeader, 1000 * 5); } } else { throw new MQClientException("The broker[" + mq.getBrokerName() + "] not exist", null); @@ -237,7 +228,7 @@ public class RemoteBrokerOffsetStore implements OffsetStore { } private long fetchConsumeOffsetFromBroker(MessageQueue mq) throws RemotingException, MQBrokerException, - InterruptedException, MQClientException { + InterruptedException, MQClientException { FindBrokerResult findBrokerResult = this.mQClientFactory.findBrokerAddressInAdmin(mq.getBrokerName()); if (null == findBrokerResult) { // TODO Here may be heavily overhead for Name Server,need tuning @@ -252,7 +243,7 @@ public class RemoteBrokerOffsetStore implements OffsetStore { requestHeader.setQueueId(mq.getQueueId()); return this.mQClientFactory.getMQClientAPIImpl().queryConsumerOffset( - findBrokerResult.getBrokerAddr(), requestHeader, 1000 * 5); + findBrokerResult.getBrokerAddr(), requestHeader, 1000 * 5); } else { throw new MQClientException("The broker[" + mq.getBrokerName() + "] not exist", null); } diff --git a/client/src/main/java/org/apache/rocketmq/client/exception/MQBrokerException.java b/client/src/main/java/org/apache/rocketmq/client/exception/MQBrokerException.java index ce4bedb1..7515a307 100644 --- a/client/src/main/java/org/apache/rocketmq/client/exception/MQBrokerException.java +++ b/client/src/main/java/org/apache/rocketmq/client/exception/MQBrokerException.java @@ -6,39 +6,35 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.exception; import org.apache.rocketmq.common.UtilAll; import org.apache.rocketmq.common.help.FAQUrl; - public class MQBrokerException extends Exception { private static final long serialVersionUID = 5975020272601250368L; private final int responseCode; private final String errorMessage; - public MQBrokerException(int responseCode, String errorMessage) { super(FAQUrl.attachDefaultURL("CODE: " + UtilAll.responseCode2String(responseCode) + " DESC: " - + errorMessage)); + + errorMessage)); this.responseCode = responseCode; this.errorMessage = errorMessage; } - public int getResponseCode() { return responseCode; } - public String getErrorMessage() { return errorMessage; } diff --git a/client/src/main/java/org/apache/rocketmq/client/exception/MQClientException.java b/client/src/main/java/org/apache/rocketmq/client/exception/MQClientException.java index 7ffab0d4..41a2b59d 100644 --- a/client/src/main/java/org/apache/rocketmq/client/exception/MQClientException.java +++ b/client/src/main/java/org/apache/rocketmq/client/exception/MQClientException.java @@ -6,36 +6,33 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.exception; import org.apache.rocketmq.common.UtilAll; import org.apache.rocketmq.common.help.FAQUrl; - public class MQClientException extends Exception { private static final long serialVersionUID = -5758410930844185841L; private int responseCode; private String errorMessage; - public MQClientException(String errorMessage, Throwable cause) { super(FAQUrl.attachDefaultURL(errorMessage), cause); this.responseCode = -1; this.errorMessage = errorMessage; } - public MQClientException(int responseCode, String errorMessage) { super(FAQUrl.attachDefaultURL("CODE: " + UtilAll.responseCode2String(responseCode) + " DESC: " - + errorMessage)); + + errorMessage)); this.responseCode = responseCode; this.errorMessage = errorMessage; } diff --git a/client/src/main/java/org/apache/rocketmq/client/hook/CheckForbiddenContext.java b/client/src/main/java/org/apache/rocketmq/client/hook/CheckForbiddenContext.java index e84befff..cf6c157f 100644 --- a/client/src/main/java/org/apache/rocketmq/client/hook/CheckForbiddenContext.java +++ b/client/src/main/java/org/apache/rocketmq/client/hook/CheckForbiddenContext.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.hook; @@ -21,7 +21,6 @@ import org.apache.rocketmq.client.producer.SendResult; import org.apache.rocketmq.common.message.Message; import org.apache.rocketmq.common.message.MessageQueue; - public class CheckForbiddenContext { private String nameSrvAddr; private String group; @@ -34,112 +33,91 @@ public class CheckForbiddenContext { private Object arg; private boolean unitMode = false; - public String getGroup() { return group; } - public void setGroup(String group) { this.group = group; } - public Message getMessage() { return message; } - public void setMessage(Message message) { this.message = message; } - public MessageQueue getMq() { return mq; } - public void setMq(MessageQueue mq) { this.mq = mq; } - public String getBrokerAddr() { return brokerAddr; } - public void setBrokerAddr(String brokerAddr) { this.brokerAddr = brokerAddr; } - public CommunicationMode getCommunicationMode() { return communicationMode; } - public void setCommunicationMode(CommunicationMode communicationMode) { this.communicationMode = communicationMode; } - public SendResult getSendResult() { return sendResult; } - public void setSendResult(SendResult sendResult) { this.sendResult = sendResult; } - public Exception getException() { return exception; } - public void setException(Exception exception) { this.exception = exception; } - public Object getArg() { return arg; } - public void setArg(Object arg) { this.arg = arg; } - public boolean isUnitMode() { return unitMode; } - public void setUnitMode(boolean isUnitMode) { this.unitMode = isUnitMode; } - public String getNameSrvAddr() { return nameSrvAddr; } - public void setNameSrvAddr(String nameSrvAddr) { this.nameSrvAddr = nameSrvAddr; } - @Override public String toString() { return "SendMessageContext [nameSrvAddr=" + nameSrvAddr + ", group=" + group + ", message=" + message - + ", mq=" + mq + ", brokerAddr=" + brokerAddr + ", communicationMode=" + communicationMode - + ", sendResult=" + sendResult + ", exception=" + exception + ", unitMode=" + unitMode - + ", arg=" + arg + "]"; + + ", mq=" + mq + ", brokerAddr=" + brokerAddr + ", communicationMode=" + communicationMode + + ", sendResult=" + sendResult + ", exception=" + exception + ", unitMode=" + unitMode + + ", arg=" + arg + "]"; } } diff --git a/client/src/main/java/org/apache/rocketmq/client/hook/CheckForbiddenHook.java b/client/src/main/java/org/apache/rocketmq/client/hook/CheckForbiddenHook.java index d6f75bbd..7faf14b5 100644 --- a/client/src/main/java/org/apache/rocketmq/client/hook/CheckForbiddenHook.java +++ b/client/src/main/java/org/apache/rocketmq/client/hook/CheckForbiddenHook.java @@ -6,23 +6,21 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.hook; import org.apache.rocketmq.client.exception.MQClientException; - public interface CheckForbiddenHook { String hookName(); - void checkForbidden(final CheckForbiddenContext context) throws MQClientException; } diff --git a/client/src/main/java/org/apache/rocketmq/client/hook/ConsumeMessageContext.java b/client/src/main/java/org/apache/rocketmq/client/hook/ConsumeMessageContext.java index f141fac8..5bababa7 100644 --- a/client/src/main/java/org/apache/rocketmq/client/hook/ConsumeMessageContext.java +++ b/client/src/main/java/org/apache/rocketmq/client/hook/ConsumeMessageContext.java @@ -6,22 +6,20 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.hook; -import org.apache.rocketmq.common.message.MessageExt; -import org.apache.rocketmq.common.message.MessageQueue; - import java.util.List; import java.util.Map; - +import org.apache.rocketmq.common.message.MessageExt; +import org.apache.rocketmq.common.message.MessageQueue; public class ConsumeMessageContext { private String consumerGroup; @@ -32,72 +30,58 @@ public class ConsumeMessageContext { private Object mqTraceContext; private Map props; - public String getConsumerGroup() { return consumerGroup; } - public void setConsumerGroup(String consumerGroup) { this.consumerGroup = consumerGroup; } - public List getMsgList() { return msgList; } - public void setMsgList(List msgList) { this.msgList = msgList; } - public MessageQueue getMq() { return mq; } - public void setMq(MessageQueue mq) { this.mq = mq; } - public boolean isSuccess() { return success; } - public void setSuccess(boolean success) { this.success = success; } - public Object getMqTraceContext() { return mqTraceContext; } - public void setMqTraceContext(Object mqTraceContext) { this.mqTraceContext = mqTraceContext; } - public Map getProps() { return props; } - public void setProps(Map props) { this.props = props; } - public String getStatus() { return status; } - public void setStatus(String status) { this.status = status; } diff --git a/client/src/main/java/org/apache/rocketmq/client/hook/ConsumeMessageHook.java b/client/src/main/java/org/apache/rocketmq/client/hook/ConsumeMessageHook.java index 8161d2ef..95db7b2c 100644 --- a/client/src/main/java/org/apache/rocketmq/client/hook/ConsumeMessageHook.java +++ b/client/src/main/java/org/apache/rocketmq/client/hook/ConsumeMessageHook.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.hook; diff --git a/client/src/main/java/org/apache/rocketmq/client/hook/FilterMessageContext.java b/client/src/main/java/org/apache/rocketmq/client/hook/FilterMessageContext.java index 23340d3d..bc22546d 100644 --- a/client/src/main/java/org/apache/rocketmq/client/hook/FilterMessageContext.java +++ b/client/src/main/java/org/apache/rocketmq/client/hook/FilterMessageContext.java @@ -6,22 +6,20 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.hook; +import java.util.List; import org.apache.rocketmq.common.message.MessageExt; import org.apache.rocketmq.common.message.MessageQueue; -import java.util.List; - - public class FilterMessageContext { private String consumerGroup; private List msgList; @@ -29,60 +27,49 @@ public class FilterMessageContext { private Object arg; private boolean unitMode; - public String getConsumerGroup() { return consumerGroup; } - public void setConsumerGroup(String consumerGroup) { this.consumerGroup = consumerGroup; } - public List getMsgList() { return msgList; } - public void setMsgList(List msgList) { this.msgList = msgList; } - public MessageQueue getMq() { return mq; } - public void setMq(MessageQueue mq) { this.mq = mq; } - public Object getArg() { return arg; } - public void setArg(Object arg) { this.arg = arg; } - public boolean isUnitMode() { return unitMode; } - public void setUnitMode(boolean isUnitMode) { this.unitMode = isUnitMode; } - @Override public String toString() { return "ConsumeMessageContext [consumerGroup=" + consumerGroup + ", msgList=" + msgList + ", mq=" - + mq + ", arg=" + arg + "]"; + + mq + ", arg=" + arg + "]"; } } diff --git a/client/src/main/java/org/apache/rocketmq/client/hook/FilterMessageHook.java b/client/src/main/java/org/apache/rocketmq/client/hook/FilterMessageHook.java index 48fd513f..095de32f 100644 --- a/client/src/main/java/org/apache/rocketmq/client/hook/FilterMessageHook.java +++ b/client/src/main/java/org/apache/rocketmq/client/hook/FilterMessageHook.java @@ -6,19 +6,18 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.hook; public interface FilterMessageHook { String hookName(); - void filterMessage(final FilterMessageContext context); } diff --git a/client/src/main/java/org/apache/rocketmq/client/hook/SendMessageContext.java b/client/src/main/java/org/apache/rocketmq/client/hook/SendMessageContext.java index bfb4a47e..34e22a3a 100644 --- a/client/src/main/java/org/apache/rocketmq/client/hook/SendMessageContext.java +++ b/client/src/main/java/org/apache/rocketmq/client/hook/SendMessageContext.java @@ -6,16 +6,17 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.hook; +import java.util.Map; import org.apache.rocketmq.client.impl.CommunicationMode; import org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl; import org.apache.rocketmq.client.producer.SendResult; @@ -23,9 +24,6 @@ import org.apache.rocketmq.common.message.Message; import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.common.message.MessageType; -import java.util.Map; - - public class SendMessageContext { private String producerGroup; private Message message; @@ -60,97 +58,78 @@ public class SendMessageContext { return producerGroup; } - public void setProducerGroup(String producerGroup) { this.producerGroup = producerGroup; } - public Message getMessage() { return message; } - public void setMessage(Message message) { this.message = message; } - public MessageQueue getMq() { return mq; } - public void setMq(MessageQueue mq) { this.mq = mq; } - public String getBrokerAddr() { return brokerAddr; } - public void setBrokerAddr(String brokerAddr) { this.brokerAddr = brokerAddr; } - public CommunicationMode getCommunicationMode() { return communicationMode; } - public void setCommunicationMode(CommunicationMode communicationMode) { this.communicationMode = communicationMode; } - public SendResult getSendResult() { return sendResult; } - public void setSendResult(SendResult sendResult) { this.sendResult = sendResult; } - public Exception getException() { return exception; } - public void setException(Exception exception) { this.exception = exception; } - public Object getMqTraceContext() { return mqTraceContext; } - public void setMqTraceContext(Object mqTraceContext) { this.mqTraceContext = mqTraceContext; } - public Map getProps() { return props; } - public void setProps(Map props) { this.props = props; } - public String getBornHost() { return bornHost; } - public void setBornHost(String bornHost) { this.bornHost = bornHost; } diff --git a/client/src/main/java/org/apache/rocketmq/client/hook/SendMessageHook.java b/client/src/main/java/org/apache/rocketmq/client/hook/SendMessageHook.java index c0408319..16a86a09 100644 --- a/client/src/main/java/org/apache/rocketmq/client/hook/SendMessageHook.java +++ b/client/src/main/java/org/apache/rocketmq/client/hook/SendMessageHook.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.hook; diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/ClientRemotingProcessor.java b/client/src/main/java/org/apache/rocketmq/client/impl/ClientRemotingProcessor.java index bb008bf4..46ce08ca 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/ClientRemotingProcessor.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/ClientRemotingProcessor.java @@ -6,16 +6,20 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.impl; +import io.netty.channel.ChannelHandlerContext; +import java.nio.ByteBuffer; +import java.util.HashMap; +import java.util.Map; import org.apache.rocketmq.client.impl.factory.MQClientInstance; import org.apache.rocketmq.client.impl.producer.MQProducerInner; import org.apache.rocketmq.client.log.ClientLogger; @@ -30,29 +34,26 @@ import org.apache.rocketmq.common.protocol.body.ConsumeMessageDirectlyResult; import org.apache.rocketmq.common.protocol.body.ConsumerRunningInfo; import org.apache.rocketmq.common.protocol.body.GetConsumerStatusBody; import org.apache.rocketmq.common.protocol.body.ResetOffsetBody; +import org.apache.rocketmq.common.protocol.header.CheckTransactionStateRequestHeader; +import org.apache.rocketmq.common.protocol.header.ConsumeMessageDirectlyResultRequestHeader; +import org.apache.rocketmq.common.protocol.header.GetConsumerRunningInfoRequestHeader; +import org.apache.rocketmq.common.protocol.header.GetConsumerStatusRequestHeader; +import org.apache.rocketmq.common.protocol.header.NotifyConsumerIdsChangedRequestHeader; +import org.apache.rocketmq.common.protocol.header.ResetOffsetRequestHeader; import org.apache.rocketmq.remoting.common.RemotingHelper; import org.apache.rocketmq.remoting.exception.RemotingCommandException; import org.apache.rocketmq.remoting.netty.NettyRequestProcessor; import org.apache.rocketmq.remoting.protocol.RemotingCommand; -import io.netty.channel.ChannelHandlerContext; -import org.apache.rocketmq.common.protocol.header.*; import org.slf4j.Logger; -import java.nio.ByteBuffer; -import java.util.HashMap; -import java.util.Map; - - public class ClientRemotingProcessor implements NettyRequestProcessor { private final Logger log = ClientLogger.getLog(); private final MQClientInstance mqClientFactory; - public ClientRemotingProcessor(final MQClientInstance mqClientFactory) { this.mqClientFactory = mqClientFactory; } - @Override public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { switch (request.getCode()) { @@ -83,7 +84,7 @@ public class ClientRemotingProcessor implements NettyRequestProcessor { public RemotingCommand checkTransactionState(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final CheckTransactionStateRequestHeader requestHeader = - (CheckTransactionStateRequestHeader) request.decodeCommandCustomHeader(CheckTransactionStateRequestHeader.class); + (CheckTransactionStateRequestHeader)request.decodeCommandCustomHeader(CheckTransactionStateRequestHeader.class); final ByteBuffer byteBuffer = ByteBuffer.wrap(request.getBody()); final MessageExt messageExt = MessageDecoder.decode(byteBuffer); if (messageExt != null) { @@ -109,10 +110,10 @@ public class ClientRemotingProcessor implements NettyRequestProcessor { public RemotingCommand notifyConsumerIdsChanged(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { try { final NotifyConsumerIdsChangedRequestHeader requestHeader = - (NotifyConsumerIdsChangedRequestHeader) request.decodeCommandCustomHeader(NotifyConsumerIdsChangedRequestHeader.class); + (NotifyConsumerIdsChangedRequestHeader)request.decodeCommandCustomHeader(NotifyConsumerIdsChangedRequestHeader.class); log.info("receive broker's notification[{}], the consumer group: {} changed, rebalance immediately", - RemotingHelper.parseChannelRemoteAddr(ctx.channel()), - requestHeader.getConsumerGroup()); + RemotingHelper.parseChannelRemoteAddr(ctx.channel()), + requestHeader.getConsumerGroup()); this.mqClientFactory.rebalanceImmediately(); } catch (Exception e) { log.error("notifyConsumerIdsChanged exception", RemotingHelper.exceptionSimpleDesc(e)); @@ -122,10 +123,11 @@ public class ClientRemotingProcessor implements NettyRequestProcessor { public RemotingCommand resetOffset(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final ResetOffsetRequestHeader requestHeader = - (ResetOffsetRequestHeader) request.decodeCommandCustomHeader(ResetOffsetRequestHeader.class); + (ResetOffsetRequestHeader)request.decodeCommandCustomHeader(ResetOffsetRequestHeader.class); log.info("invoke reset offset operation from broker. brokerAddr={}, topic={}, group={}, timestamp={}", - new Object[]{RemotingHelper.parseChannelRemoteAddr(ctx.channel()), requestHeader.getTopic(), requestHeader.getGroup(), - requestHeader.getTimestamp()}); + new Object[] { + RemotingHelper.parseChannelRemoteAddr(ctx.channel()), requestHeader.getTopic(), requestHeader.getGroup(), + requestHeader.getTimestamp()}); Map offsetTable = new HashMap(); if (request.getBody() != null) { ResetOffsetBody body = ResetOffsetBody.decode(request.getBody(), ResetOffsetBody.class); @@ -139,7 +141,7 @@ public class ClientRemotingProcessor implements NettyRequestProcessor { public RemotingCommand getConsumeStatus(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetConsumerStatusRequestHeader requestHeader = - (GetConsumerStatusRequestHeader) request.decodeCommandCustomHeader(GetConsumerStatusRequestHeader.class); + (GetConsumerStatusRequestHeader)request.decodeCommandCustomHeader(GetConsumerStatusRequestHeader.class); Map offsetTable = this.mqClientFactory.getConsumerStatus(requestHeader.getTopic(), requestHeader.getGroup()); GetConsumerStatusBody body = new GetConsumerStatusBody(); @@ -152,7 +154,7 @@ public class ClientRemotingProcessor implements NettyRequestProcessor { private RemotingCommand getConsumerRunningInfo(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetConsumerRunningInfoRequestHeader requestHeader = - (GetConsumerRunningInfoRequestHeader) request.decodeCommandCustomHeader(GetConsumerRunningInfoRequestHeader.class); + (GetConsumerRunningInfoRequestHeader)request.decodeCommandCustomHeader(GetConsumerRunningInfoRequestHeader.class); ConsumerRunningInfo consumerRunningInfo = this.mqClientFactory.consumerRunningInfo(requestHeader.getConsumerGroup()); if (null != consumerRunningInfo) { @@ -175,13 +177,13 @@ public class ClientRemotingProcessor implements NettyRequestProcessor { private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final ConsumeMessageDirectlyResultRequestHeader requestHeader = - (ConsumeMessageDirectlyResultRequestHeader) request - .decodeCommandCustomHeader(ConsumeMessageDirectlyResultRequestHeader.class); + (ConsumeMessageDirectlyResultRequestHeader)request + .decodeCommandCustomHeader(ConsumeMessageDirectlyResultRequestHeader.class); final MessageExt msg = MessageDecoder.decode(ByteBuffer.wrap(request.getBody())); ConsumeMessageDirectlyResult result = - this.mqClientFactory.consumeMessageDirectly(msg, requestHeader.getConsumerGroup(), requestHeader.getBrokerName()); + this.mqClientFactory.consumeMessageDirectly(msg, requestHeader.getConsumerGroup(), requestHeader.getBrokerName()); if (null != result) { response.setCode(ResponseCode.SUCCESS); diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/CommunicationMode.java b/client/src/main/java/org/apache/rocketmq/client/impl/CommunicationMode.java index 9af6794a..07b3a360 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/CommunicationMode.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/CommunicationMode.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.impl; diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/FindBrokerResult.java b/client/src/main/java/org/apache/rocketmq/client/impl/FindBrokerResult.java index 8773f26a..c6405d86 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/FindBrokerResult.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/FindBrokerResult.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.impl; @@ -20,18 +20,15 @@ public class FindBrokerResult { private final String brokerAddr; private final boolean slave; - public FindBrokerResult(String brokerAddr, boolean slave) { this.brokerAddr = brokerAddr; this.slave = slave; } - public String getBrokerAddr() { return brokerAddr; } - public boolean isSlave() { return slave; } diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/MQAdminImpl.java b/client/src/main/java/org/apache/rocketmq/client/impl/MQAdminImpl.java index 3e6673ce..5fdcab24 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/MQAdminImpl.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/MQAdminImpl.java @@ -16,6 +16,13 @@ */ package org.apache.rocketmq.client.impl; +import java.nio.ByteBuffer; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import org.apache.rocketmq.client.QueryResult; import org.apache.rocketmq.client.exception.MQBrokerException; import org.apache.rocketmq.client.exception.MQClientException; @@ -25,7 +32,12 @@ import org.apache.rocketmq.client.log.ClientLogger; import org.apache.rocketmq.common.MixAll; import org.apache.rocketmq.common.TopicConfig; import org.apache.rocketmq.common.help.FAQUrl; -import org.apache.rocketmq.common.message.*; +import org.apache.rocketmq.common.message.MessageClientIDSetter; +import org.apache.rocketmq.common.message.MessageConst; +import org.apache.rocketmq.common.message.MessageDecoder; +import org.apache.rocketmq.common.message.MessageExt; +import org.apache.rocketmq.common.message.MessageId; +import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.common.protocol.ResponseCode; import org.apache.rocketmq.common.protocol.header.QueryMessageRequestHeader; import org.apache.rocketmq.common.protocol.header.QueryMessageResponseHeader; @@ -39,42 +51,28 @@ import org.apache.rocketmq.remoting.netty.ResponseFuture; import org.apache.rocketmq.remoting.protocol.RemotingCommand; import org.slf4j.Logger; -import java.nio.ByteBuffer; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - - public class MQAdminImpl { private final Logger log = ClientLogger.getLog(); private final MQClientInstance mQClientFactory; private long timeoutMillis = 6000; - public MQAdminImpl(MQClientInstance mQClientFactory) { this.mQClientFactory = mQClientFactory; } - public long getTimeoutMillis() { return timeoutMillis; } - public void setTimeoutMillis(long timeoutMillis) { this.timeoutMillis = timeoutMillis; } - public void createTopic(String key, String newTopic, int queueNum) throws MQClientException { createTopic(key, newTopic, queueNum, 0); } - public void createTopic(String key, String newTopic, int queueNum, int topicSysFlag) throws MQClientException { try { TopicRouteData topicRouteData = this.mQClientFactory.getMQClientAPIImpl().getTopicRouteInfoFromNameServer(key, timeoutMillis); @@ -129,7 +127,6 @@ public class MQAdminImpl { } } - public List fetchPublishMessageQueues(String topic) throws MQClientException { try { TopicRouteData topicRouteData = this.mQClientFactory.getMQClientAPIImpl().getTopicRouteInfoFromNameServer(topic, timeoutMillis); @@ -146,7 +143,6 @@ public class MQAdminImpl { throw new MQClientException("Unknow why, Can not find Message Queue for this topic, " + topic, null); } - public Set fetchSubscribeMessageQueues(String topic) throws MQClientException { try { TopicRouteData topicRouteData = this.mQClientFactory.getMQClientAPIImpl().getTopicRouteInfoFromNameServer(topic, timeoutMillis); @@ -160,14 +156,13 @@ public class MQAdminImpl { } } catch (Exception e) { throw new MQClientException( - "Can not find Message Queue for this topic, " + topic + FAQUrl.suggestTodo(FAQUrl.MQLIST_NOT_EXIST), // - e); + "Can not find Message Queue for this topic, " + topic + FAQUrl.suggestTodo(FAQUrl.MQLIST_NOT_EXIST), // + e); } throw new MQClientException("Unknow why, Can not find Message Queue for this topic, " + topic, null); } - public long searchOffset(MessageQueue mq, long timestamp) throws MQClientException { String brokerAddr = this.mQClientFactory.findBrokerAddressInPublish(mq.getBrokerName()); if (null == brokerAddr) { @@ -178,7 +173,7 @@ public class MQAdminImpl { if (brokerAddr != null) { try { return this.mQClientFactory.getMQClientAPIImpl().searchOffset(brokerAddr, mq.getTopic(), mq.getQueueId(), timestamp, - timeoutMillis); + timeoutMillis); } catch (Exception e) { throw new MQClientException("Invoke Broker[" + brokerAddr + "] exception", e); } @@ -187,7 +182,6 @@ public class MQAdminImpl { throw new MQClientException("The broker[" + mq.getBrokerName() + "] not exist", null); } - public long maxOffset(MessageQueue mq) throws MQClientException { String brokerAddr = this.mQClientFactory.findBrokerAddressInPublish(mq.getBrokerName()); if (null == brokerAddr) { @@ -206,7 +200,6 @@ public class MQAdminImpl { throw new MQClientException("The broker[" + mq.getBrokerName() + "] not exist", null); } - public long minOffset(MessageQueue mq) throws MQClientException { String brokerAddr = this.mQClientFactory.findBrokerAddressInPublish(mq.getBrokerName()); if (null == brokerAddr) { @@ -225,7 +218,6 @@ public class MQAdminImpl { throw new MQClientException("The broker[" + mq.getBrokerName() + "] not exist", null); } - public long earliestMsgStoreTime(MessageQueue mq) throws MQClientException { String brokerAddr = this.mQClientFactory.findBrokerAddressInPublish(mq.getBrokerName()); if (null == brokerAddr) { @@ -236,7 +228,7 @@ public class MQAdminImpl { if (brokerAddr != null) { try { return this.mQClientFactory.getMQClientAPIImpl().getEarliestMsgStoretime(brokerAddr, mq.getTopic(), mq.getQueueId(), - timeoutMillis); + timeoutMillis); } catch (Exception e) { throw new MQClientException("Invoke Broker[" + brokerAddr + "] exception", e); } @@ -254,18 +246,18 @@ public class MQAdminImpl { throw new MQClientException(ResponseCode.NO_MESSAGE, "query message by id finished, but no message."); } return this.mQClientFactory.getMQClientAPIImpl().viewMessage(RemotingUtil.socketAddress2String(messageId.getAddress()), - messageId.getOffset(), timeoutMillis); + messageId.getOffset(), timeoutMillis); } public QueryResult queryMessage(String topic, String key, int maxNum, long begin, long end) throws MQClientException, - InterruptedException { + InterruptedException { return queryMessage(topic, key, maxNum, begin, end, false); } public MessageExt queryMessageByUniqKey(String topic, String uniqKey) throws InterruptedException, MQClientException { QueryResult qr = this.queryMessage(topic, uniqKey, 32, - MessageClientIDSetter.getNearlyTimeFromID(uniqKey).getTime() - 1000, Long.MAX_VALUE, true); + MessageClientIDSetter.getNearlyTimeFromID(uniqKey).getTime() - 1000, Long.MAX_VALUE, true); if (qr != null && qr.getMessageList() != null && qr.getMessageList().size() > 0) { return qr.getMessageList().get(0); } else { @@ -274,7 +266,7 @@ public class MQAdminImpl { } protected QueryResult queryMessage(String topic, String key, int maxNum, long begin, long end, boolean isUniqKey) throws MQClientException, - InterruptedException { + InterruptedException { TopicRouteData topicRouteData = this.mQClientFactory.getAnExistTopicRouteData(topic); if (null == topicRouteData) { this.mQClientFactory.updateTopicRouteInfoFromNameServer(topic); @@ -304,43 +296,43 @@ public class MQAdminImpl { requestHeader.setEndTimestamp(end); this.mQClientFactory.getMQClientAPIImpl().queryMessage(addr, requestHeader, timeoutMillis * 3, - new InvokeCallback() { - @Override - public void operationComplete(ResponseFuture responseFuture) { - try { - RemotingCommand response = responseFuture.getResponseCommand(); - if (response != null) { - switch (response.getCode()) { - case ResponseCode.SUCCESS: { - QueryMessageResponseHeader responseHeader = null; - try { - responseHeader = - (QueryMessageResponseHeader) response - .decodeCommandCustomHeader(QueryMessageResponseHeader.class); - } catch (RemotingCommandException e) { - log.error("decodeCommandCustomHeader exception", e); - return; - } - - List wrappers = - MessageDecoder.decodes(ByteBuffer.wrap(response.getBody()), true); - - QueryResult qr = new QueryResult(responseHeader.getIndexLastUpdateTimestamp(), wrappers); - queryResultList.add(qr); - break; + new InvokeCallback() { + @Override + public void operationComplete(ResponseFuture responseFuture) { + try { + RemotingCommand response = responseFuture.getResponseCommand(); + if (response != null) { + switch (response.getCode()) { + case ResponseCode.SUCCESS: { + QueryMessageResponseHeader responseHeader = null; + try { + responseHeader = + (QueryMessageResponseHeader)response + .decodeCommandCustomHeader(QueryMessageResponseHeader.class); + } catch (RemotingCommandException e) { + log.error("decodeCommandCustomHeader exception", e); + return; } - default: - log.warn("getResponseCommand failed, {} {}", response.getCode(), response.getRemark()); - break; + + List wrappers = + MessageDecoder.decodes(ByteBuffer.wrap(response.getBody()), true); + + QueryResult qr = new QueryResult(responseHeader.getIndexLastUpdateTimestamp(), wrappers); + queryResultList.add(qr); + break; } - } else { - log.warn("getResponseCommand return null"); + default: + log.warn("getResponseCommand failed, {} {}", response.getCode(), response.getRemark()); + break; } - } finally { - countDownLatch.countDown(); + } else { + log.warn("getResponseCommand return null"); } + } finally { + countDownLatch.countDown(); } - }, isUniqKey); + } + }, isUniqKey); } catch (Exception e) { log.warn("queryMessage exception", e); } diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/MQClientAPIImpl.java b/client/src/main/java/org/apache/rocketmq/client/impl/MQClientAPIImpl.java index 84ee7db9..2dd92003 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/MQClientAPIImpl.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/MQClientAPIImpl.java @@ -16,6 +16,17 @@ */ package org.apache.rocketmq.client.impl; +import java.io.UnsupportedEncodingException; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; import org.apache.rocketmq.client.ClientConfig; import org.apache.rocketmq.client.consumer.PullCallback; import org.apache.rocketmq.client.consumer.PullResult; @@ -37,21 +48,97 @@ import org.apache.rocketmq.common.TopicConfig; import org.apache.rocketmq.common.UtilAll; import org.apache.rocketmq.common.admin.ConsumeStats; import org.apache.rocketmq.common.admin.TopicStatsTable; -import org.apache.rocketmq.common.message.*; +import org.apache.rocketmq.common.message.Message; +import org.apache.rocketmq.common.message.MessageClientIDSetter; +import org.apache.rocketmq.common.message.MessageConst; +import org.apache.rocketmq.common.message.MessageDecoder; +import org.apache.rocketmq.common.message.MessageExt; +import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.common.namesrv.TopAddressing; import org.apache.rocketmq.common.protocol.RequestCode; import org.apache.rocketmq.common.protocol.ResponseCode; -import org.apache.rocketmq.common.protocol.body.*; -import org.apache.rocketmq.common.protocol.header.*; +import org.apache.rocketmq.common.protocol.body.BrokerStatsData; +import org.apache.rocketmq.common.protocol.body.ClusterInfo; +import org.apache.rocketmq.common.protocol.body.ConsumeMessageDirectlyResult; +import org.apache.rocketmq.common.protocol.body.ConsumeStatsList; +import org.apache.rocketmq.common.protocol.body.ConsumerConnection; +import org.apache.rocketmq.common.protocol.body.ConsumerRunningInfo; +import org.apache.rocketmq.common.protocol.body.GetConsumerStatusBody; +import org.apache.rocketmq.common.protocol.body.GroupList; +import org.apache.rocketmq.common.protocol.body.KVTable; +import org.apache.rocketmq.common.protocol.body.LockBatchRequestBody; +import org.apache.rocketmq.common.protocol.body.LockBatchResponseBody; +import org.apache.rocketmq.common.protocol.body.ProducerConnection; +import org.apache.rocketmq.common.protocol.body.QueryConsumeTimeSpanBody; +import org.apache.rocketmq.common.protocol.body.QueryCorrectionOffsetBody; +import org.apache.rocketmq.common.protocol.body.QueueTimeSpan; +import org.apache.rocketmq.common.protocol.body.ResetOffsetBody; +import org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper; +import org.apache.rocketmq.common.protocol.body.TopicConfigSerializeWrapper; +import org.apache.rocketmq.common.protocol.body.TopicList; +import org.apache.rocketmq.common.protocol.body.UnlockBatchRequestBody; +import org.apache.rocketmq.common.protocol.header.CloneGroupOffsetRequestHeader; +import org.apache.rocketmq.common.protocol.header.ConsumeMessageDirectlyResultRequestHeader; +import org.apache.rocketmq.common.protocol.header.ConsumerSendMsgBackRequestHeader; +import org.apache.rocketmq.common.protocol.header.CreateTopicRequestHeader; +import org.apache.rocketmq.common.protocol.header.DeleteSubscriptionGroupRequestHeader; +import org.apache.rocketmq.common.protocol.header.DeleteTopicRequestHeader; +import org.apache.rocketmq.common.protocol.header.EndTransactionRequestHeader; +import org.apache.rocketmq.common.protocol.header.GetConsumeStatsInBrokerHeader; +import org.apache.rocketmq.common.protocol.header.GetConsumeStatsRequestHeader; +import org.apache.rocketmq.common.protocol.header.GetConsumerConnectionListRequestHeader; +import org.apache.rocketmq.common.protocol.header.GetConsumerListByGroupRequestHeader; +import org.apache.rocketmq.common.protocol.header.GetConsumerListByGroupResponseBody; +import org.apache.rocketmq.common.protocol.header.GetConsumerRunningInfoRequestHeader; +import org.apache.rocketmq.common.protocol.header.GetConsumerStatusRequestHeader; +import org.apache.rocketmq.common.protocol.header.GetEarliestMsgStoretimeRequestHeader; +import org.apache.rocketmq.common.protocol.header.GetEarliestMsgStoretimeResponseHeader; +import org.apache.rocketmq.common.protocol.header.GetMaxOffsetRequestHeader; +import org.apache.rocketmq.common.protocol.header.GetMaxOffsetResponseHeader; +import org.apache.rocketmq.common.protocol.header.GetMinOffsetRequestHeader; +import org.apache.rocketmq.common.protocol.header.GetMinOffsetResponseHeader; +import org.apache.rocketmq.common.protocol.header.GetProducerConnectionListRequestHeader; +import org.apache.rocketmq.common.protocol.header.GetTopicStatsInfoRequestHeader; +import org.apache.rocketmq.common.protocol.header.GetTopicsByClusterRequestHeader; +import org.apache.rocketmq.common.protocol.header.PullMessageRequestHeader; +import org.apache.rocketmq.common.protocol.header.PullMessageResponseHeader; +import org.apache.rocketmq.common.protocol.header.QueryConsumeTimeSpanRequestHeader; +import org.apache.rocketmq.common.protocol.header.QueryConsumerOffsetRequestHeader; +import org.apache.rocketmq.common.protocol.header.QueryConsumerOffsetResponseHeader; +import org.apache.rocketmq.common.protocol.header.QueryCorrectionOffsetHeader; +import org.apache.rocketmq.common.protocol.header.QueryMessageRequestHeader; +import org.apache.rocketmq.common.protocol.header.QueryTopicConsumeByWhoRequestHeader; +import org.apache.rocketmq.common.protocol.header.ResetOffsetRequestHeader; +import org.apache.rocketmq.common.protocol.header.SearchOffsetRequestHeader; +import org.apache.rocketmq.common.protocol.header.SearchOffsetResponseHeader; +import org.apache.rocketmq.common.protocol.header.SendMessageRequestHeader; +import org.apache.rocketmq.common.protocol.header.SendMessageRequestHeaderV2; +import org.apache.rocketmq.common.protocol.header.SendMessageResponseHeader; +import org.apache.rocketmq.common.protocol.header.UnregisterClientRequestHeader; +import org.apache.rocketmq.common.protocol.header.UpdateConsumerOffsetRequestHeader; +import org.apache.rocketmq.common.protocol.header.ViewBrokerStatsDataRequestHeader; +import org.apache.rocketmq.common.protocol.header.ViewMessageRequestHeader; import org.apache.rocketmq.common.protocol.header.filtersrv.RegisterMessageFilterClassRequestHeader; -import org.apache.rocketmq.common.protocol.header.namesrv.*; +import org.apache.rocketmq.common.protocol.header.namesrv.DeleteKVConfigRequestHeader; +import org.apache.rocketmq.common.protocol.header.namesrv.GetKVConfigRequestHeader; +import org.apache.rocketmq.common.protocol.header.namesrv.GetKVConfigResponseHeader; +import org.apache.rocketmq.common.protocol.header.namesrv.GetKVListByNamespaceRequestHeader; +import org.apache.rocketmq.common.protocol.header.namesrv.GetRouteInfoRequestHeader; +import org.apache.rocketmq.common.protocol.header.namesrv.PutKVConfigRequestHeader; +import org.apache.rocketmq.common.protocol.header.namesrv.WipeWritePermOfBrokerRequestHeader; +import org.apache.rocketmq.common.protocol.header.namesrv.WipeWritePermOfBrokerResponseHeader; import org.apache.rocketmq.common.protocol.heartbeat.HeartbeatData; import org.apache.rocketmq.common.protocol.route.TopicRouteData; import org.apache.rocketmq.common.subscription.SubscriptionGroupConfig; import org.apache.rocketmq.remoting.InvokeCallback; import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.remoting.RemotingClient; -import org.apache.rocketmq.remoting.exception.*; +import org.apache.rocketmq.remoting.exception.RemotingCommandException; +import org.apache.rocketmq.remoting.exception.RemotingConnectException; +import org.apache.rocketmq.remoting.exception.RemotingException; +import org.apache.rocketmq.remoting.exception.RemotingSendRequestException; +import org.apache.rocketmq.remoting.exception.RemotingTimeoutException; +import org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException; import org.apache.rocketmq.remoting.netty.NettyClientConfig; import org.apache.rocketmq.remoting.netty.NettyRemotingClient; import org.apache.rocketmq.remoting.netty.ResponseFuture; @@ -60,17 +147,11 @@ import org.apache.rocketmq.remoting.protocol.RemotingCommand; import org.apache.rocketmq.remoting.protocol.RemotingSerializable; import org.slf4j.Logger; -import java.io.UnsupportedEncodingException; -import java.nio.ByteBuffer; -import java.util.*; -import java.util.concurrent.atomic.AtomicInteger; - - public class MQClientAPIImpl { private final static Logger log = ClientLogger.getLog(); public static boolean sendSmartMsg = - Boolean.parseBoolean(System.getProperty("org.apache.rocketmq.client.sendSmartMsg", "true")); + Boolean.parseBoolean(System.getProperty("org.apache.rocketmq.client.sendSmartMsg", "true")); static { System.setProperty(RemotingCommand.REMOTING_VERSION_KEY, Integer.toString(MQVersion.CURRENT_VERSION)); @@ -83,7 +164,7 @@ public class MQClientAPIImpl { private ClientConfig clientConfig; public MQClientAPIImpl(final NettyClientConfig nettyClientConfig, final ClientRemotingProcessor clientRemotingProcessor, - RPCHook rpcHook, final ClientConfig clientConfig) { + RPCHook rpcHook, final ClientConfig clientConfig) { this.clientConfig = clientConfig; topAddressing = new TopAddressing(MixAll.WS_ADDR, clientConfig.getUnitName()); this.remotingClient = new NettyRemotingClient(nettyClientConfig, null); @@ -149,14 +230,14 @@ public class MQClientAPIImpl { } public void createSubscriptionGroup(final String addr, final SubscriptionGroupConfig config, final long timeoutMillis) - throws RemotingException, MQBrokerException, InterruptedException, MQClientException { + throws RemotingException, MQBrokerException, InterruptedException, MQClientException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.UPDATE_AND_CREATE_SUBSCRIPTIONGROUP, null); byte[] body = RemotingSerializable.encode(config); request.setBody(body); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), - request, timeoutMillis); + request, timeoutMillis); assert response != null; switch (response.getCode()) { case ResponseCode.SUCCESS: { @@ -171,7 +252,7 @@ public class MQClientAPIImpl { } public void createTopic(final String addr, final String defaultTopic, final TopicConfig topicConfig, final long timeoutMillis) - throws RemotingException, MQBrokerException, InterruptedException, MQClientException { + throws RemotingException, MQBrokerException, InterruptedException, MQClientException { CreateTopicRequestHeader requestHeader = new CreateTopicRequestHeader(); requestHeader.setTopic(topicConfig.getTopicName()); requestHeader.setDefaultTopic(defaultTopic); @@ -185,7 +266,7 @@ public class MQClientAPIImpl { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.UPDATE_AND_CREATE_TOPIC, requestHeader); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), - request, timeoutMillis); + request, timeoutMillis); assert response != null; switch (response.getCode()) { case ResponseCode.SUCCESS: { @@ -199,31 +280,31 @@ public class MQClientAPIImpl { } public SendResult sendMessage(// - final String addr, // 1 - final String brokerName, // 2 - final Message msg, // 3 - final SendMessageRequestHeader requestHeader, // 4 - final long timeoutMillis, // 5 - final CommunicationMode communicationMode, // 6 - final SendMessageContext context, // 7 - final DefaultMQProducerImpl producer // 8 + final String addr, // 1 + final String brokerName, // 2 + final Message msg, // 3 + final SendMessageRequestHeader requestHeader, // 4 + final long timeoutMillis, // 5 + final CommunicationMode communicationMode, // 6 + final SendMessageContext context, // 7 + final DefaultMQProducerImpl producer // 8 ) throws RemotingException, MQBrokerException, InterruptedException { return sendMessage(addr, brokerName, msg, requestHeader, timeoutMillis, communicationMode, null, null, null, 0, context, producer); } public SendResult sendMessage(// - final String addr, // 1 - final String brokerName, // 2 - final Message msg, // 3 - final SendMessageRequestHeader requestHeader, // 4 - final long timeoutMillis, // 5 - final CommunicationMode communicationMode, // 6 - final SendCallback sendCallback, // 7 - final TopicPublishInfo topicPublishInfo, // 8 - final MQClientInstance instance, // 9 - final int retryTimesWhenSendFailed, // 10 - final SendMessageContext context, // 11 - final DefaultMQProducerImpl producer // 12 + final String addr, // 1 + final String brokerName, // 2 + final Message msg, // 3 + final SendMessageRequestHeader requestHeader, // 4 + final long timeoutMillis, // 5 + final CommunicationMode communicationMode, // 6 + final SendCallback sendCallback, // 7 + final TopicPublishInfo topicPublishInfo, // 8 + final MQClientInstance instance, // 9 + final int retryTimesWhenSendFailed, // 10 + final SendMessageContext context, // 11 + final DefaultMQProducerImpl producer // 12 ) throws RemotingException, MQBrokerException, InterruptedException { RemotingCommand request = null; if (sendSmartMsg) { @@ -242,7 +323,7 @@ public class MQClientAPIImpl { case ASYNC: final AtomicInteger times = new AtomicInteger(); this.sendMessageAsync(addr, brokerName, msg, timeoutMillis, request, sendCallback, topicPublishInfo, instance, - retryTimesWhenSendFailed, times, context, producer); + retryTimesWhenSendFailed, times, context, producer); return null; case SYNC: return this.sendMessageSync(addr, brokerName, msg, timeoutMillis, request); @@ -255,11 +336,11 @@ public class MQClientAPIImpl { } private SendResult sendMessageSync(// - final String addr, // - final String brokerName, // - final Message msg, // - final long timeoutMillis, // - final RemotingCommand request// + final String addr, // + final String brokerName, // + final Message msg, // + final long timeoutMillis, // + final RemotingCommand request// ) throws RemotingException, MQBrokerException, InterruptedException { RemotingCommand response = this.remotingClient.invokeSync(addr, request, timeoutMillis); assert response != null; @@ -267,18 +348,18 @@ public class MQClientAPIImpl { } private void sendMessageAsync(// - final String addr, // - final String brokerName, // - final Message msg, // - final long timeoutMillis, // - final RemotingCommand request, // - final SendCallback sendCallback, // - final TopicPublishInfo topicPublishInfo, // - final MQClientInstance instance, // - final int retryTimesWhenSendFailed, // - final AtomicInteger times, // - final SendMessageContext context, // - final DefaultMQProducerImpl producer // + final String addr, // + final String brokerName, // + final Message msg, // + final long timeoutMillis, // + final RemotingCommand request, // + final SendCallback sendCallback, // + final TopicPublishInfo topicPublishInfo, // + final MQClientInstance instance, // + final int retryTimesWhenSendFailed, // + final AtomicInteger times, // + final SendMessageContext context, // + final DefaultMQProducerImpl producer // ) throws InterruptedException, RemotingException { this.remotingClient.invokeAsync(addr, request, timeoutMillis, new InvokeCallback() { @Override @@ -318,68 +399,67 @@ public class MQClientAPIImpl { } catch (Exception e) { producer.updateFaultItem(brokerName, System.currentTimeMillis() - responseFuture.getBeginTimestamp(), true); onExceptionImpl(brokerName, msg, 0L, request, sendCallback, topicPublishInfo, instance, - retryTimesWhenSendFailed, times, e, context, false, producer); + retryTimesWhenSendFailed, times, e, context, false, producer); } } else { producer.updateFaultItem(brokerName, System.currentTimeMillis() - responseFuture.getBeginTimestamp(), true); if (!responseFuture.isSendRequestOK()) { MQClientException ex = new MQClientException("send request failed", responseFuture.getCause()); onExceptionImpl(brokerName, msg, 0L, request, sendCallback, topicPublishInfo, instance, - retryTimesWhenSendFailed, times, ex, context, true, producer); + retryTimesWhenSendFailed, times, ex, context, true, producer); } else if (responseFuture.isTimeout()) { MQClientException ex = new MQClientException("wait response timeout " + responseFuture.getTimeoutMillis() + "ms", - responseFuture.getCause()); + responseFuture.getCause()); onExceptionImpl(brokerName, msg, 0L, request, sendCallback, topicPublishInfo, instance, - retryTimesWhenSendFailed, times, ex, context, true, producer); + retryTimesWhenSendFailed, times, ex, context, true, producer); } else { MQClientException ex = new MQClientException("unknow reseaon", responseFuture.getCause()); onExceptionImpl(brokerName, msg, 0L, request, sendCallback, topicPublishInfo, instance, - retryTimesWhenSendFailed, times, ex, context, true, producer); + retryTimesWhenSendFailed, times, ex, context, true, producer); } } } }); } - private void onExceptionImpl(final String brokerName, // - final Message msg, // - final long timeoutMillis, // - final RemotingCommand request, // - final SendCallback sendCallback, // - final TopicPublishInfo topicPublishInfo, // - final MQClientInstance instance, // - final int timesTotal, // - final AtomicInteger curTimes, // - final Exception e, // - final SendMessageContext context, // - final boolean needRetry, // - final DefaultMQProducerImpl producer // 12 + final Message msg, // + final long timeoutMillis, // + final RemotingCommand request, // + final SendCallback sendCallback, // + final TopicPublishInfo topicPublishInfo, // + final MQClientInstance instance, // + final int timesTotal, // + final AtomicInteger curTimes, // + final Exception e, // + final SendMessageContext context, // + final boolean needRetry, // + final DefaultMQProducerImpl producer // 12 ) { int tmp = curTimes.incrementAndGet(); if (needRetry && tmp <= timesTotal) { MessageQueue tmpmq = producer.selectOneMessageQueue(topicPublishInfo, brokerName); String addr = instance.findBrokerAddressInPublish(tmpmq.getBrokerName()); log.info("async send msg by retry {} times. topic={}, brokerAddr={}, brokerName={}", tmp, msg.getTopic(), addr, - tmpmq.getBrokerName()); + tmpmq.getBrokerName()); try { request.setOpaque(RemotingCommand.createNewRequestId()); sendMessageAsync(addr, tmpmq.getBrokerName(), msg, timeoutMillis, request, sendCallback, topicPublishInfo, instance, - timesTotal, curTimes, context, producer); + timesTotal, curTimes, context, producer); } catch (InterruptedException e1) { onExceptionImpl(tmpmq.getBrokerName(), msg, timeoutMillis, request, sendCallback, topicPublishInfo, instance, timesTotal, curTimes, e1, - context, false, producer); + context, false, producer); } catch (RemotingConnectException e1) { producer.updateFaultItem(brokerName, 3000, true); onExceptionImpl(tmpmq.getBrokerName(), msg, timeoutMillis, request, sendCallback, topicPublishInfo, instance, timesTotal, curTimes, e1, - context, true, producer); + context, true, producer); } catch (RemotingTooMuchRequestException e1) { onExceptionImpl(tmpmq.getBrokerName(), msg, timeoutMillis, request, sendCallback, topicPublishInfo, instance, timesTotal, curTimes, e1, - context, false, producer); + context, false, producer); } catch (RemotingException e1) { producer.updateFaultItem(brokerName, 3000, true); onExceptionImpl(tmpmq.getBrokerName(), msg, timeoutMillis, request, sendCallback, topicPublishInfo, instance, timesTotal, curTimes, e1, - context, true, producer); + context, true, producer); } } else { if (context != null) { @@ -393,11 +473,10 @@ public class MQClientAPIImpl { } } - private SendResult processSendResponse(// - final String brokerName, // - final Message msg, // - final RemotingCommand response// + final String brokerName, // + final Message msg, // + final RemotingCommand response// ) throws MQBrokerException, RemotingCommandException { switch (response.getCode()) { case ResponseCode.FLUSH_DISK_TIMEOUT: @@ -426,13 +505,13 @@ public class MQClientAPIImpl { } SendMessageResponseHeader responseHeader = - (SendMessageResponseHeader) response.decodeCommandCustomHeader(SendMessageResponseHeader.class); + (SendMessageResponseHeader)response.decodeCommandCustomHeader(SendMessageResponseHeader.class); MessageQueue messageQueue = new MessageQueue(msg.getTopic(), brokerName, responseHeader.getQueueId()); SendResult sendResult = new SendResult(sendStatus, - MessageClientIDSetter.getUniqID(msg), - responseHeader.getMsgId(), messageQueue, responseHeader.getQueueOffset()); + MessageClientIDSetter.getUniqID(msg), + responseHeader.getMsgId(), messageQueue, responseHeader.getQueueOffset()); sendResult.setTransactionId(responseHeader.getTransactionId()); String regionId = response.getExtFields().get(MessageConst.PROPERTY_MSG_REGION); String traceOn = response.getExtFields().get(MessageConst.PROPERTY_TRACE_SWITCH); @@ -454,13 +533,12 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public PullResult pullMessage(// - final String addr, // - final PullMessageRequestHeader requestHeader, // - final long timeoutMillis, // - final CommunicationMode communicationMode, // - final PullCallback pullCallback// + final String addr, // + final PullMessageRequestHeader requestHeader, // + final long timeoutMillis, // + final CommunicationMode communicationMode, // + final PullCallback pullCallback// ) throws RemotingException, MQBrokerException, InterruptedException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.PULL_MESSAGE, requestHeader); @@ -481,12 +559,11 @@ public class MQClientAPIImpl { return null; } - private void pullMessageAsync(// - final String addr, // 1 - final RemotingCommand request, // - final long timeoutMillis, // - final PullCallback pullCallback// + final String addr, // 1 + final RemotingCommand request, // + final long timeoutMillis, // + final PullCallback pullCallback// ) throws RemotingException, InterruptedException { this.remotingClient.invokeAsync(addr, request, timeoutMillis, new InvokeCallback() { @Override @@ -505,7 +582,7 @@ public class MQClientAPIImpl { pullCallback.onException(new MQClientException("send request failed", responseFuture.getCause())); } else if (responseFuture.isTimeout()) { pullCallback.onException(new MQClientException("wait response timeout " + responseFuture.getTimeoutMillis() + "ms", - responseFuture.getCause())); + responseFuture.getCause())); } else { pullCallback.onException(new MQClientException("unknow reseaon", responseFuture.getCause())); } @@ -515,9 +592,9 @@ public class MQClientAPIImpl { } private PullResult pullMessageSync(// - final String addr, // 1 - final RemotingCommand request, // 2 - final long timeoutMillis// 3 + final String addr, // 1 + final RemotingCommand request, // 2 + final long timeoutMillis// 3 ) throws RemotingException, InterruptedException, MQBrokerException { RemotingCommand response = this.remotingClient.invokeSync(addr, request, timeoutMillis); assert response != null; @@ -545,20 +622,20 @@ public class MQClientAPIImpl { } PullMessageResponseHeader responseHeader = - (PullMessageResponseHeader) response.decodeCommandCustomHeader(PullMessageResponseHeader.class); + (PullMessageResponseHeader)response.decodeCommandCustomHeader(PullMessageResponseHeader.class); return new PullResultExt(pullStatus, responseHeader.getNextBeginOffset(), responseHeader.getMinOffset(), - responseHeader.getMaxOffset(), null, responseHeader.getSuggestWhichBrokerId(), response.getBody()); + responseHeader.getMaxOffset(), null, responseHeader.getSuggestWhichBrokerId(), response.getBody()); } public MessageExt viewMessage(final String addr, final long phyoffset, final long timeoutMillis) - throws RemotingException, MQBrokerException, InterruptedException { + throws RemotingException, MQBrokerException, InterruptedException { ViewMessageRequestHeader requestHeader = new ViewMessageRequestHeader(); requestHeader.setOffset(phyoffset); RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.VIEW_MESSAGE_BY_ID, requestHeader); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), - request, timeoutMillis); + request, timeoutMillis); assert response != null; switch (response.getCode()) { case ResponseCode.SUCCESS: { @@ -573,9 +650,8 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public long searchOffset(final String addr, final String topic, final int queueId, final long timestamp, final long timeoutMillis) - throws RemotingException, MQBrokerException, InterruptedException { + throws RemotingException, MQBrokerException, InterruptedException { SearchOffsetRequestHeader requestHeader = new SearchOffsetRequestHeader(); requestHeader.setTopic(topic); requestHeader.setQueueId(queueId); @@ -583,12 +659,12 @@ public class MQClientAPIImpl { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.SEARCH_OFFSET_BY_TIMESTAMP, requestHeader); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), - request, timeoutMillis); + request, timeoutMillis); assert response != null; switch (response.getCode()) { case ResponseCode.SUCCESS: { SearchOffsetResponseHeader responseHeader = - (SearchOffsetResponseHeader) response.decodeCommandCustomHeader(SearchOffsetResponseHeader.class); + (SearchOffsetResponseHeader)response.decodeCommandCustomHeader(SearchOffsetResponseHeader.class); return responseHeader.getOffset(); } default: @@ -598,21 +674,20 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public long getMaxOffset(final String addr, final String topic, final int queueId, final long timeoutMillis) - throws RemotingException, MQBrokerException, InterruptedException { + throws RemotingException, MQBrokerException, InterruptedException { GetMaxOffsetRequestHeader requestHeader = new GetMaxOffsetRequestHeader(); requestHeader.setTopic(topic); requestHeader.setQueueId(queueId); RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_MAX_OFFSET, requestHeader); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), - request, timeoutMillis); + request, timeoutMillis); assert response != null; switch (response.getCode()) { case ResponseCode.SUCCESS: { GetMaxOffsetResponseHeader responseHeader = - (GetMaxOffsetResponseHeader) response.decodeCommandCustomHeader(GetMaxOffsetResponseHeader.class); + (GetMaxOffsetResponseHeader)response.decodeCommandCustomHeader(GetMaxOffsetResponseHeader.class); return responseHeader.getOffset(); } @@ -623,24 +698,23 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public List getConsumerIdListByGroup(// - final String addr, // - final String consumerGroup, // - final long timeoutMillis) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, - MQBrokerException, InterruptedException { + final String addr, // + final String consumerGroup, // + final long timeoutMillis) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, + MQBrokerException, InterruptedException { GetConsumerListByGroupRequestHeader requestHeader = new GetConsumerListByGroupRequestHeader(); requestHeader.setConsumerGroup(consumerGroup); RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_CONSUMER_LIST_BY_GROUP, requestHeader); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), - request, timeoutMillis); + request, timeoutMillis); assert response != null; switch (response.getCode()) { case ResponseCode.SUCCESS: { if (response.getBody() != null) { GetConsumerListByGroupResponseBody body = - GetConsumerListByGroupResponseBody.decode(response.getBody(), GetConsumerListByGroupResponseBody.class); + GetConsumerListByGroupResponseBody.decode(response.getBody(), GetConsumerListByGroupResponseBody.class); return body.getConsumerIdList(); } } @@ -651,21 +725,20 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public long getMinOffset(final String addr, final String topic, final int queueId, final long timeoutMillis) - throws RemotingException, MQBrokerException, InterruptedException { + throws RemotingException, MQBrokerException, InterruptedException { GetMinOffsetRequestHeader requestHeader = new GetMinOffsetRequestHeader(); requestHeader.setTopic(topic); requestHeader.setQueueId(queueId); RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_MIN_OFFSET, requestHeader); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), - request, timeoutMillis); + request, timeoutMillis); assert response != null; switch (response.getCode()) { case ResponseCode.SUCCESS: { GetMinOffsetResponseHeader responseHeader = - (GetMinOffsetResponseHeader) response.decodeCommandCustomHeader(GetMinOffsetResponseHeader.class); + (GetMinOffsetResponseHeader)response.decodeCommandCustomHeader(GetMinOffsetResponseHeader.class); return responseHeader.getOffset(); } @@ -676,21 +749,20 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public long getEarliestMsgStoretime(final String addr, final String topic, final int queueId, final long timeoutMillis) - throws RemotingException, MQBrokerException, InterruptedException { + throws RemotingException, MQBrokerException, InterruptedException { GetEarliestMsgStoretimeRequestHeader requestHeader = new GetEarliestMsgStoretimeRequestHeader(); requestHeader.setTopic(topic); requestHeader.setQueueId(queueId); RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_EARLIEST_MSG_STORETIME, requestHeader); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), - request, timeoutMillis); + request, timeoutMillis); assert response != null; switch (response.getCode()) { case ResponseCode.SUCCESS: { GetEarliestMsgStoretimeResponseHeader responseHeader = - (GetEarliestMsgStoretimeResponseHeader) response.decodeCommandCustomHeader(GetEarliestMsgStoretimeResponseHeader.class); + (GetEarliestMsgStoretimeResponseHeader)response.decodeCommandCustomHeader(GetEarliestMsgStoretimeResponseHeader.class); return responseHeader.getTimestamp(); } @@ -701,21 +773,20 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public long queryConsumerOffset(// - final String addr, // - final QueryConsumerOffsetRequestHeader requestHeader, // - final long timeoutMillis// + final String addr, // + final QueryConsumerOffsetRequestHeader requestHeader, // + final long timeoutMillis// ) throws RemotingException, MQBrokerException, InterruptedException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.QUERY_CONSUMER_OFFSET, requestHeader); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), - request, timeoutMillis); + request, timeoutMillis); assert response != null; switch (response.getCode()) { case ResponseCode.SUCCESS: { QueryConsumerOffsetResponseHeader responseHeader = - (QueryConsumerOffsetResponseHeader) response.decodeCommandCustomHeader(QueryConsumerOffsetResponseHeader.class); + (QueryConsumerOffsetResponseHeader)response.decodeCommandCustomHeader(QueryConsumerOffsetResponseHeader.class); return responseHeader.getOffset(); } @@ -726,16 +797,15 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public void updateConsumerOffset(// - final String addr, // - final UpdateConsumerOffsetRequestHeader requestHeader, // - final long timeoutMillis// + final String addr, // + final UpdateConsumerOffsetRequestHeader requestHeader, // + final long timeoutMillis// ) throws RemotingException, MQBrokerException, InterruptedException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.UPDATE_CONSUMER_OFFSET, requestHeader); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), - request, timeoutMillis); + request, timeoutMillis); assert response != null; switch (response.getCode()) { case ResponseCode.SUCCESS: { @@ -748,23 +818,21 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public void updateConsumerOffsetOneway(// - final String addr, // - final UpdateConsumerOffsetRequestHeader requestHeader, // - final long timeoutMillis// + final String addr, // + final UpdateConsumerOffsetRequestHeader requestHeader, // + final long timeoutMillis// ) throws RemotingConnectException, RemotingTooMuchRequestException, RemotingTimeoutException, RemotingSendRequestException, - InterruptedException { + InterruptedException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.UPDATE_CONSUMER_OFFSET, requestHeader); this.remotingClient.invokeOneway(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), request, timeoutMillis); } - public void sendHearbeat(// - final String addr, // - final HeartbeatData heartbeatData, // - final long timeoutMillis// + final String addr, // + final HeartbeatData heartbeatData, // + final long timeoutMillis// ) throws RemotingException, MQBrokerException, InterruptedException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.HEART_BEAT, null); @@ -782,13 +850,12 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public void unregisterClient(// - final String addr, // - final String clientID, // - final String producerGroup, // - final String consumerGroup, // - final long timeoutMillis// + final String addr, // + final String clientID, // + final String producerGroup, // + final String consumerGroup, // + final long timeoutMillis// ) throws RemotingException, MQBrokerException, InterruptedException { final UnregisterClientRequestHeader requestHeader = new UnregisterClientRequestHeader(); requestHeader.setClientID(clientID); @@ -809,12 +876,11 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public void endTransactionOneway(// - final String addr, // - final EndTransactionRequestHeader requestHeader, // - final String remark, // - final long timeoutMillis// + final String addr, // + final EndTransactionRequestHeader requestHeader, // + final String remark, // + final long timeoutMillis// ) throws RemotingException, MQBrokerException, InterruptedException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.END_TRANSACTION, requestHeader); @@ -822,23 +888,21 @@ public class MQClientAPIImpl { this.remotingClient.invokeOneway(addr, request, timeoutMillis); } - public void queryMessage( - final String addr, - final QueryMessageRequestHeader requestHeader, - final long timeoutMillis, - final InvokeCallback invokeCallback, - final Boolean isUnqiueKey + final String addr, + final QueryMessageRequestHeader requestHeader, + final long timeoutMillis, + final InvokeCallback invokeCallback, + final Boolean isUnqiueKey ) throws RemotingException, MQBrokerException, InterruptedException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.QUERY_MESSAGE, requestHeader); request.addExtField(MixAll.UNIQUE_MSG_QUERY_FLAG, isUnqiueKey.toString()); this.remotingClient.invokeAsync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), request, timeoutMillis, - invokeCallback); + invokeCallback); } - public boolean registerClient(final String addr, final HeartbeatData heartbeat, final long timeoutMillis) - throws RemotingException, InterruptedException { + throws RemotingException, InterruptedException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.HEART_BEAT, null); request.setBody(heartbeat.encode()); @@ -846,14 +910,13 @@ public class MQClientAPIImpl { return response.getCode() == ResponseCode.SUCCESS; } - public void consumerSendMessageBack( - final String addr, - final MessageExt msg, - final String consumerGroup, - final int delayLevel, - final long timeoutMillis, - final int maxConsumeRetryTimes + final String addr, + final MessageExt msg, + final String consumerGroup, + final int delayLevel, + final long timeoutMillis, + final int maxConsumeRetryTimes ) throws RemotingException, MQBrokerException, InterruptedException { ConsumerSendMsgBackRequestHeader requestHeader = new ConsumerSendMsgBackRequestHeader(); RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.CONSUMER_SEND_MSG_BACK, requestHeader); @@ -866,7 +929,7 @@ public class MQClientAPIImpl { requestHeader.setMaxReconsumeTimes(maxConsumeRetryTimes); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), - request, timeoutMillis); + request, timeoutMillis); assert response != null; switch (response.getCode()) { case ResponseCode.SUCCESS: { @@ -879,16 +942,15 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public Set lockBatchMQ(// - final String addr, // - final LockBatchRequestBody requestBody, // - final long timeoutMillis) throws RemotingException, MQBrokerException, InterruptedException { + final String addr, // + final LockBatchRequestBody requestBody, // + final long timeoutMillis) throws RemotingException, MQBrokerException, InterruptedException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.LOCK_BATCH_MQ, null); request.setBody(requestBody.encode()); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), - request, timeoutMillis); + request, timeoutMillis); switch (response.getCode()) { case ResponseCode.SUCCESS: { LockBatchResponseBody responseBody = LockBatchResponseBody.decode(response.getBody(), LockBatchResponseBody.class); @@ -902,12 +964,11 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public void unlockBatchMQ(// - final String addr, // - final UnlockBatchRequestBody requestBody, // - final long timeoutMillis, // - final boolean oneway// + final String addr, // + final UnlockBatchRequestBody requestBody, // + final long timeoutMillis, // + final boolean oneway// ) throws RemotingException, MQBrokerException, InterruptedException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.UNLOCK_BATCH_MQ, null); @@ -917,7 +978,7 @@ public class MQClientAPIImpl { this.remotingClient.invokeOneway(addr, request, timeoutMillis); } else { RemotingCommand response = this.remotingClient - .invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), request, timeoutMillis); + .invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), request, timeoutMillis); switch (response.getCode()) { case ResponseCode.SUCCESS: { return; @@ -930,16 +991,15 @@ public class MQClientAPIImpl { } } - public TopicStatsTable getTopicStatsInfo(final String addr, final String topic, final long timeoutMillis) throws InterruptedException, - RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException { + RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException { GetTopicStatsInfoRequestHeader requestHeader = new GetTopicStatsInfoRequestHeader(); requestHeader.setTopic(topic); RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_TOPIC_STATS_INFO, requestHeader); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), - request, timeoutMillis); + request, timeoutMillis); switch (response.getCode()) { case ResponseCode.SUCCESS: { TopicStatsTable topicStatsTable = TopicStatsTable.decode(response.getBody(), TopicStatsTable.class); @@ -952,17 +1012,15 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public ConsumeStats getConsumeStats(final String addr, final String consumerGroup, final long timeoutMillis) - throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, - MQBrokerException { + throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, + MQBrokerException { return getConsumeStats(addr, consumerGroup, null, timeoutMillis); } - public ConsumeStats getConsumeStats(final String addr, final String consumerGroup, final String topic, final long timeoutMillis) - throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, - MQBrokerException { + throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, + MQBrokerException { GetConsumeStatsRequestHeader requestHeader = new GetConsumeStatsRequestHeader(); requestHeader.setConsumerGroup(consumerGroup); requestHeader.setTopic(topic); @@ -970,7 +1028,7 @@ public class MQClientAPIImpl { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_CONSUME_STATS, requestHeader); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), - request, timeoutMillis); + request, timeoutMillis); switch (response.getCode()) { case ResponseCode.SUCCESS: { ConsumeStats consumeStats = ConsumeStats.decode(response.getBody(), ConsumeStats.class); @@ -983,17 +1041,16 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public ProducerConnection getProducerConnectionList(final String addr, final String producerGroup, final long timeoutMillis) - throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, - MQBrokerException { + throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, + MQBrokerException { GetProducerConnectionListRequestHeader requestHeader = new GetProducerConnectionListRequestHeader(); requestHeader.setProducerGroup(producerGroup); RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_PRODUCER_CONNECTION_LIST, requestHeader); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), - request, timeoutMillis); + request, timeoutMillis); switch (response.getCode()) { case ResponseCode.SUCCESS: { return ProducerConnection.decode(response.getBody(), ProducerConnection.class); @@ -1005,17 +1062,16 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public ConsumerConnection getConsumerConnectionList(final String addr, final String consumerGroup, final long timeoutMillis) - throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, - MQBrokerException { + throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, + MQBrokerException { GetConsumerConnectionListRequestHeader requestHeader = new GetConsumerConnectionListRequestHeader(); requestHeader.setConsumerGroup(consumerGroup); RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_CONSUMER_CONNECTION_LIST, requestHeader); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), - request, timeoutMillis); + request, timeoutMillis); switch (response.getCode()) { case ResponseCode.SUCCESS: { ConsumerConnection consumerConnection = ConsumerConnection.decode(response.getBody(), ConsumerConnection.class); @@ -1028,14 +1084,13 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public KVTable getBrokerRuntimeInfo(final String addr, final long timeoutMillis) throws RemotingConnectException, - RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQBrokerException { + RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQBrokerException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_BROKER_RUNTIME_INFO, null); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), - request, timeoutMillis); + request, timeoutMillis); switch (response.getCode()) { case ResponseCode.SUCCESS: { return KVTable.decode(response.getBody(), KVTable.class); @@ -1047,10 +1102,9 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public void updateBrokerConfig(final String addr, final Properties properties, final long timeoutMillis) - throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, - MQBrokerException, UnsupportedEncodingException { + throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, + MQBrokerException, UnsupportedEncodingException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.UPDATE_BROKER_CONFIG, null); @@ -1058,7 +1112,7 @@ public class MQClientAPIImpl { if (str != null && str.length() > 0) { request.setBody(str.getBytes(MixAll.DEFAULT_CHARSET)); RemotingCommand response = this.remotingClient - .invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), request, timeoutMillis); + .invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), request, timeoutMillis); switch (response.getCode()) { case ResponseCode.SUCCESS: { return; @@ -1071,10 +1125,9 @@ public class MQClientAPIImpl { } } - public Properties getBrokerConfig(final String addr, final long timeoutMillis) - throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, - MQBrokerException, UnsupportedEncodingException { + throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, + MQBrokerException, UnsupportedEncodingException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_BROKER_CONFIG, null); RemotingCommand response = this.remotingClient.invokeSync(addr, request, timeoutMillis); @@ -1091,7 +1144,7 @@ public class MQClientAPIImpl { } public ClusterInfo getBrokerClusterInfo(final long timeoutMillis) throws InterruptedException, RemotingTimeoutException, - RemotingSendRequestException, RemotingConnectException, MQBrokerException { + RemotingSendRequestException, RemotingConnectException, MQBrokerException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_BROKER_CLUSTER_INFO, null); RemotingCommand response = this.remotingClient.invokeSync(null, request, timeoutMillis); @@ -1108,9 +1161,8 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public TopicRouteData getDefaultTopicRouteInfoFromNameServer(final String topic, final long timeoutMillis) - throws RemotingException, MQClientException, InterruptedException { + throws RemotingException, MQClientException, InterruptedException { GetRouteInfoRequestHeader requestHeader = new GetRouteInfoRequestHeader(); requestHeader.setTopic(topic); @@ -1136,9 +1188,8 @@ public class MQClientAPIImpl { throw new MQClientException(response.getCode(), response.getRemark()); } - public TopicRouteData getTopicRouteInfoFromNameServer(final String topic, final long timeoutMillis) - throws RemotingException, MQClientException, InterruptedException { + throws RemotingException, MQClientException, InterruptedException { GetRouteInfoRequestHeader requestHeader = new GetRouteInfoRequestHeader(); requestHeader.setTopic(topic); @@ -1165,9 +1216,8 @@ public class MQClientAPIImpl { throw new MQClientException(response.getCode(), response.getRemark()); } - public TopicList getTopicListFromNameServer(final long timeoutMillis) - throws RemotingException, MQClientException, InterruptedException { + throws RemotingException, MQClientException, InterruptedException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_TOPIC_LIST_FROM_NAMESERVER, null); RemotingCommand response = this.remotingClient.invokeSync(null, request, timeoutMillis); @@ -1187,9 +1237,8 @@ public class MQClientAPIImpl { throw new MQClientException(response.getCode(), response.getRemark()); } - public int wipeWritePermOfBroker(final String namesrvAddr, String brokerName, final long timeoutMillis) throws RemotingCommandException, - RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQClientException { + RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQClientException { WipeWritePermOfBrokerRequestHeader requestHeader = new WipeWritePermOfBrokerRequestHeader(); requestHeader.setBrokerName(brokerName); @@ -1200,7 +1249,7 @@ public class MQClientAPIImpl { switch (response.getCode()) { case ResponseCode.SUCCESS: { WipeWritePermOfBrokerResponseHeader responseHeader = - (WipeWritePermOfBrokerResponseHeader) response.decodeCommandCustomHeader(WipeWritePermOfBrokerResponseHeader.class); + (WipeWritePermOfBrokerResponseHeader)response.decodeCommandCustomHeader(WipeWritePermOfBrokerResponseHeader.class); return responseHeader.getWipeTopicCount(); } default: @@ -1210,15 +1259,14 @@ public class MQClientAPIImpl { throw new MQClientException(response.getCode(), response.getRemark()); } - public void deleteTopicInBroker(final String addr, final String topic, final long timeoutMillis) - throws RemotingException, MQBrokerException, InterruptedException, MQClientException { + throws RemotingException, MQBrokerException, InterruptedException, MQClientException { DeleteTopicRequestHeader requestHeader = new DeleteTopicRequestHeader(); requestHeader.setTopic(topic); RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.DELETE_TOPIC_IN_BROKER, requestHeader); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), - request, timeoutMillis); + request, timeoutMillis); assert response != null; switch (response.getCode()) { case ResponseCode.SUCCESS: { @@ -1231,9 +1279,8 @@ public class MQClientAPIImpl { throw new MQClientException(response.getCode(), response.getRemark()); } - public void deleteTopicInNameServer(final String addr, final String topic, final long timeoutMillis) - throws RemotingException, MQBrokerException, InterruptedException, MQClientException { + throws RemotingException, MQBrokerException, InterruptedException, MQClientException { DeleteTopicRequestHeader requestHeader = new DeleteTopicRequestHeader(); requestHeader.setTopic(topic); RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.DELETE_TOPIC_IN_NAMESRV, requestHeader); @@ -1251,15 +1298,14 @@ public class MQClientAPIImpl { throw new MQClientException(response.getCode(), response.getRemark()); } - public void deleteSubscriptionGroup(final String addr, final String groupName, final long timeoutMillis) - throws RemotingException, MQBrokerException, InterruptedException, MQClientException { + throws RemotingException, MQBrokerException, InterruptedException, MQClientException { DeleteSubscriptionGroupRequestHeader requestHeader = new DeleteSubscriptionGroupRequestHeader(); requestHeader.setGroupName(groupName); RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.DELETE_SUBSCRIPTIONGROUP, requestHeader); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), - request, timeoutMillis); + request, timeoutMillis); assert response != null; switch (response.getCode()) { case ResponseCode.SUCCESS: { @@ -1272,9 +1318,8 @@ public class MQClientAPIImpl { throw new MQClientException(response.getCode(), response.getRemark()); } - public String getKVConfigValue(final String namespace, final String key, final long timeoutMillis) - throws RemotingException, MQClientException, InterruptedException { + throws RemotingException, MQClientException, InterruptedException { GetKVConfigRequestHeader requestHeader = new GetKVConfigRequestHeader(); requestHeader.setNamespace(namespace); requestHeader.setKey(key); @@ -1286,7 +1331,7 @@ public class MQClientAPIImpl { switch (response.getCode()) { case ResponseCode.SUCCESS: { GetKVConfigResponseHeader responseHeader = - (GetKVConfigResponseHeader) response.decodeCommandCustomHeader(GetKVConfigResponseHeader.class); + (GetKVConfigResponseHeader)response.decodeCommandCustomHeader(GetKVConfigResponseHeader.class); return responseHeader.getValue(); } default: @@ -1296,9 +1341,8 @@ public class MQClientAPIImpl { throw new MQClientException(response.getCode(), response.getRemark()); } - public void putKVConfigValue(final String namespace, final String key, final String value, final long timeoutMillis) - throws RemotingException, MQClientException, InterruptedException { + throws RemotingException, MQClientException, InterruptedException { PutKVConfigRequestHeader requestHeader = new PutKVConfigRequestHeader(); requestHeader.setNamespace(namespace); requestHeader.setKey(key); @@ -1327,9 +1371,8 @@ public class MQClientAPIImpl { } } - public void deleteKVConfigValue(final String namespace, final String key, final long timeoutMillis) - throws RemotingException, MQClientException, InterruptedException { + throws RemotingException, MQClientException, InterruptedException { DeleteKVConfigRequestHeader requestHeader = new DeleteKVConfigRequestHeader(); requestHeader.setNamespace(namespace); requestHeader.setKey(key); @@ -1356,9 +1399,8 @@ public class MQClientAPIImpl { } } - public KVTable getKVListByNamespace(final String namespace, final long timeoutMillis) - throws RemotingException, MQClientException, InterruptedException { + throws RemotingException, MQClientException, InterruptedException { GetKVListByNamespaceRequestHeader requestHeader = new GetKVListByNamespaceRequestHeader(); requestHeader.setNamespace(namespace); @@ -1377,17 +1419,15 @@ public class MQClientAPIImpl { throw new MQClientException(response.getCode(), response.getRemark()); } - public Map invokeBrokerToResetOffset(final String addr, final String topic, final String group, - final long timestamp, final boolean isForce, final long timeoutMillis) - throws RemotingException, MQClientException, InterruptedException { + final long timestamp, final boolean isForce, final long timeoutMillis) + throws RemotingException, MQClientException, InterruptedException { return invokeBrokerToResetOffset(addr, topic, group, timestamp, isForce, timeoutMillis, false); } - public Map invokeBrokerToResetOffset(final String addr, final String topic, final String group, - final long timestamp, final boolean isForce, final long timeoutMillis, boolean isC) - throws RemotingException, MQClientException, InterruptedException { + final long timestamp, final boolean isForce, final long timeoutMillis, boolean isC) + throws RemotingException, MQClientException, InterruptedException { ResetOffsetRequestHeader requestHeader = new ResetOffsetRequestHeader(); requestHeader.setTopic(topic); requestHeader.setGroup(group); @@ -1400,7 +1440,7 @@ public class MQClientAPIImpl { } RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), - request, timeoutMillis); + request, timeoutMillis); assert response != null; switch (response.getCode()) { case ResponseCode.SUCCESS: { @@ -1416,9 +1456,8 @@ public class MQClientAPIImpl { throw new MQClientException(response.getCode(), response.getRemark()); } - public Map> invokeBrokerToGetConsumerStatus(final String addr, final String topic, final String group, - final String clientAddr, final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException { + final String clientAddr, final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException { GetConsumerStatusRequestHeader requestHeader = new GetConsumerStatusRequestHeader(); requestHeader.setTopic(topic); requestHeader.setGroup(group); @@ -1427,7 +1466,7 @@ public class MQClientAPIImpl { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.INVOKE_BROKER_TO_GET_CONSUMER_STATUS, requestHeader); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), - request, timeoutMillis); + request, timeoutMillis); assert response != null; switch (response.getCode()) { case ResponseCode.SUCCESS: { @@ -1443,17 +1482,16 @@ public class MQClientAPIImpl { throw new MQClientException(response.getCode(), response.getRemark()); } - public GroupList queryTopicConsumeByWho(final String addr, final String topic, final long timeoutMillis) - throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, - MQBrokerException { + throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, + MQBrokerException { QueryTopicConsumeByWhoRequestHeader requestHeader = new QueryTopicConsumeByWhoRequestHeader(); requestHeader.setTopic(topic); RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.QUERY_TOPIC_CONSUME_BY_WHO, requestHeader); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), - request, timeoutMillis); + request, timeoutMillis); switch (response.getCode()) { case ResponseCode.SUCCESS: { GroupList groupList = GroupList.decode(response.getBody(), GroupList.class); @@ -1466,10 +1504,9 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public List queryConsumeTimeSpan(final String addr, final String topic, final String group, final long timeoutMillis) - throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, - MQBrokerException { + throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, + MQBrokerException { QueryConsumeTimeSpanRequestHeader requestHeader = new QueryConsumeTimeSpanRequestHeader(); requestHeader.setTopic(topic); requestHeader.setGroup(group); @@ -1477,7 +1514,7 @@ public class MQClientAPIImpl { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.QUERY_CONSUME_TIME_SPAN, requestHeader); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), - request, timeoutMillis); + request, timeoutMillis); switch (response.getCode()) { case ResponseCode.SUCCESS: { QueryConsumeTimeSpanBody consumeTimeSpanBody = GroupList.decode(response.getBody(), QueryConsumeTimeSpanBody.class); @@ -1490,9 +1527,8 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public TopicList getTopicsByCluster(final String cluster, final long timeoutMillis) - throws RemotingException, MQClientException, InterruptedException { + throws RemotingException, MQClientException, InterruptedException { GetTopicsByClusterRequestHeader requestHeader = new GetTopicsByClusterRequestHeader(); requestHeader.setCluster(cluster); RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_TOPICS_BY_CLUSTER, requestHeader); @@ -1514,15 +1550,14 @@ public class MQClientAPIImpl { throw new MQClientException(response.getCode(), response.getRemark()); } - public void registerMessageFilterClass(final String addr, // - final String consumerGroup, // - final String topic, // - final String className, // - final int classCRC, // - final byte[] classBody, // - final long timeoutMillis) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, - InterruptedException, MQBrokerException { + final String consumerGroup, // + final String topic, // + final String className, // + final int classCRC, // + final byte[] classBody, // + final long timeoutMillis) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, + InterruptedException, MQBrokerException { RegisterMessageFilterClassRequestHeader requestHeader = new RegisterMessageFilterClassRequestHeader(); requestHeader.setConsumerGroup(consumerGroup); requestHeader.setClassName(className); @@ -1543,7 +1578,6 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public TopicList getSystemTopicList(final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_SYSTEM_TOPIC_LIST_FROM_NS, null); @@ -1555,7 +1589,7 @@ public class MQClientAPIImpl { if (body != null) { TopicList topicList = TopicList.decode(response.getBody(), TopicList.class); if (topicList.getTopicList() != null && !topicList.getTopicList().isEmpty() - && !UtilAll.isBlank(topicList.getBrokerAddr())) { + && !UtilAll.isBlank(topicList.getBrokerAddr())) { TopicList tmp = getSystemTopicListFromBroker(topicList.getBrokerAddr(), timeoutMillis); if (tmp.getTopicList() != null && !tmp.getTopicList().isEmpty()) { topicList.getTopicList().addAll(tmp.getTopicList()); @@ -1571,13 +1605,12 @@ public class MQClientAPIImpl { throw new MQClientException(response.getCode(), response.getRemark()); } - public TopicList getSystemTopicListFromBroker(final String addr, final long timeoutMillis) - throws RemotingException, MQClientException, InterruptedException { + throws RemotingException, MQClientException, InterruptedException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_SYSTEM_TOPIC_LIST_FROM_BROKER, null); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), - request, timeoutMillis); + request, timeoutMillis); assert response != null; switch (response.getCode()) { case ResponseCode.SUCCESS: { @@ -1594,12 +1627,11 @@ public class MQClientAPIImpl { throw new MQClientException(response.getCode(), response.getRemark()); } - public boolean cleanExpiredConsumeQueue(final String addr, long timeoutMillis) throws MQClientException, RemotingConnectException, - RemotingSendRequestException, RemotingTimeoutException, InterruptedException { + RemotingSendRequestException, RemotingTimeoutException, InterruptedException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.CLEAN_EXPIRED_CONSUMEQUEUE, null); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), - request, timeoutMillis); + request, timeoutMillis); switch (response.getCode()) { case ResponseCode.SUCCESS: { return true; @@ -1611,12 +1643,11 @@ public class MQClientAPIImpl { throw new MQClientException(response.getCode(), response.getRemark()); } - public boolean cleanUnusedTopicByAddr(final String addr, long timeoutMillis) throws MQClientException, RemotingConnectException, - RemotingSendRequestException, RemotingTimeoutException, InterruptedException { + RemotingSendRequestException, RemotingTimeoutException, InterruptedException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.CLEAN_UNUSED_TOPIC, null); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), - request, timeoutMillis); + request, timeoutMillis); switch (response.getCode()) { case ResponseCode.SUCCESS: { return true; @@ -1629,7 +1660,7 @@ public class MQClientAPIImpl { } public ConsumerRunningInfo getConsumerRunningInfo(final String addr, String consumerGroup, String clientId, boolean jstack, - final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException { + final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException { GetConsumerRunningInfoRequestHeader requestHeader = new GetConsumerRunningInfoRequestHeader(); requestHeader.setConsumerGroup(consumerGroup); requestHeader.setClientId(clientId); @@ -1638,7 +1669,7 @@ public class MQClientAPIImpl { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_CONSUMER_RUNNING_INFO, requestHeader); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), - request, timeoutMillis); + request, timeoutMillis); assert response != null; switch (response.getCode()) { case ResponseCode.SUCCESS: { @@ -1656,10 +1687,10 @@ public class MQClientAPIImpl { } public ConsumeMessageDirectlyResult consumeMessageDirectly(final String addr, // - String consumerGroup, // - String clientId, // - String msgId, // - final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException { + String consumerGroup, // + String clientId, // + String msgId, // + final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException { ConsumeMessageDirectlyResultRequestHeader requestHeader = new ConsumeMessageDirectlyResultRequestHeader(); requestHeader.setConsumerGroup(consumerGroup); requestHeader.setClientId(clientId); @@ -1668,7 +1699,7 @@ public class MQClientAPIImpl { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.CONSUME_MESSAGE_DIRECTLY, requestHeader); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), - request, timeoutMillis); + request, timeoutMillis); assert response != null; switch (response.getCode()) { case ResponseCode.SUCCESS: { @@ -1686,8 +1717,8 @@ public class MQClientAPIImpl { } public Map queryCorrectionOffset(final String addr, final String topic, final String group, Set filterGroup, - long timeoutMillis) throws MQClientException, RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, - InterruptedException { + long timeoutMillis) throws MQClientException, RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, + InterruptedException { QueryCorrectionOffsetHeader requestHeader = new QueryCorrectionOffsetHeader(); requestHeader.setCompareGroup(group); requestHeader.setTopic(topic); @@ -1703,7 +1734,7 @@ public class MQClientAPIImpl { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.QUERY_CORRECTION_OFFSET, requestHeader); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), - request, timeoutMillis); + request, timeoutMillis); assert response != null; switch (response.getCode()) { case ResponseCode.SUCCESS: { @@ -1720,7 +1751,7 @@ public class MQClientAPIImpl { } public TopicList getUnitTopicList(final boolean containRetry, final long timeoutMillis) - throws RemotingException, MQClientException, InterruptedException { + throws RemotingException, MQClientException, InterruptedException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_UNIT_TOPIC_LIST, null); RemotingCommand response = this.remotingClient.invokeSync(null, request, timeoutMillis); @@ -1749,9 +1780,8 @@ public class MQClientAPIImpl { throw new MQClientException(response.getCode(), response.getRemark()); } - public TopicList getHasUnitSubTopicList(final boolean containRetry, final long timeoutMillis) - throws RemotingException, MQClientException, InterruptedException { + throws RemotingException, MQClientException, InterruptedException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_HAS_UNIT_SUB_TOPIC_LIST, null); RemotingCommand response = this.remotingClient.invokeSync(null, request, timeoutMillis); @@ -1779,9 +1809,8 @@ public class MQClientAPIImpl { throw new MQClientException(response.getCode(), response.getRemark()); } - public TopicList getHasUnitSubUnUnitTopicList(final boolean containRetry, final long timeoutMillis) - throws RemotingException, MQClientException, InterruptedException { + throws RemotingException, MQClientException, InterruptedException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_HAS_UNIT_SUB_UNUNIT_TOPIC_LIST, null); RemotingCommand response = this.remotingClient.invokeSync(null, request, timeoutMillis); @@ -1809,9 +1838,8 @@ public class MQClientAPIImpl { throw new MQClientException(response.getCode(), response.getRemark()); } - public void cloneGroupOffset(final String addr, final String srcGroup, final String destGroup, final String topic, - final boolean isOffline, final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException { + final boolean isOffline, final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException { CloneGroupOffsetRequestHeader requestHeader = new CloneGroupOffsetRequestHeader(); requestHeader.setSrcGroup(srcGroup); requestHeader.setDestGroup(destGroup); @@ -1820,7 +1848,7 @@ public class MQClientAPIImpl { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.CLONE_GROUP_OFFSET, requestHeader); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), - request, timeoutMillis); + request, timeoutMillis); assert response != null; switch (response.getCode()) { case ResponseCode.SUCCESS: { @@ -1833,10 +1861,9 @@ public class MQClientAPIImpl { throw new MQClientException(response.getCode(), response.getRemark()); } - public BrokerStatsData viewBrokerStatsData(String brokerAddr, String statsName, String statsKey, long timeoutMillis) - throws MQClientException, RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, - InterruptedException { + throws MQClientException, RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, + InterruptedException { ViewBrokerStatsDataRequestHeader requestHeader = new ViewBrokerStatsDataRequestHeader(); requestHeader.setStatsName(statsName); requestHeader.setStatsKey(statsKey); @@ -1844,7 +1871,7 @@ public class MQClientAPIImpl { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.VIEW_BROKER_STATS_DATA, requestHeader); RemotingCommand response = this.remotingClient - .invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), brokerAddr), request, timeoutMillis); + .invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), brokerAddr), request, timeoutMillis); assert response != null; switch (response.getCode()) { case ResponseCode.SUCCESS: { @@ -1860,23 +1887,21 @@ public class MQClientAPIImpl { throw new MQClientException(response.getCode(), response.getRemark()); } - public Set getClusterList(String topic, long timeoutMillis) throws MQClientException, RemotingConnectException, - RemotingSendRequestException, RemotingTimeoutException, InterruptedException { + RemotingSendRequestException, RemotingTimeoutException, InterruptedException { // todo:jodie return Collections.EMPTY_SET; } - public ConsumeStatsList fetchConsumeStatsInBroker(String brokerAddr, boolean isOrder, long timeoutMillis) throws MQClientException, - RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException { + RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException { GetConsumeStatsInBrokerHeader requestHeader = new GetConsumeStatsInBrokerHeader(); requestHeader.setIsOrder(isOrder); RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_BROKER_CONSUME_STATS, requestHeader); RemotingCommand response = this.remotingClient - .invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), brokerAddr), request, timeoutMillis); + .invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), brokerAddr), request, timeoutMillis); assert response != null; switch (response.getCode()) { case ResponseCode.SUCCESS: { @@ -1892,12 +1917,11 @@ public class MQClientAPIImpl { throw new MQClientException(response.getCode(), response.getRemark()); } - public SubscriptionGroupWrapper getAllSubscriptionGroup(final String brokerAddr, long timeoutMillis) throws InterruptedException, - RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException { + RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_SUBSCRIPTIONGROUP_CONFIG, null); RemotingCommand response = this.remotingClient - .invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), brokerAddr), request, timeoutMillis); + .invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), brokerAddr), request, timeoutMillis); assert response != null; switch (response.getCode()) { case ResponseCode.SUCCESS: { @@ -1909,13 +1933,12 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public TopicConfigSerializeWrapper getAllTopicConfig(final String addr, long timeoutMillis) throws RemotingConnectException, - RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQBrokerException { + RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQBrokerException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_TOPIC_CONFIG, null); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), - request, timeoutMillis); + request, timeoutMillis); assert response != null; switch (response.getCode()) { case ResponseCode.SUCCESS: { @@ -1929,15 +1952,15 @@ public class MQClientAPIImpl { } public void updateNameServerConfig(final Properties properties, final List nameServers, long timeoutMillis) - throws UnsupportedEncodingException, - MQBrokerException, InterruptedException, RemotingTimeoutException, RemotingSendRequestException, - RemotingConnectException, MQClientException { + throws UnsupportedEncodingException, + MQBrokerException, InterruptedException, RemotingTimeoutException, RemotingSendRequestException, + RemotingConnectException, MQClientException { String str = MixAll.properties2String(properties); if (str == null || str.length() < 1) { return; } List invokeNameServers = (nameServers == null || nameServers.isEmpty()) ? - this.remotingClient.getNameServerAddressList() : nameServers; + this.remotingClient.getNameServerAddressList() : nameServers; if (invokeNameServers == null || invokeNameServers.isEmpty()) { return; } @@ -1964,11 +1987,11 @@ public class MQClientAPIImpl { } public Map getNameServerConfig(final List nameServers, long timeoutMillis) - throws InterruptedException, - RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, - MQClientException, UnsupportedEncodingException { + throws InterruptedException, + RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, + MQClientException, UnsupportedEncodingException { List invokeNameServers = (nameServers == null || nameServers.isEmpty()) ? - this.remotingClient.getNameServerAddressList() : nameServers; + this.remotingClient.getNameServerAddressList() : nameServers; if (invokeNameServers == null || invokeNameServers.isEmpty()) { return null; } diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/MQClientManager.java b/client/src/main/java/org/apache/rocketmq/client/impl/MQClientManager.java index 3cc2fdf0..9fd1b34b 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/MQClientManager.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/MQClientManager.java @@ -6,36 +6,32 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.impl; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicInteger; import org.apache.rocketmq.client.ClientConfig; import org.apache.rocketmq.client.impl.factory.MQClientInstance; import org.apache.rocketmq.remoting.RPCHook; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicInteger; - - public class MQClientManager { private static MQClientManager instance = new MQClientManager(); private AtomicInteger factoryIndexGenerator = new AtomicInteger(); private ConcurrentHashMap factoryTable = - new ConcurrentHashMap(); - + new ConcurrentHashMap(); private MQClientManager() { } - public static MQClientManager getInstance() { return instance; } @@ -49,8 +45,8 @@ public class MQClientManager { MQClientInstance instance = this.factoryTable.get(clientId); if (null == instance) { instance = - new MQClientInstance(clientConfig.cloneClientConfig(), - this.factoryIndexGenerator.getAndIncrement(), clientId, rpcHook); + new MQClientInstance(clientConfig.cloneClientConfig(), + this.factoryIndexGenerator.getAndIncrement(), clientId, rpcHook); MQClientInstance prev = this.factoryTable.putIfAbsent(clientId, instance); if (prev != null) { instance = prev; diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageConcurrentlyService.java b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageConcurrentlyService.java index e02bd4f0..e7a6ca37 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageConcurrentlyService.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageConcurrentlyService.java @@ -16,6 +16,19 @@ */ package org.apache.rocketmq.client.impl.consumer; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.Executors; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.RejectedExecutionException; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext; import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; @@ -35,10 +48,6 @@ import org.apache.rocketmq.common.protocol.body.ConsumeMessageDirectlyResult; import org.apache.rocketmq.remoting.common.RemotingHelper; import org.slf4j.Logger; -import java.util.*; -import java.util.concurrent.*; - - public class ConsumeMessageConcurrentlyService implements ConsumeMessageService { private static final Logger log = ClientLogger.getLog(); private final DefaultMQPushConsumerImpl defaultMQPushConsumerImpl; @@ -51,9 +60,8 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService private final ScheduledExecutorService scheduledExecutorService; private final ScheduledExecutorService cleanExpireMsgExecutors; - public ConsumeMessageConcurrentlyService(DefaultMQPushConsumerImpl defaultMQPushConsumerImpl, - MessageListenerConcurrently messageListener) { + MessageListenerConcurrently messageListener) { this.defaultMQPushConsumerImpl = defaultMQPushConsumerImpl; this.messageListener = messageListener; @@ -62,18 +70,17 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService this.consumeRequestQueue = new LinkedBlockingQueue(); this.consumeExecutor = new ThreadPoolExecutor(// - this.defaultMQPushConsumer.getConsumeThreadMin(), // - this.defaultMQPushConsumer.getConsumeThreadMax(), // - 1000 * 60, // - TimeUnit.MILLISECONDS, // - this.consumeRequestQueue, // - new ThreadFactoryImpl("ConsumeMessageThread_")); + this.defaultMQPushConsumer.getConsumeThreadMin(), // + this.defaultMQPushConsumer.getConsumeThreadMax(), // + 1000 * 60, // + TimeUnit.MILLISECONDS, // + this.consumeRequestQueue, // + new ThreadFactoryImpl("ConsumeMessageThread_")); this.scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryImpl("ConsumeMessageScheduledThread_")); this.cleanExpireMsgExecutors = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryImpl("CleanExpireMsgScheduledThread_")); } - public void start() { this.cleanExpireMsgExecutors.scheduleAtFixedRate(new Runnable() { @@ -85,7 +92,6 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService }, this.defaultMQPushConsumer.getConsumeTimeout(), this.defaultMQPushConsumer.getConsumeTimeout(), TimeUnit.MINUTES); } - public void shutdown() { this.scheduledExecutorService.shutdown(); this.consumeExecutor.shutdown(); @@ -95,8 +101,8 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService @Override public void updateCorePoolSize(int corePoolSize) { if (corePoolSize > 0 // - && corePoolSize <= Short.MAX_VALUE // - && corePoolSize < this.defaultMQPushConsumer.getConsumeThreadMax()) { + && corePoolSize <= Short.MAX_VALUE // + && corePoolSize < this.defaultMQPushConsumer.getConsumeThreadMax()) { this.consumeExecutor.setCorePoolSize(corePoolSize); } } @@ -180,10 +186,10 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService result.setRemark(RemotingHelper.exceptionSimpleDesc(e)); log.warn(String.format("consumeMessageDirectly exception: %s Group: %s Msgs: %s MQ: %s", // - RemotingHelper.exceptionSimpleDesc(e), // - ConsumeMessageConcurrentlyService.this.consumerGroup, // - msgs, // - mq), e); + RemotingHelper.exceptionSimpleDesc(e), // + ConsumeMessageConcurrentlyService.this.consumerGroup, // + msgs, // + mq), e); } result.setSpentTimeMills(System.currentTimeMillis() - beginTime); @@ -195,10 +201,10 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService @Override public void submitConsumeRequest(// - final List msgs, // - final ProcessQueue processQueue, // - final MessageQueue messageQueue, // - final boolean dispatchToConsume) { + final List msgs, // + final ProcessQueue processQueue, // + final MessageQueue messageQueue, // + final boolean dispatchToConsume) { final int consumeBatchSize = this.defaultMQPushConsumer.getConsumeMessageBatchMaxSize(); if (msgs.size() <= consumeBatchSize) { ConsumeRequest consumeRequest = new ConsumeRequest(msgs, processQueue, messageQueue); @@ -244,7 +250,7 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService private void cleanExpireMsg() { Iterator> it = - this.defaultMQPushConsumerImpl.getRebalanceImpl().getProcessQueueTable().entrySet().iterator(); + this.defaultMQPushConsumerImpl.getRebalanceImpl().getProcessQueueTable().entrySet().iterator(); while (it.hasNext()) { Map.Entry next = it.next(); ProcessQueue pq = next.getValue(); @@ -253,9 +259,9 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService } public void processConsumeResult(// - final ConsumeConcurrentlyStatus status, // - final ConsumeConcurrentlyContext context, // - final ConsumeRequest consumeRequest// + final ConsumeConcurrentlyStatus status, // + final ConsumeConcurrentlyContext context, // + final ConsumeRequest consumeRequest// ) { int ackIndex = context.getAckIndex(); @@ -275,7 +281,7 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService case RECONSUME_LATER: ackIndex = -1; this.getConsumerStatsManager().incConsumeFailedTPS(consumerGroup, consumeRequest.getMessageQueue().getTopic(), - consumeRequest.getMsgs().size()); + consumeRequest.getMsgs().size()); break; default: break; @@ -333,9 +339,9 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService } private void submitConsumeRequestLater(// - final List msgs, // - final ProcessQueue processQueue, // - final MessageQueue messageQueue// + final List msgs, // + final ProcessQueue processQueue, // + final MessageQueue messageQueue// ) { this.scheduledExecutorService.schedule(new Runnable() { @@ -364,7 +370,6 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService private final ProcessQueue processQueue; private final MessageQueue messageQueue; - public ConsumeRequest(List msgs, ProcessQueue processQueue, MessageQueue messageQueue) { this.msgs = msgs; this.processQueue = processQueue; @@ -414,10 +419,10 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService status = listener.consumeMessage(Collections.unmodifiableList(msgs), context); } catch (Throwable e) { log.warn("consumeMessage exception: {} Group: {} Msgs: {} MQ: {}", - RemotingHelper.exceptionSimpleDesc(e), // - ConsumeMessageConcurrentlyService.this.consumerGroup, - msgs, - messageQueue); + RemotingHelper.exceptionSimpleDesc(e), // + ConsumeMessageConcurrentlyService.this.consumerGroup, + msgs, + messageQueue); hasException = true; } long consumeRT = System.currentTimeMillis() - beginTimestamp; @@ -437,9 +442,9 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService consumeMessageContext.getProps().put(MixAll.CONSUME_CONTEXT_TYPE, returnType.name()); if (null == status) { log.warn("consumeMessage return null, Group: {} Msgs: {} MQ: {}", - ConsumeMessageConcurrentlyService.this.consumerGroup, - msgs, - messageQueue); + ConsumeMessageConcurrentlyService.this.consumerGroup, + msgs, + messageQueue); status = ConsumeConcurrentlyStatus.RECONSUME_LATER; } @@ -450,7 +455,7 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService } ConsumeMessageConcurrentlyService.this.getConsumerStatsManager() - .incConsumeRT(ConsumeMessageConcurrentlyService.this.consumerGroup, messageQueue.getTopic(), consumeRT); + .incConsumeRT(ConsumeMessageConcurrentlyService.this.consumerGroup, messageQueue.getTopic(), consumeRT); if (!processQueue.isDropped()) { ConsumeMessageConcurrentlyService.this.processConsumeResult(status, context, this); @@ -463,6 +468,5 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService return messageQueue; } - } } diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageOrderlyService.java b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageOrderlyService.java index f6a1e4dc..3def2237 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageOrderlyService.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageOrderlyService.java @@ -16,35 +16,42 @@ */ package org.apache.rocketmq.client.impl.consumer; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.Executors; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; +import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyContext; import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyStatus; import org.apache.rocketmq.client.consumer.listener.ConsumeReturnType; +import org.apache.rocketmq.client.consumer.listener.MessageListenerOrderly; import org.apache.rocketmq.client.hook.ConsumeMessageContext; import org.apache.rocketmq.client.log.ClientLogger; import org.apache.rocketmq.client.stat.ConsumerStatsManager; import org.apache.rocketmq.common.MixAll; import org.apache.rocketmq.common.ThreadFactoryImpl; import org.apache.rocketmq.common.UtilAll; -import org.apache.rocketmq.common.message.*; +import org.apache.rocketmq.common.message.Message; +import org.apache.rocketmq.common.message.MessageAccessor; +import org.apache.rocketmq.common.message.MessageConst; +import org.apache.rocketmq.common.message.MessageExt; +import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.common.protocol.body.CMResult; import org.apache.rocketmq.common.protocol.body.ConsumeMessageDirectlyResult; import org.apache.rocketmq.common.protocol.heartbeat.MessageModel; import org.apache.rocketmq.remoting.common.RemotingHelper; -import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyContext; -import org.apache.rocketmq.client.consumer.listener.MessageListenerOrderly; import org.slf4j.Logger; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.concurrent.*; - - public class ConsumeMessageOrderlyService implements ConsumeMessageService { private static final Logger log = ClientLogger.getLog(); private final static long MAX_TIME_CONSUME_CONTINUOUSLY = - Long.parseLong(System.getProperty("rocketmq.client.maxTimeConsumeContinuously", "60000")); + Long.parseLong(System.getProperty("rocketmq.client.maxTimeConsumeContinuously", "60000")); private final DefaultMQPushConsumerImpl defaultMQPushConsumerImpl; private final DefaultMQPushConsumer defaultMQPushConsumer; private final MessageListenerOrderly messageListener; @@ -55,7 +62,6 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService { private final ScheduledExecutorService scheduledExecutorService; private volatile boolean stopped = false; - public ConsumeMessageOrderlyService(DefaultMQPushConsumerImpl defaultMQPushConsumerImpl, MessageListenerOrderly messageListener) { this.defaultMQPushConsumerImpl = defaultMQPushConsumerImpl; this.messageListener = messageListener; @@ -65,17 +71,16 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService { this.consumeRequestQueue = new LinkedBlockingQueue(); this.consumeExecutor = new ThreadPoolExecutor(// - this.defaultMQPushConsumer.getConsumeThreadMin(), // - this.defaultMQPushConsumer.getConsumeThreadMax(), // - 1000 * 60, // - TimeUnit.MILLISECONDS, // - this.consumeRequestQueue, // - new ThreadFactoryImpl("ConsumeMessageThread_")); + this.defaultMQPushConsumer.getConsumeThreadMin(), // + this.defaultMQPushConsumer.getConsumeThreadMax(), // + 1000 * 60, // + TimeUnit.MILLISECONDS, // + this.consumeRequestQueue, // + new ThreadFactoryImpl("ConsumeMessageThread_")); this.scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryImpl("ConsumeMessageScheduledThread_")); } - public void start() { if (MessageModel.CLUSTERING.equals(ConsumeMessageOrderlyService.this.defaultMQPushConsumerImpl.messageModel())) { this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() { @@ -87,7 +92,6 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService { } } - public void shutdown() { this.stopped = true; this.scheduledExecutorService.shutdown(); @@ -97,7 +101,6 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService { } } - public synchronized void unlockAllMQ() { this.defaultMQPushConsumerImpl.getRebalanceImpl().unlockAll(false); } @@ -105,8 +108,8 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService { @Override public void updateCorePoolSize(int corePoolSize) { if (corePoolSize > 0 // - && corePoolSize <= Short.MAX_VALUE // - && corePoolSize < this.defaultMQPushConsumer.getConsumeThreadMax()) { + && corePoolSize <= Short.MAX_VALUE // + && corePoolSize < this.defaultMQPushConsumer.getConsumeThreadMax()) { this.consumeExecutor.setCorePoolSize(corePoolSize); } } @@ -169,10 +172,10 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService { result.setRemark(RemotingHelper.exceptionSimpleDesc(e)); log.warn(String.format("consumeMessageDirectly exception: %s Group: %s Msgs: %s MQ: %s", // - RemotingHelper.exceptionSimpleDesc(e), // - ConsumeMessageOrderlyService.this.consumerGroup, // - msgs, // - mq), e); + RemotingHelper.exceptionSimpleDesc(e), // + ConsumeMessageOrderlyService.this.consumerGroup, // + msgs, // + mq), e); } result.setAutoCommit(context.isAutoCommit()); @@ -185,10 +188,10 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService { @Override public void submitConsumeRequest(// - final List msgs, // - final ProcessQueue processQueue, // - final MessageQueue messageQueue, // - final boolean dispathToConsume) { + final List msgs, // + final ProcessQueue processQueue, // + final MessageQueue messageQueue, // + final boolean dispathToConsume) { if (dispathToConsume) { ConsumeRequest consumeRequest = new ConsumeRequest(processQueue, messageQueue); this.consumeExecutor.submit(consumeRequest); @@ -224,9 +227,9 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService { } private void submitConsumeRequestLater(// - final ProcessQueue processQueue, // - final MessageQueue messageQueue, // - final long suspendTimeMillis// + final ProcessQueue processQueue, // + final MessageQueue messageQueue, // + final long suspendTimeMillis// ) { long timeMillis = suspendTimeMillis; if (timeMillis == -1) { @@ -249,10 +252,10 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService { } public boolean processConsumeResult(// - final List msgs, // - final ConsumeOrderlyStatus status, // - final ConsumeOrderlyContext context, // - final ConsumeRequest consumeRequest// + final List msgs, // + final ConsumeOrderlyStatus status, // + final ConsumeOrderlyContext context, // + final ConsumeRequest consumeRequest// ) { boolean continueConsume = true; long commitOffset = -1L; @@ -261,7 +264,7 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService { case COMMIT: case ROLLBACK: log.warn("the message queue consume result is illegal, we think you want to ack these message {}", - consumeRequest.getMessageQueue()); + consumeRequest.getMessageQueue()); case SUCCESS: commitOffset = consumeRequest.getProcessQueue().commit(); this.getConsumerStatsManager().incConsumeOKTPS(consumerGroup, consumeRequest.getMessageQueue().getTopic(), msgs.size()); @@ -271,9 +274,9 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService { if (checkReconsumeTimes(msgs)) { consumeRequest.getProcessQueue().makeMessageToCosumeAgain(msgs); this.submitConsumeRequestLater(// - consumeRequest.getProcessQueue(), // - consumeRequest.getMessageQueue(), // - context.getSuspendCurrentQueueTimeMillis()); + consumeRequest.getProcessQueue(), // + consumeRequest.getMessageQueue(), // + context.getSuspendCurrentQueueTimeMillis()); continueConsume = false; } else { commitOffset = consumeRequest.getProcessQueue().commit(); @@ -293,9 +296,9 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService { case ROLLBACK: consumeRequest.getProcessQueue().rollback(); this.submitConsumeRequestLater(// - consumeRequest.getProcessQueue(), // - consumeRequest.getMessageQueue(), // - context.getSuspendCurrentQueueTimeMillis()); + consumeRequest.getProcessQueue(), // + consumeRequest.getMessageQueue(), // + context.getSuspendCurrentQueueTimeMillis()); continueConsume = false; break; case SUSPEND_CURRENT_QUEUE_A_MOMENT: @@ -303,9 +306,9 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService { if (checkReconsumeTimes(msgs)) { consumeRequest.getProcessQueue().makeMessageToCosumeAgain(msgs); this.submitConsumeRequestLater(// - consumeRequest.getProcessQueue(), // - consumeRequest.getMessageQueue(), // - context.getSuspendCurrentQueueTimeMillis()); + consumeRequest.getProcessQueue(), // + consumeRequest.getMessageQueue(), // + context.getSuspendCurrentQueueTimeMillis()); continueConsume = false; } break; @@ -379,7 +382,6 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService { private final ProcessQueue processQueue; private final MessageQueue messageQueue; - public ConsumeRequest(ProcessQueue processQueue, MessageQueue messageQueue) { this.processQueue = processQueue; this.messageQueue = messageQueue; @@ -403,7 +405,7 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService { final Object objLock = messageQueueLock.fetchLockObject(this.messageQueue); synchronized (objLock) { if (MessageModel.BROADCASTING.equals(ConsumeMessageOrderlyService.this.defaultMQPushConsumerImpl.messageModel()) - || (this.processQueue.isLocked() && !this.processQueue.isLockExpired())) { + || (this.processQueue.isLocked() && !this.processQueue.isLockExpired())) { final long beginTime = System.currentTimeMillis(); for (boolean continueConsume = true; continueConsume; ) { if (this.processQueue.isDropped()) { @@ -412,14 +414,14 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService { } if (MessageModel.CLUSTERING.equals(ConsumeMessageOrderlyService.this.defaultMQPushConsumerImpl.messageModel()) - && !this.processQueue.isLocked()) { + && !this.processQueue.isLocked()) { log.warn("the message queue not locked, so consume later, {}", this.messageQueue); ConsumeMessageOrderlyService.this.tryLockLaterAndReconsume(this.messageQueue, this.processQueue, 10); break; } if (MessageModel.CLUSTERING.equals(ConsumeMessageOrderlyService.this.defaultMQPushConsumerImpl.messageModel()) - && this.processQueue.isLockExpired()) { + && this.processQueue.isLockExpired()) { log.warn("the message queue lock expired, so consume later, {}", this.messageQueue); ConsumeMessageOrderlyService.this.tryLockLaterAndReconsume(this.messageQueue, this.processQueue, 10); break; @@ -432,7 +434,7 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService { } final int consumeBatchSize = - ConsumeMessageOrderlyService.this.defaultMQPushConsumer.getConsumeMessageBatchMaxSize(); + ConsumeMessageOrderlyService.this.defaultMQPushConsumer.getConsumeMessageBatchMaxSize(); List msgs = this.processQueue.takeMessags(consumeBatchSize); if (!msgs.isEmpty()) { @@ -444,7 +446,7 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService { if (ConsumeMessageOrderlyService.this.defaultMQPushConsumerImpl.hasHook()) { consumeMessageContext = new ConsumeMessageContext(); consumeMessageContext - .setConsumerGroup(ConsumeMessageOrderlyService.this.defaultMQPushConsumer.getConsumerGroup()); + .setConsumerGroup(ConsumeMessageOrderlyService.this.defaultMQPushConsumer.getConsumerGroup()); consumeMessageContext.setMq(messageQueue); consumeMessageContext.setMsgList(msgs); consumeMessageContext.setSuccess(false); @@ -460,29 +462,29 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService { this.processQueue.getLockConsume().lock(); if (this.processQueue.isDropped()) { log.warn("consumeMessage, the message queue not be able to consume, because it's dropped. {}", - this.messageQueue); + this.messageQueue); break; } status = messageListener.consumeMessage(Collections.unmodifiableList(msgs), context); } catch (Throwable e) { log.warn("consumeMessage exception: {} Group: {} Msgs: {} MQ: {}", // - RemotingHelper.exceptionSimpleDesc(e), // - ConsumeMessageOrderlyService.this.consumerGroup, // - msgs, // - messageQueue); + RemotingHelper.exceptionSimpleDesc(e), // + ConsumeMessageOrderlyService.this.consumerGroup, // + msgs, // + messageQueue); hasException = true; } finally { this.processQueue.getLockConsume().unlock(); } if (null == status // - || ConsumeOrderlyStatus.ROLLBACK == status// - || ConsumeOrderlyStatus.SUSPEND_CURRENT_QUEUE_A_MOMENT == status) { + || ConsumeOrderlyStatus.ROLLBACK == status// + || ConsumeOrderlyStatus.SUSPEND_CURRENT_QUEUE_A_MOMENT == status) { log.warn("consumeMessage Orderly return not OK, Group: {} Msgs: {} MQ: {}", // - ConsumeMessageOrderlyService.this.consumerGroup, // - msgs, // - messageQueue); + ConsumeMessageOrderlyService.this.consumerGroup, // + msgs, // + messageQueue); } long consumeRT = System.currentTimeMillis() - beginTimestamp; @@ -507,12 +509,12 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService { if (ConsumeMessageOrderlyService.this.defaultMQPushConsumerImpl.hasHook()) { consumeMessageContext.setStatus(status.toString()); consumeMessageContext - .setSuccess(ConsumeOrderlyStatus.SUCCESS == status || ConsumeOrderlyStatus.COMMIT == status); + .setSuccess(ConsumeOrderlyStatus.SUCCESS == status || ConsumeOrderlyStatus.COMMIT == status); ConsumeMessageOrderlyService.this.defaultMQPushConsumerImpl.executeHookAfter(consumeMessageContext); } ConsumeMessageOrderlyService.this.getConsumerStatsManager() - .incConsumeRT(ConsumeMessageOrderlyService.this.consumerGroup, messageQueue.getTopic(), consumeRT); + .incConsumeRT(ConsumeMessageOrderlyService.this.consumerGroup, messageQueue.getTopic(), consumeRT); continueConsume = ConsumeMessageOrderlyService.this.processConsumeResult(msgs, status, context, this); } else { @@ -530,7 +532,6 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService { } } - } } diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageService.java b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageService.java index 3dc768c0..a59ab981 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageService.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageService.java @@ -6,48 +6,39 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.impl.consumer; +import java.util.List; import org.apache.rocketmq.common.message.MessageExt; import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.common.protocol.body.ConsumeMessageDirectlyResult; -import java.util.List; - - public interface ConsumeMessageService { void start(); - void shutdown(); - void updateCorePoolSize(int corePoolSize); - void incCorePoolSize(); - void decCorePoolSize(); - int getCorePoolSize(); - ConsumeMessageDirectlyResult consumeMessageDirectly(final MessageExt msg, final String brokerName); - void submitConsumeRequest(// - final List msgs, // - final ProcessQueue processQueue, // - final MessageQueue messageQueue, // - final boolean dispathToConsume); + final List msgs, // + final ProcessQueue processQueue, // + final MessageQueue messageQueue, // + final boolean dispathToConsume); } diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/DefaultMQPullConsumerImpl.java b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/DefaultMQPullConsumerImpl.java index f2165331..7c1b4d69 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/DefaultMQPullConsumerImpl.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/DefaultMQPullConsumerImpl.java @@ -16,6 +16,13 @@ */ package org.apache.rocketmq.client.impl.consumer; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import org.apache.rocketmq.client.QueryResult; import org.apache.rocketmq.client.Validators; import org.apache.rocketmq.client.consumer.DefaultMQPullConsumer; @@ -41,7 +48,11 @@ import org.apache.rocketmq.common.UtilAll; import org.apache.rocketmq.common.consumer.ConsumeFromWhere; import org.apache.rocketmq.common.filter.FilterAPI; import org.apache.rocketmq.common.help.FAQUrl; -import org.apache.rocketmq.common.message.*; +import org.apache.rocketmq.common.message.Message; +import org.apache.rocketmq.common.message.MessageAccessor; +import org.apache.rocketmq.common.message.MessageConst; +import org.apache.rocketmq.common.message.MessageExt; +import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.common.protocol.body.ConsumerRunningInfo; import org.apache.rocketmq.common.protocol.heartbeat.ConsumeType; import org.apache.rocketmq.common.protocol.heartbeat.MessageModel; @@ -52,10 +63,6 @@ import org.apache.rocketmq.remoting.common.RemotingHelper; import org.apache.rocketmq.remoting.exception.RemotingException; import org.slf4j.Logger; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; - - public class DefaultMQPullConsumerImpl implements MQConsumerInner { private final Logger log = ClientLogger.getLog(); private final DefaultMQPullConsumer defaultMQPullConsumer; @@ -69,7 +76,6 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner { private OffsetStore offsetStore; private RebalanceImpl rebalanceImpl = new RebalancePullImpl(this); - public DefaultMQPullConsumerImpl(final DefaultMQPullConsumer defaultMQPullConsumer, final RPCHook rpcHook) { this.defaultMQPullConsumer = defaultMQPullConsumer; this.rpcHook = rpcHook; @@ -92,9 +98,9 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner { private void makeSureStateOK() throws MQClientException { if (this.serviceState != ServiceState.RUNNING) { throw new MQClientException("The consumer service state not OK, "// - + this.serviceState// - + FAQUrl.suggestTodo(FAQUrl.CLIENT_SERVICE_NOT_OK), - null); + + this.serviceState// + + FAQUrl.suggestTodo(FAQUrl.CLIENT_SERVICE_NOT_OK), + null); } } @@ -146,17 +152,17 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner { } public PullResult pull(MessageQueue mq, String subExpression, long offset, int maxNums) - throws MQClientException, RemotingException, MQBrokerException, InterruptedException { + throws MQClientException, RemotingException, MQBrokerException, InterruptedException { return pull(mq, subExpression, offset, maxNums, this.defaultMQPullConsumer.getConsumerPullTimeoutMillis()); } public PullResult pull(MessageQueue mq, String subExpression, long offset, int maxNums, long timeout) - throws MQClientException, RemotingException, MQBrokerException, InterruptedException { + throws MQClientException, RemotingException, MQBrokerException, InterruptedException { return this.pullSyncImpl(mq, subExpression, offset, maxNums, false, timeout); } private PullResult pullSyncImpl(MessageQueue mq, String subExpression, long offset, int maxNums, boolean block, long timeout) - throws MQClientException, RemotingException, MQBrokerException, InterruptedException { + throws MQClientException, RemotingException, MQBrokerException, InterruptedException { this.makeSureStateOK(); if (null == mq) { @@ -179,7 +185,7 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner { SubscriptionData subscriptionData; try { subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPullConsumer.getConsumerGroup(), // - mq.getTopic(), subExpression); + mq.getTopic(), subExpression); } catch (Exception e) { throw new MQClientException("parse subscription error", e); } @@ -187,17 +193,17 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner { long timeoutMillis = block ? this.defaultMQPullConsumer.getConsumerTimeoutMillisWhenSuspend() : timeout; PullResult pullResult = this.pullAPIWrapper.pullKernelImpl(// - mq, // 1 - subscriptionData.getSubString(), // 2 - 0L, // 3 - offset, // 4 - maxNums, // 5 - sysFlag, // 6 - 0, // 7 - this.defaultMQPullConsumer.getBrokerSuspendMaxTimeMillis(), // 8 - timeoutMillis, // 9 - CommunicationMode.SYNC, // 10 - null// 11 + mq, // 1 + subscriptionData.getSubString(), // 2 + 0L, // 3 + offset, // 4 + maxNums, // 5 + sysFlag, // 6 + 0, // 7 + this.defaultMQPullConsumer.getBrokerSuspendMaxTimeMillis(), // 8 + timeoutMillis, // 9 + CommunicationMode.SYNC, // 10 + null// 11 ); this.pullAPIWrapper.processPullResult(mq, pullResult, subscriptionData); if (!this.consumeMessageHookList.isEmpty()) { @@ -219,7 +225,7 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner { if (!this.rebalanceImpl.getSubscriptionInner().containsKey(topic)) { try { SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPullConsumer.getConsumerGroup(), // - topic, SubscriptionData.SUB_ALL); + topic, SubscriptionData.SUB_ALL); this.rebalanceImpl.subscriptionInner.putIfAbsent(topic, subscriptionData); } catch (Exception e) { } @@ -357,23 +363,23 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner { } public void pull(MessageQueue mq, String subExpression, long offset, int maxNums, PullCallback pullCallback) - throws MQClientException, RemotingException, InterruptedException { + throws MQClientException, RemotingException, InterruptedException { pull(mq, subExpression, offset, maxNums, pullCallback, this.defaultMQPullConsumer.getConsumerPullTimeoutMillis()); } public void pull(MessageQueue mq, String subExpression, long offset, int maxNums, PullCallback pullCallback, long timeout) - throws MQClientException, RemotingException, InterruptedException { + throws MQClientException, RemotingException, InterruptedException { this.pullAsyncImpl(mq, subExpression, offset, maxNums, pullCallback, false, timeout); } private void pullAsyncImpl(// - final MessageQueue mq, // - final String subExpression, // - final long offset, // - final int maxNums, // - final PullCallback pullCallback, // - final boolean block, // - final long timeout) throws MQClientException, RemotingException, InterruptedException { + final MessageQueue mq, // + final String subExpression, // + final long offset, // + final int maxNums, // + final PullCallback pullCallback, // + final boolean block, // + final long timeout) throws MQClientException, RemotingException, InterruptedException { this.makeSureStateOK(); if (null == mq) { @@ -400,7 +406,7 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner { final SubscriptionData subscriptionData; try { subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPullConsumer.getConsumerGroup(), // - mq.getTopic(), subExpression); + mq.getTopic(), subExpression); } catch (Exception e) { throw new MQClientException("parse subscription error", e); } @@ -408,36 +414,36 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner { long timeoutMillis = block ? this.defaultMQPullConsumer.getConsumerTimeoutMillisWhenSuspend() : timeout; this.pullAPIWrapper.pullKernelImpl(// - mq, // 1 - subscriptionData.getSubString(), // 2 - 0L, // 3 - offset, // 4 - maxNums, // 5 - sysFlag, // 6 - 0, // 7 - this.defaultMQPullConsumer.getBrokerSuspendMaxTimeMillis(), // 8 - timeoutMillis, // 9 - CommunicationMode.ASYNC, // 10 - new PullCallback() { - - @Override - public void onSuccess(PullResult pullResult) { - pullCallback - .onSuccess(DefaultMQPullConsumerImpl.this.pullAPIWrapper.processPullResult(mq, pullResult, subscriptionData)); - } - - @Override - public void onException(Throwable e) { - pullCallback.onException(e); - } - }); + mq, // 1 + subscriptionData.getSubString(), // 2 + 0L, // 3 + offset, // 4 + maxNums, // 5 + sysFlag, // 6 + 0, // 7 + this.defaultMQPullConsumer.getBrokerSuspendMaxTimeMillis(), // 8 + timeoutMillis, // 9 + CommunicationMode.ASYNC, // 10 + new PullCallback() { + + @Override + public void onSuccess(PullResult pullResult) { + pullCallback + .onSuccess(DefaultMQPullConsumerImpl.this.pullAPIWrapper.processPullResult(mq, pullResult, subscriptionData)); + } + + @Override + public void onException(Throwable e) { + pullCallback.onException(e); + } + }); } catch (MQBrokerException e) { throw new MQClientException("pullAsync unknow exception", e); } } public PullResult pullBlockIfNotFound(MessageQueue mq, String subExpression, long offset, int maxNums) - throws MQClientException, RemotingException, MQBrokerException, InterruptedException { + throws MQClientException, RemotingException, MQBrokerException, InterruptedException { return this.pullSyncImpl(mq, subExpression, offset, maxNums, true, this.getDefaultMQPullConsumer().getConsumerPullTimeoutMillis()); } @@ -446,19 +452,19 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner { } public void pullBlockIfNotFound(MessageQueue mq, String subExpression, long offset, int maxNums, PullCallback pullCallback) - throws MQClientException, RemotingException, InterruptedException { + throws MQClientException, RemotingException, InterruptedException { this.pullAsyncImpl(mq, subExpression, offset, maxNums, pullCallback, true, - this.getDefaultMQPullConsumer().getConsumerPullTimeoutMillis()); + this.getDefaultMQPullConsumer().getConsumerPullTimeoutMillis()); } public QueryResult queryMessage(String topic, String key, int maxNum, long begin, long end) - throws MQClientException, InterruptedException { + throws MQClientException, InterruptedException { this.makeSureStateOK(); return this.mQClientFactory.getMQAdminImpl().queryMessage(topic, key, maxNum, begin, end); } public MessageExt queryMessageByUniqKey(String topic, String uniqKey) - throws MQClientException, InterruptedException { + throws MQClientException, InterruptedException { this.makeSureStateOK(); return this.mQClientFactory.getMQAdminImpl().queryMessageByUniqKey(topic, uniqKey); } @@ -469,27 +475,27 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner { } public void sendMessageBack(MessageExt msg, int delayLevel, final String brokerName) - throws RemotingException, MQBrokerException, InterruptedException, MQClientException { + throws RemotingException, MQBrokerException, InterruptedException, MQClientException { sendMessageBack(msg, delayLevel, brokerName, this.defaultMQPullConsumer.getConsumerGroup()); } public void updateConsumeOffsetToBroker(MessageQueue mq, long offset, boolean isOneway) throws RemotingException, - MQBrokerException, InterruptedException, MQClientException { + MQBrokerException, InterruptedException, MQClientException { this.offsetStore.updateConsumeOffsetToBroker(mq, offset, isOneway); } public void sendMessageBack(MessageExt msg, int delayLevel, final String brokerName, String consumerGroup) - throws RemotingException, MQBrokerException, InterruptedException, MQClientException { + throws RemotingException, MQBrokerException, InterruptedException, MQClientException { try { String brokerAddr = (null != brokerName) ? this.mQClientFactory.findBrokerAddressInPublish(brokerName) - : RemotingHelper.parseSocketAddressAddr(msg.getStoreHost()); + : RemotingHelper.parseSocketAddressAddr(msg.getStoreHost()); if (UtilAll.isBlank(consumerGroup)) { consumerGroup = this.defaultMQPullConsumer.getConsumerGroup(); } this.mQClientFactory.getMQClientAPIImpl().consumerSendMessageBack(brokerAddr, msg, consumerGroup, delayLevel, 3000, - this.defaultMQPullConsumer.getMaxReconsumeTimes()); + this.defaultMQPullConsumer.getMaxReconsumeTimes()); } catch (Exception e) { log.error("sendMessageBack Exception, " + this.defaultMQPullConsumer.getConsumerGroup(), e); @@ -545,8 +551,8 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner { this.rebalanceImpl.setmQClientFactory(this.mQClientFactory); this.pullAPIWrapper = new PullAPIWrapper(// - mQClientFactory, // - this.defaultMQPullConsumer.getConsumerGroup(), isUnitMode()); + mQClientFactory, // + this.defaultMQPullConsumer.getConsumerGroup(), isUnitMode()); this.pullAPIWrapper.registerFilterMessageHook(filterMessageHookList); if (this.defaultMQPullConsumer.getOffsetStore() != null) { @@ -571,8 +577,8 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner { this.serviceState = ServiceState.CREATE_JUST; throw new MQClientException("The consumer group[" + this.defaultMQPullConsumer.getConsumerGroup() - + "] has been created before, specify another name please." + FAQUrl.suggestTodo(FAQUrl.GROUP_NAME_DUPLICATE_URL), - null); + + "] has been created before, specify another name please." + FAQUrl.suggestTodo(FAQUrl.GROUP_NAME_DUPLICATE_URL), + null); } mQClientFactory.start(); @@ -583,9 +589,9 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner { case START_FAILED: case SHUTDOWN_ALREADY: throw new MQClientException("The PullConsumer service state not OK, maybe started once, "// - + this.serviceState// - + FAQUrl.suggestTodo(FAQUrl.CLIENT_SERVICE_NOT_OK), - null); + + this.serviceState// + + FAQUrl.suggestTodo(FAQUrl.CLIENT_SERVICE_NOT_OK), + null); default: break; } @@ -598,43 +604,43 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner { // consumerGroup if (null == this.defaultMQPullConsumer.getConsumerGroup()) { throw new MQClientException( - "consumerGroup is null" // - + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), // - null); + "consumerGroup is null" // + + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), // + null); } // consumerGroup if (this.defaultMQPullConsumer.getConsumerGroup().equals(MixAll.DEFAULT_CONSUMER_GROUP)) { throw new MQClientException( - "consumerGroup can not equal "// - + MixAll.DEFAULT_CONSUMER_GROUP // - + ", please specify another one."// - + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), // - null); + "consumerGroup can not equal "// + + MixAll.DEFAULT_CONSUMER_GROUP // + + ", please specify another one."// + + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), // + null); } // messageModel if (null == this.defaultMQPullConsumer.getMessageModel()) { throw new MQClientException( - "messageModel is null" // - + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), // - null); + "messageModel is null" // + + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), // + null); } // allocateMessageQueueStrategy if (null == this.defaultMQPullConsumer.getAllocateMessageQueueStrategy()) { throw new MQClientException( - "allocateMessageQueueStrategy is null" // - + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), // - null); + "allocateMessageQueueStrategy is null" // + + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), // + null); } // allocateMessageQueueStrategy if (this.defaultMQPullConsumer.getConsumerTimeoutMillisWhenSuspend() < this.defaultMQPullConsumer.getBrokerSuspendMaxTimeMillis()) { throw new MQClientException( - "Long polling mode, the consumer consumerTimeoutMillisWhenSuspend must greater than brokerSuspendMaxTimeMillis" // - + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), // - null); + "Long polling mode, the consumer consumerTimeoutMillisWhenSuspend must greater than brokerSuspendMaxTimeMillis" // + + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), // + null); } } @@ -644,7 +650,7 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner { if (registerTopics != null) { for (final String topic : registerTopics) { SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPullConsumer.getConsumerGroup(), // - topic, SubscriptionData.SUB_ALL); + topic, SubscriptionData.SUB_ALL); this.rebalanceImpl.getSubscriptionInner().put(topic, subscriptionData); } } @@ -696,7 +702,6 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner { return consumerStartTimestamp; } - public RebalanceImpl getRebalanceImpl() { return rebalanceImpl; } diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/DefaultMQPushConsumerImpl.java b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/DefaultMQPushConsumerImpl.java index 4241c0e8..c22c515a 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/DefaultMQPushConsumerImpl.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/DefaultMQPushConsumerImpl.java @@ -16,6 +16,17 @@ */ package org.apache.rocketmq.client.impl.consumer; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Properties; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import org.apache.rocketmq.client.QueryResult; import org.apache.rocketmq.client.Validators; import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; @@ -44,7 +55,11 @@ import org.apache.rocketmq.common.UtilAll; import org.apache.rocketmq.common.consumer.ConsumeFromWhere; import org.apache.rocketmq.common.filter.FilterAPI; import org.apache.rocketmq.common.help.FAQUrl; -import org.apache.rocketmq.common.message.*; +import org.apache.rocketmq.common.message.Message; +import org.apache.rocketmq.common.message.MessageAccessor; +import org.apache.rocketmq.common.message.MessageConst; +import org.apache.rocketmq.common.message.MessageExt; +import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.common.protocol.body.ConsumeStatus; import org.apache.rocketmq.common.protocol.body.ConsumerRunningInfo; import org.apache.rocketmq.common.protocol.body.ProcessQueueInfo; @@ -60,11 +75,6 @@ import org.apache.rocketmq.remoting.common.RemotingHelper; import org.apache.rocketmq.remoting.exception.RemotingException; import org.slf4j.Logger; -import java.util.*; -import java.util.Map.Entry; -import java.util.concurrent.ConcurrentHashMap; - - public class DefaultMQPushConsumerImpl implements MQConsumerInner { /** * Delay some time when exception occur @@ -98,7 +108,6 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { private long flowControlTimes1 = 0; private long flowControlTimes2 = 0; - public DefaultMQPushConsumerImpl(DefaultMQPushConsumer defaultMQPushConsumer, RPCHook rpcHook) { this.defaultMQPushConsumer = defaultMQPushConsumer; this.rpcHook = rpcHook; @@ -214,8 +223,8 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { this.executePullRequestLater(pullRequest, PULL_TIME_DELAY_MILLS_WHEN_FLOW_CONTROL); if ((flowControlTimes1++ % 1000) == 0) { log.warn( - "the consumer message buffer is full, so do flow control, minOffset={}, maxOffset={}, size={}, pullRequest={}, flowControlTimes={}", - processQueue.getMsgTreeMap().firstKey(), processQueue.getMsgTreeMap().lastKey(), size, pullRequest, flowControlTimes1); + "the consumer message buffer is full, so do flow control, minOffset={}, maxOffset={}, size={}, pullRequest={}, flowControlTimes={}", + processQueue.getMsgTreeMap().firstKey(), processQueue.getMsgTreeMap().lastKey(), size, pullRequest, flowControlTimes1); } return; } @@ -225,9 +234,9 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { this.executePullRequestLater(pullRequest, PULL_TIME_DELAY_MILLS_WHEN_FLOW_CONTROL); if ((flowControlTimes2++ % 1000) == 0) { log.warn( - "the queue's messages, span too long, so do flow control, minOffset={}, maxOffset={}, maxSpan={}, pullRequest={}, flowControlTimes={}", - processQueue.getMsgTreeMap().firstKey(), processQueue.getMsgTreeMap().lastKey(), processQueue.getMaxSpan(), - pullRequest, flowControlTimes2); + "the queue's messages, span too long, so do flow control, minOffset={}, maxOffset={}, maxSpan={}, pullRequest={}, flowControlTimes={}", + processQueue.getMsgTreeMap().firstKey(), processQueue.getMsgTreeMap().lastKey(), processQueue.getMaxSpan(), + pullRequest, flowControlTimes2); } return; } @@ -237,10 +246,10 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { final long offset = this.rebalanceImpl.computePullFromWhere(pullRequest.getMessageQueue()); boolean brokerBusy = offset < pullRequest.getNextOffset(); log.info("the first time to pull message, so fix offset from broker. pullRequest: {} NewOffset: {} brokerBusy: {}", - pullRequest, offset, brokerBusy); + pullRequest, offset, brokerBusy); if (brokerBusy) { log.info("[NOTIFYME]the first time to pull message, but pull request offset larger than broker consume offset. pullRequest: {} NewOffset: {}", - pullRequest, offset); + pullRequest, offset); } pullRequest.setLockedFirst(true); @@ -267,7 +276,7 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { public void onSuccess(PullResult pullResult) { if (pullResult != null) { pullResult = DefaultMQPushConsumerImpl.this.pullAPIWrapper.processPullResult(pullRequest.getMessageQueue(), pullResult, - subscriptionData); + subscriptionData); switch (pullResult.getPullStatus()) { case FOUND: @@ -275,7 +284,7 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { pullRequest.setNextOffset(pullResult.getNextBeginOffset()); long pullRT = System.currentTimeMillis() - beginTimestamp; DefaultMQPushConsumerImpl.this.getConsumerStatsManager().incPullRT(pullRequest.getConsumerGroup(), - pullRequest.getMessageQueue().getTopic(), pullRT); + pullRequest.getMessageQueue().getTopic(), pullRT); long firstMsgOffset = Long.MAX_VALUE; if (pullResult.getMsgFoundList() == null || pullResult.getMsgFoundList().isEmpty()) { @@ -284,30 +293,30 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { firstMsgOffset = pullResult.getMsgFoundList().get(0).getQueueOffset(); DefaultMQPushConsumerImpl.this.getConsumerStatsManager().incPullTPS(pullRequest.getConsumerGroup(), - pullRequest.getMessageQueue().getTopic(), pullResult.getMsgFoundList().size()); + pullRequest.getMessageQueue().getTopic(), pullResult.getMsgFoundList().size()); boolean dispathToConsume = processQueue.putMessage(pullResult.getMsgFoundList()); DefaultMQPushConsumerImpl.this.consumeMessageService.submitConsumeRequest(// - pullResult.getMsgFoundList(), // - processQueue, // - pullRequest.getMessageQueue(), // - dispathToConsume); + pullResult.getMsgFoundList(), // + processQueue, // + pullRequest.getMessageQueue(), // + dispathToConsume); if (DefaultMQPushConsumerImpl.this.defaultMQPushConsumer.getPullInterval() > 0) { DefaultMQPushConsumerImpl.this.executePullRequestLater(pullRequest, - DefaultMQPushConsumerImpl.this.defaultMQPushConsumer.getPullInterval()); + DefaultMQPushConsumerImpl.this.defaultMQPushConsumer.getPullInterval()); } else { DefaultMQPushConsumerImpl.this.executePullRequestImmediately(pullRequest); } } if (pullResult.getNextBeginOffset() < prevRequestOffset// - || firstMsgOffset < prevRequestOffset) { + || firstMsgOffset < prevRequestOffset) { log.warn( - "[BUG] pull message result maybe data wrong, nextBeginOffset: {} firstMsgOffset: {} prevRequestOffset: {}", // - pullResult.getNextBeginOffset(), // - firstMsgOffset, // - prevRequestOffset); + "[BUG] pull message result maybe data wrong, nextBeginOffset: {} firstMsgOffset: {} prevRequestOffset: {}", // + pullResult.getNextBeginOffset(), // + firstMsgOffset, // + prevRequestOffset); } break; @@ -327,7 +336,7 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { break; case OFFSET_ILLEGAL: log.warn("the pull request offset illegal, {} {}", // - pullRequest.toString(), pullResult.toString()); + pullRequest.toString(), pullResult.toString()); pullRequest.setNextOffset(pullResult.getNextBeginOffset()); pullRequest.getProcessQueue().setDropped(true); @@ -337,7 +346,7 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { public void run() { try { DefaultMQPushConsumerImpl.this.offsetStore.updateOffset(pullRequest.getMessageQueue(), - pullRequest.getNextOffset(), false); + pullRequest.getNextOffset(), false); DefaultMQPushConsumerImpl.this.offsetStore.persist(pullRequest.getMessageQueue()); @@ -356,7 +365,6 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { } } - @Override public void onException(Throwable e) { if (!pullRequest.getMessageQueue().getTopic().startsWith(MixAll.RETRY_GROUP_TOPIC_PREFIX)) { @@ -388,24 +396,24 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { } int sysFlag = PullSysFlag.buildSysFlag(// - commitOffsetEnable, // commitOffset - true, // suspend - subExpression != null, // subscription - classFilter // class filter + commitOffsetEnable, // commitOffset + true, // suspend + subExpression != null, // subscription + classFilter // class filter ); try { this.pullAPIWrapper.pullKernelImpl(// - pullRequest.getMessageQueue(), // 1 - subExpression, // 2 - subscriptionData.getSubVersion(), // 3 - pullRequest.getNextOffset(), // 4 - this.defaultMQPushConsumer.getPullBatchSize(), // 5 - sysFlag, // 6 - commitOffsetValue, // 7 - BROKER_SUSPEND_MAX_TIME_MILLIS, // 8 - CONSUMER_TIMEOUT_MILLIS_WHEN_SUSPEND, // 9 - CommunicationMode.ASYNC, // 10 - pullCallback// 11 + pullRequest.getMessageQueue(), // 1 + subExpression, // 2 + subscriptionData.getSubVersion(), // 3 + pullRequest.getNextOffset(), // 4 + this.defaultMQPushConsumer.getPullBatchSize(), // 5 + sysFlag, // 6 + commitOffsetValue, // 7 + BROKER_SUSPEND_MAX_TIME_MILLIS, // 8 + CONSUMER_TIMEOUT_MILLIS_WHEN_SUSPEND, // 9 + CommunicationMode.ASYNC, // 10 + pullCallback// 11 ); } catch (Exception e) { log.error("pullKernelImpl exception", e); @@ -416,9 +424,9 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { private void makeSureStateOK() throws MQClientException { if (this.serviceState != ServiceState.RUNNING) { throw new MQClientException("The consumer service state not OK, "// - + this.serviceState// - + FAQUrl.suggestTodo(FAQUrl.CLIENT_SERVICE_NOT_OK), - null); + + this.serviceState// + + FAQUrl.suggestTodo(FAQUrl.CLIENT_SERVICE_NOT_OK), + null); } } @@ -453,16 +461,15 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { } public QueryResult queryMessage(String topic, String key, int maxNum, long begin, long end) - throws MQClientException, InterruptedException { + throws MQClientException, InterruptedException { return this.mQClientFactory.getMQAdminImpl().queryMessage(topic, key, maxNum, begin, end); } public MessageExt queryMessageByUniqKey(String topic, String uniqKey) throws MQClientException, - InterruptedException { + InterruptedException { return this.mQClientFactory.getMQAdminImpl().queryMessageByUniqKey(topic, uniqKey); } - public void registerMessageListener(MessageListener messageListener) { this.messageListenerInner = messageListener; } @@ -474,12 +481,12 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { } public void sendMessageBack(MessageExt msg, int delayLevel, final String brokerName) - throws RemotingException, MQBrokerException, InterruptedException, MQClientException { + throws RemotingException, MQBrokerException, InterruptedException, MQClientException { try { String brokerAddr = (null != brokerName) ? this.mQClientFactory.findBrokerAddressInPublish(brokerName) - : RemotingHelper.parseSocketAddressAddr(msg.getStoreHost()); + : RemotingHelper.parseSocketAddressAddr(msg.getStoreHost()); this.mQClientFactory.getMQClientAPIImpl().consumerSendMessageBack(brokerAddr, msg, - this.defaultMQPushConsumer.getConsumerGroup(), delayLevel, 5000, getMaxReconsumeTimes()); + this.defaultMQPushConsumer.getConsumerGroup(), delayLevel, 5000, getMaxReconsumeTimes()); } catch (Exception e) { log.error("sendMessageBack Exception, " + this.defaultMQPushConsumer.getConsumerGroup(), e); @@ -532,7 +539,7 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { switch (this.serviceState) { case CREATE_JUST: log.info("the consumer [{}] start beginning. messageModel={}, isUnitMode={}", this.defaultMQPushConsumer.getConsumerGroup(), - this.defaultMQPushConsumer.getMessageModel(), this.defaultMQPushConsumer.isUnitMode()); + this.defaultMQPushConsumer.getMessageModel(), this.defaultMQPushConsumer.isUnitMode()); this.serviceState = ServiceState.START_FAILED; this.checkConfig(); @@ -551,8 +558,8 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { this.rebalanceImpl.setmQClientFactory(this.mQClientFactory); this.pullAPIWrapper = new PullAPIWrapper( - mQClientFactory, - this.defaultMQPushConsumer.getConsumerGroup(), isUnitMode()); + mQClientFactory, + this.defaultMQPushConsumer.getConsumerGroup(), isUnitMode()); this.pullAPIWrapper.registerFilterMessageHook(filterMessageHookList); if (this.defaultMQPushConsumer.getOffsetStore() != null) { @@ -574,11 +581,11 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { if (this.getMessageListenerInner() instanceof MessageListenerOrderly) { this.consumeOrderly = true; this.consumeMessageService = - new ConsumeMessageOrderlyService(this, (MessageListenerOrderly) this.getMessageListenerInner()); + new ConsumeMessageOrderlyService(this, (MessageListenerOrderly)this.getMessageListenerInner()); } else if (this.getMessageListenerInner() instanceof MessageListenerConcurrently) { this.consumeOrderly = false; this.consumeMessageService = - new ConsumeMessageConcurrentlyService(this, (MessageListenerConcurrently) this.getMessageListenerInner()); + new ConsumeMessageConcurrentlyService(this, (MessageListenerConcurrently)this.getMessageListenerInner()); } this.consumeMessageService.start(); @@ -588,8 +595,8 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { this.serviceState = ServiceState.CREATE_JUST; this.consumeMessageService.shutdown(); throw new MQClientException("The consumer group[" + this.defaultMQPushConsumer.getConsumerGroup() - + "] has been created before, specify another name please." + FAQUrl.suggestTodo(FAQUrl.GROUP_NAME_DUPLICATE_URL), - null); + + "] has been created before, specify another name please." + FAQUrl.suggestTodo(FAQUrl.GROUP_NAME_DUPLICATE_URL), + null); } mQClientFactory.start(); @@ -600,9 +607,9 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { case START_FAILED: case SHUTDOWN_ALREADY: throw new MQClientException("The PushConsumer service state not OK, maybe started once, "// - + this.serviceState// - + FAQUrl.suggestTodo(FAQUrl.CLIENT_SERVICE_NOT_OK), - null); + + this.serviceState// + + FAQUrl.suggestTodo(FAQUrl.CLIENT_SERVICE_NOT_OK), + null); default: break; } @@ -619,133 +626,133 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { if (null == this.defaultMQPushConsumer.getConsumerGroup()) { throw new MQClientException( - "consumerGroup is null" - + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), - null); + "consumerGroup is null" + + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), + null); } if (this.defaultMQPushConsumer.getConsumerGroup().equals(MixAll.DEFAULT_CONSUMER_GROUP)) { throw new MQClientException( - "consumerGroup can not equal " - + MixAll.DEFAULT_CONSUMER_GROUP - + ", please specify another one." - + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), - null); + "consumerGroup can not equal " + + MixAll.DEFAULT_CONSUMER_GROUP + + ", please specify another one." + + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), + null); } if (null == this.defaultMQPushConsumer.getMessageModel()) { throw new MQClientException( - "messageModel is null" - + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), - null); + "messageModel is null" + + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), + null); } if (null == this.defaultMQPushConsumer.getConsumeFromWhere()) { throw new MQClientException( - "consumeFromWhere is null" - + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), - null); + "consumeFromWhere is null" + + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), + null); } Date dt = UtilAll.parseDate(this.defaultMQPushConsumer.getConsumeTimestamp(), UtilAll.YYYY_MMDD_HHMMSS); if (null == dt) { throw new MQClientException( - "consumeTimestamp is invalid, YYYY_MMDD_HHMMSS" - + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), - null); + "consumeTimestamp is invalid, YYYY_MMDD_HHMMSS" + + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), + null); } // allocateMessageQueueStrategy if (null == this.defaultMQPushConsumer.getAllocateMessageQueueStrategy()) { throw new MQClientException( - "allocateMessageQueueStrategy is null" - + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), - null); + "allocateMessageQueueStrategy is null" + + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), + null); } // subscription if (null == this.defaultMQPushConsumer.getSubscription()) { throw new MQClientException( - "subscription is null" - + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), - null); + "subscription is null" + + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), + null); } // messageListener if (null == this.defaultMQPushConsumer.getMessageListener()) { throw new MQClientException( - "messageListener is null" - + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), - null); + "messageListener is null" + + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), + null); } boolean orderly = this.defaultMQPushConsumer.getMessageListener() instanceof MessageListenerOrderly; boolean concurrently = this.defaultMQPushConsumer.getMessageListener() instanceof MessageListenerConcurrently; if (!orderly && !concurrently) { throw new MQClientException( - "messageListener must be instanceof MessageListenerOrderly or MessageListenerConcurrently" - + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), - null); + "messageListener must be instanceof MessageListenerOrderly or MessageListenerConcurrently" + + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), + null); } // consumeThreadMin if (this.defaultMQPushConsumer.getConsumeThreadMin() < 1 - || this.defaultMQPushConsumer.getConsumeThreadMin() > 1000 - || this.defaultMQPushConsumer.getConsumeThreadMin() > this.defaultMQPushConsumer.getConsumeThreadMax()) { + || this.defaultMQPushConsumer.getConsumeThreadMin() > 1000 + || this.defaultMQPushConsumer.getConsumeThreadMin() > this.defaultMQPushConsumer.getConsumeThreadMax()) { throw new MQClientException( - "consumeThreadMin Out of range [1, 1000]" - + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), - null); + "consumeThreadMin Out of range [1, 1000]" + + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), + null); } // consumeThreadMax if (this.defaultMQPushConsumer.getConsumeThreadMax() < 1 || this.defaultMQPushConsumer.getConsumeThreadMax() > 1000) { throw new MQClientException( - "consumeThreadMax Out of range [1, 1000]" - + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), - null); + "consumeThreadMax Out of range [1, 1000]" + + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), + null); } // consumeConcurrentlyMaxSpan if (this.defaultMQPushConsumer.getConsumeConcurrentlyMaxSpan() < 1 - || this.defaultMQPushConsumer.getConsumeConcurrentlyMaxSpan() > 65535) { + || this.defaultMQPushConsumer.getConsumeConcurrentlyMaxSpan() > 65535) { throw new MQClientException( - "consumeConcurrentlyMaxSpan Out of range [1, 65535]" - + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), - null); + "consumeConcurrentlyMaxSpan Out of range [1, 65535]" + + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), + null); } // pullThresholdForQueue if (this.defaultMQPushConsumer.getPullThresholdForQueue() < 1 || this.defaultMQPushConsumer.getPullThresholdForQueue() > 65535) { throw new MQClientException( - "pullThresholdForQueue Out of range [1, 65535]" - + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), - null); + "pullThresholdForQueue Out of range [1, 65535]" + + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), + null); } // pullInterval if (this.defaultMQPushConsumer.getPullInterval() < 0 || this.defaultMQPushConsumer.getPullInterval() > 65535) { throw new MQClientException( - "pullInterval Out of range [0, 65535]" - + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), - null); + "pullInterval Out of range [0, 65535]" + + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), + null); } // consumeMessageBatchMaxSize if (this.defaultMQPushConsumer.getConsumeMessageBatchMaxSize() < 1 - || this.defaultMQPushConsumer.getConsumeMessageBatchMaxSize() > 1024) { + || this.defaultMQPushConsumer.getConsumeMessageBatchMaxSize() > 1024) { throw new MQClientException( - "consumeMessageBatchMaxSize Out of range [1, 1024]" - + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), - null); + "consumeMessageBatchMaxSize Out of range [1, 1024]" + + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), + null); } // pullBatchSize if (this.defaultMQPushConsumer.getPullBatchSize() < 1 || this.defaultMQPushConsumer.getPullBatchSize() > 1024) { throw new MQClientException( - "pullBatchSize Out of range [1, 1024]" - + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), - null); + "pullBatchSize Out of range [1, 1024]" + + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), + null); } } @@ -757,7 +764,7 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { final String topic = entry.getKey(); final String subString = entry.getValue(); SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPushConsumer.getConsumerGroup(), // - topic, subString); + topic, subString); this.rebalanceImpl.getSubscriptionInner().put(topic, subscriptionData); } } @@ -772,7 +779,7 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { case CLUSTERING: final String retryTopic = MixAll.getRetryTopic(this.defaultMQPushConsumer.getConsumerGroup()); SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPushConsumer.getConsumerGroup(), // - retryTopic, SubscriptionData.SUB_ALL); + retryTopic, SubscriptionData.SUB_ALL); this.rebalanceImpl.getSubscriptionInner().put(retryTopic, subscriptionData); break; default: @@ -804,7 +811,7 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { public void subscribe(String topic, String subExpression) throws MQClientException { try { SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPushConsumer.getConsumerGroup(), // - topic, subExpression); + topic, subExpression); this.rebalanceImpl.getSubscriptionInner().put(topic, subscriptionData); if (this.mQClientFactory != null) { this.mQClientFactory.sendHeartbeatToAllBrokerWithLock(); @@ -817,7 +824,7 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { public void subscribe(String topic, String fullClassName, String filterClassSource) throws MQClientException { try { SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPushConsumer.getConsumerGroup(), // - topic, "*"); + topic, "*"); subscriptionData.setSubString(fullClassName); subscriptionData.setClassFilterMode(true); subscriptionData.setFilterClassSource(filterClassSource); @@ -865,7 +872,7 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { } public void resetOffsetByTimeStamp(long timeStamp) - throws RemotingException, MQBrokerException, InterruptedException, MQClientException { + throws RemotingException, MQBrokerException, InterruptedException, MQClientException { for (String topic : rebalanceImpl.getSubscriptionInner().keySet()) { Set mqs = rebalanceImpl.getTopicSubscribeInfoTable().get(topic); Map offsetTable = new HashMap(); @@ -1017,9 +1024,9 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { long computeAccTotal = this.computeAccumulationTotal(); long adjustThreadPoolNumsThreshold = this.defaultMQPushConsumer.getAdjustThreadPoolNumsThreshold(); - long incThreshold = (long) (adjustThreadPoolNumsThreshold * 1.0); + long incThreshold = (long)(adjustThreadPoolNumsThreshold * 1.0); - long decThreshold = (long) (adjustThreadPoolNumsThreshold * 0.8); + long decThreshold = (long)(adjustThreadPoolNumsThreshold * 0.8); if (computeAccTotal >= incThreshold) { this.consumeMessageService.incCorePoolSize(); @@ -1044,7 +1051,7 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { } public List queryConsumeTimeSpan(final String topic) - throws RemotingException, MQClientException, InterruptedException, MQBrokerException { + throws RemotingException, MQClientException, InterruptedException, MQBrokerException { List queueTimeSpan = new ArrayList(); TopicRouteData routeData = this.mQClientFactory.getMQClientAPIImpl().getTopicRouteInfoFromNameServer(topic, 3000); for (BrokerData brokerData : routeData.getBrokerDatas()) { @@ -1055,12 +1062,10 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { return queueTimeSpan; } - public ConsumeMessageService getConsumeMessageService() { return consumeMessageService; } - public void setConsumeMessageService(ConsumeMessageService consumeMessageService) { this.consumeMessageService = consumeMessageService; diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/MQConsumerInner.java b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/MQConsumerInner.java index b1a2a250..ce4f2b96 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/MQConsumerInner.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/MQConsumerInner.java @@ -6,16 +6,17 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.impl.consumer; +import java.util.Set; import org.apache.rocketmq.common.consumer.ConsumeFromWhere; import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.common.protocol.body.ConsumerRunningInfo; @@ -23,9 +24,6 @@ import org.apache.rocketmq.common.protocol.heartbeat.ConsumeType; import org.apache.rocketmq.common.protocol.heartbeat.MessageModel; import org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData; -import java.util.Set; - - /** * Consumer inner interface * @@ -33,33 +31,23 @@ import java.util.Set; public interface MQConsumerInner { String groupName(); - MessageModel messageModel(); - ConsumeType consumeType(); - ConsumeFromWhere consumeFromWhere(); - Set subscriptions(); - void doRebalance(); - void persistConsumerOffset(); - void updateTopicSubscribeInfo(final String topic, final Set info); - boolean isSubscribeTopicNeedUpdate(final String topic); - boolean isUnitMode(); - ConsumerRunningInfo consumerRunningInfo(); } diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/MessageQueueLock.java b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/MessageQueueLock.java index 1e573c3b..47ae2b0d 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/MessageQueueLock.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/MessageQueueLock.java @@ -6,20 +6,18 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.impl.consumer; -import org.apache.rocketmq.common.message.MessageQueue; - import java.util.concurrent.ConcurrentHashMap; - +import org.apache.rocketmq.common.message.MessageQueue; /** * Message lock,strictly ensure the single queue only one thread at a time consuming @@ -27,8 +25,7 @@ import java.util.concurrent.ConcurrentHashMap; */ public class MessageQueueLock { private ConcurrentHashMap mqLockTable = - new ConcurrentHashMap(); - + new ConcurrentHashMap(); public Object fetchLockObject(final MessageQueue mq) { Object objLock = this.mqLockTable.get(mq); diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ProcessQueue.java b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ProcessQueue.java index f361f1fd..2d177038 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ProcessQueue.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ProcessQueue.java @@ -6,24 +6,16 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.impl.consumer; -import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; -import org.apache.rocketmq.client.log.ClientLogger; -import org.apache.rocketmq.common.message.MessageAccessor; -import org.apache.rocketmq.common.message.MessageConst; -import org.apache.rocketmq.common.message.MessageExt; -import org.apache.rocketmq.common.protocol.body.ProcessQueueInfo; -import org.slf4j.Logger; - import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -33,7 +25,13 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantReadWriteLock; - +import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; +import org.apache.rocketmq.client.log.ClientLogger; +import org.apache.rocketmq.common.message.MessageAccessor; +import org.apache.rocketmq.common.message.MessageConst; +import org.apache.rocketmq.common.message.MessageExt; +import org.apache.rocketmq.common.protocol.body.ProcessQueueInfo; +import org.slf4j.Logger; /** * Queue consumption snapshot @@ -41,7 +39,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; */ public class ProcessQueue { public final static long REBALANCE_LOCK_MAX_LIVE_TIME = - Long.parseLong(System.getProperty("rocketmq.client.rebalance.lockMaxLiveTime", "30000")); + Long.parseLong(System.getProperty("rocketmq.client.rebalance.lockMaxLiveTime", "30000")); public final static long REBALANCE_LOCK_INTERVAL = Long.parseLong(System.getProperty("rocketmq.client.rebalance.lockInterval", "20000")); private final static long PULL_MAX_IDLE_TIME = Long.parseLong(System.getProperty("rocketmq.client.pull.pullMaxIdleTime", "120000")); private final Logger log = ClientLogger.getLog(); @@ -65,7 +63,6 @@ public class ProcessQueue { return result; } - public boolean isPullExpired() { boolean result = (System.currentTimeMillis() - this.lastPullTimestamp) > PULL_MAX_IDLE_TIME; return result; @@ -80,7 +77,7 @@ public class ProcessQueue { if (pushConsumer.getDefaultMQPushConsumerImpl().isConsumeOrderly()) { return; } - + int loop = msgTreeMap.size() < 16 ? msgTreeMap.size() : 16; for (int i = 0; i < loop; i++) { MessageExt msg = null; @@ -126,7 +123,6 @@ public class ProcessQueue { } } - public boolean putMessage(final List msgs) { boolean dispatchToConsume = false; try { @@ -167,7 +163,6 @@ public class ProcessQueue { return dispatchToConsume; } - public long getMaxSpan() { try { this.lockTreeMap.readLock().lockInterruptibly(); @@ -185,7 +180,6 @@ public class ProcessQueue { return 0; } - public long removeMessage(final List msgs) { long result = -1; final long now = System.currentTimeMillis(); @@ -218,22 +212,18 @@ public class ProcessQueue { return result; } - public TreeMap getMsgTreeMap() { return msgTreeMap; } - public AtomicLong getMsgCount() { return msgCount; } - public boolean isDropped() { return dropped; } - public void setDropped(boolean dropped) { this.dropped = dropped; } @@ -260,7 +250,6 @@ public class ProcessQueue { } } - public long commit() { try { this.lockTreeMap.writeLock().lockInterruptibly(); @@ -281,7 +270,6 @@ public class ProcessQueue { return -1; } - public void makeMessageToCosumeAgain(List msgs) { try { this.lockTreeMap.writeLock().lockInterruptibly(); @@ -298,7 +286,6 @@ public class ProcessQueue { } } - public List takeMessags(final int batchSize) { List result = new ArrayList(batchSize); final long now = System.currentTimeMillis(); @@ -331,7 +318,6 @@ public class ProcessQueue { return result; } - public boolean hasTempMessage() { try { this.lockTreeMap.readLock().lockInterruptibly(); @@ -346,7 +332,6 @@ public class ProcessQueue { return true; } - public void clear() { try { this.lockTreeMap.writeLock().lockInterruptibly(); @@ -363,52 +348,42 @@ public class ProcessQueue { } } - public long getLastLockTimestamp() { return lastLockTimestamp; } - public void setLastLockTimestamp(long lastLockTimestamp) { this.lastLockTimestamp = lastLockTimestamp; } - public Lock getLockConsume() { return lockConsume; } - public long getLastPullTimestamp() { return lastPullTimestamp; } - public void setLastPullTimestamp(long lastPullTimestamp) { this.lastPullTimestamp = lastPullTimestamp; } - public long getMsgAccCnt() { return msgAccCnt; } - public void setMsgAccCnt(long msgAccCnt) { this.msgAccCnt = msgAccCnt; } - public long getTryUnlockTimes() { return this.tryUnlockTimes.get(); } - public void incTryUnlockTimes() { this.tryUnlockTimes.incrementAndGet(); } - public void fillProcessQueueInfo(final ProcessQueueInfo info) { try { this.lockTreeMap.readLock().lockInterruptibly(); @@ -438,12 +413,10 @@ public class ProcessQueue { } } - public long getLastConsumeTimestamp() { return lastConsumeTimestamp; } - public void setLastConsumeTimestamp(long lastConsumeTimestamp) { this.lastConsumeTimestamp = lastConsumeTimestamp; } diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/PullAPIWrapper.java b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/PullAPIWrapper.java index 59c9b1c6..d3581753 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/PullAPIWrapper.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/PullAPIWrapper.java @@ -16,6 +16,12 @@ */ package org.apache.rocketmq.client.impl.consumer; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicLong; import org.apache.rocketmq.client.consumer.PullCallback; import org.apache.rocketmq.client.consumer.PullResult; import org.apache.rocketmq.client.consumer.PullStatus; @@ -28,7 +34,11 @@ import org.apache.rocketmq.client.impl.FindBrokerResult; import org.apache.rocketmq.client.impl.factory.MQClientInstance; import org.apache.rocketmq.client.log.ClientLogger; import org.apache.rocketmq.common.MixAll; -import org.apache.rocketmq.common.message.*; +import org.apache.rocketmq.common.message.MessageAccessor; +import org.apache.rocketmq.common.message.MessageConst; +import org.apache.rocketmq.common.message.MessageDecoder; +import org.apache.rocketmq.common.message.MessageExt; +import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.common.protocol.header.PullMessageRequestHeader; import org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData; import org.apache.rocketmq.common.protocol.route.TopicRouteData; @@ -36,21 +46,13 @@ import org.apache.rocketmq.common.sysflag.PullSysFlag; import org.apache.rocketmq.remoting.exception.RemotingException; import org.slf4j.Logger; -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicLong; - - public class PullAPIWrapper { private final Logger log = ClientLogger.getLog(); private final MQClientInstance mQClientFactory; private final String consumerGroup; private final boolean unitMode; private ConcurrentHashMap pullFromWhichNodeTable = - new ConcurrentHashMap(32); + new ConcurrentHashMap(32); private volatile boolean connectBrokerByUser = false; private volatile long defaultBrokerId = MixAll.MASTER_ID; private Random random = new Random(System.currentTimeMillis()); @@ -63,8 +65,8 @@ public class PullAPIWrapper { } public PullResult processPullResult(final MessageQueue mq, final PullResult pullResult, - final SubscriptionData subscriptionData) { - PullResultExt pullResultExt = (PullResultExt) pullResult; + final SubscriptionData subscriptionData) { + PullResultExt pullResultExt = (PullResultExt)pullResult; this.updatePullFromWhichNode(mq, pullResultExt.getSuggestWhichBrokerId()); if (PullStatus.FOUND == pullResult.getPullStatus()) { @@ -92,9 +94,9 @@ public class PullAPIWrapper { for (MessageExt msg : msgListFilterAgain) { MessageAccessor.putProperty(msg, MessageConst.PROPERTY_MIN_OFFSET, - Long.toString(pullResult.getMinOffset())); + Long.toString(pullResult.getMinOffset())); MessageAccessor.putProperty(msg, MessageConst.PROPERTY_MAX_OFFSET, - Long.toString(pullResult.getMaxOffset())); + Long.toString(pullResult.getMaxOffset())); } pullResultExt.setMsgFoundList(msgListFilterAgain); @@ -131,26 +133,26 @@ public class PullAPIWrapper { } public PullResult pullKernelImpl( - final MessageQueue mq, - final String subExpression, - final long subVersion, - final long offset, - final int maxNums, - final int sysFlag, - final long commitOffset, - final long brokerSuspendMaxTimeMillis, - final long timeoutMillis, - final CommunicationMode communicationMode, - final PullCallback pullCallback + final MessageQueue mq, + final String subExpression, + final long subVersion, + final long offset, + final int maxNums, + final int sysFlag, + final long commitOffset, + final long brokerSuspendMaxTimeMillis, + final long timeoutMillis, + final CommunicationMode communicationMode, + final PullCallback pullCallback ) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { FindBrokerResult findBrokerResult = - this.mQClientFactory.findBrokerAddressInSubscribe(mq.getBrokerName(), - this.recalculatePullFromWhichNode(mq), false); + this.mQClientFactory.findBrokerAddressInSubscribe(mq.getBrokerName(), + this.recalculatePullFromWhichNode(mq), false); if (null == findBrokerResult) { this.mQClientFactory.updateTopicRouteInfoFromNameServer(mq.getTopic()); findBrokerResult = - this.mQClientFactory.findBrokerAddressInSubscribe(mq.getBrokerName(), - this.recalculatePullFromWhichNode(mq), false); + this.mQClientFactory.findBrokerAddressInSubscribe(mq.getBrokerName(), + this.recalculatePullFromWhichNode(mq), false); } if (findBrokerResult != null) { @@ -178,11 +180,11 @@ public class PullAPIWrapper { } PullResult pullResult = this.mQClientFactory.getMQClientAPIImpl().pullMessage( - brokerAddr, - requestHeader, - timeoutMillis, - communicationMode, - pullCallback); + brokerAddr, + requestHeader, + timeoutMillis, + communicationMode, + pullCallback); return pullResult; } @@ -204,7 +206,7 @@ public class PullAPIWrapper { } private String computPullFromWhichFilterServer(final String topic, final String brokerAddr) - throws MQClientException { + throws MQClientException { ConcurrentHashMap topicRouteTable = this.mQClientFactory.getTopicRouteTable(); if (topicRouteTable != null) { TopicRouteData topicRouteData = topicRouteTable.get(topic); @@ -216,13 +218,18 @@ public class PullAPIWrapper { } throw new MQClientException("Find Filter Server Failed, Broker Addr: " + brokerAddr + " topic: " - + topic, null); + + topic, null); } public boolean isConnectBrokerByUser() { return connectBrokerByUser; } + public void setConnectBrokerByUser(boolean connectBrokerByUser) { + this.connectBrokerByUser = connectBrokerByUser; + + } + public int randomNum() { int value = random.nextInt(); if (value < 0) { @@ -233,11 +240,6 @@ public class PullAPIWrapper { return value; } - public void setConnectBrokerByUser(boolean connectBrokerByUser) { - this.connectBrokerByUser = connectBrokerByUser; - - } - public void registerFilterMessageHook(ArrayList filterMessageHookList) { this.filterMessageHookList = filterMessageHookList; } diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/PullMessageService.java b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/PullMessageService.java index 4634c242..55e3d59e 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/PullMessageService.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/PullMessageService.java @@ -6,35 +6,37 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.impl.consumer; +import java.util.concurrent.Executors; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; import org.apache.rocketmq.client.impl.factory.MQClientInstance; import org.apache.rocketmq.client.log.ClientLogger; import org.apache.rocketmq.common.ServiceThread; import org.slf4j.Logger; -import java.util.concurrent.*; - - public class PullMessageService extends ServiceThread { private final Logger log = ClientLogger.getLog(); private final LinkedBlockingQueue pullRequestQueue = new LinkedBlockingQueue(); private final MQClientInstance mQClientFactory; private final ScheduledExecutorService scheduledExecutorService = Executors - .newSingleThreadScheduledExecutor(new ThreadFactory() { - @Override - public Thread newThread(Runnable r) { - return new Thread(r, "PullMessageServiceScheduledThread"); - } - }); + .newSingleThreadScheduledExecutor(new ThreadFactory() { + @Override + public Thread newThread(Runnable r) { + return new Thread(r, "PullMessageServiceScheduledThread"); + } + }); public PullMessageService(MQClientInstance mQClientFactory) { this.mQClientFactory = mQClientFactory; @@ -69,14 +71,13 @@ public class PullMessageService extends ServiceThread { private void pullMessage(final PullRequest pullRequest) { final MQConsumerInner consumer = this.mQClientFactory.selectConsumer(pullRequest.getConsumerGroup()); if (consumer != null) { - DefaultMQPushConsumerImpl impl = (DefaultMQPushConsumerImpl) consumer; + DefaultMQPushConsumerImpl impl = (DefaultMQPushConsumerImpl)consumer; impl.pullMessage(pullRequest); } else { log.warn("No matched consumer for the PullRequest {}, drop it", pullRequest); } } - @Override public void run() { log.info(this.getServiceName() + " service started"); @@ -96,11 +97,9 @@ public class PullMessageService extends ServiceThread { log.info(this.getServiceName() + " service end"); } - @Override public String getServiceName() { return PullMessageService.class.getSimpleName(); } - } diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/PullRequest.java b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/PullRequest.java index ccc624bd..4850313d 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/PullRequest.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/PullRequest.java @@ -6,19 +6,18 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.impl.consumer; import org.apache.rocketmq.common.message.MessageQueue; - public class PullRequest { private String consumerGroup; private MessageQueue messageQueue; @@ -38,27 +37,22 @@ public class PullRequest { return consumerGroup; } - public void setConsumerGroup(String consumerGroup) { this.consumerGroup = consumerGroup; } - public MessageQueue getMessageQueue() { return messageQueue; } - public void setMessageQueue(MessageQueue messageQueue) { this.messageQueue = messageQueue; } - public long getNextOffset() { return nextOffset; } - public void setNextOffset(long nextOffset) { this.nextOffset = nextOffset; } @@ -80,7 +74,7 @@ public class PullRequest { return false; if (getClass() != obj.getClass()) return false; - PullRequest other = (PullRequest) obj; + PullRequest other = (PullRequest)obj; if (consumerGroup == null) { if (other.consumerGroup != null) return false; @@ -97,14 +91,13 @@ public class PullRequest { @Override public String toString() { return "PullRequest [consumerGroup=" + consumerGroup + ", messageQueue=" + messageQueue - + ", nextOffset=" + nextOffset + "]"; + + ", nextOffset=" + nextOffset + "]"; } public ProcessQueue getProcessQueue() { return processQueue; } - public void setProcessQueue(ProcessQueue processQueue) { this.processQueue = processQueue; } diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/PullResultExt.java b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/PullResultExt.java index d2486033..c43c9a92 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/PullResultExt.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/PullResultExt.java @@ -6,46 +6,40 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.impl.consumer; +import java.util.List; import org.apache.rocketmq.client.consumer.PullResult; import org.apache.rocketmq.client.consumer.PullStatus; import org.apache.rocketmq.common.message.MessageExt; -import java.util.List; - - public class PullResultExt extends PullResult { private final long suggestWhichBrokerId; private byte[] messageBinary; - public PullResultExt(PullStatus pullStatus, long nextBeginOffset, long minOffset, long maxOffset, - List msgFoundList, final long suggestWhichBrokerId, final byte[] messageBinary) { + List msgFoundList, final long suggestWhichBrokerId, final byte[] messageBinary) { super(pullStatus, nextBeginOffset, minOffset, maxOffset, msgFoundList); this.suggestWhichBrokerId = suggestWhichBrokerId; this.messageBinary = messageBinary; } - public byte[] getMessageBinary() { return messageBinary; } - public void setMessageBinary(byte[] messageBinary) { this.messageBinary = messageBinary; } - public long getSuggestWhichBrokerId() { return suggestWhichBrokerId; } diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalanceImpl.java b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalanceImpl.java index 53d775fa..91bfd1a2 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalanceImpl.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalanceImpl.java @@ -16,6 +16,16 @@ */ package org.apache.rocketmq.client.impl.consumer; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import org.apache.rocketmq.client.consumer.AllocateMessageQueueStrategy; import org.apache.rocketmq.client.impl.FindBrokerResult; import org.apache.rocketmq.client.impl.factory.MQClientInstance; @@ -29,30 +39,23 @@ import org.apache.rocketmq.common.protocol.heartbeat.MessageModel; import org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData; import org.slf4j.Logger; -import java.util.*; -import java.util.Map.Entry; -import java.util.concurrent.ConcurrentHashMap; - - /** * Base class for rebalance algorithm - * */ public abstract class RebalanceImpl { protected static final Logger log = ClientLogger.getLog(); protected final ConcurrentHashMap processQueueTable = new ConcurrentHashMap(64); protected final ConcurrentHashMap> topicSubscribeInfoTable = - new ConcurrentHashMap>(); + new ConcurrentHashMap>(); protected final ConcurrentHashMap subscriptionInner = - new ConcurrentHashMap(); + new ConcurrentHashMap(); protected String consumerGroup; protected MessageModel messageModel; protected AllocateMessageQueueStrategy allocateMessageQueueStrategy; protected MQClientInstance mQClientFactory; - public RebalanceImpl(String consumerGroup, MessageModel messageModel, AllocateMessageQueueStrategy allocateMessageQueueStrategy, - MQClientInstance mQClientFactory) { + MQClientInstance mQClientFactory) { this.consumerGroup = consumerGroup; this.messageModel = messageModel; this.allocateMessageQueueStrategy = allocateMessageQueueStrategy; @@ -70,9 +73,9 @@ public abstract class RebalanceImpl { try { this.mQClientFactory.getMQClientAPIImpl().unlockBatchMQ(findBrokerResult.getBrokerAddr(), requestBody, 1000, oneway); log.warn("unlock messageQueue. group:{}, clientId:{}, mq:{}", // - this.consumerGroup, // - this.mQClientFactory.getClientId(), // - mq); + this.consumerGroup, // + this.mQClientFactory.getClientId(), // + mq); } catch (Exception e) { log.error("unlockBatchMQ exception, " + mq, e); } @@ -138,7 +141,7 @@ public abstract class RebalanceImpl { try { Set lockedMq = - this.mQClientFactory.getMQClientAPIImpl().lockBatchMQ(findBrokerResult.getBrokerAddr(), requestBody, 1000); + this.mQClientFactory.getMQClientAPIImpl().lockBatchMQ(findBrokerResult.getBrokerAddr(), requestBody, 1000); for (MessageQueue mmqq : lockedMq) { ProcessQueue processQueue = this.processQueueTable.get(mmqq); if (processQueue != null) { @@ -149,9 +152,9 @@ public abstract class RebalanceImpl { boolean lockOK = lockedMq.contains(mq); log.info("the message queue lock {}, {} {}", - lockOK ? "OK" : "Failed", - this.consumerGroup, - mq); + lockOK ? "OK" : "Failed", + this.consumerGroup, + mq); return lockOK; } catch (Exception e) { log.error("lockBatchMQ exception, " + mq, e); @@ -182,7 +185,7 @@ public abstract class RebalanceImpl { try { Set lockOKMQSet = - this.mQClientFactory.getMQClientAPIImpl().lockBatchMQ(findBrokerResult.getBrokerAddr(), requestBody, 1000); + this.mQClientFactory.getMQClientAPIImpl().lockBatchMQ(findBrokerResult.getBrokerAddr(), requestBody, 1000); for (MessageQueue mq : lockOKMQSet) { ProcessQueue processQueue = this.processQueueTable.get(mq); @@ -242,10 +245,10 @@ public abstract class RebalanceImpl { if (changed) { this.messageQueueChanged(topic, mqSet, mqSet); log.info("messageQueueChanged {} {} {} {}", // - consumerGroup, // - topic, // - mqSet, // - mqSet); + consumerGroup, // + topic, // + mqSet, // + mqSet); } } else { log.warn("doRebalance, {}, but the topic[{}] not exist.", consumerGroup, topic); @@ -277,13 +280,13 @@ public abstract class RebalanceImpl { List allocateResult = null; try { allocateResult = strategy.allocate(// - this.consumerGroup, // - this.mQClientFactory.getClientId(), // - mqAll, // - cidAll); + this.consumerGroup, // + this.mQClientFactory.getClientId(), // + mqAll, // + cidAll); } catch (Throwable e) { log.error("AllocateMessageQueueStrategy.allocate Exception. allocateMessageQueueStrategyName={}", strategy.getName(), - e); + e); return; } @@ -295,9 +298,9 @@ public abstract class RebalanceImpl { boolean changed = this.updateProcessQueueTableInRebalance(topic, allocateResultSet, isOrder); if (changed) { log.info( - "rebalanced result changed. allocateMessageQueueStrategyName={}, group={}, topic={}, clientId={}, mqAllSize={}, cidAllSize={}, rebalanceResultSize={}, rebalanceResultSet={}", - strategy.getName(), consumerGroup, topic, this.mQClientFactory.getClientId(), mqSet.size(), cidAll.size(), - allocateResultSet.size(), allocateResultSet); + "rebalanced result changed. allocateMessageQueueStrategyName={}, group={}, topic={}, clientId={}, mqAllSize={}, cidAllSize={}, rebalanceResultSize={}, rebalanceResultSet={}", + strategy.getName(), consumerGroup, topic, this.mQClientFactory.getClientId(), mqSet.size(), cidAll.size(), + allocateResultSet.size(), allocateResultSet); this.messageQueueChanged(topic, mqSet, allocateResultSet); } } @@ -350,7 +353,7 @@ public abstract class RebalanceImpl { it.remove(); changed = true; log.error("[BUG]doRebalance, {}, remove unnecessary mq, {}, because pull is pause, so try to fixed it", - consumerGroup, mq); + consumerGroup, mq); } break; default: @@ -422,52 +425,42 @@ public abstract class RebalanceImpl { return processQueueTable; } - public ConcurrentHashMap> getTopicSubscribeInfoTable() { return topicSubscribeInfoTable; } - public String getConsumerGroup() { return consumerGroup; } - public void setConsumerGroup(String consumerGroup) { this.consumerGroup = consumerGroup; } - public MessageModel getMessageModel() { return messageModel; } - public void setMessageModel(MessageModel messageModel) { this.messageModel = messageModel; } - public AllocateMessageQueueStrategy getAllocateMessageQueueStrategy() { return allocateMessageQueueStrategy; } - public void setAllocateMessageQueueStrategy(AllocateMessageQueueStrategy allocateMessageQueueStrategy) { this.allocateMessageQueueStrategy = allocateMessageQueueStrategy; } - public MQClientInstance getmQClientFactory() { return mQClientFactory; } - public void setmQClientFactory(MQClientInstance mQClientFactory) { this.mQClientFactory = mQClientFactory; } - public void destroy() { Iterator> it = this.processQueueTable.entrySet().iterator(); while (it.hasNext()) { diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalancePullImpl.java b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalancePullImpl.java index d37090d3..11309433 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalancePullImpl.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalancePullImpl.java @@ -6,16 +6,18 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.impl.consumer; +import java.util.List; +import java.util.Set; import org.apache.rocketmq.client.consumer.AllocateMessageQueueStrategy; import org.apache.rocketmq.client.consumer.MessageQueueListener; import org.apache.rocketmq.client.impl.factory.MQClientInstance; @@ -23,21 +25,15 @@ import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.common.protocol.heartbeat.ConsumeType; import org.apache.rocketmq.common.protocol.heartbeat.MessageModel; -import java.util.List; -import java.util.Set; - - public class RebalancePullImpl extends RebalanceImpl { private final DefaultMQPullConsumerImpl defaultMQPullConsumerImpl; - public RebalancePullImpl(DefaultMQPullConsumerImpl defaultMQPullConsumerImpl) { this(null, null, null, null, defaultMQPullConsumerImpl); } - public RebalancePullImpl(String consumerGroup, MessageModel messageModel, AllocateMessageQueueStrategy allocateMessageQueueStrategy, - MQClientInstance mQClientFactory, DefaultMQPullConsumerImpl defaultMQPullConsumerImpl) { + MQClientInstance mQClientFactory, DefaultMQPullConsumerImpl defaultMQPullConsumerImpl) { super(consumerGroup, messageModel, allocateMessageQueueStrategy, mQClientFactory); this.defaultMQPullConsumerImpl = defaultMQPullConsumerImpl; } diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalancePushImpl.java b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalancePushImpl.java index 4d0d47f6..707b9a1e 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalancePushImpl.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalancePushImpl.java @@ -6,16 +6,19 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.impl.consumer; +import java.util.List; +import java.util.Set; +import java.util.concurrent.TimeUnit; import org.apache.rocketmq.client.consumer.AllocateMessageQueueStrategy; import org.apache.rocketmq.client.consumer.store.OffsetStore; import org.apache.rocketmq.client.consumer.store.ReadOffsetType; @@ -28,23 +31,16 @@ import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.common.protocol.heartbeat.ConsumeType; import org.apache.rocketmq.common.protocol.heartbeat.MessageModel; -import java.util.List; -import java.util.Set; -import java.util.concurrent.TimeUnit; - - public class RebalancePushImpl extends RebalanceImpl { private final static long UNLOCK_DELAY_TIME_MILLS = Long.parseLong(System.getProperty("rocketmq.client.unlockDelayTimeMills", "20000")); private final DefaultMQPushConsumerImpl defaultMQPushConsumerImpl; - public RebalancePushImpl(DefaultMQPushConsumerImpl defaultMQPushConsumerImpl) { this(null, null, null, null, defaultMQPushConsumerImpl); } - public RebalancePushImpl(String consumerGroup, MessageModel messageModel, AllocateMessageQueueStrategy allocateMessageQueueStrategy, - MQClientInstance mQClientFactory, DefaultMQPushConsumerImpl defaultMQPushConsumerImpl) { + MQClientInstance mQClientFactory, DefaultMQPushConsumerImpl defaultMQPushConsumerImpl) { super(consumerGroup, messageModel, allocateMessageQueueStrategy, mQClientFactory); this.defaultMQPushConsumerImpl = defaultMQPushConsumerImpl; } @@ -58,7 +54,7 @@ public class RebalancePushImpl extends RebalanceImpl { this.defaultMQPushConsumerImpl.getOffsetStore().persist(mq); this.defaultMQPushConsumerImpl.getOffsetStore().removeOffset(mq); if (this.defaultMQPushConsumerImpl.isConsumeOrderly() - && MessageModel.CLUSTERING.equals(this.defaultMQPushConsumerImpl.messageModel())) { + && MessageModel.CLUSTERING.equals(this.defaultMQPushConsumerImpl.messageModel())) { try { if (pq.getLockConsume().tryLock(1000, TimeUnit.MILLISECONDS)) { try { @@ -68,8 +64,8 @@ public class RebalancePushImpl extends RebalanceImpl { } } else { log.warn("[WRONG]mq is consuming, so can not unlock it, {}. maybe hanged for a while, {}", // - mq, // - pq.getTryUnlockTimes()); + mq, // + pq.getTryUnlockTimes()); pq.incTryUnlockTimes(); } @@ -164,7 +160,7 @@ public class RebalancePushImpl extends RebalanceImpl { } else { try { long timestamp = UtilAll.parseDate(this.defaultMQPushConsumerImpl.getDefaultMQPushConsumer().getConsumeTimestamp(), - UtilAll.YYYY_MMDD_HHMMSS).getTime(); + UtilAll.YYYY_MMDD_HHMMSS).getTime(); result = this.mQClientFactory.getMQAdminImpl().searchOffset(mq, timestamp); } catch (MQClientException e) { result = -1; diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalanceService.java b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalanceService.java index 5b5ab2a5..985129e5 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalanceService.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalanceService.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.impl.consumer; @@ -21,15 +21,14 @@ import org.apache.rocketmq.client.log.ClientLogger; import org.apache.rocketmq.common.ServiceThread; import org.slf4j.Logger; - /** * Rebalance Service * */ public class RebalanceService extends ServiceThread { private static long waitInterval = - Long.parseLong(System.getProperty( - "rocketmq.client.rebalance.waitInterval", "20000")); + Long.parseLong(System.getProperty( + "rocketmq.client.rebalance.waitInterval", "20000")); private final Logger log = ClientLogger.getLog(); private final MQClientInstance mqClientFactory; @@ -49,7 +48,6 @@ public class RebalanceService extends ServiceThread { log.info(this.getServiceName() + " service end"); } - @Override public String getServiceName() { return RebalanceService.class.getSimpleName(); diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/factory/MQClientInstance.java b/client/src/main/java/org/apache/rocketmq/client/impl/factory/MQClientInstance.java index 6e0e3799..42b7a828 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/factory/MQClientInstance.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/factory/MQClientInstance.java @@ -16,11 +16,40 @@ */ package org.apache.rocketmq.client.impl.factory; +import java.io.UnsupportedEncodingException; +import java.net.DatagramSocket; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Random; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; import org.apache.rocketmq.client.ClientConfig; import org.apache.rocketmq.client.admin.MQAdminExtInner; import org.apache.rocketmq.client.exception.MQBrokerException; import org.apache.rocketmq.client.exception.MQClientException; -import org.apache.rocketmq.client.impl.*; +import org.apache.rocketmq.client.impl.ClientRemotingProcessor; +import org.apache.rocketmq.client.impl.FindBrokerResult; +import org.apache.rocketmq.client.impl.MQAdminImpl; +import org.apache.rocketmq.client.impl.MQClientAPIImpl; +import org.apache.rocketmq.client.impl.MQClientManager; +import org.apache.rocketmq.client.impl.consumer.DefaultMQPullConsumerImpl; +import org.apache.rocketmq.client.impl.consumer.DefaultMQPushConsumerImpl; +import org.apache.rocketmq.client.impl.consumer.MQConsumerInner; +import org.apache.rocketmq.client.impl.consumer.ProcessQueue; +import org.apache.rocketmq.client.impl.consumer.PullMessageService; +import org.apache.rocketmq.client.impl.consumer.RebalanceService; import org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl; import org.apache.rocketmq.client.impl.producer.MQProducerInner; import org.apache.rocketmq.client.impl.producer.TopicPublishInfo; @@ -36,7 +65,11 @@ import org.apache.rocketmq.common.message.MessageExt; import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.common.protocol.body.ConsumeMessageDirectlyResult; import org.apache.rocketmq.common.protocol.body.ConsumerRunningInfo; -import org.apache.rocketmq.common.protocol.heartbeat.*; +import org.apache.rocketmq.common.protocol.heartbeat.ConsumeType; +import org.apache.rocketmq.common.protocol.heartbeat.ConsumerData; +import org.apache.rocketmq.common.protocol.heartbeat.HeartbeatData; +import org.apache.rocketmq.common.protocol.heartbeat.ProducerData; +import org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData; import org.apache.rocketmq.common.protocol.route.BrokerData; import org.apache.rocketmq.common.protocol.route.QueueData; import org.apache.rocketmq.common.protocol.route.TopicRouteData; @@ -45,19 +78,8 @@ import org.apache.rocketmq.remoting.common.RemotingHelper; import org.apache.rocketmq.remoting.exception.RemotingException; import org.apache.rocketmq.remoting.netty.NettyClientConfig; import org.apache.rocketmq.remoting.protocol.RemotingCommand; -import org.apache.rocketmq.client.impl.consumer.*; import org.slf4j.Logger; -import java.io.UnsupportedEncodingException; -import java.net.DatagramSocket; -import java.util.*; -import java.util.Map.Entry; -import java.util.concurrent.*; -import java.util.concurrent.atomic.AtomicLong; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; - - public class MQClientInstance { private final static long LOCK_TIMEOUT_MILLIS = 3000; private final Logger log = ClientLogger.getLog(); @@ -75,7 +97,7 @@ public class MQClientInstance { private final Lock lockNamesrv = new ReentrantLock(); private final Lock lockHeartbeat = new ReentrantLock(); private final ConcurrentHashMap> brokerAddrTable = - new ConcurrentHashMap>(); + new ConcurrentHashMap>(); private final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { @Override public Thread newThread(Runnable r) { @@ -92,12 +114,10 @@ public class MQClientInstance { private DatagramSocket datagramSocket; private Random random = new Random(); - public MQClientInstance(ClientConfig clientConfig, int instanceIndex, String clientId) { this(clientConfig, instanceIndex, clientId, null); } - public MQClientInstance(ClientConfig clientConfig, int instanceIndex, String clientId, RPCHook rpcHook) { this.clientConfig = clientConfig; this.instanceIndex = instanceIndex; @@ -125,10 +145,74 @@ public class MQClientInstance { this.consumerStatsManager = new ConsumerStatsManager(this.scheduledExecutorService); log.info("created a new client Instance, FactoryIndex: {} ClinetID: {} {} {}, serializeType={}", // - this.instanceIndex, // - this.clientId, // - this.clientConfig, // - MQVersion.getVersionDesc(MQVersion.CURRENT_VERSION), RemotingCommand.getSerializeTypeConfigInThisServer()); + this.instanceIndex, // + this.clientId, // + this.clientConfig, // + MQVersion.getVersionDesc(MQVersion.CURRENT_VERSION), RemotingCommand.getSerializeTypeConfigInThisServer()); + } + + public static TopicPublishInfo topicRouteData2TopicPublishInfo(final String topic, final TopicRouteData route) { + TopicPublishInfo info = new TopicPublishInfo(); + info.setTopicRouteData(route); + if (route.getOrderTopicConf() != null && route.getOrderTopicConf().length() > 0) { + String[] brokers = route.getOrderTopicConf().split(";"); + for (String broker : brokers) { + String[] item = broker.split(":"); + int nums = Integer.parseInt(item[1]); + for (int i = 0; i < nums; i++) { + MessageQueue mq = new MessageQueue(topic, item[0], i); + info.getMessageQueueList().add(mq); + } + } + + info.setOrderTopic(true); + } else { + List qds = route.getQueueDatas(); + Collections.sort(qds); + for (QueueData qd : qds) { + if (PermName.isWriteable(qd.getPerm())) { + BrokerData brokerData = null; + for (BrokerData bd : route.getBrokerDatas()) { + if (bd.getBrokerName().equals(qd.getBrokerName())) { + brokerData = bd; + break; + } + } + + if (null == brokerData) { + continue; + } + + if (!brokerData.getBrokerAddrs().containsKey(MixAll.MASTER_ID)) { + continue; + } + + for (int i = 0; i < qd.getWriteQueueNums(); i++) { + MessageQueue mq = new MessageQueue(topic, qd.getBrokerName(), i); + info.getMessageQueueList().add(mq); + } + } + } + + info.setOrderTopic(false); + } + + return info; + } + + public static Set topicRouteData2TopicSubscribeInfo(final String topic, final TopicRouteData route) { + Set mqList = new HashSet(); + List qds = route.getQueueDatas(); + for (QueueData qd : qds) { + if (PermName.isReadable(qd.getPerm())) { + for (int i = 0; i < qd.getReadQueueNums(); i++) { + MessageQueue mq = new MessageQueue(topic, qd.getBrokerName(), i); + mqList.add(mq); + } + } + } + + return mqList; } public void start() throws MQClientException { @@ -166,7 +250,6 @@ public class MQClientInstance { } } - private void startScheduledTask() { if (null == this.clientConfig.getNamesrvAddr()) { this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() { @@ -353,7 +436,7 @@ public class MQClientInstance { if (impl != null) { try { if (impl instanceof DefaultMQPushConsumerImpl) { - DefaultMQPushConsumerImpl dmq = (DefaultMQPushConsumerImpl) impl; + DefaultMQPushConsumerImpl dmq = (DefaultMQPushConsumerImpl)impl; dmq.adjustThreadPool(); } } catch (Exception e) { @@ -420,7 +503,7 @@ public class MQClientInstance { log.error("send heart beat to broker exception", e); } else { log.info("send heart beat to broker[{} {} {}] exception, because the broker not up, forget it", brokerName, - id, addr); + id, addr); } } } @@ -460,7 +543,7 @@ public class MQClientInstance { TopicRouteData topicRouteData; if (isDefault && defaultMQProducer != null) { topicRouteData = this.mQClientAPIImpl.getDefaultTopicRouteInfoFromNameServer(defaultMQProducer.getCreateTopicKey(), - 1000 * 3); + 1000 * 3); if (topicRouteData != null) { for (QueueData data : topicRouteData.getQueueDatas()) { int queueNums = Math.min(defaultMQProducer.getDefaultTopicQueueNums(), data.getReadQueueNums()); @@ -559,7 +642,6 @@ public class MQClientInstance { } } - // Producer for (Map.Entry entry : this.producerTable.entrySet()) { MQProducerInner impl = entry.getValue(); @@ -590,7 +672,7 @@ public class MQClientInstance { } private void uploadFilterClassToAllFilterServer(final String consumerGroup, final String fullClassName, final String topic, - final String filterClassSource) throws UnsupportedEncodingException { + final String filterClassSource) throws UnsupportedEncodingException { byte[] classBody = null; int classCRC = 0; try { @@ -598,13 +680,13 @@ public class MQClientInstance { classCRC = UtilAll.crc32(classBody); } catch (Exception e1) { log.warn("uploadFilterClassToAllFilterServer Exception, ClassName: {} {}", // - fullClassName, // - RemotingHelper.exceptionSimpleDesc(e1)); + fullClassName, // + RemotingHelper.exceptionSimpleDesc(e1)); } TopicRouteData topicRouteData = this.topicRouteTable.get(topic); if (topicRouteData != null // - && topicRouteData.getFilterServerTable() != null && !topicRouteData.getFilterServerTable().isEmpty()) { + && topicRouteData.getFilterServerTable() != null && !topicRouteData.getFilterServerTable().isEmpty()) { Iterator>> it = topicRouteData.getFilterServerTable().entrySet().iterator(); while (it.hasNext()) { Entry> next = it.next(); @@ -612,10 +694,10 @@ public class MQClientInstance { for (final String fsAddr : value) { try { this.mQClientAPIImpl.registerMessageFilterClass(fsAddr, consumerGroup, topic, fullClassName, classCRC, classBody, - 5000); + 5000); log.info("register message class filter to {} OK, ConsumerGroup: {} Topic: {} ClassName: {}", fsAddr, consumerGroup, - topic, fullClassName); + topic, fullClassName); } catch (Exception e) { log.error("uploadFilterClassToAllFilterServer Exception", e); @@ -624,7 +706,7 @@ public class MQClientInstance { } } else { log.warn("register message class filter failed, because no filter server, ConsumerGroup: {} Topic: {} ClassName: {}", - consumerGroup, topic, fullClassName); + consumerGroup, topic, fullClassName); } } @@ -668,70 +750,6 @@ public class MQClientInstance { return result; } - public static TopicPublishInfo topicRouteData2TopicPublishInfo(final String topic, final TopicRouteData route) { - TopicPublishInfo info = new TopicPublishInfo(); - info.setTopicRouteData(route); - if (route.getOrderTopicConf() != null && route.getOrderTopicConf().length() > 0) { - String[] brokers = route.getOrderTopicConf().split(";"); - for (String broker : brokers) { - String[] item = broker.split(":"); - int nums = Integer.parseInt(item[1]); - for (int i = 0; i < nums; i++) { - MessageQueue mq = new MessageQueue(topic, item[0], i); - info.getMessageQueueList().add(mq); - } - } - - info.setOrderTopic(true); - } else { - List qds = route.getQueueDatas(); - Collections.sort(qds); - for (QueueData qd : qds) { - if (PermName.isWriteable(qd.getPerm())) { - BrokerData brokerData = null; - for (BrokerData bd : route.getBrokerDatas()) { - if (bd.getBrokerName().equals(qd.getBrokerName())) { - brokerData = bd; - break; - } - } - - if (null == brokerData) { - continue; - } - - if (!brokerData.getBrokerAddrs().containsKey(MixAll.MASTER_ID)) { - continue; - } - - for (int i = 0; i < qd.getWriteQueueNums(); i++) { - MessageQueue mq = new MessageQueue(topic, qd.getBrokerName(), i); - info.getMessageQueueList().add(mq); - } - } - } - - info.setOrderTopic(false); - } - - return info; - } - - public static Set topicRouteData2TopicSubscribeInfo(final String topic, final TopicRouteData route) { - Set mqList = new HashSet(); - List qds = route.getQueueDatas(); - for (QueueData qd : qds) { - if (PermName.isReadable(qd.getPerm())) { - for (int i = 0; i < qd.getReadQueueNums(); i++) { - MessageQueue mq = new MessageQueue(topic, qd.getBrokerName(), i); - mqList.add(mq); - } - } - } - - return mqList; - } - public void shutdown() { // Consumer if (!this.consumerTable.isEmpty()) @@ -824,7 +842,7 @@ public class MQClientInstance { try { this.mQClientAPIImpl.unregisterClient(addr, this.clientId, producerGroup, consumerGroup, 3000); log.info("unregister client[Producer: {} Consumer: {}] from broker[{} {} {}] success", producerGroup, - consumerGroup, brokerName, entry1.getKey(), addr); + consumerGroup, brokerName, entry1.getKey(), addr); } catch (RemotingException e) { log.error("unregister client exception from broker: " + addr, e); } catch (MQBrokerException e) { @@ -942,9 +960,9 @@ public class MQClientInstance { } public FindBrokerResult findBrokerAddressInSubscribe(// - final String brokerName, // - final long brokerId, // - final boolean onlyThisBroker// + final String brokerName, // + final long brokerId, // + final boolean onlyThisBroker// ) { String brokerAddr = null; boolean slave = false; @@ -1008,7 +1026,7 @@ public class MQClientInstance { try { MQConsumerInner impl = this.consumerTable.get(group); if (impl != null && impl instanceof DefaultMQPushConsumerImpl) { - consumer = (DefaultMQPushConsumerImpl) impl; + consumer = (DefaultMQPushConsumerImpl)impl; } else { log.info("[reset-offset] consumer dose not exist. group={}", group); return; @@ -1053,10 +1071,10 @@ public class MQClientInstance { public Map getConsumerStatus(String topic, String group) { MQConsumerInner impl = this.consumerTable.get(group); if (impl != null && impl instanceof DefaultMQPushConsumerImpl) { - DefaultMQPushConsumerImpl consumer = (DefaultMQPushConsumerImpl) impl; + DefaultMQPushConsumerImpl consumer = (DefaultMQPushConsumerImpl)impl; return consumer.getOffsetStore().cloneOffsetTable(topic); } else if (impl != null && impl instanceof DefaultMQPullConsumerImpl) { - DefaultMQPullConsumerImpl consumer = (DefaultMQPullConsumerImpl) impl; + DefaultMQPullConsumerImpl consumer = (DefaultMQPullConsumerImpl)impl; return consumer.getOffsetStore().cloneOffsetTable(topic); } else { return Collections.EMPTY_MAP; @@ -1096,11 +1114,11 @@ public class MQClientInstance { } public ConsumeMessageDirectlyResult consumeMessageDirectly(final MessageExt msg, // - final String consumerGroup, // - final String brokerName) { + final String consumerGroup, // + final String brokerName) { MQConsumerInner mqConsumerInner = this.consumerTable.get(consumerGroup); if (null != mqConsumerInner) { - DefaultMQPushConsumerImpl consumer = (DefaultMQPushConsumerImpl) mqConsumerInner; + DefaultMQPushConsumerImpl consumer = (DefaultMQPushConsumerImpl)mqConsumerInner; ConsumeMessageDirectlyResult result = consumer.getConsumeMessageService().consumeMessageDirectly(msg, brokerName); return result; @@ -1109,7 +1127,6 @@ public class MQClientInstance { return null; } - public ConsumerRunningInfo consumerRunningInfo(final String consumerGroup) { MQConsumerInner mqConsumerInner = this.consumerTable.get(consumerGroup); @@ -1128,12 +1145,11 @@ public class MQClientInstance { consumerRunningInfo.getProperties().put(ConsumerRunningInfo.PROP_NAMESERVER_ADDR, nsAddr); consumerRunningInfo.getProperties().put(ConsumerRunningInfo.PROP_CONSUME_TYPE, mqConsumerInner.consumeType().name()); consumerRunningInfo.getProperties().put(ConsumerRunningInfo.PROP_CLIENT_VERSION, - MQVersion.getVersionDesc(MQVersion.CURRENT_VERSION)); + MQVersion.getVersionDesc(MQVersion.CURRENT_VERSION)); return consumerRunningInfo; } - public ConsumerStatsManager getConsumerStatsManager() { return consumerStatsManager; } diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/producer/DefaultMQProducerImpl.java b/client/src/main/java/org/apache/rocketmq/client/impl/producer/DefaultMQProducerImpl.java index b53fa194..42bf360b 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/producer/DefaultMQProducerImpl.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/producer/DefaultMQProducerImpl.java @@ -16,6 +16,20 @@ */ package org.apache.rocketmq.client.impl.producer; +import java.io.IOException; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Random; +import java.util.Set; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; import org.apache.rocketmq.client.QueryResult; import org.apache.rocketmq.client.Validators; import org.apache.rocketmq.client.common.ClientErrorCode; @@ -30,11 +44,29 @@ import org.apache.rocketmq.client.impl.MQClientManager; import org.apache.rocketmq.client.impl.factory.MQClientInstance; import org.apache.rocketmq.client.latency.MQFaultStrategy; import org.apache.rocketmq.client.log.ClientLogger; +import org.apache.rocketmq.client.producer.DefaultMQProducer; +import org.apache.rocketmq.client.producer.LocalTransactionExecuter; +import org.apache.rocketmq.client.producer.LocalTransactionState; +import org.apache.rocketmq.client.producer.MessageQueueSelector; +import org.apache.rocketmq.client.producer.SendCallback; +import org.apache.rocketmq.client.producer.SendResult; +import org.apache.rocketmq.client.producer.SendStatus; +import org.apache.rocketmq.client.producer.TransactionCheckListener; +import org.apache.rocketmq.client.producer.TransactionMQProducer; +import org.apache.rocketmq.client.producer.TransactionSendResult; import org.apache.rocketmq.common.MixAll; import org.apache.rocketmq.common.ServiceState; import org.apache.rocketmq.common.UtilAll; import org.apache.rocketmq.common.help.FAQUrl; -import org.apache.rocketmq.common.message.*; +import org.apache.rocketmq.common.message.Message; +import org.apache.rocketmq.common.message.MessageAccessor; +import org.apache.rocketmq.common.message.MessageClientIDSetter; +import org.apache.rocketmq.common.message.MessageConst; +import org.apache.rocketmq.common.message.MessageDecoder; +import org.apache.rocketmq.common.message.MessageExt; +import org.apache.rocketmq.common.message.MessageId; +import org.apache.rocketmq.common.message.MessageQueue; +import org.apache.rocketmq.common.message.MessageType; import org.apache.rocketmq.common.protocol.ResponseCode; import org.apache.rocketmq.common.protocol.header.CheckTransactionStateRequestHeader; import org.apache.rocketmq.common.protocol.header.EndTransactionRequestHeader; @@ -45,21 +77,14 @@ import org.apache.rocketmq.remoting.common.RemotingHelper; import org.apache.rocketmq.remoting.exception.RemotingConnectException; import org.apache.rocketmq.remoting.exception.RemotingException; import org.apache.rocketmq.remoting.exception.RemotingTimeoutException; -import org.apache.rocketmq.client.producer.*; import org.slf4j.Logger; -import java.io.IOException; -import java.net.UnknownHostException; -import java.util.*; -import java.util.concurrent.*; - - public class DefaultMQProducerImpl implements MQProducerInner { private final Logger log = ClientLogger.getLog(); private final Random random = new Random(); private final DefaultMQProducer defaultMQProducer; private final ConcurrentHashMap topicPublishInfoTable = - new ConcurrentHashMap(); + new ConcurrentHashMap(); private final ArrayList sendMessageHookList = new ArrayList(); private final RPCHook rpcHook; protected BlockingQueue checkRequestQueue; @@ -71,12 +96,10 @@ public class DefaultMQProducerImpl implements MQProducerInner { private MQFaultStrategy mqFaultStrategy = new MQFaultStrategy(); - public DefaultMQProducerImpl(final DefaultMQProducer defaultMQProducer) { this(defaultMQProducer, null); } - public DefaultMQProducerImpl(final DefaultMQProducer defaultMQProducer, RPCHook rpcHook) { this.defaultMQProducer = defaultMQProducer; this.rpcHook = rpcHook; @@ -85,18 +108,18 @@ public class DefaultMQProducerImpl implements MQProducerInner { public void registerCheckForbiddenHook(CheckForbiddenHook checkForbiddenHook) { this.checkForbiddenHookList.add(checkForbiddenHook); log.info("register a new checkForbiddenHook. hookName={}, allHookSize={}", checkForbiddenHook.hookName(), - checkForbiddenHookList.size()); + checkForbiddenHookList.size()); } public void initTransactionEnv() { - TransactionMQProducer producer = (TransactionMQProducer) this.defaultMQProducer; + TransactionMQProducer producer = (TransactionMQProducer)this.defaultMQProducer; this.checkRequestQueue = new LinkedBlockingQueue(producer.getCheckRequestHoldMax()); this.checkExecutor = new ThreadPoolExecutor(// - producer.getCheckThreadPoolMinSize(), // - producer.getCheckThreadPoolMaxSize(), // - 1000 * 60, // - TimeUnit.MILLISECONDS, // - this.checkRequestQueue); + producer.getCheckThreadPoolMinSize(), // + producer.getCheckThreadPoolMaxSize(), // + 1000 * 60, // + TimeUnit.MILLISECONDS, // + this.checkRequestQueue); } public void destroyTransactionEnv() { @@ -130,8 +153,8 @@ public class DefaultMQProducerImpl implements MQProducerInner { if (!registerOK) { this.serviceState = ServiceState.CREATE_JUST; throw new MQClientException("The producer group[" + this.defaultMQProducer.getProducerGroup() - + "] has been created before, specify another name please." + FAQUrl.suggestTodo(FAQUrl.GROUP_NAME_DUPLICATE_URL), - null); + + "] has been created before, specify another name please." + FAQUrl.suggestTodo(FAQUrl.GROUP_NAME_DUPLICATE_URL), + null); } this.topicPublishInfoTable.put(this.defaultMQProducer.getCreateTopicKey(), new TopicPublishInfo()); @@ -141,16 +164,16 @@ public class DefaultMQProducerImpl implements MQProducerInner { } log.info("the producer [{}] start OK. sendMessageWithVIPChannel={}", this.defaultMQProducer.getProducerGroup(), - this.defaultMQProducer.isSendMessageWithVIPChannel()); + this.defaultMQProducer.isSendMessageWithVIPChannel()); this.serviceState = ServiceState.RUNNING; break; case RUNNING: case START_FAILED: case SHUTDOWN_ALREADY: throw new MQClientException("The producer service state not OK, maybe started once, "// - + this.serviceState// - + FAQUrl.suggestTodo(FAQUrl.CLIENT_SERVICE_NOT_OK), - null); + + this.serviceState// + + FAQUrl.suggestTodo(FAQUrl.CLIENT_SERVICE_NOT_OK), + null); default: break; } @@ -167,7 +190,7 @@ public class DefaultMQProducerImpl implements MQProducerInner { if (this.defaultMQProducer.getProducerGroup().equals(MixAll.DEFAULT_PRODUCER_GROUP)) { throw new MQClientException("producerGroup can not equal " + MixAll.DEFAULT_PRODUCER_GROUP + ", please specify another one.", - null); + null); } } @@ -215,7 +238,7 @@ public class DefaultMQProducerImpl implements MQProducerInner { @Override public TransactionCheckListener checkListener() { if (this.defaultMQProducer instanceof TransactionMQProducer) { - TransactionMQProducer producer = (TransactionMQProducer) defaultMQProducer; + TransactionMQProducer producer = (TransactionMQProducer)defaultMQProducer; return producer.getTransactionCheckListener(); } @@ -230,7 +253,6 @@ public class DefaultMQProducerImpl implements MQProducerInner { private final CheckTransactionStateRequestHeader checkRequestHeader = header; private final String group = DefaultMQProducerImpl.this.defaultMQProducer.getProducerGroup(); - @Override public void run() { TransactionCheckListener transactionCheckListener = DefaultMQProducerImpl.this.checkListener(); @@ -245,19 +267,18 @@ public class DefaultMQProducerImpl implements MQProducerInner { } this.processTransactionState(// - localTransactionState, // - group, // - exception); + localTransactionState, // + group, // + exception); } else { log.warn("checkTransactionState, pick transactionCheckListener by group[{}] failed", group); } } - private void processTransactionState(// - final LocalTransactionState localTransactionState, // - final String producerGroup, // - final Throwable exception) { + final LocalTransactionState localTransactionState, // + final String producerGroup, // + final Throwable exception) { final EndTransactionRequestHeader thisHeader = new EndTransactionRequestHeader(); thisHeader.setCommitLogOffset(checkRequestHeader.getCommitLogOffset()); thisHeader.setProducerGroup(producerGroup); @@ -293,7 +314,7 @@ public class DefaultMQProducerImpl implements MQProducerInner { try { DefaultMQProducerImpl.this.mQClientFactory.getMQClientAPIImpl().endTransactionOneway(brokerAddr, thisHeader, remark, - 3000); + 3000); } catch (Exception e) { log.error("endTransactionOneway exception", e); } @@ -332,9 +353,9 @@ public class DefaultMQProducerImpl implements MQProducerInner { private void makeSureStateOK() throws MQClientException { if (this.serviceState != ServiceState.RUNNING) { throw new MQClientException("The producer service state not OK, "// - + this.serviceState// - + FAQUrl.suggestTodo(FAQUrl.CLIENT_SERVICE_NOT_OK), - null); + + this.serviceState// + + FAQUrl.suggestTodo(FAQUrl.CLIENT_SERVICE_NOT_OK), + null); } } @@ -370,13 +391,13 @@ public class DefaultMQProducerImpl implements MQProducerInner { } public QueryResult queryMessage(String topic, String key, int maxNum, long begin, long end) - throws MQClientException, InterruptedException { + throws MQClientException, InterruptedException { this.makeSureStateOK(); return this.mQClientFactory.getMQAdminImpl().queryMessage(topic, key, maxNum, begin, end); } public MessageExt queryMessageByUniqKey(String topic, String uniqKey) - throws MQClientException, InterruptedException { + throws MQClientException, InterruptedException { this.makeSureStateOK(); return this.mQClientFactory.getMQAdminImpl().queryMessageByUniqKey(topic, uniqKey); } @@ -389,7 +410,7 @@ public class DefaultMQProducerImpl implements MQProducerInner { } public void send(Message msg, SendCallback sendCallback, long timeout) - throws MQClientException, RemotingException, InterruptedException { + throws MQClientException, RemotingException, InterruptedException { try { this.sendDefaultImpl(msg, CommunicationMode.ASYNC, sendCallback, timeout); } catch (MQBrokerException e) { @@ -406,10 +427,10 @@ public class DefaultMQProducerImpl implements MQProducerInner { } private SendResult sendDefaultImpl(// - Message msg, // - final CommunicationMode communicationMode, // - final SendCallback sendCallback, // - final long timeout// + Message msg, // + final CommunicationMode communicationMode, // + final SendCallback sendCallback, // + final long timeout// ) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { this.makeSureStateOK(); Validators.checkMessage(msg, this.defaultMQProducer); @@ -508,16 +529,16 @@ public class DefaultMQProducerImpl implements MQProducerInner { } String info = String.format("Send [%d] times, still failed, cost [%d]ms, Topic: %s, BrokersSent: %s", - times, - System.currentTimeMillis() - beginTimestampFirst, - msg.getTopic(), - Arrays.toString(brokersSent)); + times, + System.currentTimeMillis() - beginTimestampFirst, + msg.getTopic(), + Arrays.toString(brokersSent)); info += FAQUrl.suggestTodo(FAQUrl.SEND_MSG_FAILED); MQClientException mqClientException = new MQClientException(info, exception); if (exception instanceof MQBrokerException) { - mqClientException.setResponseCode(((MQBrokerException) exception).getResponseCode()); + mqClientException.setResponseCode(((MQBrokerException)exception).getResponseCode()); } else if (exception instanceof RemotingConnectException) { mqClientException.setResponseCode(ClientErrorCode.CONNECT_BROKER_EXCEPTION); } else if (exception instanceof RemotingTimeoutException) { @@ -532,11 +553,11 @@ public class DefaultMQProducerImpl implements MQProducerInner { List nsList = this.getmQClientFactory().getMQClientAPIImpl().getNameServerAddressList(); if (null == nsList || nsList.isEmpty()) { throw new MQClientException( - "No name server address, please set it." + FAQUrl.suggestTodo(FAQUrl.NAME_SERVER_ADDR_NOT_EXIST_URL), null).setResponseCode(ClientErrorCode.NO_NAME_SERVER_EXCEPTION); + "No name server address, please set it." + FAQUrl.suggestTodo(FAQUrl.NAME_SERVER_ADDR_NOT_EXIST_URL), null).setResponseCode(ClientErrorCode.NO_NAME_SERVER_EXCEPTION); } throw new MQClientException("No route info of this topic, " + msg.getTopic() + FAQUrl.suggestTodo(FAQUrl.NO_TOPIC_ROUTE_INFO), - null).setResponseCode(ClientErrorCode.NOT_FOUND_TOPIC_EXCEPTION); + null).setResponseCode(ClientErrorCode.NOT_FOUND_TOPIC_EXCEPTION); } private TopicPublishInfo tryToFindTopicPublishInfo(final String topic) { @@ -557,11 +578,11 @@ public class DefaultMQProducerImpl implements MQProducerInner { } private SendResult sendKernelImpl(final Message msg, // - final MessageQueue mq, // - final CommunicationMode communicationMode, // - final SendCallback sendCallback, // - final TopicPublishInfo topicPublishInfo, // - final long timeout) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { + final MessageQueue mq, // + final CommunicationMode communicationMode, // + final SendCallback sendCallback, // + final TopicPublishInfo topicPublishInfo, // + final long timeout) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { String brokerAddr = this.mQClientFactory.findBrokerAddressInPublish(mq.getBrokerName()); if (null == brokerAddr) { tryToFindTopicPublishInfo(mq.getTopic()); @@ -649,30 +670,30 @@ public class DefaultMQProducerImpl implements MQProducerInner { switch (communicationMode) { case ASYNC: sendResult = this.mQClientFactory.getMQClientAPIImpl().sendMessage(// - brokerAddr, // 1 - mq.getBrokerName(), // 2 - msg, // 3 - requestHeader, // 4 - timeout, // 5 - communicationMode, // 6 - sendCallback, // 7 - topicPublishInfo, // 8 - this.mQClientFactory, // 9 - this.defaultMQProducer.getRetryTimesWhenSendAsyncFailed(), // 10 - context, // - this); + brokerAddr, // 1 + mq.getBrokerName(), // 2 + msg, // 3 + requestHeader, // 4 + timeout, // 5 + communicationMode, // 6 + sendCallback, // 7 + topicPublishInfo, // 8 + this.mQClientFactory, // 9 + this.defaultMQProducer.getRetryTimesWhenSendAsyncFailed(), // 10 + context, // + this); break; case ONEWAY: case SYNC: sendResult = this.mQClientFactory.getMQClientAPIImpl().sendMessage( - brokerAddr, - mq.getBrokerName(), - msg, - requestHeader, - timeout, - communicationMode, - context, - this); + brokerAddr, + mq.getBrokerName(), + msg, + requestHeader, + timeout, + communicationMode, + context, + this); break; default: assert false; @@ -790,12 +811,12 @@ public class DefaultMQProducerImpl implements MQProducerInner { * KERNEL SYNC ------------------------------------------------------- */ public SendResult send(Message msg, MessageQueue mq) - throws MQClientException, RemotingException, MQBrokerException, InterruptedException { + throws MQClientException, RemotingException, MQBrokerException, InterruptedException { return send(msg, mq, this.defaultMQProducer.getSendMsgTimeout()); } public SendResult send(Message msg, MessageQueue mq, long timeout) - throws MQClientException, RemotingException, MQBrokerException, InterruptedException { + throws MQClientException, RemotingException, MQBrokerException, InterruptedException { this.makeSureStateOK(); Validators.checkMessage(msg, this.defaultMQProducer); @@ -810,12 +831,12 @@ public class DefaultMQProducerImpl implements MQProducerInner { * KERNEL ASYNC ------------------------------------------------------- */ public void send(Message msg, MessageQueue mq, SendCallback sendCallback) - throws MQClientException, RemotingException, InterruptedException { + throws MQClientException, RemotingException, InterruptedException { send(msg, mq, sendCallback, this.defaultMQProducer.getSendMsgTimeout()); } public void send(Message msg, MessageQueue mq, SendCallback sendCallback, long timeout) - throws MQClientException, RemotingException, InterruptedException { + throws MQClientException, RemotingException, InterruptedException { this.makeSureStateOK(); Validators.checkMessage(msg, this.defaultMQProducer); @@ -848,21 +869,21 @@ public class DefaultMQProducerImpl implements MQProducerInner { * SELECT SYNC ------------------------------------------------------- */ public SendResult send(Message msg, MessageQueueSelector selector, Object arg) - throws MQClientException, RemotingException, MQBrokerException, InterruptedException { + throws MQClientException, RemotingException, MQBrokerException, InterruptedException { return send(msg, selector, arg, this.defaultMQProducer.getSendMsgTimeout()); } public SendResult send(Message msg, MessageQueueSelector selector, Object arg, long timeout) - throws MQClientException, RemotingException, MQBrokerException, InterruptedException { + throws MQClientException, RemotingException, MQBrokerException, InterruptedException { return this.sendSelectImpl(msg, selector, arg, CommunicationMode.SYNC, null, timeout); } private SendResult sendSelectImpl(// - Message msg, // - MessageQueueSelector selector, // - Object arg, // - final CommunicationMode communicationMode, // - final SendCallback sendCallback, final long timeout// + Message msg, // + MessageQueueSelector selector, // + Object arg, // + final CommunicationMode communicationMode, // + final SendCallback sendCallback, final long timeout// ) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { this.makeSureStateOK(); Validators.checkMessage(msg, this.defaultMQProducer); @@ -890,12 +911,12 @@ public class DefaultMQProducerImpl implements MQProducerInner { * SELECT ASYNC ------------------------------------------------------- */ public void send(Message msg, MessageQueueSelector selector, Object arg, SendCallback sendCallback) - throws MQClientException, RemotingException, InterruptedException { + throws MQClientException, RemotingException, InterruptedException { send(msg, selector, arg, sendCallback, this.defaultMQProducer.getSendMsgTimeout()); } public void send(Message msg, MessageQueueSelector selector, Object arg, SendCallback sendCallback, long timeout) - throws MQClientException, RemotingException, InterruptedException { + throws MQClientException, RemotingException, InterruptedException { try { this.sendSelectImpl(msg, selector, arg, CommunicationMode.ASYNC, sendCallback, timeout); } catch (MQBrokerException e) { @@ -907,7 +928,7 @@ public class DefaultMQProducerImpl implements MQProducerInner { * SELECT ONEWAY ------------------------------------------------------- */ public void sendOneway(Message msg, MessageQueueSelector selector, Object arg) - throws MQClientException, RemotingException, InterruptedException { + throws MQClientException, RemotingException, InterruptedException { try { this.sendSelectImpl(msg, selector, arg, CommunicationMode.ONEWAY, null, this.defaultMQProducer.getSendMsgTimeout()); } catch (MQBrokerException e) { @@ -916,7 +937,7 @@ public class DefaultMQProducerImpl implements MQProducerInner { } public TransactionSendResult sendMessageInTransaction(final Message msg, final LocalTransactionExecuter tranExecuter, final Object arg) - throws MQClientException { + throws MQClientException { if (null == tranExecuter) { throw new MQClientException("tranExecutor is null", null); } @@ -988,9 +1009,9 @@ public class DefaultMQProducerImpl implements MQProducerInner { } public void endTransaction(// - final SendResult sendResult, // - final LocalTransactionState localTransactionState, // - final Throwable localException) throws RemotingException, MQBrokerException, InterruptedException, UnknownHostException { + final SendResult sendResult, // + final LocalTransactionState localTransactionState, // + final Throwable localException) throws RemotingException, MQBrokerException, InterruptedException, UnknownHostException { final MessageId id; if (sendResult.getOffsetMsgId() != null) { id = MessageDecoder.decodeMessageId(sendResult.getOffsetMsgId()); @@ -1021,7 +1042,7 @@ public class DefaultMQProducerImpl implements MQProducerInner { requestHeader.setMsgId(sendResult.getMsgId()); String remark = localException != null ? ("executeLocalTransactionBranch exception: " + localException.toString()) : null; this.mQClientFactory.getMQClientAPIImpl().endTransactionOneway(brokerAddr, requestHeader, remark, - this.defaultMQProducer.getSendMsgTimeout()); + this.defaultMQProducer.getSendMsgTimeout()); } public SendResult send(Message msg, long timeout) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { @@ -1036,17 +1057,14 @@ public class DefaultMQProducerImpl implements MQProducerInner { return zipCompressLevel; } - public void setZipCompressLevel(int zipCompressLevel) { this.zipCompressLevel = zipCompressLevel; } - public ServiceState getServiceState() { return serviceState; } - public void setServiceState(ServiceState serviceState) { this.serviceState = serviceState; } diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/producer/MQProducerInner.java b/client/src/main/java/org/apache/rocketmq/client/impl/producer/MQProducerInner.java index cac77ae6..cf613262 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/producer/MQProducerInner.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/producer/MQProducerInner.java @@ -6,41 +6,34 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.impl.producer; +import java.util.Set; import org.apache.rocketmq.client.producer.TransactionCheckListener; import org.apache.rocketmq.common.message.MessageExt; import org.apache.rocketmq.common.protocol.header.CheckTransactionStateRequestHeader; -import java.util.Set; - - public interface MQProducerInner { Set getPublishTopicList(); - boolean isPublishTopicNeedUpdate(final String topic); - TransactionCheckListener checkListener(); - void checkTransactionState(// - final String addr, // - final MessageExt msg, // - final CheckTransactionStateRequestHeader checkRequestHeader); - + final String addr, // + final MessageExt msg, // + final CheckTransactionStateRequestHeader checkRequestHeader); void updateTopicPublishInfo(final String topic, final TopicPublishInfo info); - boolean isUnitMode(); } diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/producer/TopicPublishInfo.java b/client/src/main/java/org/apache/rocketmq/client/impl/producer/TopicPublishInfo.java index dca20cb6..c6f9d45b 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/producer/TopicPublishInfo.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/producer/TopicPublishInfo.java @@ -16,15 +16,13 @@ */ package org.apache.rocketmq.client.impl.producer; +import java.util.ArrayList; +import java.util.List; import org.apache.rocketmq.client.common.ThreadLocalIndex; import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.common.protocol.route.QueueData; import org.apache.rocketmq.common.protocol.route.TopicRouteData; -import java.util.ArrayList; -import java.util.List; - - public class TopicPublishInfo { private boolean orderTopic = false; private boolean haveTopicRouterInfo = false; @@ -32,7 +30,6 @@ public class TopicPublishInfo { private volatile ThreadLocalIndex sendWhichQueue = new ThreadLocalIndex(0); private TopicRouteData topicRouteData; - public boolean isOrderTopic() { return orderTopic; } @@ -49,32 +46,26 @@ public class TopicPublishInfo { return messageQueueList; } - public void setMessageQueueList(List messageQueueList) { this.messageQueueList = messageQueueList; } - public ThreadLocalIndex getSendWhichQueue() { return sendWhichQueue; } - public void setSendWhichQueue(ThreadLocalIndex sendWhichQueue) { this.sendWhichQueue = sendWhichQueue; } - public boolean isHaveTopicRouterInfo() { return haveTopicRouterInfo; } - public void setHaveTopicRouterInfo(boolean haveTopicRouterInfo) { this.haveTopicRouterInfo = haveTopicRouterInfo; } - public MessageQueue selectOneMessageQueue(final String lastBrokerName) { if (lastBrokerName == null) { return selectOneMessageQueue(); @@ -93,7 +84,6 @@ public class TopicPublishInfo { } } - public MessageQueue selectOneMessageQueue() { int index = this.sendWhichQueue.getAndIncrement(); int pos = Math.abs(index) % this.messageQueueList.size(); @@ -113,11 +103,10 @@ public class TopicPublishInfo { return -1; } - @Override public String toString() { return "TopicPublishInfo [orderTopic=" + orderTopic + ", messageQueueList=" + messageQueueList - + ", sendWhichQueue=" + sendWhichQueue + ", haveTopicRouterInfo=" + haveTopicRouterInfo + "]"; + + ", sendWhichQueue=" + sendWhichQueue + ", haveTopicRouterInfo=" + haveTopicRouterInfo + "]"; } public TopicRouteData getTopicRouteData() { diff --git a/client/src/main/java/org/apache/rocketmq/client/latency/LatencyFaultToleranceImpl.java b/client/src/main/java/org/apache/rocketmq/client/latency/LatencyFaultToleranceImpl.java index 12dac4b7..b61d855e 100644 --- a/client/src/main/java/org/apache/rocketmq/client/latency/LatencyFaultToleranceImpl.java +++ b/client/src/main/java/org/apache/rocketmq/client/latency/LatencyFaultToleranceImpl.java @@ -17,13 +17,12 @@ package org.apache.rocketmq.client.latency; -import org.apache.rocketmq.client.common.ThreadLocalIndex; - import java.util.Collections; import java.util.Enumeration; import java.util.LinkedList; import java.util.List; import java.util.concurrent.ConcurrentHashMap; +import org.apache.rocketmq.client.common.ThreadLocalIndex; public class LatencyFaultToleranceImpl implements LatencyFaultTolerance { private final ConcurrentHashMap faultItemTable = new ConcurrentHashMap(16); @@ -89,6 +88,14 @@ public class LatencyFaultToleranceImpl implements LatencyFaultTolerance return null; } + @Override + public String toString() { + return "LatencyFaultToleranceImpl{" + + "faultItemTable=" + faultItemTable + + ", whichItemWorst=" + whichItemWorst + + '}'; + } + class FaultItem implements Comparable { private final String name; private volatile long currentLatency; @@ -101,9 +108,11 @@ public class LatencyFaultToleranceImpl implements LatencyFaultTolerance @Override public int compareTo(final FaultItem other) { if (this.isAvailable() != other.isAvailable()) { - if (this.isAvailable()) return -1; + if (this.isAvailable()) + return -1; - if (other.isAvailable()) return 1; + if (other.isAvailable()) + return 1; } if (this.currentLatency < other.currentLatency) @@ -128,20 +137,24 @@ public class LatencyFaultToleranceImpl implements LatencyFaultTolerance @Override public int hashCode() { int result = getName() != null ? getName().hashCode() : 0; - result = 31 * result + (int) (getCurrentLatency() ^ (getCurrentLatency() >>> 32)); - result = 31 * result + (int) (getStartTimestamp() ^ (getStartTimestamp() >>> 32)); + result = 31 * result + (int)(getCurrentLatency() ^ (getCurrentLatency() >>> 32)); + result = 31 * result + (int)(getStartTimestamp() ^ (getStartTimestamp() >>> 32)); return result; } @Override public boolean equals(final Object o) { - if (this == o) return true; - if (!(o instanceof FaultItem)) return false; + if (this == o) + return true; + if (!(o instanceof FaultItem)) + return false; - final FaultItem faultItem = (FaultItem) o; + final FaultItem faultItem = (FaultItem)o; - if (getCurrentLatency() != faultItem.getCurrentLatency()) return false; - if (getStartTimestamp() != faultItem.getStartTimestamp()) return false; + if (getCurrentLatency() != faultItem.getCurrentLatency()) + return false; + if (getStartTimestamp() != faultItem.getStartTimestamp()) + return false; return getName() != null ? getName().equals(faultItem.getName()) : faultItem.getName() == null; } @@ -149,10 +162,10 @@ public class LatencyFaultToleranceImpl implements LatencyFaultTolerance @Override public String toString() { return "FaultItem{" + - "name='" + name + '\'' + - ", currentLatency=" + currentLatency + - ", startTimestamp=" + startTimestamp + - '}'; + "name='" + name + '\'' + + ", currentLatency=" + currentLatency + + ", startTimestamp=" + startTimestamp + + '}'; } public String getName() { @@ -175,14 +188,5 @@ public class LatencyFaultToleranceImpl implements LatencyFaultTolerance this.startTimestamp = startTimestamp; } - - } - - @Override - public String toString() { - return "LatencyFaultToleranceImpl{" + - "faultItemTable=" + faultItemTable + - ", whichItemWorst=" + whichItemWorst + - '}'; } } diff --git a/client/src/main/java/org/apache/rocketmq/client/latency/MQFaultStrategy.java b/client/src/main/java/org/apache/rocketmq/client/latency/MQFaultStrategy.java index cdfd5d1e..70758dcb 100644 --- a/client/src/main/java/org/apache/rocketmq/client/latency/MQFaultStrategy.java +++ b/client/src/main/java/org/apache/rocketmq/client/latency/MQFaultStrategy.java @@ -25,8 +25,8 @@ public class MQFaultStrategy { private boolean sendLatencyFaultEnable = false; - private long[] latencyMax = {50L, 100L, 550L, 1000L, 2000L, 3000L, 15000L}; - private long[] notAvailableDuration = {0L, 0L, 30000L, 60000L, 120000L, 180000L, 600000L}; + private long[] latencyMax = {50L, 100L, 550L, 1000L, 2000L, 3000L, 15000L}; + private long[] notAvailableDuration = {0L, 0L, 30000L, 60000L, 120000L, 180000L, 600000L}; public long[] getNotAvailableDuration() { return notAvailableDuration; @@ -97,7 +97,8 @@ public class MQFaultStrategy { private long computeNotAvailableDuration(final long currentLatency) { for (int i = latencyMax.length - 1; i >= 0; i--) { - if (currentLatency >= latencyMax[i]) return this.notAvailableDuration[i]; + if (currentLatency >= latencyMax[i]) + return this.notAvailableDuration[i]; } return 0; diff --git a/client/src/main/java/org/apache/rocketmq/client/log/ClientLogger.java b/client/src/main/java/org/apache/rocketmq/client/log/ClientLogger.java index 30551197..7a05e763 100644 --- a/client/src/main/java/org/apache/rocketmq/client/log/ClientLogger.java +++ b/client/src/main/java/org/apache/rocketmq/client/log/ClientLogger.java @@ -16,38 +16,35 @@ */ package org.apache.rocketmq.client.log; +import java.lang.reflect.Method; +import java.net.URL; import org.apache.rocketmq.common.constant.LoggerName; import org.slf4j.ILoggerFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.lang.reflect.Method; -import java.net.URL; - - public class ClientLogger { - private static Logger log; public static final String CLIENT_LOG_ROOT = "rocketmq.client.logRoot"; public static final String CLIENT_LOG_MAXINDEX = "rocketmq.client.logFileMaxIndex"; public static final String CLIENT_LOG_LEVEL = "rocketmq.client.logLevel"; + private static Logger log; static { log = createLogger(LoggerName.CLIENT_LOGGER_NAME); } - private static Logger createLogger(final String loggerName) { String logConfigFilePath = - System.getProperty("rocketmq.client.log.configFile", - System.getenv("ROCKETMQ_CLIENT_LOG_CONFIGFILE")); + System.getProperty("rocketmq.client.log.configFile", + System.getenv("ROCKETMQ_CLIENT_LOG_CONFIGFILE")); Boolean isloadconfig = - Boolean.parseBoolean(System.getProperty("rocketmq.client.log.loadconfig", "true")); + Boolean.parseBoolean(System.getProperty("rocketmq.client.log.loadconfig", "true")); final String log4JResourceFile = - System.getProperty("rocketmq.client.log4j.resource.fileName", "log4j_rocketmq_client.xml"); + System.getProperty("rocketmq.client.log4j.resource.fileName", "log4j_rocketmq_client.xml"); final String logbackResourceFile = - System.getProperty("rocketmq.client.logback.resource.fileName", "logback_rocketmq_client.xml"); + System.getProperty("rocketmq.client.logback.resource.fileName", "logback_rocketmq_client.xml"); String clientLogRoot = System.getProperty(CLIENT_LOG_ROOT, "${user.home}/logs/rocketmqlogs"); System.setProperty("client.logRoot", clientLogRoot); @@ -85,11 +82,11 @@ public class ClientLogger { if (null == logConfigFilePath) { URL url = ClientLogger.class.getClassLoader().getResource(logbackResourceFile); Method doConfigure = - joranConfiguratoroObj.getClass().getMethod("doConfigure", URL.class); + joranConfiguratoroObj.getClass().getMethod("doConfigure", URL.class); doConfigure.invoke(joranConfiguratoroObj, url); } else { Method doConfigure = - joranConfiguratoroObj.getClass().getMethod("doConfigure", String.class); + joranConfiguratoroObj.getClass().getMethod("doConfigure", String.class); doConfigure.invoke(joranConfiguratoroObj, logConfigFilePath); } @@ -101,12 +98,10 @@ public class ClientLogger { return LoggerFactory.getLogger(LoggerName.CLIENT_LOGGER_NAME); } - public static Logger getLog() { return log; } - public static void setLog(Logger log) { ClientLogger.log = log; } diff --git a/client/src/main/java/org/apache/rocketmq/client/producer/DefaultMQProducer.java b/client/src/main/java/org/apache/rocketmq/client/producer/DefaultMQProducer.java index 340b1ffe..736aa158 100644 --- a/client/src/main/java/org/apache/rocketmq/client/producer/DefaultMQProducer.java +++ b/client/src/main/java/org/apache/rocketmq/client/producer/DefaultMQProducer.java @@ -6,28 +6,30 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.producer; +import java.util.List; import org.apache.rocketmq.client.ClientConfig; import org.apache.rocketmq.client.QueryResult; import org.apache.rocketmq.client.exception.MQBrokerException; import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl; import org.apache.rocketmq.common.MixAll; +import org.apache.rocketmq.common.message.Message; +import org.apache.rocketmq.common.message.MessageDecoder; +import org.apache.rocketmq.common.message.MessageExt; +import org.apache.rocketmq.common.message.MessageId; +import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.remoting.exception.RemotingException; -import org.apache.rocketmq.common.message.*; - -import java.util.List; - public class DefaultMQProducer extends ClientConfig implements MQProducer { protected final transient DefaultMQProducerImpl defaultMQProducerImpl; @@ -44,27 +46,24 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer { private boolean retryAnotherBrokerWhenNotStoreOK = false; private int maxMessageSize = 1024 * 1024 * 4; // 4M + public DefaultMQProducer() { this(MixAll.DEFAULT_PRODUCER_GROUP, null); } - public DefaultMQProducer(final String producerGroup, RPCHook rpcHook) { this.producerGroup = producerGroup; defaultMQProducerImpl = new DefaultMQProducerImpl(this, rpcHook); } - public DefaultMQProducer(final String producerGroup) { this(producerGroup, null); } - public DefaultMQProducer(RPCHook rpcHook) { this(MixAll.DEFAULT_PRODUCER_GROUP, rpcHook); } - @Override public void start() throws MQClientException { this.defaultMQProducerImpl.start(); @@ -75,169 +74,143 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer { this.defaultMQProducerImpl.shutdown(); } - @Override public List fetchPublishMessageQueues(String topic) throws MQClientException { return this.defaultMQProducerImpl.fetchPublishMessageQueues(topic); } - @Override public SendResult send(Message msg) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { return this.defaultMQProducerImpl.send(msg); } - @Override public SendResult send(Message msg, long timeout) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { return this.defaultMQProducerImpl.send(msg, timeout); } - @Override public void send(Message msg, SendCallback sendCallback) throws MQClientException, RemotingException, InterruptedException { this.defaultMQProducerImpl.send(msg, sendCallback); } - @Override public void send(Message msg, SendCallback sendCallback, long timeout) - throws MQClientException, RemotingException, InterruptedException { + throws MQClientException, RemotingException, InterruptedException { this.defaultMQProducerImpl.send(msg, sendCallback, timeout); } - @Override public void sendOneway(Message msg) throws MQClientException, RemotingException, InterruptedException { this.defaultMQProducerImpl.sendOneway(msg); } - @Override public SendResult send(Message msg, MessageQueue mq) - throws MQClientException, RemotingException, MQBrokerException, InterruptedException { + throws MQClientException, RemotingException, MQBrokerException, InterruptedException { return this.defaultMQProducerImpl.send(msg, mq); } - @Override public SendResult send(Message msg, MessageQueue mq, long timeout) - throws MQClientException, RemotingException, MQBrokerException, InterruptedException { + throws MQClientException, RemotingException, MQBrokerException, InterruptedException { return this.defaultMQProducerImpl.send(msg, mq, timeout); } - @Override public void send(Message msg, MessageQueue mq, SendCallback sendCallback) - throws MQClientException, RemotingException, InterruptedException { + throws MQClientException, RemotingException, InterruptedException { this.defaultMQProducerImpl.send(msg, mq, sendCallback); } - @Override public void send(Message msg, MessageQueue mq, SendCallback sendCallback, long timeout) - throws MQClientException, RemotingException, InterruptedException { + throws MQClientException, RemotingException, InterruptedException { this.defaultMQProducerImpl.send(msg, mq, sendCallback, timeout); } - @Override public void sendOneway(Message msg, MessageQueue mq) throws MQClientException, RemotingException, InterruptedException { this.defaultMQProducerImpl.sendOneway(msg, mq); } - @Override public SendResult send(Message msg, MessageQueueSelector selector, Object arg) - throws MQClientException, RemotingException, MQBrokerException, InterruptedException { + throws MQClientException, RemotingException, MQBrokerException, InterruptedException { return this.defaultMQProducerImpl.send(msg, selector, arg); } - @Override public SendResult send(Message msg, MessageQueueSelector selector, Object arg, long timeout) - throws MQClientException, RemotingException, MQBrokerException, InterruptedException { + throws MQClientException, RemotingException, MQBrokerException, InterruptedException { return this.defaultMQProducerImpl.send(msg, selector, arg, timeout); } - @Override public void send(Message msg, MessageQueueSelector selector, Object arg, SendCallback sendCallback) - throws MQClientException, RemotingException, InterruptedException { + throws MQClientException, RemotingException, InterruptedException { this.defaultMQProducerImpl.send(msg, selector, arg, sendCallback); } - @Override public void send(Message msg, MessageQueueSelector selector, Object arg, SendCallback sendCallback, long timeout) - throws MQClientException, RemotingException, InterruptedException { + throws MQClientException, RemotingException, InterruptedException { this.defaultMQProducerImpl.send(msg, selector, arg, sendCallback, timeout); } - @Override public void sendOneway(Message msg, MessageQueueSelector selector, Object arg) - throws MQClientException, RemotingException, InterruptedException { + throws MQClientException, RemotingException, InterruptedException { this.defaultMQProducerImpl.sendOneway(msg, selector, arg); } - @Override public TransactionSendResult sendMessageInTransaction(Message msg, LocalTransactionExecuter tranExecuter, final Object arg) - throws MQClientException { + throws MQClientException { throw new RuntimeException("sendMessageInTransaction not implement, please use TransactionMQProducer class"); } - @Override public void createTopic(String key, String newTopic, int queueNum) throws MQClientException { createTopic(key, newTopic, queueNum, 0); } - @Override public void createTopic(String key, String newTopic, int queueNum, int topicSysFlag) throws MQClientException { this.defaultMQProducerImpl.createTopic(key, newTopic, queueNum, topicSysFlag); } - @Override public long searchOffset(MessageQueue mq, long timestamp) throws MQClientException { return this.defaultMQProducerImpl.searchOffset(mq, timestamp); } - @Override public long maxOffset(MessageQueue mq) throws MQClientException { return this.defaultMQProducerImpl.maxOffset(mq); } - @Override public long minOffset(MessageQueue mq) throws MQClientException { return this.defaultMQProducerImpl.minOffset(mq); } - @Override public long earliestMsgStoreTime(MessageQueue mq) throws MQClientException { return this.defaultMQProducerImpl.earliestMsgStoreTime(mq); } - @Override public MessageExt viewMessage(String offsetMsgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { return this.defaultMQProducerImpl.viewMessage(offsetMsgId); } - @Override public QueryResult queryMessage(String topic, String key, int maxNum, long begin, long end) - throws MQClientException, InterruptedException { + throws MQClientException, InterruptedException { return this.defaultMQProducerImpl.queryMessage(topic, key, maxNum, begin, end); } - @Override public MessageExt viewMessage(String topic, String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { try { @@ -252,97 +225,78 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer { return producerGroup; } - public void setProducerGroup(String producerGroup) { this.producerGroup = producerGroup; } - public String getCreateTopicKey() { return createTopicKey; } - public void setCreateTopicKey(String createTopicKey) { this.createTopicKey = createTopicKey; } - public int getSendMsgTimeout() { return sendMsgTimeout; } - public void setSendMsgTimeout(int sendMsgTimeout) { this.sendMsgTimeout = sendMsgTimeout; } - public int getCompressMsgBodyOverHowmuch() { return compressMsgBodyOverHowmuch; } - public void setCompressMsgBodyOverHowmuch(int compressMsgBodyOverHowmuch) { this.compressMsgBodyOverHowmuch = compressMsgBodyOverHowmuch; } - public DefaultMQProducerImpl getDefaultMQProducerImpl() { return defaultMQProducerImpl; } - public boolean isRetryAnotherBrokerWhenNotStoreOK() { return retryAnotherBrokerWhenNotStoreOK; } - public void setRetryAnotherBrokerWhenNotStoreOK(boolean retryAnotherBrokerWhenNotStoreOK) { this.retryAnotherBrokerWhenNotStoreOK = retryAnotherBrokerWhenNotStoreOK; } - public int getMaxMessageSize() { return maxMessageSize; } - public void setMaxMessageSize(int maxMessageSize) { this.maxMessageSize = maxMessageSize; } - public int getDefaultTopicQueueNums() { return defaultTopicQueueNums; } - public void setDefaultTopicQueueNums(int defaultTopicQueueNums) { this.defaultTopicQueueNums = defaultTopicQueueNums; } - public int getRetryTimesWhenSendFailed() { return retryTimesWhenSendFailed; } - public void setRetryTimesWhenSendFailed(int retryTimesWhenSendFailed) { this.retryTimesWhenSendFailed = retryTimesWhenSendFailed; } - public boolean isSendMessageWithVIPChannel() { return isVipChannelEnabled(); } - public void setSendMessageWithVIPChannel(final boolean sendMessageWithVIPChannel) { this.setVipChannelEnabled(sendMessageWithVIPChannel); } - public long[] getNotAvailableDuration() { return this.defaultMQProducerImpl.getNotAvailableDuration(); } diff --git a/client/src/main/java/org/apache/rocketmq/client/producer/LocalTransactionExecuter.java b/client/src/main/java/org/apache/rocketmq/client/producer/LocalTransactionExecuter.java index a7246e0e..1083f9b2 100644 --- a/client/src/main/java/org/apache/rocketmq/client/producer/LocalTransactionExecuter.java +++ b/client/src/main/java/org/apache/rocketmq/client/producer/LocalTransactionExecuter.java @@ -6,19 +6,18 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.producer; import org.apache.rocketmq.common.message.Message; - public interface LocalTransactionExecuter { public LocalTransactionState executeLocalTransactionBranch(final Message msg, final Object arg); } diff --git a/client/src/main/java/org/apache/rocketmq/client/producer/LocalTransactionState.java b/client/src/main/java/org/apache/rocketmq/client/producer/LocalTransactionState.java index b907f816..209619a8 100644 --- a/client/src/main/java/org/apache/rocketmq/client/producer/LocalTransactionState.java +++ b/client/src/main/java/org/apache/rocketmq/client/producer/LocalTransactionState.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.producer; diff --git a/client/src/main/java/org/apache/rocketmq/client/producer/MQProducer.java b/client/src/main/java/org/apache/rocketmq/client/producer/MQProducer.java index 492604ef..b53652a3 100644 --- a/client/src/main/java/org/apache/rocketmq/client/producer/MQProducer.java +++ b/client/src/main/java/org/apache/rocketmq/client/producer/MQProducer.java @@ -6,16 +6,17 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.producer; +import java.util.List; import org.apache.rocketmq.client.MQAdmin; import org.apache.rocketmq.client.exception.MQBrokerException; import org.apache.rocketmq.client.exception.MQClientException; @@ -23,81 +24,61 @@ import org.apache.rocketmq.common.message.Message; import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.remoting.exception.RemotingException; -import java.util.List; - - public interface MQProducer extends MQAdmin { void start() throws MQClientException; void shutdown(); - List fetchPublishMessageQueues(final String topic) throws MQClientException; - SendResult send(final Message msg) throws MQClientException, RemotingException, MQBrokerException, - InterruptedException; - + InterruptedException; SendResult send(final Message msg, final long timeout) throws MQClientException, - RemotingException, MQBrokerException, InterruptedException; - + RemotingException, MQBrokerException, InterruptedException; void send(final Message msg, final SendCallback sendCallback) throws MQClientException, - RemotingException, InterruptedException; - + RemotingException, InterruptedException; void send(final Message msg, final SendCallback sendCallback, final long timeout) - throws MQClientException, RemotingException, InterruptedException; - + throws MQClientException, RemotingException, InterruptedException; void sendOneway(final Message msg) throws MQClientException, RemotingException, - InterruptedException; - + InterruptedException; SendResult send(final Message msg, final MessageQueue mq) throws MQClientException, - RemotingException, MQBrokerException, InterruptedException; - + RemotingException, MQBrokerException, InterruptedException; SendResult send(final Message msg, final MessageQueue mq, final long timeout) - throws MQClientException, RemotingException, MQBrokerException, InterruptedException; - + throws MQClientException, RemotingException, MQBrokerException, InterruptedException; void send(final Message msg, final MessageQueue mq, final SendCallback sendCallback) - throws MQClientException, RemotingException, InterruptedException; - + throws MQClientException, RemotingException, InterruptedException; void send(final Message msg, final MessageQueue mq, final SendCallback sendCallback, long timeout) - throws MQClientException, RemotingException, InterruptedException; - + throws MQClientException, RemotingException, InterruptedException; void sendOneway(final Message msg, final MessageQueue mq) throws MQClientException, - RemotingException, InterruptedException; - + RemotingException, InterruptedException; SendResult send(final Message msg, final MessageQueueSelector selector, final Object arg) - throws MQClientException, RemotingException, MQBrokerException, InterruptedException; - + throws MQClientException, RemotingException, MQBrokerException, InterruptedException; SendResult send(final Message msg, final MessageQueueSelector selector, final Object arg, - final long timeout) throws MQClientException, RemotingException, MQBrokerException, - InterruptedException; - + final long timeout) throws MQClientException, RemotingException, MQBrokerException, + InterruptedException; void send(final Message msg, final MessageQueueSelector selector, final Object arg, - final SendCallback sendCallback) throws MQClientException, RemotingException, - InterruptedException; - + final SendCallback sendCallback) throws MQClientException, RemotingException, + InterruptedException; void send(final Message msg, final MessageQueueSelector selector, final Object arg, - final SendCallback sendCallback, final long timeout) throws MQClientException, RemotingException, - InterruptedException; - + final SendCallback sendCallback, final long timeout) throws MQClientException, RemotingException, + InterruptedException; void sendOneway(final Message msg, final MessageQueueSelector selector, final Object arg) - throws MQClientException, RemotingException, InterruptedException; - + throws MQClientException, RemotingException, InterruptedException; TransactionSendResult sendMessageInTransaction(final Message msg, - final LocalTransactionExecuter tranExecuter, final Object arg) throws MQClientException; + final LocalTransactionExecuter tranExecuter, final Object arg) throws MQClientException; } diff --git a/client/src/main/java/org/apache/rocketmq/client/producer/MessageQueueSelector.java b/client/src/main/java/org/apache/rocketmq/client/producer/MessageQueueSelector.java index 47956bbb..761f45e0 100644 --- a/client/src/main/java/org/apache/rocketmq/client/producer/MessageQueueSelector.java +++ b/client/src/main/java/org/apache/rocketmq/client/producer/MessageQueueSelector.java @@ -6,22 +6,20 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.producer; +import java.util.List; import org.apache.rocketmq.common.message.Message; import org.apache.rocketmq.common.message.MessageQueue; -import java.util.List; - - public interface MessageQueueSelector { MessageQueue select(final List mqs, final Message msg, final Object arg); } diff --git a/client/src/main/java/org/apache/rocketmq/client/producer/SendCallback.java b/client/src/main/java/org/apache/rocketmq/client/producer/SendCallback.java index f599d836..178e79a3 100644 --- a/client/src/main/java/org/apache/rocketmq/client/producer/SendCallback.java +++ b/client/src/main/java/org/apache/rocketmq/client/producer/SendCallback.java @@ -6,19 +6,18 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.producer; public interface SendCallback { public void onSuccess(final SendResult sendResult); - public void onException(final Throwable e); } diff --git a/client/src/main/java/org/apache/rocketmq/client/producer/SendResult.java b/client/src/main/java/org/apache/rocketmq/client/producer/SendResult.java index 0fce69e5..a9dadcc8 100644 --- a/client/src/main/java/org/apache/rocketmq/client/producer/SendResult.java +++ b/client/src/main/java/org/apache/rocketmq/client/producer/SendResult.java @@ -19,7 +19,6 @@ package org.apache.rocketmq.client.producer; import com.alibaba.fastjson.JSON; import org.apache.rocketmq.common.message.MessageQueue; - public class SendResult { private SendStatus sendStatus; private String msgId; @@ -41,7 +40,8 @@ public class SendResult { this.queueOffset = queueOffset; } - public SendResult(final SendStatus sendStatus, final String msgId, final MessageQueue messageQueue, final long queueOffset, final String transactionId, final String offsetMsgId, final String regionId) { + public SendResult(final SendStatus sendStatus, final String msgId, final MessageQueue messageQueue, final long queueOffset, final String transactionId, + final String offsetMsgId, final String regionId) { this.sendStatus = sendStatus; this.msgId = msgId; this.messageQueue = messageQueue; @@ -51,6 +51,14 @@ public class SendResult { this.regionId = regionId; } + public static String encoderSendResultToJson(final Object obj) { + return JSON.toJSONString(obj); + } + + public static SendResult decoderSendResultFromJson(String json) { + return JSON.parseObject(json, SendResult.class); + } + public boolean isTraceOn() { return traceOn; } @@ -67,59 +75,42 @@ public class SendResult { this.regionId = regionId; } - public static String encoderSendResultToJson(final Object obj) { - return JSON.toJSONString(obj); - } - - public static SendResult decoderSendResultFromJson(String json) { - return JSON.parseObject(json, SendResult.class); - } - public String getMsgId() { return msgId; } - public void setMsgId(String msgId) { this.msgId = msgId; } - public SendStatus getSendStatus() { return sendStatus; } - public void setSendStatus(SendStatus sendStatus) { this.sendStatus = sendStatus; } - public MessageQueue getMessageQueue() { return messageQueue; } - public void setMessageQueue(MessageQueue messageQueue) { this.messageQueue = messageQueue; } - public long getQueueOffset() { return queueOffset; } - public void setQueueOffset(long queueOffset) { this.queueOffset = queueOffset; } - public String getTransactionId() { return transactionId; } - public void setTransactionId(String transactionId) { this.transactionId = transactionId; } @@ -135,6 +126,6 @@ public class SendResult { @Override public String toString() { return "SendResult [sendStatus=" + sendStatus + ", msgId=" + msgId + ", offsetMsgId=" + offsetMsgId + ", messageQueue=" + messageQueue - + ", queueOffset=" + queueOffset + "]"; + + ", queueOffset=" + queueOffset + "]"; } } diff --git a/client/src/main/java/org/apache/rocketmq/client/producer/SendStatus.java b/client/src/main/java/org/apache/rocketmq/client/producer/SendStatus.java index a12c6894..95a27117 100644 --- a/client/src/main/java/org/apache/rocketmq/client/producer/SendStatus.java +++ b/client/src/main/java/org/apache/rocketmq/client/producer/SendStatus.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.producer; diff --git a/client/src/main/java/org/apache/rocketmq/client/producer/TransactionCheckListener.java b/client/src/main/java/org/apache/rocketmq/client/producer/TransactionCheckListener.java index 6da0737e..bf312aa2 100644 --- a/client/src/main/java/org/apache/rocketmq/client/producer/TransactionCheckListener.java +++ b/client/src/main/java/org/apache/rocketmq/client/producer/TransactionCheckListener.java @@ -6,19 +6,18 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.producer; import org.apache.rocketmq.common.message.MessageExt; - public interface TransactionCheckListener { LocalTransactionState checkLocalTransactionState(final MessageExt msg); } diff --git a/client/src/main/java/org/apache/rocketmq/client/producer/TransactionMQProducer.java b/client/src/main/java/org/apache/rocketmq/client/producer/TransactionMQProducer.java index b404216a..1ea28e35 100644 --- a/client/src/main/java/org/apache/rocketmq/client/producer/TransactionMQProducer.java +++ b/client/src/main/java/org/apache/rocketmq/client/producer/TransactionMQProducer.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.producer; @@ -20,18 +20,15 @@ import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.common.message.Message; import org.apache.rocketmq.remoting.RPCHook; - public class TransactionMQProducer extends DefaultMQProducer { private TransactionCheckListener transactionCheckListener; private int checkThreadPoolMinSize = 1; private int checkThreadPoolMaxSize = 1; private int checkRequestHoldMax = 2000; - public TransactionMQProducer() { } - public TransactionMQProducer(final String producerGroup) { super(producerGroup); } @@ -46,17 +43,15 @@ public class TransactionMQProducer extends DefaultMQProducer { super.start(); } - @Override public void shutdown() { super.shutdown(); this.defaultMQProducerImpl.destroyTransactionEnv(); } - @Override public TransactionSendResult sendMessageInTransaction(final Message msg, - final LocalTransactionExecuter tranExecuter, final Object arg) throws MQClientException { + final LocalTransactionExecuter tranExecuter, final Object arg) throws MQClientException { if (null == this.transactionCheckListener) { throw new MQClientException("localTransactionBranchCheckListener is null", null); } @@ -64,42 +59,34 @@ public class TransactionMQProducer extends DefaultMQProducer { return this.defaultMQProducerImpl.sendMessageInTransaction(msg, tranExecuter, arg); } - public TransactionCheckListener getTransactionCheckListener() { return transactionCheckListener; } - public void setTransactionCheckListener(TransactionCheckListener transactionCheckListener) { this.transactionCheckListener = transactionCheckListener; } - public int getCheckThreadPoolMinSize() { return checkThreadPoolMinSize; } - public void setCheckThreadPoolMinSize(int checkThreadPoolMinSize) { this.checkThreadPoolMinSize = checkThreadPoolMinSize; } - public int getCheckThreadPoolMaxSize() { return checkThreadPoolMaxSize; } - public void setCheckThreadPoolMaxSize(int checkThreadPoolMaxSize) { this.checkThreadPoolMaxSize = checkThreadPoolMaxSize; } - public int getCheckRequestHoldMax() { return checkRequestHoldMax; } - public void setCheckRequestHoldMax(int checkRequestHoldMax) { this.checkRequestHoldMax = checkRequestHoldMax; } diff --git a/client/src/main/java/org/apache/rocketmq/client/producer/TransactionSendResult.java b/client/src/main/java/org/apache/rocketmq/client/producer/TransactionSendResult.java index ca9e7136..c2395ab3 100644 --- a/client/src/main/java/org/apache/rocketmq/client/producer/TransactionSendResult.java +++ b/client/src/main/java/org/apache/rocketmq/client/producer/TransactionSendResult.java @@ -6,29 +6,26 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.producer; public class TransactionSendResult extends SendResult { private LocalTransactionState localTransactionState; - public TransactionSendResult() { } - public LocalTransactionState getLocalTransactionState() { return localTransactionState; } - public void setLocalTransactionState(LocalTransactionState localTransactionState) { this.localTransactionState = localTransactionState; } diff --git a/client/src/main/java/org/apache/rocketmq/client/producer/selector/SelectMessageQueueByHash.java b/client/src/main/java/org/apache/rocketmq/client/producer/selector/SelectMessageQueueByHash.java index 15c7e558..35740394 100644 --- a/client/src/main/java/org/apache/rocketmq/client/producer/selector/SelectMessageQueueByHash.java +++ b/client/src/main/java/org/apache/rocketmq/client/producer/selector/SelectMessageQueueByHash.java @@ -6,23 +6,21 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.producer.selector; +import java.util.List; import org.apache.rocketmq.client.producer.MessageQueueSelector; import org.apache.rocketmq.common.message.Message; import org.apache.rocketmq.common.message.MessageQueue; -import java.util.List; - - public class SelectMessageQueueByHash implements MessageQueueSelector { @Override diff --git a/client/src/main/java/org/apache/rocketmq/client/producer/selector/SelectMessageQueueByMachineRoom.java b/client/src/main/java/org/apache/rocketmq/client/producer/selector/SelectMessageQueueByMachineRoom.java index d2bf6f30..07f8b701 100644 --- a/client/src/main/java/org/apache/rocketmq/client/producer/selector/SelectMessageQueueByMachineRoom.java +++ b/client/src/main/java/org/apache/rocketmq/client/producer/selector/SelectMessageQueueByMachineRoom.java @@ -6,39 +6,34 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.producer.selector; +import java.util.List; +import java.util.Set; import org.apache.rocketmq.client.producer.MessageQueueSelector; import org.apache.rocketmq.common.message.Message; import org.apache.rocketmq.common.message.MessageQueue; -import java.util.List; -import java.util.Set; - - public class SelectMessageQueueByMachineRoom implements MessageQueueSelector { private Set consumeridcs; - @Override public MessageQueue select(List mqs, Message msg, Object arg) { return null; } - public Set getConsumeridcs() { return consumeridcs; } - public void setConsumeridcs(Set consumeridcs) { this.consumeridcs = consumeridcs; } diff --git a/client/src/main/java/org/apache/rocketmq/client/producer/selector/SelectMessageQueueByRandoom.java b/client/src/main/java/org/apache/rocketmq/client/producer/selector/SelectMessageQueueByRandoom.java index 38d04c13..685afc9a 100644 --- a/client/src/main/java/org/apache/rocketmq/client/producer/selector/SelectMessageQueueByRandoom.java +++ b/client/src/main/java/org/apache/rocketmq/client/producer/selector/SelectMessageQueueByRandoom.java @@ -6,28 +6,25 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.producer.selector; +import java.util.List; +import java.util.Random; import org.apache.rocketmq.client.producer.MessageQueueSelector; import org.apache.rocketmq.common.message.Message; import org.apache.rocketmq.common.message.MessageQueue; -import java.util.List; -import java.util.Random; - - public class SelectMessageQueueByRandoom implements MessageQueueSelector { private Random random = new Random(System.currentTimeMillis()); - @Override public MessageQueue select(List mqs, Message msg, Object arg) { int value = random.nextInt(); diff --git a/client/src/main/java/org/apache/rocketmq/client/stat/ConsumerStatsManager.java b/client/src/main/java/org/apache/rocketmq/client/stat/ConsumerStatsManager.java index 3234ada2..c723951f 100644 --- a/client/src/main/java/org/apache/rocketmq/client/stat/ConsumerStatsManager.java +++ b/client/src/main/java/org/apache/rocketmq/client/stat/ConsumerStatsManager.java @@ -6,17 +6,18 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client.stat; +import java.util.concurrent.ScheduledExecutorService; import org.apache.rocketmq.common.constant.LoggerName; import org.apache.rocketmq.common.protocol.body.ConsumeStatus; import org.apache.rocketmq.common.stats.StatsItemSet; @@ -24,9 +25,6 @@ import org.apache.rocketmq.common.stats.StatsSnapshot; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.concurrent.ScheduledExecutorService; - - public class ConsumerStatsManager { private static final Logger log = LoggerFactory.getLogger(LoggerName.CLIENT_LOGGER_NAME); @@ -42,53 +40,45 @@ public class ConsumerStatsManager { private final StatsItemSet topicAndGroupPullTPS; private final StatsItemSet topicAndGroupPullRT; - public ConsumerStatsManager(final ScheduledExecutorService scheduledExecutorService) { this.topicAndGroupConsumeOKTPS = - new StatsItemSet(TOPIC_AND_GROUP_CONSUME_OK_TPS, scheduledExecutorService, log); + new StatsItemSet(TOPIC_AND_GROUP_CONSUME_OK_TPS, scheduledExecutorService, log); this.topicAndGroupConsumeRT = - new StatsItemSet(TOPIC_AND_GROUP_CONSUME_RT, scheduledExecutorService, log); + new StatsItemSet(TOPIC_AND_GROUP_CONSUME_RT, scheduledExecutorService, log); this.topicAndGroupConsumeFailedTPS = - new StatsItemSet(TOPIC_AND_GROUP_CONSUME_FAILED_TPS, scheduledExecutorService, log); + new StatsItemSet(TOPIC_AND_GROUP_CONSUME_FAILED_TPS, scheduledExecutorService, log); this.topicAndGroupPullTPS = new StatsItemSet(TOPIC_AND_GROUP_PULL_TPS, scheduledExecutorService, log); this.topicAndGroupPullRT = new StatsItemSet(TOPIC_AND_GROUP_PULL_RT, scheduledExecutorService, log); } - public void start() { } - public void shutdown() { } - public void incPullRT(final String group, final String topic, final long rt) { - this.topicAndGroupPullRT.addValue(topic + "@" + group, (int) rt, 1); + this.topicAndGroupPullRT.addValue(topic + "@" + group, (int)rt, 1); } - public void incPullTPS(final String group, final String topic, final long msgs) { - this.topicAndGroupPullTPS.addValue(topic + "@" + group, (int) msgs, 1); + this.topicAndGroupPullTPS.addValue(topic + "@" + group, (int)msgs, 1); } - public void incConsumeRT(final String group, final String topic, final long rt) { - this.topicAndGroupConsumeRT.addValue(topic + "@" + group, (int) rt, 1); + this.topicAndGroupConsumeRT.addValue(topic + "@" + group, (int)rt, 1); } - public void incConsumeOKTPS(final String group, final String topic, final long msgs) { - this.topicAndGroupConsumeOKTPS.addValue(topic + "@" + group, (int) msgs, 1); + this.topicAndGroupConsumeOKTPS.addValue(topic + "@" + group, (int)msgs, 1); } - public void incConsumeFailedTPS(final String group, final String topic, final long msgs) { - this.topicAndGroupConsumeFailedTPS.addValue(topic + "@" + group, (int) msgs, 1); + this.topicAndGroupConsumeFailedTPS.addValue(topic + "@" + group, (int)msgs, 1); } public ConsumeStatus consumeStatus(final String group, final String topic) { diff --git a/client/src/main/resources/logback_rocketmq_client.xml b/client/src/main/resources/logback_rocketmq_client.xml index a845ee4c..94688aba 100644 --- a/client/src/main/resources/logback_rocketmq_client.xml +++ b/client/src/main/resources/logback_rocketmq_client.xml @@ -28,7 +28,7 @@ ${client.logFileMaxIndex} + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> 100MB diff --git a/client/src/test/java/org/apache/rocketmq/client/ValidatorsTest.java b/client/src/test/java/org/apache/rocketmq/client/ValidatorsTest.java index a3daba5b..d4530c06 100644 --- a/client/src/test/java/org/apache/rocketmq/client/ValidatorsTest.java +++ b/client/src/test/java/org/apache/rocketmq/client/ValidatorsTest.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.client; @@ -20,7 +20,6 @@ package org.apache.rocketmq.client; import org.apache.rocketmq.client.exception.MQClientException; import org.junit.Test; - public class ValidatorsTest { @Test diff --git a/common/pom.xml b/common/pom.xml index ec95a76a..b46d2d54 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -15,7 +15,7 @@ limitations under the License. --> - org.apache.rocketmq diff --git a/common/src/main/java/org/apache/rocketmq/common/BrokerConfig.java b/common/src/main/java/org/apache/rocketmq/common/BrokerConfig.java index e11122aa..aaaa0c1f 100644 --- a/common/src/main/java/org/apache/rocketmq/common/BrokerConfig.java +++ b/common/src/main/java/org/apache/rocketmq/common/BrokerConfig.java @@ -16,14 +16,12 @@ */ package org.apache.rocketmq.common; +import java.net.InetAddress; +import java.net.UnknownHostException; import org.apache.rocketmq.common.annotation.ImportantField; import org.apache.rocketmq.common.constant.PermName; import org.apache.rocketmq.remoting.common.RemotingUtil; -import java.net.InetAddress; -import java.net.UnknownHostException; - - public class BrokerConfig { private String rocketmqHome = System.getProperty(MixAll.ROCKETMQ_HOME_PROPERTY, System.getenv(MixAll.ROCKETMQ_HOME_ENV)); @ImportantField @@ -87,7 +85,6 @@ public class BrokerConfig { private boolean transferMsgByHeap = true; private int maxDelayTime = 40; - private String regionId = MixAll.DEFAULT_TRACE_REGION_ID; private int registerBrokerTimeoutMills = 6000; @@ -102,6 +99,16 @@ public class BrokerConfig { private boolean traceOn = true; + public static String localHostName() { + try { + return InetAddress.getLocalHost().getHostName(); + } catch (UnknownHostException e) { + e.printStackTrace(); + } + + return "DEFAULT_BROKER"; + } + public boolean isTraceOn() { return traceOn; } @@ -150,16 +157,6 @@ public class BrokerConfig { this.slaveReadEnable = slaveReadEnable; } - public static String localHostName() { - try { - return InetAddress.getLocalHost().getHostName(); - } catch (UnknownHostException e) { - e.printStackTrace(); - } - - return "DEFAULT_BROKER"; - } - public int getRegisterBrokerTimeoutMills() { return registerBrokerTimeoutMills; } @@ -196,87 +193,70 @@ public class BrokerConfig { return highSpeedMode; } - public void setHighSpeedMode(final boolean highSpeedMode) { this.highSpeedMode = highSpeedMode; } - public String getRocketmqHome() { return rocketmqHome; } - public void setRocketmqHome(String rocketmqHome) { this.rocketmqHome = rocketmqHome; } - public String getBrokerName() { return brokerName; } - public void setBrokerName(String brokerName) { this.brokerName = brokerName; } - public int getBrokerPermission() { return brokerPermission; } - public void setBrokerPermission(int brokerPermission) { this.brokerPermission = brokerPermission; } - public int getDefaultTopicQueueNums() { return defaultTopicQueueNums; } - public void setDefaultTopicQueueNums(int defaultTopicQueueNums) { this.defaultTopicQueueNums = defaultTopicQueueNums; } - public boolean isAutoCreateTopicEnable() { return autoCreateTopicEnable; } - public void setAutoCreateTopicEnable(boolean autoCreateTopic) { this.autoCreateTopicEnable = autoCreateTopic; } - public String getBrokerClusterName() { return brokerClusterName; } - public void setBrokerClusterName(String brokerClusterName) { this.brokerClusterName = brokerClusterName; } - public String getBrokerIP1() { return brokerIP1; } - public void setBrokerIP1(String brokerIP1) { this.brokerIP1 = brokerIP1; } - public String getBrokerIP2() { return brokerIP2; } - public void setBrokerIP2(String brokerIP2) { this.brokerIP2 = brokerIP2; } @@ -289,192 +269,154 @@ public class BrokerConfig { this.sendMessageThreadPoolNums = sendMessageThreadPoolNums; } - public int getPullMessageThreadPoolNums() { return pullMessageThreadPoolNums; } - public void setPullMessageThreadPoolNums(int pullMessageThreadPoolNums) { this.pullMessageThreadPoolNums = pullMessageThreadPoolNums; } - public int getAdminBrokerThreadPoolNums() { return adminBrokerThreadPoolNums; } - public void setAdminBrokerThreadPoolNums(int adminBrokerThreadPoolNums) { this.adminBrokerThreadPoolNums = adminBrokerThreadPoolNums; } - public int getFlushConsumerOffsetInterval() { return flushConsumerOffsetInterval; } - public void setFlushConsumerOffsetInterval(int flushConsumerOffsetInterval) { this.flushConsumerOffsetInterval = flushConsumerOffsetInterval; } - public int getFlushConsumerOffsetHistoryInterval() { return flushConsumerOffsetHistoryInterval; } - public void setFlushConsumerOffsetHistoryInterval(int flushConsumerOffsetHistoryInterval) { this.flushConsumerOffsetHistoryInterval = flushConsumerOffsetHistoryInterval; } - public boolean isClusterTopicEnable() { return clusterTopicEnable; } - public void setClusterTopicEnable(boolean clusterTopicEnable) { this.clusterTopicEnable = clusterTopicEnable; } - public String getNamesrvAddr() { return namesrvAddr; } - public void setNamesrvAddr(String namesrvAddr) { this.namesrvAddr = namesrvAddr; } - public long getBrokerId() { return brokerId; } - public void setBrokerId(long brokerId) { this.brokerId = brokerId; } - public boolean isAutoCreateSubscriptionGroup() { return autoCreateSubscriptionGroup; } - public void setAutoCreateSubscriptionGroup(boolean autoCreateSubscriptionGroup) { this.autoCreateSubscriptionGroup = autoCreateSubscriptionGroup; } - public boolean isRejectTransactionMessage() { return rejectTransactionMessage; } - public void setRejectTransactionMessage(boolean rejectTransactionMessage) { this.rejectTransactionMessage = rejectTransactionMessage; } - public boolean isFetchNamesrvAddrByAddressServer() { return fetchNamesrvAddrByAddressServer; } - public void setFetchNamesrvAddrByAddressServer(boolean fetchNamesrvAddrByAddressServer) { this.fetchNamesrvAddrByAddressServer = fetchNamesrvAddrByAddressServer; } - public int getSendThreadPoolQueueCapacity() { return sendThreadPoolQueueCapacity; } - public void setSendThreadPoolQueueCapacity(int sendThreadPoolQueueCapacity) { this.sendThreadPoolQueueCapacity = sendThreadPoolQueueCapacity; } - public int getPullThreadPoolQueueCapacity() { return pullThreadPoolQueueCapacity; } - public void setPullThreadPoolQueueCapacity(int pullThreadPoolQueueCapacity) { this.pullThreadPoolQueueCapacity = pullThreadPoolQueueCapacity; } - public boolean isBrokerTopicEnable() { return brokerTopicEnable; } - public void setBrokerTopicEnable(boolean brokerTopicEnable) { this.brokerTopicEnable = brokerTopicEnable; } - public int getFilterServerNums() { return filterServerNums; } - public void setFilterServerNums(int filterServerNums) { this.filterServerNums = filterServerNums; } - public boolean isLongPollingEnable() { return longPollingEnable; } - public void setLongPollingEnable(boolean longPollingEnable) { this.longPollingEnable = longPollingEnable; } - public boolean isNotifyConsumerIdsChangedEnable() { return notifyConsumerIdsChangedEnable; } - public void setNotifyConsumerIdsChangedEnable(boolean notifyConsumerIdsChangedEnable) { this.notifyConsumerIdsChangedEnable = notifyConsumerIdsChangedEnable; } - public long getShortPollingTimeMills() { return shortPollingTimeMills; } - public void setShortPollingTimeMills(long shortPollingTimeMills) { this.shortPollingTimeMills = shortPollingTimeMills; } - public int getClientManageThreadPoolNums() { return clientManageThreadPoolNums; } - public void setClientManageThreadPoolNums(int clientManageThreadPoolNums) { this.clientManageThreadPoolNums = clientManageThreadPoolNums; } - public boolean isCommercialEnable() { return commercialEnable; } - public void setCommercialEnable(final boolean commercialEnable) { this.commercialEnable = commercialEnable; } @@ -507,7 +449,6 @@ public class BrokerConfig { return maxDelayTime; } - public void setMaxDelayTime(final int maxDelayTime) { this.maxDelayTime = maxDelayTime; } diff --git a/common/src/main/java/org/apache/rocketmq/common/BrokerConfigSingleton.java b/common/src/main/java/org/apache/rocketmq/common/BrokerConfigSingleton.java index fc73b71e..1dae6d42 100644 --- a/common/src/main/java/org/apache/rocketmq/common/BrokerConfigSingleton.java +++ b/common/src/main/java/org/apache/rocketmq/common/BrokerConfigSingleton.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common; diff --git a/common/src/main/java/org/apache/rocketmq/common/ConfigManager.java b/common/src/main/java/org/apache/rocketmq/common/ConfigManager.java index 1ade5217..0510b085 100644 --- a/common/src/main/java/org/apache/rocketmq/common/ConfigManager.java +++ b/common/src/main/java/org/apache/rocketmq/common/ConfigManager.java @@ -6,27 +6,24 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common; +import java.io.IOException; import org.apache.rocketmq.common.constant.LoggerName; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; - - public abstract class ConfigManager { private static final Logger PLOG = LoggerFactory.getLogger(LoggerName.COMMON_LOGGER_NAME); - public abstract String encode(); public boolean load() { diff --git a/common/src/main/java/org/apache/rocketmq/common/Configuration.java b/common/src/main/java/org/apache/rocketmq/common/Configuration.java index 1f81ba6e..54020573 100644 --- a/common/src/main/java/org/apache/rocketmq/common/Configuration.java +++ b/common/src/main/java/org/apache/rocketmq/common/Configuration.java @@ -6,19 +6,17 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common; -import org.slf4j.Logger; - import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.Modifier; @@ -27,6 +25,7 @@ import java.util.List; import java.util.Properties; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; +import org.slf4j.Logger; public class Configuration { @@ -135,7 +134,7 @@ public class Configuration { // check this.storePathField = object.getClass().getDeclaredField(fieldName); assert this.storePathField != null - && !Modifier.isStatic(this.storePathField.getModifiers()); + && !Modifier.isStatic(this.storePathField.getModifiers()); this.storePathField.setAccessible(true); } catch (NoSuchFieldException e) { throw new RuntimeException(e); @@ -157,7 +156,7 @@ public class Configuration { if (this.storePathFromConfig) { try { - realStorePath = (String) storePathField.get(this.storePathObject); + realStorePath = (String)storePathField.get(this.storePathObject); } catch (IllegalAccessException e) { log.error("getStorePath error, ", e); } @@ -172,6 +171,10 @@ public class Configuration { return realStorePath; } + public void setStorePath(final String storePath) { + this.storePath = storePath; + } + public void update(Properties properties) { try { readWriteLock.writeLock().lockInterruptibly(); @@ -276,10 +279,6 @@ public class Configuration { return stringBuilder.toString(); } - public void setStorePath(final String storePath) { - this.storePath = storePath; - } - private void merge(Properties from, Properties to) { for (Object key : from.keySet()) { Object fromObj = from.get(key), toObj = to.get(key); diff --git a/common/src/main/java/org/apache/rocketmq/common/CountDownLatch2.java b/common/src/main/java/org/apache/rocketmq/common/CountDownLatch2.java index 23c27acc..c3e3372b 100644 --- a/common/src/main/java/org/apache/rocketmq/common/CountDownLatch2.java +++ b/common/src/main/java/org/apache/rocketmq/common/CountDownLatch2.java @@ -22,62 +22,19 @@ import java.util.concurrent.locks.AbstractQueuedSynchronizer; /** * Add reset feature for @see java.util.concurrent.CountDownLatch2 - * */ public class CountDownLatch2 { - /** - * Synchronization control For CountDownLatch2. - * Uses AQS state to represent count. - */ - private static final class Sync extends AbstractQueuedSynchronizer { - private static final long serialVersionUID = 4982264981922014374L; - - private final int startCount; - - Sync(int count) { - this.startCount = count; - setState(count); - } - - int getCount() { - return getState(); - } - - protected int tryAcquireShared(int acquires) { - return (getState() == 0) ? 1 : -1; - } - - protected boolean tryReleaseShared(int releases) { - // Decrement count; signal when transition to zero - for (;;) { - int c = getState(); - if (c == 0) - return false; - int nextc = c - 1; - if (compareAndSetState(c, nextc)) - return nextc == 0; - } - } - - protected void reset() { - setState(startCount); - } - } - private final Sync sync; /** * Constructs a {@code CountDownLatch2} initialized with the given count. * - * @param count - * the number of times {@link #countDown} must be invoked - * before threads can pass through {@link #await} - * - * @throws IllegalArgumentException - * if {@code count} is negative + * @param count the number of times {@link #countDown} must be invoked before threads can pass through {@link #await} + * @throws IllegalArgumentException if {@code count} is negative */ public CountDownLatch2(int count) { - if (count < 0) throw new IllegalArgumentException("count < 0"); + if (count < 0) + throw new IllegalArgumentException("count < 0"); this.sync = new Sync(count); } @@ -105,9 +62,7 @@ public class CountDownLatch2 { * then {@link InterruptedException} is thrown and the current thread's * interrupted status is cleared. * - * @throws InterruptedException - * if the current thread is interrupted - * while waiting + * @throws InterruptedException if the current thread is interrupted while waiting */ public void await() throws InterruptedException { sync.acquireSharedInterruptibly(1); @@ -147,20 +102,13 @@ public class CountDownLatch2 { * is returned. If the time is less than or equal to zero, the method * will not wait at all. * - * @param timeout - * the maximum time to wait - * @param unit - * the time unit of the {@code timeout} argument - * - * @return {@code true} if the count reached zero and {@code false} - * if the waiting time elapsed before the count reached zero - * - * @throws InterruptedException - * if the current thread is interrupted - * while waiting + * @param timeout the maximum time to wait + * @param unit the time unit of the {@code timeout} argument + * @return {@code true} if the count reached zero and {@code false} if the waiting time elapsed before the count reached zero + * @throws InterruptedException if the current thread is interrupted while waiting */ public boolean await(long timeout, TimeUnit unit) - throws InterruptedException { + throws InterruptedException { return sync.tryAcquireSharedNanos(1, unit.toNanos(timeout)); } @@ -203,4 +151,43 @@ public class CountDownLatch2 { public String toString() { return super.toString() + "[Count = " + sync.getCount() + "]"; } + + /** + * Synchronization control For CountDownLatch2. + * Uses AQS state to represent count. + */ + private static final class Sync extends AbstractQueuedSynchronizer { + private static final long serialVersionUID = 4982264981922014374L; + + private final int startCount; + + Sync(int count) { + this.startCount = count; + setState(count); + } + + int getCount() { + return getState(); + } + + protected int tryAcquireShared(int acquires) { + return (getState() == 0) ? 1 : -1; + } + + protected boolean tryReleaseShared(int releases) { + // Decrement count; signal when transition to zero + for (; ; ) { + int c = getState(); + if (c == 0) + return false; + int nextc = c - 1; + if (compareAndSetState(c, nextc)) + return nextc == 0; + } + } + + protected void reset() { + setState(startCount); + } + } } diff --git a/common/src/main/java/org/apache/rocketmq/common/DataVersion.java b/common/src/main/java/org/apache/rocketmq/common/DataVersion.java index 1bb223fc..f3e46158 100644 --- a/common/src/main/java/org/apache/rocketmq/common/DataVersion.java +++ b/common/src/main/java/org/apache/rocketmq/common/DataVersion.java @@ -6,73 +6,67 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common; -import org.apache.rocketmq.remoting.protocol.RemotingSerializable; - import java.util.concurrent.atomic.AtomicLong; - +import org.apache.rocketmq.remoting.protocol.RemotingSerializable; public class DataVersion extends RemotingSerializable { private long timestatmp = System.currentTimeMillis(); private AtomicLong counter = new AtomicLong(0); - public void assignNewOne(final DataVersion dataVersion) { this.timestatmp = dataVersion.timestatmp; this.counter.set(dataVersion.counter.get()); } - public void nextVersion() { this.timestatmp = System.currentTimeMillis(); this.counter.incrementAndGet(); } - public long getTimestatmp() { return timestatmp; } - public void setTimestatmp(long timestatmp) { this.timestatmp = timestatmp; } - public AtomicLong getCounter() { return counter; } - public void setCounter(AtomicLong counter) { this.counter = counter; } - @Override public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; - final DataVersion that = (DataVersion) o; + final DataVersion that = (DataVersion)o; - if (timestatmp != that.timestatmp) return false; + if (timestatmp != that.timestatmp) + return false; return counter != null ? counter.equals(that.counter) : that.counter == null; } @Override public int hashCode() { - int result = (int) (timestatmp ^ (timestatmp >>> 32)); + int result = (int)(timestatmp ^ (timestatmp >>> 32)); result = 31 * result + (counter != null ? counter.hashCode() : 0); return result; } diff --git a/common/src/main/java/org/apache/rocketmq/common/MQVersion.java b/common/src/main/java/org/apache/rocketmq/common/MQVersion.java index 35431612..d12ee558 100644 --- a/common/src/main/java/org/apache/rocketmq/common/MQVersion.java +++ b/common/src/main/java/org/apache/rocketmq/common/MQVersion.java @@ -20,7 +20,6 @@ public class MQVersion { public static final int CURRENT_VERSION = Version.V4_0_0_SNAPSHOT.ordinal(); - public static String getVersionDesc(int value) { try { Version v = Version.values()[value]; @@ -31,7 +30,6 @@ public class MQVersion { return "HigherVersion"; } - public static Version value2Version(int value) { return Version.values()[value]; } diff --git a/common/src/main/java/org/apache/rocketmq/common/MixAll.java b/common/src/main/java/org/apache/rocketmq/common/MixAll.java index bca55f5b..8307dd58 100644 --- a/common/src/main/java/org/apache/rocketmq/common/MixAll.java +++ b/common/src/main/java/org/apache/rocketmq/common/MixAll.java @@ -16,10 +16,6 @@ */ package org.apache.rocketmq.common; -import org.apache.rocketmq.common.annotation.ImportantField; -import org.apache.rocketmq.common.help.FAQUrl; -import org.slf4j.Logger; - import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileReader; @@ -46,7 +42,9 @@ import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.concurrent.atomic.AtomicLong; - +import org.apache.rocketmq.common.annotation.ImportantField; +import org.apache.rocketmq.common.help.FAQUrl; +import org.slf4j.Logger; public class MixAll { public static final String ROCKETMQ_HOME_ENV = "ROCKETMQ_HOME"; @@ -94,7 +92,6 @@ public class MixAll { return RETRY_GROUP_TOPIC_PREFIX + consumerGroup; } - public static boolean isSysConsumerGroup(final String consumerGroup) { return consumerGroup.startsWith(CID_RMQ_SYS_PREFIX); } @@ -107,7 +104,6 @@ public class MixAll { return DLQ_GROUP_TOPIC_PREFIX + consumerGroup; } - public static String brokerVIPChannel(final boolean isChange, final String brokerAddr) { if (isChange) { String[] ipAndPort = brokerAddr.split(":"); @@ -118,7 +114,6 @@ public class MixAll { } } - public static long getPID() { String processName = java.lang.management.ManagementFactory.getRuntimeMXBean().getName(); if (processName != null && processName.length() > 0) { @@ -132,7 +127,6 @@ public class MixAll { return 0; } - public static long createBrokerId(final String ip, final int port) { InetSocketAddress isa = new InetSocketAddress(ip, port); byte[] ipArray = isa.getAddress().getAddress(); @@ -148,23 +142,19 @@ public class MixAll { String tmpFile = fileName + ".tmp"; string2FileNotSafe(str, tmpFile); - String bakFile = fileName + ".bak"; String prevContent = file2String(fileName); if (prevContent != null) { string2FileNotSafe(prevContent, bakFile); } - File file = new File(fileName); file.delete(); - file = new File(tmpFile); file.renameTo(new File(fileName)); } - public static final void string2FileNotSafe(final String str, final String fileName) throws IOException { File file = new File(fileName); File fileParent = file.getParentFile(); @@ -189,7 +179,6 @@ public class MixAll { } } - public static final String file2String(final String fileName) { File file = new File(fileName); return file2String(file); @@ -197,7 +186,7 @@ public class MixAll { public static final String file2String(final File file) { if (file.exists()) { - char[] data = new char[(int) file.length()]; + char[] data = new char[(int)file.length()]; boolean result = false; FileReader fileReader = null; @@ -252,12 +241,10 @@ public class MixAll { return url.getPath(); } - public static void printObjectProperties(final Logger log, final Object object) { printObjectProperties(log, object, false); } - public static void printObjectProperties(final Logger log, final Object object, final boolean onlyImportantField) { Field[] fields = object.getClass().getDeclaredFields(); for (Field field : fields) { @@ -293,7 +280,6 @@ public class MixAll { } } - public static String properties2String(final Properties properties) { StringBuilder sb = new StringBuilder(); for (Map.Entry entry : properties.entrySet()) { @@ -379,7 +365,7 @@ public class MixAll { } else { continue; } - method.invoke(object, new Object[]{arg}); + method.invoke(object, new Object[] {arg}); } } } catch (Throwable e) { @@ -388,12 +374,10 @@ public class MixAll { } } - public static boolean isPropertiesEqual(final Properties p1, final Properties p2) { return p1.equals(p2); } - public static List getLocalInetAddress() { List inetAddressList = new ArrayList(); try { @@ -412,7 +396,6 @@ public class MixAll { return inetAddressList; } - public static boolean isLocalAddr(String address) { for (String addr : LOCAL_INET_ADDRESS) { if (address.contains(addr)) @@ -421,19 +404,17 @@ public class MixAll { return false; } - private static String localhost() { try { InetAddress addr = InetAddress.getLocalHost(); return addr.getHostAddress(); } catch (Throwable e) { throw new RuntimeException("InetAddress java.net.InetAddress.getLocalHost() throws UnknownHostException" - + FAQUrl.suggestTodo(FAQUrl.UNKNOWN_HOST_EXCEPTION), - e); + + FAQUrl.suggestTodo(FAQUrl.UNKNOWN_HOST_EXCEPTION), + e); } } - public static boolean compareAndIncreaseOnly(final AtomicLong target, final long value) { long prev = target.get(); while (value > prev) { @@ -452,11 +433,20 @@ public class MixAll { return InetAddress.getLocalHost().getHostName(); } catch (Throwable e) { throw new RuntimeException("InetAddress java.net.InetAddress.getLocalHost() throws UnknownHostException" - + FAQUrl.suggestTodo(FAQUrl.UNKNOWN_HOST_EXCEPTION), - e); + + FAQUrl.suggestTodo(FAQUrl.UNKNOWN_HOST_EXCEPTION), + e); } } + public static String humanReadableByteCount(long bytes, boolean si) { + int unit = si ? 1000 : 1024; + if (bytes < unit) + return bytes + " B"; + int exp = (int)(Math.log(bytes) / Math.log(unit)); + String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i"); + return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre); + } + public Set list2Set(List values) { Set result = new HashSet(); for (String v : values) { @@ -472,12 +462,4 @@ public class MixAll { } return result; } - - public static String humanReadableByteCount(long bytes, boolean si) { - int unit = si ? 1000 : 1024; - if (bytes < unit) return bytes + " B"; - int exp = (int) (Math.log(bytes) / Math.log(unit)); - String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i"); - return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre); - } } diff --git a/common/src/main/java/org/apache/rocketmq/common/Pair.java b/common/src/main/java/org/apache/rocketmq/common/Pair.java index 45f6deed..805d0a3b 100644 --- a/common/src/main/java/org/apache/rocketmq/common/Pair.java +++ b/common/src/main/java/org/apache/rocketmq/common/Pair.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common; @@ -20,28 +20,23 @@ public class Pair { private T1 object1; private T2 object2; - public Pair(T1 object1, T2 object2) { this.object1 = object1; this.object2 = object2; } - public T1 getObject1() { return object1; } - public void setObject1(T1 object1) { this.object1 = object1; } - public T2 getObject2() { return object2; } - public void setObject2(T2 object2) { this.object2 = object2; } diff --git a/common/src/main/java/org/apache/rocketmq/common/ServiceState.java b/common/src/main/java/org/apache/rocketmq/common/ServiceState.java index c8fbfeaa..53dd75b9 100644 --- a/common/src/main/java/org/apache/rocketmq/common/ServiceState.java +++ b/common/src/main/java/org/apache/rocketmq/common/ServiceState.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common; diff --git a/common/src/main/java/org/apache/rocketmq/common/ServiceThread.java b/common/src/main/java/org/apache/rocketmq/common/ServiceThread.java index c0ae430c..7d29868b 100644 --- a/common/src/main/java/org/apache/rocketmq/common/ServiceThread.java +++ b/common/src/main/java/org/apache/rocketmq/common/ServiceThread.java @@ -6,49 +6,41 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; import org.apache.rocketmq.common.constant.LoggerName; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; - public abstract class ServiceThread implements Runnable { private static final Logger STLOG = LoggerFactory.getLogger(LoggerName.COMMON_LOGGER_NAME); private static final long JOIN_TIME = 90 * 1000; protected final Thread thread; - + protected final CountDownLatch2 waitPoint = new CountDownLatch2(1); protected volatile AtomicBoolean hasNotified = new AtomicBoolean(false); - protected volatile boolean stopped = false; - protected final CountDownLatch2 waitPoint = new CountDownLatch2(1); - - public ServiceThread() { this.thread = new Thread(this, this.getServiceName()); } - public abstract String getServiceName(); - public void start() { this.thread.start(); } - public void shutdown() { this.shutdown(false); } @@ -72,7 +64,7 @@ public abstract class ServiceThread implements Runnable { } long eclipseTime = System.currentTimeMillis() - beginTime; STLOG.info("join thread " + this.getServiceName() + " eclipse time(ms) " + eclipseTime + " " - + this.getJointime()); + + this.getJointime()); } catch (InterruptedException e) { e.printStackTrace(); } diff --git a/common/src/main/java/org/apache/rocketmq/common/SystemClock.java b/common/src/main/java/org/apache/rocketmq/common/SystemClock.java index 5abc805c..ff14915c 100644 --- a/common/src/main/java/org/apache/rocketmq/common/SystemClock.java +++ b/common/src/main/java/org/apache/rocketmq/common/SystemClock.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common; diff --git a/common/src/main/java/org/apache/rocketmq/common/ThreadFactoryImpl.java b/common/src/main/java/org/apache/rocketmq/common/ThreadFactoryImpl.java index 43ab2f2c..e417da80 100644 --- a/common/src/main/java/org/apache/rocketmq/common/ThreadFactoryImpl.java +++ b/common/src/main/java/org/apache/rocketmq/common/ThreadFactoryImpl.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common; @@ -20,17 +20,14 @@ package org.apache.rocketmq.common; import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicLong; - public class ThreadFactoryImpl implements ThreadFactory { private final AtomicLong threadIndex = new AtomicLong(0); private final String threadNamePrefix; - public ThreadFactoryImpl(final String threadNamePrefix) { this.threadNamePrefix = threadNamePrefix; } - @Override public Thread newThread(Runnable r) { return new Thread(r, threadNamePrefix + this.threadIndex.incrementAndGet()); diff --git a/common/src/main/java/org/apache/rocketmq/common/TopicConfig.java b/common/src/main/java/org/apache/rocketmq/common/TopicConfig.java index 9eec2780..2582b9f2 100644 --- a/common/src/main/java/org/apache/rocketmq/common/TopicConfig.java +++ b/common/src/main/java/org/apache/rocketmq/common/TopicConfig.java @@ -6,19 +6,18 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common; import org.apache.rocketmq.common.constant.PermName; - public class TopicConfig { private static final String SEPARATOR = " "; public static int defaultReadQueueNums = 16; @@ -31,16 +30,13 @@ public class TopicConfig { private int topicSysFlag = 0; private boolean order = false; - public TopicConfig() { } - public TopicConfig(String topicName) { this.topicName = topicName; } - public TopicConfig(String topicName, int readQueueNums, int writeQueueNums, int perm) { this.topicName = topicName; this.readQueueNums = readQueueNums; @@ -48,7 +44,6 @@ public class TopicConfig { this.perm = perm; } - public String encode() { StringBuilder sb = new StringBuilder(); @@ -74,7 +69,6 @@ public class TopicConfig { return sb.toString(); } - public boolean decode(final String in) { String[] strs = in.split(SEPARATOR); if (strs != null && strs.length == 5) { @@ -94,89 +88,83 @@ public class TopicConfig { return false; } - public String getTopicName() { return topicName; } - public void setTopicName(String topicName) { this.topicName = topicName; } - public int getReadQueueNums() { return readQueueNums; } - public void setReadQueueNums(int readQueueNums) { this.readQueueNums = readQueueNums; } - public int getWriteQueueNums() { return writeQueueNums; } - public void setWriteQueueNums(int writeQueueNums) { this.writeQueueNums = writeQueueNums; } - public int getPerm() { return perm; } - public void setPerm(int perm) { this.perm = perm; } - public TopicFilterType getTopicFilterType() { return topicFilterType; } - public void setTopicFilterType(TopicFilterType topicFilterType) { this.topicFilterType = topicFilterType; } - public int getTopicSysFlag() { return topicSysFlag; } - public void setTopicSysFlag(int topicSysFlag) { this.topicSysFlag = topicSysFlag; } - public boolean isOrder() { return order; } - public void setOrder(boolean isOrder) { this.order = isOrder; } @Override public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - final TopicConfig that = (TopicConfig) o; - - if (readQueueNums != that.readQueueNums) return false; - if (writeQueueNums != that.writeQueueNums) return false; - if (perm != that.perm) return false; - if (topicSysFlag != that.topicSysFlag) return false; - if (order != that.order) return false; - if (topicName != null ? !topicName.equals(that.topicName) : that.topicName != null) return false; + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + + final TopicConfig that = (TopicConfig)o; + + if (readQueueNums != that.readQueueNums) + return false; + if (writeQueueNums != that.writeQueueNums) + return false; + if (perm != that.perm) + return false; + if (topicSysFlag != that.topicSysFlag) + return false; + if (order != that.order) + return false; + if (topicName != null ? !topicName.equals(that.topicName) : that.topicName != null) + return false; return topicFilterType == that.topicFilterType; } @@ -196,8 +184,8 @@ public class TopicConfig { @Override public String toString() { return "TopicConfig [topicName=" + topicName + ", readQueueNums=" + readQueueNums - + ", writeQueueNums=" + writeQueueNums + ", perm=" + PermName.perm2String(perm) - + ", topicFilterType=" + topicFilterType + ", topicSysFlag=" + topicSysFlag + ", order=" - + order + "]"; + + ", writeQueueNums=" + writeQueueNums + ", perm=" + PermName.perm2String(perm) + + ", topicFilterType=" + topicFilterType + ", topicSysFlag=" + topicSysFlag + ", order=" + + order + "]"; } } diff --git a/common/src/main/java/org/apache/rocketmq/common/TopicFilterType.java b/common/src/main/java/org/apache/rocketmq/common/TopicFilterType.java index cd3490a6..182ecc77 100644 --- a/common/src/main/java/org/apache/rocketmq/common/TopicFilterType.java +++ b/common/src/main/java/org/apache/rocketmq/common/TopicFilterType.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common; diff --git a/common/src/main/java/org/apache/rocketmq/common/UtilAll.java b/common/src/main/java/org/apache/rocketmq/common/UtilAll.java index 55d9b3f8..54bcdef8 100644 --- a/common/src/main/java/org/apache/rocketmq/common/UtilAll.java +++ b/common/src/main/java/org/apache/rocketmq/common/UtilAll.java @@ -16,8 +16,6 @@ */ package org.apache.rocketmq.common; -import org.apache.rocketmq.remoting.common.RemotingHelper; - import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; @@ -30,17 +28,21 @@ import java.net.NetworkInterface; import java.text.NumberFormat; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.*; +import java.util.Calendar; +import java.util.Date; +import java.util.Enumeration; +import java.util.Iterator; +import java.util.Map; import java.util.zip.CRC32; import java.util.zip.DeflaterOutputStream; import java.util.zip.InflaterInputStream; - +import org.apache.rocketmq.remoting.common.RemotingHelper; public class UtilAll { public static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss"; public static final String YYYY_MM_DD_HH_MM_SS_SSS = "yyyy-MM-dd#HH:mm:ss:SSS"; public static final String YYYY_MMDD_HHMMSS = "yyyyMMddHHmmss"; - + final static char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray(); public static int getPid() { RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); @@ -75,7 +77,6 @@ public class UtilAll { return System.currentTimeMillis() - beginTime; } - public static boolean isItTimeToDo(final String when) { String[] whiles = when.split(";"); if (whiles != null && whiles.length > 0) { @@ -91,21 +92,18 @@ public class UtilAll { return false; } - public static String timeMillisToHumanString() { return timeMillisToHumanString(System.currentTimeMillis()); } - public static String timeMillisToHumanString(final long t) { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(t); return String.format("%04d%02d%02d%02d%02d%02d%03d", cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, - cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND), - cal.get(Calendar.MILLISECOND)); + cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND), + cal.get(Calendar.MILLISECOND)); } - public static long computNextMorningTimeMillis() { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(System.currentTimeMillis()); @@ -118,7 +116,6 @@ public class UtilAll { return cal.getTimeInMillis(); } - public static long computNextMinutesTimeMillis() { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(System.currentTimeMillis()); @@ -131,7 +128,6 @@ public class UtilAll { return cal.getTimeInMillis(); } - public static long computNextHourTimeMillis() { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(System.currentTimeMillis()); @@ -144,7 +140,6 @@ public class UtilAll { return cal.getTimeInMillis(); } - public static long computNextHalfHourTimeMillis() { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(System.currentTimeMillis()); @@ -157,34 +152,31 @@ public class UtilAll { return cal.getTimeInMillis(); } - public static String timeMillisToHumanString2(final long t) { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(t); return String.format("%04d-%02d-%02d %02d:%02d:%02d,%03d", - cal.get(Calendar.YEAR), - cal.get(Calendar.MONTH) + 1, - cal.get(Calendar.DAY_OF_MONTH), - cal.get(Calendar.HOUR_OF_DAY), - cal.get(Calendar.MINUTE), - cal.get(Calendar.SECOND), - cal.get(Calendar.MILLISECOND)); + cal.get(Calendar.YEAR), + cal.get(Calendar.MONTH) + 1, + cal.get(Calendar.DAY_OF_MONTH), + cal.get(Calendar.HOUR_OF_DAY), + cal.get(Calendar.MINUTE), + cal.get(Calendar.SECOND), + cal.get(Calendar.MILLISECOND)); } - public static String timeMillisToHumanString3(final long t) { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(t); return String.format("%04d%02d%02d%02d%02d%02d", - cal.get(Calendar.YEAR), - cal.get(Calendar.MONTH) + 1, - cal.get(Calendar.DAY_OF_MONTH), - cal.get(Calendar.HOUR_OF_DAY), - cal.get(Calendar.MINUTE), - cal.get(Calendar.SECOND)); + cal.get(Calendar.YEAR), + cal.get(Calendar.MONTH) + 1, + cal.get(Calendar.DAY_OF_MONTH), + cal.get(Calendar.HOUR_OF_DAY), + cal.get(Calendar.MINUTE), + cal.get(Calendar.SECOND)); } - public static double getDiskPartitionSpaceUsedPercent(final String path) { if (null == path || path.isEmpty()) return -1; @@ -201,7 +193,7 @@ public class UtilAll { long freeSpace = file.getFreeSpace(); long usedSpace = totalSpace - freeSpace; if (totalSpace > 0) { - return usedSpace / (double) totalSpace; + return usedSpace / (double)totalSpace; } } catch (Exception e) { return -1; @@ -210,7 +202,6 @@ public class UtilAll { return -1; } - public static final int crc32(byte[] array) { if (array != null) { return crc32(array, 0, array.length); @@ -219,15 +210,12 @@ public class UtilAll { return 0; } - public static final int crc32(byte[] array, int offset, int length) { CRC32 crc32 = new CRC32(); crc32.update(array, offset, length); - return (int) (crc32.getValue() & 0x7FFFFFFF); + return (int)(crc32.getValue() & 0x7FFFFFFF); } - final static char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray(); - public static String bytes2string(byte[] src) { char[] hexChars = new char[src.length * 2]; for (int j = 0; j < src.length; j++) { @@ -248,17 +236,15 @@ public class UtilAll { byte[] d = new byte[length]; for (int i = 0; i < length; i++) { int pos = i * 2; - d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1])); + d[i] = (byte)(charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1])); } return d; } - private static byte charToByte(char c) { - return (byte) "0123456789ABCDEF".indexOf(c); + return (byte)"0123456789ABCDEF".indexOf(c); } - public static byte[] uncompress(final byte[] src) throws IOException { byte[] result = src; byte[] uncompressData = new byte[src.length]; @@ -296,7 +282,6 @@ public class UtilAll { return result; } - public static byte[] compress(final byte[] src, final int level) throws IOException { byte[] result = src; ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(src.length); @@ -322,7 +307,6 @@ public class UtilAll { return result; } - public static int asInt(String str, int defaultValue) { try { return Integer.parseInt(str); @@ -331,7 +315,6 @@ public class UtilAll { } } - public static long asLong(String str, long defaultValue) { try { return Long.parseLong(str); @@ -340,13 +323,11 @@ public class UtilAll { } } - public static String formatDate(Date date, String pattern) { SimpleDateFormat df = new SimpleDateFormat(pattern); return df.format(date); } - public static Date parseDate(String date, String pattern) { SimpleDateFormat df = new SimpleDateFormat(pattern); try { @@ -356,12 +337,10 @@ public class UtilAll { } } - public static String responseCode2String(final int code) { return Integer.toString(code); } - public static String frontStringAtLeast(final String str, final int size) { if (str != null) { if (str.length() > size) { @@ -372,7 +351,6 @@ public class UtilAll { return str; } - public static boolean isBlank(String str) { int strLen; if (str == null || (strLen = str.length()) == 0) { @@ -386,12 +364,10 @@ public class UtilAll { return true; } - public static String jstack() { return jstack(Thread.getAllStackTraces()); } - public static String jstack(Map map) { StringBuilder result = new StringBuilder(); try { @@ -421,19 +397,18 @@ public class UtilAll { throw new RuntimeException("illegal ipv4 bytes"); } - //10.0.0.0~10.255.255.255 //172.16.0.0~172.31.255.255 //192.168.0.0~192.168.255.255 - if (ip[0] == (byte) 10) { + if (ip[0] == (byte)10) { return true; - } else if (ip[0] == (byte) 172) { - if (ip[1] >= (byte) 16 && ip[1] <= (byte) 31) { + } else if (ip[0] == (byte)172) { + if (ip[1] >= (byte)16 && ip[1] <= (byte)31) { return true; } - } else if (ip[0] == (byte) 192) { - if (ip[1] == (byte) 168) { + } else if (ip[0] == (byte)192) { + if (ip[1] == (byte)168) { return true; } } @@ -448,28 +423,27 @@ public class UtilAll { // if (ip[0] == (byte)30 && ip[1] == (byte)10 && ip[2] == (byte)163 && ip[3] == (byte)120) { // } - - if (ip[0] >= (byte) 1 && ip[0] <= (byte) 126) { - if (ip[1] == (byte) 1 && ip[2] == (byte) 1 && ip[3] == (byte) 1) { + if (ip[0] >= (byte)1 && ip[0] <= (byte)126) { + if (ip[1] == (byte)1 && ip[2] == (byte)1 && ip[3] == (byte)1) { return false; } - if (ip[1] == (byte) 0 && ip[2] == (byte) 0 && ip[3] == (byte) 0) { + if (ip[1] == (byte)0 && ip[2] == (byte)0 && ip[3] == (byte)0) { return false; } return true; - } else if (ip[0] >= (byte) 128 && ip[0] <= (byte) 191) { - if (ip[2] == (byte) 1 && ip[3] == (byte) 1) { + } else if (ip[0] >= (byte)128 && ip[0] <= (byte)191) { + if (ip[2] == (byte)1 && ip[3] == (byte)1) { return false; } - if (ip[2] == (byte) 0 && ip[3] == (byte) 0) { + if (ip[2] == (byte)0 && ip[3] == (byte)0) { return false; } return true; - } else if (ip[0] >= (byte) 192 && ip[0] <= (byte) 223) { - if (ip[3] == (byte) 1) { + } else if (ip[0] >= (byte)192 && ip[0] <= (byte)223) { + if (ip[3] == (byte)1) { return false; } - if (ip[3] == (byte) 0) { + if (ip[3] == (byte)0) { return false; } return true; @@ -482,8 +456,8 @@ public class UtilAll { return null; } return new StringBuilder().append(ip[0] & 0xFF).append(".").append( - ip[1] & 0xFF).append(".").append(ip[2] & 0xFF) - .append(".").append(ip[3] & 0xFF).toString(); + ip[1] & 0xFF).append(".").append(ip[2] & 0xFF) + .append(".").append(ip[3] & 0xFF).toString(); } public static byte[] getIP() { @@ -492,10 +466,10 @@ public class UtilAll { InetAddress ip = null; byte[] internalIP = null; while (allNetInterfaces.hasMoreElements()) { - NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement(); + NetworkInterface netInterface = (NetworkInterface)allNetInterfaces.nextElement(); Enumeration addresses = netInterface.getInetAddresses(); while (addresses.hasMoreElements()) { - ip = (InetAddress) addresses.nextElement(); + ip = (InetAddress)addresses.nextElement(); if (ip != null && ip instanceof Inet4Address) { byte[] ipByte = ip.getAddress(); if (ipByte.length == 4) { diff --git a/common/src/main/java/org/apache/rocketmq/common/admin/ConsumeStats.java b/common/src/main/java/org/apache/rocketmq/common/admin/ConsumeStats.java index efab41b9..1fc8897c 100644 --- a/common/src/main/java/org/apache/rocketmq/common/admin/ConsumeStats.java +++ b/common/src/main/java/org/apache/rocketmq/common/admin/ConsumeStats.java @@ -6,23 +6,21 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.admin; -import org.apache.rocketmq.common.message.MessageQueue; -import org.apache.rocketmq.remoting.protocol.RemotingSerializable; - import java.util.HashMap; import java.util.Iterator; import java.util.Map.Entry; - +import org.apache.rocketmq.common.message.MessageQueue; +import org.apache.rocketmq.remoting.protocol.RemotingSerializable; /** * @@ -32,7 +30,6 @@ public class ConsumeStats extends RemotingSerializable { private HashMap offsetTable = new HashMap(); private double consumeTps = 0; - public long computeTotalDiff() { long diffTotal = 0L; @@ -46,12 +43,10 @@ public class ConsumeStats extends RemotingSerializable { return diffTotal; } - public HashMap getOffsetTable() { return offsetTable; } - public void setOffsetTable(HashMap offsetTable) { this.offsetTable = offsetTable; } diff --git a/common/src/main/java/org/apache/rocketmq/common/admin/OffsetWrapper.java b/common/src/main/java/org/apache/rocketmq/common/admin/OffsetWrapper.java index 170509ad..a5697ecb 100644 --- a/common/src/main/java/org/apache/rocketmq/common/admin/OffsetWrapper.java +++ b/common/src/main/java/org/apache/rocketmq/common/admin/OffsetWrapper.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.admin; @@ -26,32 +26,26 @@ public class OffsetWrapper { private long lastTimestamp; - public long getBrokerOffset() { return brokerOffset; } - public void setBrokerOffset(long brokerOffset) { this.brokerOffset = brokerOffset; } - public long getConsumerOffset() { return consumerOffset; } - public void setConsumerOffset(long consumerOffset) { this.consumerOffset = consumerOffset; } - public long getLastTimestamp() { return lastTimestamp; } - public void setLastTimestamp(long lastTimestamp) { this.lastTimestamp = lastTimestamp; } diff --git a/common/src/main/java/org/apache/rocketmq/common/admin/RollbackStats.java b/common/src/main/java/org/apache/rocketmq/common/admin/RollbackStats.java index 3af6a0ce..2f90e692 100644 --- a/common/src/main/java/org/apache/rocketmq/common/admin/RollbackStats.java +++ b/common/src/main/java/org/apache/rocketmq/common/admin/RollbackStats.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.admin; @@ -28,62 +28,50 @@ public class RollbackStats { private long timestampOffset; private long rollbackOffset; - public String getBrokerName() { return brokerName; } - public void setBrokerName(String brokerName) { this.brokerName = brokerName; } - public long getQueueId() { return queueId; } - public void setQueueId(long queueId) { this.queueId = queueId; } - public long getBrokerOffset() { return brokerOffset; } - public void setBrokerOffset(long brokerOffset) { this.brokerOffset = brokerOffset; } - public long getConsumerOffset() { return consumerOffset; } - public void setConsumerOffset(long consumerOffset) { this.consumerOffset = consumerOffset; } - public long getTimestampOffset() { return timestampOffset; } - public void setTimestampOffset(long timestampOffset) { this.timestampOffset = timestampOffset; } - public long getRollbackOffset() { return rollbackOffset; } - public void setRollbackOffset(long rollbackOffset) { this.rollbackOffset = rollbackOffset; } diff --git a/common/src/main/java/org/apache/rocketmq/common/admin/TopicOffset.java b/common/src/main/java/org/apache/rocketmq/common/admin/TopicOffset.java index f64ddcb4..8147d634 100644 --- a/common/src/main/java/org/apache/rocketmq/common/admin/TopicOffset.java +++ b/common/src/main/java/org/apache/rocketmq/common/admin/TopicOffset.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.admin; @@ -25,32 +25,26 @@ public class TopicOffset { private long maxOffset; private long lastUpdateTimestamp; - public long getMinOffset() { return minOffset; } - public void setMinOffset(long minOffset) { this.minOffset = minOffset; } - public long getMaxOffset() { return maxOffset; } - public void setMaxOffset(long maxOffset) { this.maxOffset = maxOffset; } - public long getLastUpdateTimestamp() { return lastUpdateTimestamp; } - public void setLastUpdateTimestamp(long lastUpdateTimestamp) { this.lastUpdateTimestamp = lastUpdateTimestamp; } diff --git a/common/src/main/java/org/apache/rocketmq/common/admin/TopicStatsTable.java b/common/src/main/java/org/apache/rocketmq/common/admin/TopicStatsTable.java index a9e9e848..01f4557d 100644 --- a/common/src/main/java/org/apache/rocketmq/common/admin/TopicStatsTable.java +++ b/common/src/main/java/org/apache/rocketmq/common/admin/TopicStatsTable.java @@ -6,22 +6,20 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.admin; +import java.util.HashMap; import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.remoting.protocol.RemotingSerializable; -import java.util.HashMap; - - /** * * @@ -29,12 +27,10 @@ import java.util.HashMap; public class TopicStatsTable extends RemotingSerializable { private HashMap offsetTable = new HashMap(); - public HashMap getOffsetTable() { return offsetTable; } - public void setOffsetTable(HashMap offsetTable) { this.offsetTable = offsetTable; } diff --git a/common/src/main/java/org/apache/rocketmq/common/constant/DBMsgConstants.java b/common/src/main/java/org/apache/rocketmq/common/constant/DBMsgConstants.java index 298a427e..ee3e52ab 100644 --- a/common/src/main/java/org/apache/rocketmq/common/constant/DBMsgConstants.java +++ b/common/src/main/java/org/apache/rocketmq/common/constant/DBMsgConstants.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.constant; diff --git a/common/src/main/java/org/apache/rocketmq/common/constant/LoggerName.java b/common/src/main/java/org/apache/rocketmq/common/constant/LoggerName.java index 2bcfacf5..482a04e0 100644 --- a/common/src/main/java/org/apache/rocketmq/common/constant/LoggerName.java +++ b/common/src/main/java/org/apache/rocketmq/common/constant/LoggerName.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.constant; diff --git a/common/src/main/java/org/apache/rocketmq/common/constant/PermName.java b/common/src/main/java/org/apache/rocketmq/common/constant/PermName.java index e5ab1fcc..72ac372e 100644 --- a/common/src/main/java/org/apache/rocketmq/common/constant/PermName.java +++ b/common/src/main/java/org/apache/rocketmq/common/constant/PermName.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.constant; diff --git a/common/src/main/java/org/apache/rocketmq/common/consumer/ConsumeFromWhere.java b/common/src/main/java/org/apache/rocketmq/common/consumer/ConsumeFromWhere.java index 2c8e989d..2e6c2db7 100644 --- a/common/src/main/java/org/apache/rocketmq/common/consumer/ConsumeFromWhere.java +++ b/common/src/main/java/org/apache/rocketmq/common/consumer/ConsumeFromWhere.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.consumer; diff --git a/common/src/main/java/org/apache/rocketmq/common/filter/FilterAPI.java b/common/src/main/java/org/apache/rocketmq/common/filter/FilterAPI.java index 7f558eff..01c17327 100644 --- a/common/src/main/java/org/apache/rocketmq/common/filter/FilterAPI.java +++ b/common/src/main/java/org/apache/rocketmq/common/filter/FilterAPI.java @@ -6,20 +6,18 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.filter; -import org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData; - import java.net.URL; - +import org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData; /** * @@ -42,7 +40,7 @@ public class FilterAPI { } public static SubscriptionData buildSubscriptionData(final String consumerGroup, String topic, - String subString) throws Exception { + String subString) throws Exception { SubscriptionData subscriptionData = new SubscriptionData(); subscriptionData.setTopic(topic); subscriptionData.setSubString(subString); diff --git a/common/src/main/java/org/apache/rocketmq/common/filter/FilterContext.java b/common/src/main/java/org/apache/rocketmq/common/filter/FilterContext.java index e18fe489..3501d269 100644 --- a/common/src/main/java/org/apache/rocketmq/common/filter/FilterContext.java +++ b/common/src/main/java/org/apache/rocketmq/common/filter/FilterContext.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.filter; @@ -20,12 +20,10 @@ package org.apache.rocketmq.common.filter; public class FilterContext { private String consumerGroup; - public String getConsumerGroup() { return consumerGroup; } - public void setConsumerGroup(String consumerGroup) { this.consumerGroup = consumerGroup; } diff --git a/common/src/main/java/org/apache/rocketmq/common/filter/MessageFilter.java b/common/src/main/java/org/apache/rocketmq/common/filter/MessageFilter.java index c20e7375..3af3d108 100644 --- a/common/src/main/java/org/apache/rocketmq/common/filter/MessageFilter.java +++ b/common/src/main/java/org/apache/rocketmq/common/filter/MessageFilter.java @@ -19,7 +19,6 @@ package org.apache.rocketmq.common.filter; import org.apache.rocketmq.common.message.MessageExt; - public interface MessageFilter { boolean match(final MessageExt msg, final FilterContext context); } diff --git a/common/src/main/java/org/apache/rocketmq/common/filter/impl/Op.java b/common/src/main/java/org/apache/rocketmq/common/filter/impl/Op.java index af545669..ac85e4d0 100644 --- a/common/src/main/java/org/apache/rocketmq/common/filter/impl/Op.java +++ b/common/src/main/java/org/apache/rocketmq/common/filter/impl/Op.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.filter.impl; @@ -21,17 +21,14 @@ public abstract class Op { private String symbol; - protected Op(String symbol) { this.symbol = symbol; } - public String getSymbol() { return symbol; } - public String toString() { return symbol; } diff --git a/common/src/main/java/org/apache/rocketmq/common/filter/impl/Operand.java b/common/src/main/java/org/apache/rocketmq/common/filter/impl/Operand.java index ce21d909..5de03b7c 100644 --- a/common/src/main/java/org/apache/rocketmq/common/filter/impl/Operand.java +++ b/common/src/main/java/org/apache/rocketmq/common/filter/impl/Operand.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.filter.impl; diff --git a/common/src/main/java/org/apache/rocketmq/common/filter/impl/Operator.java b/common/src/main/java/org/apache/rocketmq/common/filter/impl/Operator.java index 45bebf0c..a232fe43 100644 --- a/common/src/main/java/org/apache/rocketmq/common/filter/impl/Operator.java +++ b/common/src/main/java/org/apache/rocketmq/common/filter/impl/Operator.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.filter.impl; @@ -27,7 +27,6 @@ public class Operator extends Op { private int priority; private boolean compareable; - private Operator(String symbol, int priority, boolean compareable) { super(symbol); this.priority = priority; @@ -55,7 +54,6 @@ public class Operator extends Op { return compareable; } - public int compare(Operator operator) { if (this.priority > operator.priority) return 1; diff --git a/common/src/main/java/org/apache/rocketmq/common/filter/impl/PolishExpr.java b/common/src/main/java/org/apache/rocketmq/common/filter/impl/PolishExpr.java index 73b51b64..2b89944d 100644 --- a/common/src/main/java/org/apache/rocketmq/common/filter/impl/PolishExpr.java +++ b/common/src/main/java/org/apache/rocketmq/common/filter/impl/PolishExpr.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.filter.impl; @@ -49,7 +49,7 @@ public class PolishExpr { segments.add(token); } else if (isLeftParenthesis(token)) { - operatorStack.push((Operator) token); + operatorStack.push((Operator)token); } else if (isRightParenthesis(token)) { Operator opNew = null; @@ -60,7 +60,7 @@ public class PolishExpr { throw new IllegalArgumentException("mismatched parentheses"); } else if (isOperator(token)) { - Operator opNew = (Operator) token; + Operator opNew = (Operator)token; if (!operatorStack.empty()) { Operator opOld = operatorStack.peek(); if (opOld.isCompareable() && opNew.compare(opOld) != 1) { @@ -99,17 +99,16 @@ public class PolishExpr { Type preType = Type.NULL; for (int i = 0; i < size; i++) { - int chValue = (int) expression.charAt(i); + int chValue = (int)expression.charAt(i); if ((97 <= chValue && chValue <= 122) || (65 <= chValue && chValue <= 90) - || (49 <= chValue && chValue <= 57) || 95 == chValue) { - + || (49 <= chValue && chValue <= 57) || 95 == chValue) { if (Type.OPERATOR == preType || Type.SEPAERATOR == preType || Type.NULL == preType - || Type.PARENTHESIS == preType) { + || Type.PARENTHESIS == preType) { if (Type.OPERATOR == preType) { segments.add(createOperator(expression.substring(wordStartIndex, wordStartIndex - + wordLen))); + + wordLen))); } wordStartIndex = i; wordLen = 0; @@ -118,10 +117,9 @@ public class PolishExpr { wordLen++; } else if (40 == chValue || 41 == chValue) { - if (Type.OPERATOR == preType) { segments.add(createOperator(expression - .substring(wordStartIndex, wordStartIndex + wordLen))); + .substring(wordStartIndex, wordStartIndex + wordLen))); wordStartIndex = -1; wordLen = 0; } else if (Type.OPERAND == preType) { @@ -131,13 +129,13 @@ public class PolishExpr { } preType = Type.PARENTHESIS; - segments.add(createOperator((char) chValue + "")); + segments.add(createOperator((char)chValue + "")); } else if (38 == chValue || 124 == chValue) { if (Type.OPERAND == preType || Type.SEPAERATOR == preType || Type.PARENTHESIS == preType) { if (Type.OPERAND == preType) { segments.add(new Operand(expression.substring(wordStartIndex, wordStartIndex - + wordLen))); + + wordLen))); } wordStartIndex = i; wordLen = 0; @@ -146,10 +144,9 @@ public class PolishExpr { wordLen++; } else if (32 == chValue || 9 == chValue) { - if (Type.OPERATOR == preType) { segments.add(createOperator(expression - .substring(wordStartIndex, wordStartIndex + wordLen))); + .substring(wordStartIndex, wordStartIndex + wordLen))); wordStartIndex = -1; wordLen = 0; } else if (Type.OPERAND == preType) { @@ -160,7 +157,7 @@ public class PolishExpr { preType = Type.SEPAERATOR; } else { - throw new IllegalArgumentException("illegal expression, at index " + i + " " + (char) chValue); + throw new IllegalArgumentException("illegal expression, at index " + i + " " + (char)chValue); } } @@ -176,11 +173,11 @@ public class PolishExpr { } public static boolean isLeftParenthesis(Op token) { - return token instanceof Operator && LEFTPARENTHESIS == (Operator) token; + return token instanceof Operator && LEFTPARENTHESIS == (Operator)token; } public static boolean isRightParenthesis(Op token) { - return token instanceof Operator && RIGHTPARENTHESIS == (Operator) token; + return token instanceof Operator && RIGHTPARENTHESIS == (Operator)token; } public static boolean isOperator(Op token) { diff --git a/common/src/main/java/org/apache/rocketmq/common/filter/impl/Type.java b/common/src/main/java/org/apache/rocketmq/common/filter/impl/Type.java index 834bde82..68797ded 100644 --- a/common/src/main/java/org/apache/rocketmq/common/filter/impl/Type.java +++ b/common/src/main/java/org/apache/rocketmq/common/filter/impl/Type.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.filter.impl; diff --git a/common/src/main/java/org/apache/rocketmq/common/help/FAQUrl.java b/common/src/main/java/org/apache/rocketmq/common/help/FAQUrl.java index d3c5f331..603db279 100644 --- a/common/src/main/java/org/apache/rocketmq/common/help/FAQUrl.java +++ b/common/src/main/java/org/apache/rocketmq/common/help/FAQUrl.java @@ -6,72 +6,61 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.help; public class FAQUrl { public static final String APPLY_TOPIC_URL = // - "http://docs.aliyun.com/cn#/pub/ons/faq/exceptions&topic_not_exist"; - + "http://docs.aliyun.com/cn#/pub/ons/faq/exceptions&topic_not_exist"; public static final String NAME_SERVER_ADDR_NOT_EXIST_URL = // - "http://docs.aliyun.com/cn#/pub/ons/faq/exceptions&namesrv_not_exist"; - + "http://docs.aliyun.com/cn#/pub/ons/faq/exceptions&namesrv_not_exist"; public static final String GROUP_NAME_DUPLICATE_URL = // - "http://docs.aliyun.com/cn#/pub/ons/faq/exceptions&group_duplicate"; - + "http://docs.aliyun.com/cn#/pub/ons/faq/exceptions&group_duplicate"; public static final String CLIENT_PARAMETER_CHECK_URL = // - "http://docs.aliyun.com/cn#/pub/ons/faq/exceptions¶meter_check_failed"; - + "http://docs.aliyun.com/cn#/pub/ons/faq/exceptions¶meter_check_failed"; public static final String SUBSCRIPTION_GROUP_NOT_EXIST = // - "http://docs.aliyun.com/cn#/pub/ons/faq/exceptions&subGroup_not_exist"; - + "http://docs.aliyun.com/cn#/pub/ons/faq/exceptions&subGroup_not_exist"; public static final String CLIENT_SERVICE_NOT_OK = // - "http://docs.aliyun.com/cn#/pub/ons/faq/exceptions&service_not_ok"; + "http://docs.aliyun.com/cn#/pub/ons/faq/exceptions&service_not_ok"; // FAQ: No route info of this topic, TopicABC public static final String NO_TOPIC_ROUTE_INFO = // - "http://docs.aliyun.com/cn#/pub/ons/faq/exceptions&topic_not_exist"; - + "http://docs.aliyun.com/cn#/pub/ons/faq/exceptions&topic_not_exist"; public static final String LOAD_JSON_EXCEPTION = // - "http://docs.aliyun.com/cn#/pub/ons/faq/exceptions&load_json_exception"; - + "http://docs.aliyun.com/cn#/pub/ons/faq/exceptions&load_json_exception"; public static final String SAME_GROUP_DIFFERENT_TOPIC = // - "http://docs.aliyun.com/cn#/pub/ons/faq/exceptions&subscription_exception"; - + "http://docs.aliyun.com/cn#/pub/ons/faq/exceptions&subscription_exception"; public static final String MQLIST_NOT_EXIST = // - "http://docs.aliyun.com/cn#/pub/ons/faq/exceptions&queue_not_exist"; + "http://docs.aliyun.com/cn#/pub/ons/faq/exceptions&queue_not_exist"; public static final String UNEXPECTED_EXCEPTION_URL = // - "http://docs.aliyun.com/cn#/pub/ons/faq/exceptions&unexpected_exception"; - + "http://docs.aliyun.com/cn#/pub/ons/faq/exceptions&unexpected_exception"; public static final String SEND_MSG_FAILED = // - "http://docs.aliyun.com/cn#/pub/ons/faq/exceptions&send_msg_failed"; - + "http://docs.aliyun.com/cn#/pub/ons/faq/exceptions&send_msg_failed"; public static final String UNKNOWN_HOST_EXCEPTION = // - "http://docs.aliyun.com/cn#/pub/ons/faq/exceptions&unknown_host"; + "http://docs.aliyun.com/cn#/pub/ons/faq/exceptions&unknown_host"; private static final String TIP_STRING_BEGIN = "\nSee "; private static final String TIP_STRING_END = " for further details."; - public static String suggestTodo(final String url) { StringBuilder sb = new StringBuilder(); sb.append(TIP_STRING_BEGIN); diff --git a/common/src/main/java/org/apache/rocketmq/common/hook/FilterCheckHook.java b/common/src/main/java/org/apache/rocketmq/common/hook/FilterCheckHook.java index 10b10977..a0a79257 100644 --- a/common/src/main/java/org/apache/rocketmq/common/hook/FilterCheckHook.java +++ b/common/src/main/java/org/apache/rocketmq/common/hook/FilterCheckHook.java @@ -6,20 +6,19 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.hook; import java.nio.ByteBuffer; - /** * * @@ -27,6 +26,5 @@ import java.nio.ByteBuffer; public interface FilterCheckHook { public String hookName(); - public boolean isFilterMatched(final boolean isUnitMode, final ByteBuffer byteBuffer); } diff --git a/common/src/main/java/org/apache/rocketmq/common/message/Message.java b/common/src/main/java/org/apache/rocketmq/common/message/Message.java index 258104c8..00cb6d16 100644 --- a/common/src/main/java/org/apache/rocketmq/common/message/Message.java +++ b/common/src/main/java/org/apache/rocketmq/common/message/Message.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.message; @@ -21,7 +21,6 @@ import java.util.Collection; import java.util.HashMap; import java.util.Map; - /** * * @@ -34,16 +33,13 @@ public class Message implements Serializable { private Map properties; private byte[] body; - public Message() { } - public Message(String topic, byte[] body) { this(topic, "", "", 0, body, true); } - public Message(String topic, String tags, String keys, int flag, byte[] body, boolean waitStoreMsgOK) { this.topic = topic; this.flag = flag; @@ -58,6 +54,14 @@ public class Message implements Serializable { this.setWaitStoreMsgOK(waitStoreMsgOK); } + public Message(String topic, String tags, byte[] body) { + this(topic, tags, "", 0, body, true); + } + + public Message(String topic, String tags, String keys, byte[] body) { + this(topic, tags, keys, 0, body, true); + } + public void setKeys(String keys) { this.putProperty(MessageConst.PROPERTY_KEYS, keys); } @@ -70,16 +74,6 @@ public class Message implements Serializable { this.properties.put(name, value); } - - public Message(String topic, String tags, byte[] body) { - this(topic, tags, "", 0, body, true); - } - - - public Message(String topic, String tags, String keys, byte[] body) { - this(topic, tags, keys, 0, body, true); - } - void clearProperty(final String name) { if (null != this.properties) { this.properties.remove(name); @@ -89,7 +83,7 @@ public class Message implements Serializable { public void putUserProperty(final String name, final String value) { if (MessageConst.STRING_HASH_SET.contains(name)) { throw new RuntimeException(String.format( - "The Property<%s> is used by system, input another please", name)); + "The Property<%s> is used by system, input another please", name)); } this.putProperty(name, value); } @@ -136,7 +130,6 @@ public class Message implements Serializable { this.setKeys(sb.toString().trim()); } - public int getDelayTimeLevel() { String t = this.getProperty(MessageConst.PROPERTY_DELAY_TIME_LEVEL); if (t != null) { @@ -146,12 +139,10 @@ public class Message implements Serializable { return 0; } - public void setDelayTimeLevel(int level) { this.putProperty(MessageConst.PROPERTY_DELAY_TIME_LEVEL, String.valueOf(level)); } - public boolean isWaitStoreMsgOK() { String result = this.getProperty(MessageConst.PROPERTY_WAIT_STORE_MSG_OK); if (null == result) @@ -160,37 +151,30 @@ public class Message implements Serializable { return Boolean.parseBoolean(result); } - public void setWaitStoreMsgOK(boolean waitStoreMsgOK) { this.putProperty(MessageConst.PROPERTY_WAIT_STORE_MSG_OK, Boolean.toString(waitStoreMsgOK)); } - public int getFlag() { return flag; } - public void setFlag(int flag) { this.flag = flag; } - public byte[] getBody() { return body; } - public void setBody(byte[] body) { this.body = body; } - public Map getProperties() { return properties; } - void setProperties(Map properties) { this.properties = properties; } @@ -206,6 +190,6 @@ public class Message implements Serializable { @Override public String toString() { return "Message [topic=" + topic + ", flag=" + flag + ", properties=" + properties + ", body=" - + (body != null ? body.length : 0) + "]"; + + (body != null ? body.length : 0) + "]"; } } diff --git a/common/src/main/java/org/apache/rocketmq/common/message/MessageAccessor.java b/common/src/main/java/org/apache/rocketmq/common/message/MessageAccessor.java index 5cd0ba85..7663ecd2 100644 --- a/common/src/main/java/org/apache/rocketmq/common/message/MessageAccessor.java +++ b/common/src/main/java/org/apache/rocketmq/common/message/MessageAccessor.java @@ -6,20 +6,19 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.message; import java.util.Map; - public class MessageAccessor { public static void clearProperty(final Message msg, final String name) { @@ -42,52 +41,42 @@ public class MessageAccessor { return msg.getProperty(MessageConst.PROPERTY_TRANSFER_FLAG); } - public static void setCorrectionFlag(final Message msg, String unit) { putProperty(msg, MessageConst.PROPERTY_CORRECTION_FLAG, unit); } - public static String getCorrectionFlag(final Message msg) { return msg.getProperty(MessageConst.PROPERTY_CORRECTION_FLAG); } - public static void setOriginMessageId(final Message msg, String originMessageId) { putProperty(msg, MessageConst.PROPERTY_ORIGIN_MESSAGE_ID, originMessageId); } - public static String getOriginMessageId(final Message msg) { return msg.getProperty(MessageConst.PROPERTY_ORIGIN_MESSAGE_ID); } - public static void setMQ2Flag(final Message msg, String flag) { putProperty(msg, MessageConst.PROPERTY_MQ2_FLAG, flag); } - public static String getMQ2Flag(final Message msg) { return msg.getProperty(MessageConst.PROPERTY_MQ2_FLAG); } - public static void setReconsumeTime(final Message msg, String reconsumeTimes) { putProperty(msg, MessageConst.PROPERTY_RECONSUME_TIME, reconsumeTimes); } - public static String getReconsumeTime(final Message msg) { return msg.getProperty(MessageConst.PROPERTY_RECONSUME_TIME); } - public static void setMaxReconsumeTimes(final Message msg, String maxReconsumeTimes) { putProperty(msg, MessageConst.PROPERTY_MAX_RECONSUME_TIMES, maxReconsumeTimes); } - public static String getMaxReconsumeTimes(final Message msg) { return msg.getProperty(MessageConst.PROPERTY_MAX_RECONSUME_TIMES); } @@ -96,7 +85,6 @@ public class MessageAccessor { putProperty(msg, MessageConst.PROPERTY_CONSUME_START_TIMESTAMP, propertyConsumeStartTimeStamp); } - public static String getConsumeStartTimeStamp(final Message msg) { return msg.getProperty(MessageConst.PROPERTY_CONSUME_START_TIMESTAMP); } diff --git a/common/src/main/java/org/apache/rocketmq/common/message/MessageClientExt.java b/common/src/main/java/org/apache/rocketmq/common/message/MessageClientExt.java index 90703cae..8fa6a157 100644 --- a/common/src/main/java/org/apache/rocketmq/common/message/MessageClientExt.java +++ b/common/src/main/java/org/apache/rocketmq/common/message/MessageClientExt.java @@ -6,40 +6,38 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.message; public class MessageClientExt extends MessageExt { - - public void setOffsetMsgId(String offsetMsgId) { - super.setMsgId(offsetMsgId); - } - public String getOffsetMsgId() { return super.getMsgId(); } - - public void setMsgId(String msgId) { - //DO NOTHING - //MessageClientIDSetter.setUniqID(this); + + public void setOffsetMsgId(String offsetMsgId) { + super.setMsgId(offsetMsgId); } - + @Override public String getMsgId() { String uniqID = MessageClientIDSetter.getUniqID(this); if (uniqID == null) { return this.getOffsetMsgId(); - } - else { + } else { return uniqID; } } + + public void setMsgId(String msgId) { + //DO NOTHING + //MessageClientIDSetter.setUniqID(this); + } } diff --git a/common/src/main/java/org/apache/rocketmq/common/message/MessageClientIDSetter.java b/common/src/main/java/org/apache/rocketmq/common/message/MessageClientIDSetter.java index 1c3a1b79..1c279200 100644 --- a/common/src/main/java/org/apache/rocketmq/common/message/MessageClientIDSetter.java +++ b/common/src/main/java/org/apache/rocketmq/common/message/MessageClientIDSetter.java @@ -16,12 +16,11 @@ */ package org.apache.rocketmq.common.message; -import org.apache.rocketmq.common.UtilAll; - import java.nio.ByteBuffer; import java.util.Calendar; import java.util.Date; import java.util.concurrent.atomic.AtomicInteger; +import org.apache.rocketmq.common.UtilAll; public class MessageClientIDSetter { private static final String TOPIC_KEY_SPLITTER = "#"; @@ -65,10 +64,10 @@ public class MessageClientIDSetter { public static Date getNearlyTimeFromID(String msgID) { ByteBuffer buf = ByteBuffer.allocate(8); byte[] bytes = UtilAll.string2bytes(msgID); - buf.put((byte) 0); - buf.put((byte) 0); - buf.put((byte) 0); - buf.put((byte) 0); + buf.put((byte)0); + buf.put((byte)0); + buf.put((byte)0); + buf.put((byte)0); buf.put(bytes, 10, 4); buf.position(0); long spanMS = buf.getLong(); @@ -107,7 +106,6 @@ public class MessageClientIDSetter { return sb.toString(); } - private static byte[] createUniqIDBuffer() { ByteBuffer buffer = ByteBuffer.allocate(4 + 2); long current = System.currentTimeMillis(); @@ -115,8 +113,8 @@ public class MessageClientIDSetter { setStartTime(current); } buffer.position(0); - buffer.putInt((int) (System.currentTimeMillis() - startTime)); - buffer.putShort((short) COUNTER.getAndIncrement()); + buffer.putInt((int)(System.currentTimeMillis() - startTime)); + buffer.putShort((short)COUNTER.getAndIncrement()); return buffer.array(); } diff --git a/common/src/main/java/org/apache/rocketmq/common/message/MessageConst.java b/common/src/main/java/org/apache/rocketmq/common/message/MessageConst.java index d65160b8..a4c15a8f 100644 --- a/common/src/main/java/org/apache/rocketmq/common/message/MessageConst.java +++ b/common/src/main/java/org/apache/rocketmq/common/message/MessageConst.java @@ -18,7 +18,6 @@ package org.apache.rocketmq.common.message; import java.util.HashSet; - public class MessageConst { public static final String PROPERTY_KEYS = "KEYS"; public static final String PROPERTY_TAGS = "TAGS"; @@ -47,7 +46,6 @@ public class MessageConst { public static final HashSet STRING_HASH_SET = new HashSet(); - static { STRING_HASH_SET.add(PROPERTY_TRACE_SWITCH); STRING_HASH_SET.add(PROPERTY_MSG_REGION); diff --git a/common/src/main/java/org/apache/rocketmq/common/message/MessageDecoder.java b/common/src/main/java/org/apache/rocketmq/common/message/MessageDecoder.java index 375cc475..6ae1d2a7 100644 --- a/common/src/main/java/org/apache/rocketmq/common/message/MessageDecoder.java +++ b/common/src/main/java/org/apache/rocketmq/common/message/MessageDecoder.java @@ -16,9 +16,6 @@ */ package org.apache.rocketmq.common.message; -import org.apache.rocketmq.common.UtilAll; -import org.apache.rocketmq.common.sysflag.MessageSysFlag; - import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.SocketAddress; @@ -30,7 +27,8 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; - +import org.apache.rocketmq.common.UtilAll; +import org.apache.rocketmq.common.sysflag.MessageSysFlag; public class MessageDecoder { public final static int MSG_ID_LENGTH = 8 + 8; @@ -41,7 +39,8 @@ public class MessageDecoder { public final static int MESSAGE_PHYSIC_OFFSET_POSTION = 28; public final static int MESSAGE_STORE_TIMESTAMP_POSTION = 56; public final static int MESSAGE_MAGIC_CODE = 0xAABBCCDD ^ 1880681586 + 8; - + public static final char NAME_VALUE_SEPARATOR = 1; + public static final char PROPERTY_SEPARATOR = 2; public static String createMessageId(final ByteBuffer input, final ByteBuffer addr, final long offset) { input.flip(); @@ -53,10 +52,9 @@ public class MessageDecoder { return UtilAll.bytes2string(input.array()); } - public static String createMessageId(SocketAddress socketAddress, long transactionIdhashCode) { ByteBuffer byteBuffer = ByteBuffer.allocate(MessageDecoder.MSG_ID_LENGTH); - InetSocketAddress inetSocketAddress = (InetSocketAddress) socketAddress; + InetSocketAddress inetSocketAddress = (InetSocketAddress)socketAddress; byteBuffer.put(inetSocketAddress.getAddress().getAddress()); byteBuffer.putInt(inetSocketAddress.getPort()); byteBuffer.putLong(transactionIdhashCode); @@ -64,12 +62,10 @@ public class MessageDecoder { return UtilAll.bytes2string(byteBuffer.array()); } - public static MessageId decodeMessageId(final String msgId) throws UnknownHostException { SocketAddress address; long offset; - byte[] ip = UtilAll.string2bytes(msgId.substring(0, 8)); byte[] port = UtilAll.string2bytes(msgId.substring(8, 16)); ByteBuffer bb = ByteBuffer.wrap(port); @@ -84,7 +80,6 @@ public class MessageDecoder { return new MessageId(address, offset); } - public static MessageExt decode(java.nio.ByteBuffer byteBuffer) { return decode(byteBuffer, true, true, false); } @@ -97,14 +92,13 @@ public class MessageDecoder { return decode(byteBuffer, readBody, true, false); } - public static byte[] encode(MessageExt messageExt, boolean needCompress) throws Exception { byte[] body = messageExt.getBody(); byte[] topics = messageExt.getTopic().getBytes(CHARSET_UTF8); - byte topicLen = (byte) topics.length; + byte topicLen = (byte)topics.length; String properties = messageProperties2String(messageExt.getProperties()); byte[] propertiesBytes = properties.getBytes(CHARSET_UTF8); - short propertiesLength = (short) propertiesBytes.length; + short propertiesLength = (short)propertiesBytes.length; int sysFlag = messageExt.getSysFlag(); byte[] newBody = messageExt.getBody(); if (needCompress && (sysFlag & MessageSysFlag.COMPRESSED_FLAG) == MessageSysFlag.COMPRESSED_FLAG) { @@ -117,23 +111,23 @@ public class MessageDecoder { byteBuffer = ByteBuffer.allocate(storeSize); } else { storeSize = 4 // 1 TOTALSIZE - + 4 // 2 MAGICCODE - + 4 // 3 BODYCRC - + 4 // 4 QUEUEID - + 4 // 5 FLAG - + 8 // 6 QUEUEOFFSET - + 8 // 7 PHYSICALOFFSET - + 4 // 8 SYSFLAG - + 8 // 9 BORNTIMESTAMP - + 8 // 10 BORNHOST - + 8 // 11 STORETIMESTAMP - + 8 // 12 STOREHOSTADDRESS - + 4 // 13 RECONSUMETIMES - + 8 // 14 Prepared Transaction Offset - + 4 + bodyLength // 14 BODY - + 1 + topicLen // 15 TOPIC - + 2 + propertiesLength // 16 propertiesLength - + 0; + + 4 // 2 MAGICCODE + + 4 // 3 BODYCRC + + 4 // 4 QUEUEID + + 4 // 5 FLAG + + 8 // 6 QUEUEOFFSET + + 8 // 7 PHYSICALOFFSET + + 4 // 8 SYSFLAG + + 8 // 9 BORNTIMESTAMP + + 8 // 10 BORNHOST + + 8 // 11 STORETIMESTAMP + + 8 // 12 STOREHOSTADDRESS + + 4 // 13 RECONSUMETIMES + + 8 // 14 Prepared Transaction Offset + + 4 + bodyLength // 14 BODY + + 1 + topicLen // 15 TOPIC + + 2 + propertiesLength // 16 propertiesLength + + 0; byteBuffer = ByteBuffer.allocate(storeSize); } // 1 TOTALSIZE @@ -170,7 +164,7 @@ public class MessageDecoder { byteBuffer.putLong(bornTimeStamp); // 10 BORNHOST - InetSocketAddress bornHost = (InetSocketAddress) messageExt.getBornHost(); + InetSocketAddress bornHost = (InetSocketAddress)messageExt.getBornHost(); byteBuffer.put(bornHost.getAddress().getAddress()); byteBuffer.putInt(bornHost.getPort()); @@ -179,7 +173,7 @@ public class MessageDecoder { byteBuffer.putLong(storeTimestamp); // 12 STOREHOST - InetSocketAddress serverHost = (InetSocketAddress) messageExt.getStoreHost(); + InetSocketAddress serverHost = (InetSocketAddress)messageExt.getStoreHost(); byteBuffer.put(serverHost.getAddress().getAddress()); byteBuffer.putInt(serverHost.getPort()); @@ -207,12 +201,12 @@ public class MessageDecoder { } public static MessageExt decode( - java.nio.ByteBuffer byteBuffer, final boolean readBody, final boolean deCompressBody) { + java.nio.ByteBuffer byteBuffer, final boolean readBody, final boolean deCompressBody) { return decode(byteBuffer, readBody, deCompressBody, false); } public static MessageExt decode( - java.nio.ByteBuffer byteBuffer, final boolean readBody, final boolean deCompressBody, final boolean isClient) { + java.nio.ByteBuffer byteBuffer, final boolean readBody, final boolean deCompressBody, final boolean isClient) { try { MessageExt msgExt; @@ -301,7 +295,7 @@ public class MessageDecoder { // 16 TOPIC byte topicLen = byteBuffer.get(); - byte[] topic = new byte[(int) topicLen]; + byte[] topic = new byte[(int)topicLen]; byteBuffer.get(topic); msgExt.setTopic(new String(topic, CHARSET_UTF8)); @@ -320,7 +314,7 @@ public class MessageDecoder { msgExt.setMsgId(msgId); if (isClient) { - ((MessageClientExt) msgExt).setOffsetMsgId(msgId); + ((MessageClientExt)msgExt).setOffsetMsgId(msgId); } return msgExt; @@ -335,7 +329,6 @@ public class MessageDecoder { return null; } - public static List decodes(java.nio.ByteBuffer byteBuffer) { return decodes(byteBuffer, true); } @@ -353,10 +346,6 @@ public class MessageDecoder { return msgExts; } - public static final char NAME_VALUE_SEPARATOR = 1; - public static final char PROPERTY_SEPARATOR = 2; - - public static String messageProperties2String(Map properties) { StringBuilder sb = new StringBuilder(); if (properties != null) { diff --git a/common/src/main/java/org/apache/rocketmq/common/message/MessageExt.java b/common/src/main/java/org/apache/rocketmq/common/message/MessageExt.java index b7716669..9fec0ca2 100644 --- a/common/src/main/java/org/apache/rocketmq/common/message/MessageExt.java +++ b/common/src/main/java/org/apache/rocketmq/common/message/MessageExt.java @@ -6,23 +6,21 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.message; -import org.apache.rocketmq.common.TopicFilterType; -import org.apache.rocketmq.common.sysflag.MessageSysFlag; - import java.net.InetSocketAddress; import java.net.SocketAddress; import java.nio.ByteBuffer; - +import org.apache.rocketmq.common.TopicFilterType; +import org.apache.rocketmq.common.sysflag.MessageSysFlag; public class MessageExt extends Message { private static final long serialVersionUID = 5720810158625748049L; @@ -45,13 +43,11 @@ public class MessageExt extends Message { private long preparedTransactionOffset; - public MessageExt() { } - public MessageExt(int queueId, long bornTimestamp, SocketAddress bornHost, long storeTimestamp, - SocketAddress storeHost, String msgId) { + SocketAddress storeHost, String msgId) { this.queueId = queueId; this.bornTimestamp = bornTimestamp; this.bornHost = bornHost; @@ -68,16 +64,8 @@ public class MessageExt extends Message { return TopicFilterType.SINGLE_TAG; } - public ByteBuffer getBornHostBytes() { - return socketAddress2ByteBuffer(this.bornHost); - } - - public ByteBuffer getBornHostBytes(ByteBuffer byteBuffer) { - return socketAddress2ByteBuffer(this.bornHost, byteBuffer); - } - private static ByteBuffer socketAddress2ByteBuffer(final SocketAddress socketAddress, final ByteBuffer byteBuffer) { - InetSocketAddress inetSocketAddress = (InetSocketAddress) socketAddress; + InetSocketAddress inetSocketAddress = (InetSocketAddress)socketAddress; byteBuffer.put(inetSocketAddress.getAddress().getAddress(), 0, 4); byteBuffer.putInt(inetSocketAddress.getPort()); byteBuffer.flip(); @@ -89,6 +77,14 @@ public class MessageExt extends Message { return socketAddress2ByteBuffer(socketAddress, byteBuffer); } + public ByteBuffer getBornHostBytes() { + return socketAddress2ByteBuffer(this.bornHost); + } + + public ByteBuffer getBornHostBytes(ByteBuffer byteBuffer) { + return socketAddress2ByteBuffer(this.bornHost, byteBuffer); + } + public ByteBuffer getStoreHostBytes() { return socketAddress2ByteBuffer(this.storeHost); } @@ -123,7 +119,7 @@ public class MessageExt extends Message { public String getBornHostString() { if (this.bornHost != null) { - InetSocketAddress inetSocketAddress = (InetSocketAddress) this.bornHost; + InetSocketAddress inetSocketAddress = (InetSocketAddress)this.bornHost; return inetSocketAddress.getAddress().getHostAddress(); } @@ -132,7 +128,7 @@ public class MessageExt extends Message { public String getBornHostNameString() { if (this.bornHost != null) { - InetSocketAddress inetSocketAddress = (InetSocketAddress) this.bornHost; + InetSocketAddress inetSocketAddress = (InetSocketAddress)this.bornHost; return inetSocketAddress.getAddress().getHostName(); } @@ -207,29 +203,25 @@ public class MessageExt extends Message { return reconsumeTimes; } - public void setReconsumeTimes(int reconsumeTimes) { this.reconsumeTimes = reconsumeTimes; } - public long getPreparedTransactionOffset() { return preparedTransactionOffset; } - public void setPreparedTransactionOffset(long preparedTransactionOffset) { this.preparedTransactionOffset = preparedTransactionOffset; } - @Override public String toString() { return "MessageExt [queueId=" + queueId + ", storeSize=" + storeSize + ", queueOffset=" + queueOffset - + ", sysFlag=" + sysFlag + ", bornTimestamp=" + bornTimestamp + ", bornHost=" + bornHost - + ", storeTimestamp=" + storeTimestamp + ", storeHost=" + storeHost + ", msgId=" + msgId - + ", commitLogOffset=" + commitLogOffset + ", bodyCRC=" + bodyCRC + ", reconsumeTimes=" - + reconsumeTimes + ", preparedTransactionOffset=" + preparedTransactionOffset - + ", toString()=" + super.toString() + "]"; + + ", sysFlag=" + sysFlag + ", bornTimestamp=" + bornTimestamp + ", bornHost=" + bornHost + + ", storeTimestamp=" + storeTimestamp + ", storeHost=" + storeHost + ", msgId=" + msgId + + ", commitLogOffset=" + commitLogOffset + ", bodyCRC=" + bodyCRC + ", reconsumeTimes=" + + reconsumeTimes + ", preparedTransactionOffset=" + preparedTransactionOffset + + ", toString()=" + super.toString() + "]"; } } diff --git a/common/src/main/java/org/apache/rocketmq/common/message/MessageId.java b/common/src/main/java/org/apache/rocketmq/common/message/MessageId.java index 04dd01f9..0de33184 100644 --- a/common/src/main/java/org/apache/rocketmq/common/message/MessageId.java +++ b/common/src/main/java/org/apache/rocketmq/common/message/MessageId.java @@ -6,45 +6,39 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.message; import java.net.SocketAddress; - public class MessageId { private SocketAddress address; private long offset; - public MessageId(SocketAddress address, long offset) { this.address = address; this.offset = offset; } - public SocketAddress getAddress() { return address; } - public void setAddress(SocketAddress address) { this.address = address; } - public long getOffset() { return offset; } - public void setOffset(long offset) { this.offset = offset; } diff --git a/common/src/main/java/org/apache/rocketmq/common/message/MessageQueue.java b/common/src/main/java/org/apache/rocketmq/common/message/MessageQueue.java index 6274d96f..fa2745d4 100644 --- a/common/src/main/java/org/apache/rocketmq/common/message/MessageQueue.java +++ b/common/src/main/java/org/apache/rocketmq/common/message/MessageQueue.java @@ -6,68 +6,58 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.message; import java.io.Serializable; - public class MessageQueue implements Comparable, Serializable { private static final long serialVersionUID = 6191200464116433425L; private String topic; private String brokerName; private int queueId; - public MessageQueue() { } - public MessageQueue(String topic, String brokerName, int queueId) { this.topic = topic; this.brokerName = brokerName; this.queueId = queueId; } - public String getTopic() { return topic; } - public void setTopic(String topic) { this.topic = topic; } - public String getBrokerName() { return brokerName; } - public void setBrokerName(String brokerName) { this.brokerName = brokerName; } - public int getQueueId() { return queueId; } - public void setQueueId(int queueId) { this.queueId = queueId; } - @Override public int hashCode() { final int prime = 31; @@ -78,7 +68,6 @@ public class MessageQueue implements Comparable, Serializable { return result; } - @Override public boolean equals(Object obj) { if (this == obj) @@ -87,7 +76,7 @@ public class MessageQueue implements Comparable, Serializable { return false; if (getClass() != obj.getClass()) return false; - MessageQueue other = (MessageQueue) obj; + MessageQueue other = (MessageQueue)obj; if (brokerName == null) { if (other.brokerName != null) return false; @@ -103,13 +92,11 @@ public class MessageQueue implements Comparable, Serializable { return true; } - @Override public String toString() { return "MessageQueue [topic=" + topic + ", brokerName=" + brokerName + ", queueId=" + queueId + "]"; } - @Override public int compareTo(MessageQueue o) { { diff --git a/common/src/main/java/org/apache/rocketmq/common/message/MessageQueueForC.java b/common/src/main/java/org/apache/rocketmq/common/message/MessageQueueForC.java index 4a8fb6f1..f5c43c9e 100644 --- a/common/src/main/java/org/apache/rocketmq/common/message/MessageQueueForC.java +++ b/common/src/main/java/org/apache/rocketmq/common/message/MessageQueueForC.java @@ -6,20 +6,19 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.message; import java.io.Serializable; - public class MessageQueueForC implements Comparable, Serializable { private static final long serialVersionUID = 5320967846569962104L; @@ -28,7 +27,6 @@ public class MessageQueueForC implements Comparable, Serializa private int queueId; private long offset; - public MessageQueueForC(String topic, String brokerName, int queueId, long offset) { this.topic = topic; this.brokerName = brokerName; @@ -36,7 +34,6 @@ public class MessageQueueForC implements Comparable, Serializa this.offset = offset; } - @Override public int compareTo(MessageQueueForC o) { int result = this.topic.compareTo(o.topic); @@ -60,7 +57,6 @@ public class MessageQueueForC implements Comparable, Serializa } } - @Override public int hashCode() { final int prime = 31; @@ -71,7 +67,6 @@ public class MessageQueueForC implements Comparable, Serializa return result; } - @Override public boolean equals(Object obj) { if (this == obj) @@ -80,7 +75,7 @@ public class MessageQueueForC implements Comparable, Serializa return false; if (getClass() != obj.getClass()) return false; - MessageQueueForC other = (MessageQueueForC) obj; + MessageQueueForC other = (MessageQueueForC)obj; if (brokerName == null) { if (other.brokerName != null) return false; @@ -100,49 +95,40 @@ public class MessageQueueForC implements Comparable, Serializa return true; } - @Override public String toString() { return "MessageQueueForC [topic=" + topic + ", brokerName=" + brokerName + ", queueId=" + queueId - + ", offset=" + offset + "]"; + + ", offset=" + offset + "]"; } - public String getTopic() { return topic; } - public void setTopic(String topic) { this.topic = topic; } - public String getBrokerName() { return brokerName; } - public void setBrokerName(String brokerName) { this.brokerName = brokerName; } - public int getQueueId() { return queueId; } - public void setQueueId(int queueId) { this.queueId = queueId; } - public long getOffset() { return offset; } - public void setOffset(long offset) { this.offset = offset; } diff --git a/common/src/main/java/org/apache/rocketmq/common/message/MessageType.java b/common/src/main/java/org/apache/rocketmq/common/message/MessageType.java index a1913a5d..c6497448 100644 --- a/common/src/main/java/org/apache/rocketmq/common/message/MessageType.java +++ b/common/src/main/java/org/apache/rocketmq/common/message/MessageType.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.message; diff --git a/common/src/main/java/org/apache/rocketmq/common/namesrv/NamesrvConfig.java b/common/src/main/java/org/apache/rocketmq/common/namesrv/NamesrvConfig.java index fe3e8e32..d58ccf25 100644 --- a/common/src/main/java/org/apache/rocketmq/common/namesrv/NamesrvConfig.java +++ b/common/src/main/java/org/apache/rocketmq/common/namesrv/NamesrvConfig.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: NamesrvConfig.java 1839 2013-05-16 02:12:02Z vintagewang@apache.org $ */ /** @@ -20,14 +22,12 @@ */ package org.apache.rocketmq.common.namesrv; +import java.io.File; import org.apache.rocketmq.common.MixAll; import org.apache.rocketmq.common.constant.LoggerName; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; - - /** * */ @@ -53,37 +53,30 @@ public class NamesrvConfig { return rocketmqHome; } - public void setRocketmqHome(String rocketmqHome) { this.rocketmqHome = rocketmqHome; } - public String getKvConfigPath() { return kvConfigPath; } - public void setKvConfigPath(String kvConfigPath) { this.kvConfigPath = kvConfigPath; } - public String getProductEnvName() { return productEnvName; } - public void setProductEnvName(String productEnvName) { this.productEnvName = productEnvName; } - public boolean isClusterTest() { return clusterTest; } - public void setClusterTest(boolean clusterTest) { this.clusterTest = clusterTest; } diff --git a/common/src/main/java/org/apache/rocketmq/common/namesrv/NamesrvUtil.java b/common/src/main/java/org/apache/rocketmq/common/namesrv/NamesrvUtil.java index 2b0a1ed4..33ac4bd6 100644 --- a/common/src/main/java/org/apache/rocketmq/common/namesrv/NamesrvUtil.java +++ b/common/src/main/java/org/apache/rocketmq/common/namesrv/NamesrvUtil.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.namesrv; diff --git a/common/src/main/java/org/apache/rocketmq/common/namesrv/RegisterBrokerResult.java b/common/src/main/java/org/apache/rocketmq/common/namesrv/RegisterBrokerResult.java index d74b4777..f94d1384 100644 --- a/common/src/main/java/org/apache/rocketmq/common/namesrv/RegisterBrokerResult.java +++ b/common/src/main/java/org/apache/rocketmq/common/namesrv/RegisterBrokerResult.java @@ -6,51 +6,44 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.namesrv; import org.apache.rocketmq.common.protocol.body.KVTable; - public class RegisterBrokerResult { private String haServerAddr; private String masterAddr; private KVTable kvTable; - public String getHaServerAddr() { return haServerAddr; } - public void setHaServerAddr(String haServerAddr) { this.haServerAddr = haServerAddr; } - public String getMasterAddr() { return masterAddr; } - public void setMasterAddr(String masterAddr) { this.masterAddr = masterAddr; } - public KVTable getKvTable() { return kvTable; } - public void setKvTable(KVTable kvTable) { this.kvTable = kvTable; } diff --git a/common/src/main/java/org/apache/rocketmq/common/namesrv/TopAddressing.java b/common/src/main/java/org/apache/rocketmq/common/namesrv/TopAddressing.java index 15a2f135..4f0dfce6 100644 --- a/common/src/main/java/org/apache/rocketmq/common/namesrv/TopAddressing.java +++ b/common/src/main/java/org/apache/rocketmq/common/namesrv/TopAddressing.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: TopAddressing.java 1831 2013-05-16 01:39:51Z vintagewang@apache.org $ */ /** @@ -20,6 +22,7 @@ */ package org.apache.rocketmq.common.namesrv; +import java.io.IOException; import org.apache.rocketmq.common.MixAll; import org.apache.rocketmq.common.UtilAll; import org.apache.rocketmq.common.constant.LoggerName; @@ -28,26 +31,36 @@ import org.apache.rocketmq.common.utils.HttpTinyClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; - - public class TopAddressing { private static final Logger log = LoggerFactory.getLogger(LoggerName.COMMON_LOGGER_NAME); private String nsAddr; private String wsAddr; private String unitName; - public TopAddressing(final String wsAddr) { this(wsAddr, null); } - public TopAddressing(final String wsAddr, final String unitName) { this.wsAddr = wsAddr; this.unitName = unitName; } + private static String clearNewLine(final String str) { + String newString = str.trim(); + int index = newString.indexOf("\r"); + if (index != -1) { + return newString.substring(0, index); + } + + index = newString.indexOf("\n"); + if (index != -1) { + return newString.substring(0, index); + } + + return newString; + } + public final String fetchNSAddr() { return fetchNSAddr(true, 3000); } @@ -77,7 +90,7 @@ public class TopAddressing { if (verbose) { String errorMsg = - "connect to " + url + " failed, maybe the domain name " + MixAll.WS_DOMAIN_NAME + " not bind in /etc/hosts"; + "connect to " + url + " failed, maybe the domain name " + MixAll.WS_DOMAIN_NAME + " not bind in /etc/hosts"; errorMsg += FAQUrl.suggestTodo(FAQUrl.NAME_SERVER_ADDR_NOT_EXIST_URL); log.warn(errorMsg); @@ -85,26 +98,10 @@ public class TopAddressing { return null; } - private static String clearNewLine(final String str) { - String newString = str.trim(); - int index = newString.indexOf("\r"); - if (index != -1) { - return newString.substring(0, index); - } - - index = newString.indexOf("\n"); - if (index != -1) { - return newString.substring(0, index); - } - - return newString; - } - public String getNsAddr() { return nsAddr; } - public void setNsAddr(String nsAddr) { this.nsAddr = nsAddr; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/MQProtosHelper.java b/common/src/main/java/org/apache/rocketmq/common/protocol/MQProtosHelper.java index 0ea12eba..bbe80f0b 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/MQProtosHelper.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/MQProtosHelper.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol; @@ -24,15 +24,14 @@ import org.apache.rocketmq.remoting.exception.RemotingSendRequestException; import org.apache.rocketmq.remoting.exception.RemotingTimeoutException; import org.apache.rocketmq.remoting.protocol.RemotingCommand; - public class MQProtosHelper { public static boolean registerBrokerToNameServer(final String nsaddr, final String brokerAddr, - final long timeoutMillis) { + final long timeoutMillis) { RegisterBrokerRequestHeader requestHeader = new RegisterBrokerRequestHeader(); requestHeader.setBrokerAddr(brokerAddr); RemotingCommand request = - RemotingCommand.createRequestCommand(RequestCode.REGISTER_BROKER, requestHeader); + RemotingCommand.createRequestCommand(RequestCode.REGISTER_BROKER, requestHeader); try { RemotingCommand response = RemotingHelper.invokeSync(nsaddr, request, timeoutMillis); diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/RequestCode.java b/common/src/main/java/org/apache/rocketmq/common/protocol/RequestCode.java index d8787262..217dba52 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/RequestCode.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/RequestCode.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol; @@ -87,7 +87,6 @@ public class RequestCode { public static final int GET_PRODUCER_CONNECTION_LIST = 204; public static final int WIPE_WRITE_PERM_OF_BROKER = 205; - public static final int GET_ALL_TOPIC_LIST_FROM_NAMESERVER = 206; public static final int DELETE_SUBSCRIPTIONGROUP = 207; @@ -103,13 +102,11 @@ public class RequestCode { public static final int WHO_CONSUME_THE_MESSAGE = 214; - public static final int DELETE_TOPIC_IN_BROKER = 215; public static final int DELETE_TOPIC_IN_NAMESRV = 216; public static final int GET_KVLIST_BY_NAMESPACE = 219; - public static final int RESET_CONSUMER_CLIENT_OFFSET = 220; public static final int GET_CONSUMER_STATUS_FROM_CLIENT = 221; @@ -118,7 +115,6 @@ public class RequestCode { public static final int INVOKE_BROKER_TO_GET_CONSUMER_STATUS = 223; - public static final int QUERY_TOPIC_CONSUME_BY_WHO = 300; public static final int GET_TOPICS_BY_CLUSTER = 224; diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/ResponseCode.java b/common/src/main/java/org/apache/rocketmq/common/protocol/ResponseCode.java index a5b4e2ef..11ed9c31 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/ResponseCode.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/ResponseCode.java @@ -6,20 +6,19 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol; import org.apache.rocketmq.remoting.protocol.RemotingSysResponseCode; - public class ResponseCode extends RemotingSysResponseCode { public static final int FLUSH_DISK_TIMEOUT = 10; @@ -63,15 +62,11 @@ public class ResponseCode extends RemotingSysResponseCode { public static final int TRANSACTION_STATE_GROUP_WRONG = 203; public static final int NO_BUYER_ID = 204; - public static final int NOT_IN_CURRENT_UNIT = 205; - public static final int CONSUMER_NOT_ONLINE = 206; - public static final int CONSUME_MSG_TIMEOUT = 207; - public static final int NO_MESSAGE = 208; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/body/BrokerStatsData.java b/common/src/main/java/org/apache/rocketmq/common/protocol/body/BrokerStatsData.java index f1ac124f..4aa3279a 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/body/BrokerStatsData.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/body/BrokerStatsData.java @@ -6,20 +6,19 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.body; import org.apache.rocketmq.remoting.protocol.RemotingSerializable; - public class BrokerStatsData extends RemotingSerializable { private BrokerStatsItem statsMinute; @@ -28,32 +27,26 @@ public class BrokerStatsData extends RemotingSerializable { private BrokerStatsItem statsDay; - public BrokerStatsItem getStatsMinute() { return statsMinute; } - public void setStatsMinute(BrokerStatsItem statsMinute) { this.statsMinute = statsMinute; } - public BrokerStatsItem getStatsHour() { return statsHour; } - public void setStatsHour(BrokerStatsItem statsHour) { this.statsHour = statsHour; } - public BrokerStatsItem getStatsDay() { return statsDay; } - public void setStatsDay(BrokerStatsItem statsDay) { this.statsDay = statsDay; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/body/BrokerStatsItem.java b/common/src/main/java/org/apache/rocketmq/common/protocol/body/BrokerStatsItem.java index 904770f4..e789e0a2 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/body/BrokerStatsItem.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/body/BrokerStatsItem.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.body; @@ -22,32 +22,26 @@ public class BrokerStatsItem { private double tps; private double avgpt; - public long getSum() { return sum; } - public void setSum(long sum) { this.sum = sum; } - public double getTps() { return tps; } - public void setTps(double tps) { this.tps = tps; } - public double getAvgpt() { return avgpt; } - public void setAvgpt(double avgpt) { this.avgpt = avgpt; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/body/CMResult.java b/common/src/main/java/org/apache/rocketmq/common/protocol/body/CMResult.java index 85eda7bd..7dee8fbe 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/body/CMResult.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/body/CMResult.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.body; diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/body/ClusterInfo.java b/common/src/main/java/org/apache/rocketmq/common/protocol/body/ClusterInfo.java index a88616f2..dfb045d2 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/body/ClusterInfo.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/body/ClusterInfo.java @@ -6,51 +6,44 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.body; -import org.apache.rocketmq.common.protocol.route.BrokerData; -import org.apache.rocketmq.remoting.protocol.RemotingSerializable; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Set; - +import org.apache.rocketmq.common.protocol.route.BrokerData; +import org.apache.rocketmq.remoting.protocol.RemotingSerializable; public class ClusterInfo extends RemotingSerializable { private HashMap brokerAddrTable; private HashMap> clusterAddrTable; - public HashMap getBrokerAddrTable() { return brokerAddrTable; } - public void setBrokerAddrTable(HashMap brokerAddrTable) { this.brokerAddrTable = brokerAddrTable; } - public HashMap> getClusterAddrTable() { return clusterAddrTable; } - public void setClusterAddrTable(HashMap> clusterAddrTable) { this.clusterAddrTable = clusterAddrTable; } - public String[] retrieveAllAddrByCluster(String cluster) { List addrs = new ArrayList(); if (clusterAddrTable.containsKey(cluster)) { @@ -63,11 +56,10 @@ public class ClusterInfo extends RemotingSerializable { } } - return addrs.toArray(new String[]{}); + return addrs.toArray(new String[] {}); } - public String[] retrieveAllClusterNames() { - return clusterAddrTable.keySet().toArray(new String[]{}); + return clusterAddrTable.keySet().toArray(new String[] {}); } } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/body/Connection.java b/common/src/main/java/org/apache/rocketmq/common/protocol/body/Connection.java index 76f09216..c9da1046 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/body/Connection.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/body/Connection.java @@ -6,62 +6,53 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.body; import org.apache.rocketmq.remoting.protocol.LanguageCode; - public class Connection { private String clientId; private String clientAddr; private LanguageCode language; private int version; - public String getClientId() { return clientId; } - public void setClientId(String clientId) { this.clientId = clientId; } - public String getClientAddr() { return clientAddr; } - public void setClientAddr(String clientAddr) { this.clientAddr = clientAddr; } - public LanguageCode getLanguage() { return language; } - public void setLanguage(LanguageCode language) { this.language = language; } - public int getVersion() { return version; } - public void setVersion(int version) { this.version = version; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/body/ConsumeByWho.java b/common/src/main/java/org/apache/rocketmq/common/protocol/body/ConsumeByWho.java index 8342144a..8eb62a14 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/body/ConsumeByWho.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/body/ConsumeByWho.java @@ -6,20 +6,18 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.body; -import org.apache.rocketmq.remoting.protocol.RemotingSerializable; - import java.util.HashSet; - +import org.apache.rocketmq.remoting.protocol.RemotingSerializable; /** * @@ -31,52 +29,42 @@ public class ConsumeByWho extends RemotingSerializable { private int queueId; private long offset; - public HashSet getConsumedGroup() { return consumedGroup; } - public void setConsumedGroup(HashSet consumedGroup) { this.consumedGroup = consumedGroup; } - public HashSet getNotConsumedGroup() { return notConsumedGroup; } - public void setNotConsumedGroup(HashSet notConsumedGroup) { this.notConsumedGroup = notConsumedGroup; } - public String getTopic() { return topic; } - public void setTopic(String topic) { this.topic = topic; } - public int getQueueId() { return queueId; } - public void setQueueId(int queueId) { this.queueId = queueId; } - public long getOffset() { return offset; } - public void setOffset(long offset) { this.offset = offset; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/body/ConsumeMessageDirectlyResult.java b/common/src/main/java/org/apache/rocketmq/common/protocol/body/ConsumeMessageDirectlyResult.java index 9c630102..2020659b 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/body/ConsumeMessageDirectlyResult.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/body/ConsumeMessageDirectlyResult.java @@ -6,20 +6,19 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.body; import org.apache.rocketmq.remoting.protocol.RemotingSerializable; - public class ConsumeMessageDirectlyResult extends RemotingSerializable { private boolean order = false; private boolean autoCommit = true; @@ -27,61 +26,50 @@ public class ConsumeMessageDirectlyResult extends RemotingSerializable { private String remark; private long spentTimeMills; - public boolean isOrder() { return order; } - public void setOrder(boolean order) { this.order = order; } - public boolean isAutoCommit() { return autoCommit; } - public void setAutoCommit(boolean autoCommit) { this.autoCommit = autoCommit; } - public String getRemark() { return remark; } - public void setRemark(String remark) { this.remark = remark; } - public CMResult getConsumeResult() { return consumeResult; } - public void setConsumeResult(CMResult consumeResult) { this.consumeResult = consumeResult; } - public long getSpentTimeMills() { return spentTimeMills; } - public void setSpentTimeMills(long spentTimeMills) { this.spentTimeMills = spentTimeMills; } - @Override public String toString() { return "ConsumeMessageDirectlyResult [order=" + order + ", autoCommit=" + autoCommit - + ", consumeResult=" + consumeResult + ", remark=" + remark + ", spentTimeMills=" - + spentTimeMills + "]"; + + ", consumeResult=" + consumeResult + ", remark=" + remark + ", spentTimeMills=" + + spentTimeMills + "]"; } } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/body/ConsumeStatsList.java b/common/src/main/java/org/apache/rocketmq/common/protocol/body/ConsumeStatsList.java index c9075553..07dc3e44 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/body/ConsumeStatsList.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/body/ConsumeStatsList.java @@ -6,23 +6,21 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.body; -import org.apache.rocketmq.common.admin.ConsumeStats; -import org.apache.rocketmq.remoting.protocol.RemotingSerializable; - import java.util.ArrayList; import java.util.List; import java.util.Map; - +import org.apache.rocketmq.common.admin.ConsumeStats; +import org.apache.rocketmq.remoting.protocol.RemotingSerializable; public class ConsumeStatsList extends RemotingSerializable { private List>> consumeStatsList = new ArrayList>>(); diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/body/ConsumeStatus.java b/common/src/main/java/org/apache/rocketmq/common/protocol/body/ConsumeStatus.java index 35b6a02b..a2276453 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/body/ConsumeStatus.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/body/ConsumeStatus.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.body; @@ -26,62 +26,50 @@ public class ConsumeStatus { private long consumeFailedMsgs; - public double getPullRT() { return pullRT; } - public void setPullRT(double pullRT) { this.pullRT = pullRT; } - public double getPullTPS() { return pullTPS; } - public void setPullTPS(double pullTPS) { this.pullTPS = pullTPS; } - public double getConsumeRT() { return consumeRT; } - public void setConsumeRT(double consumeRT) { this.consumeRT = consumeRT; } - public double getConsumeOKTPS() { return consumeOKTPS; } - public void setConsumeOKTPS(double consumeOKTPS) { this.consumeOKTPS = consumeOKTPS; } - public double getConsumeFailedTPS() { return consumeFailedTPS; } - public void setConsumeFailedTPS(double consumeFailedTPS) { this.consumeFailedTPS = consumeFailedTPS; } - public long getConsumeFailedMsgs() { return consumeFailedMsgs; } - public void setConsumeFailedMsgs(long consumeFailedMsgs) { this.consumeFailedMsgs = consumeFailedMsgs; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/body/ConsumerConnection.java b/common/src/main/java/org/apache/rocketmq/common/protocol/body/ConsumerConnection.java index bc2acad8..1de12e1e 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/body/ConsumerConnection.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/body/ConsumerConnection.java @@ -6,36 +6,33 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.body; +import java.util.HashSet; +import java.util.concurrent.ConcurrentHashMap; import org.apache.rocketmq.common.consumer.ConsumeFromWhere; import org.apache.rocketmq.common.protocol.heartbeat.ConsumeType; import org.apache.rocketmq.common.protocol.heartbeat.MessageModel; import org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData; import org.apache.rocketmq.remoting.protocol.RemotingSerializable; -import java.util.HashSet; -import java.util.concurrent.ConcurrentHashMap; - - public class ConsumerConnection extends RemotingSerializable { private HashSet connectionSet = new HashSet(); private ConcurrentHashMap subscriptionTable = - new ConcurrentHashMap(); + new ConcurrentHashMap(); private ConsumeType consumeType; private MessageModel messageModel; private ConsumeFromWhere consumeFromWhere; - public int computeMinVersion() { int minVersion = Integer.MAX_VALUE; for (Connection c : this.connectionSet) { @@ -47,52 +44,42 @@ public class ConsumerConnection extends RemotingSerializable { return minVersion; } - public HashSet getConnectionSet() { return connectionSet; } - public void setConnectionSet(HashSet connectionSet) { this.connectionSet = connectionSet; } - public ConcurrentHashMap getSubscriptionTable() { return subscriptionTable; } - public void setSubscriptionTable(ConcurrentHashMap subscriptionTable) { this.subscriptionTable = subscriptionTable; } - public ConsumeType getConsumeType() { return consumeType; } - public void setConsumeType(ConsumeType consumeType) { this.consumeType = consumeType; } - public MessageModel getMessageModel() { return messageModel; } - public void setMessageModel(MessageModel messageModel) { this.messageModel = messageModel; } - public ConsumeFromWhere getConsumeFromWhere() { return consumeFromWhere; } - public void setConsumeFromWhere(ConsumeFromWhere consumeFromWhere) { this.consumeFromWhere = consumeFromWhere; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/body/ConsumerOffsetSerializeWrapper.java b/common/src/main/java/org/apache/rocketmq/common/protocol/body/ConsumerOffsetSerializeWrapper.java index 1ce7cf4e..520a99ba 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/body/ConsumerOffsetSerializeWrapper.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/body/ConsumerOffsetSerializeWrapper.java @@ -6,32 +6,28 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.body; -import org.apache.rocketmq.remoting.protocol.RemotingSerializable; - import java.util.concurrent.ConcurrentHashMap; - +import org.apache.rocketmq.remoting.protocol.RemotingSerializable; public class ConsumerOffsetSerializeWrapper extends RemotingSerializable { private ConcurrentHashMap> offsetTable = - new ConcurrentHashMap>(512); - + new ConcurrentHashMap>(512); public ConcurrentHashMap> getOffsetTable() { return offsetTable; } - public void setOffsetTable(ConcurrentHashMap> offsetTable) { this.offsetTable = offsetTable; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/body/ConsumerRunningInfo.java b/common/src/main/java/org/apache/rocketmq/common/protocol/body/ConsumerRunningInfo.java index 9b0b3839..9836b8d3 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/body/ConsumerRunningInfo.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/body/ConsumerRunningInfo.java @@ -17,14 +17,16 @@ package org.apache.rocketmq.common.protocol.body; +import java.util.Iterator; +import java.util.Map.Entry; +import java.util.Properties; +import java.util.TreeMap; +import java.util.TreeSet; import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.common.protocol.heartbeat.ConsumeType; import org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData; import org.apache.rocketmq.remoting.protocol.RemotingSerializable; -import java.util.*; -import java.util.Map.Entry; - public class ConsumerRunningInfo extends RemotingSerializable { public static final String PROP_NAMESERVER_ADDR = "PROP_NAMESERVER_ADDR"; public static final String PROP_THREADPOOL_CORE_SIZE = "PROP_THREADPOOL_CORE_SIZE"; @@ -33,7 +35,6 @@ public class ConsumerRunningInfo extends RemotingSerializable { public static final String PROP_CLIENT_VERSION = "PROP_CLIENT_VERSION"; public static final String PROP_CONSUMER_START_TIMESTAMP = "PROP_CONSUMER_START_TIMESTAMP"; - private Properties properties = new Properties(); private TreeSet subscriptionSet = new TreeSet(); @@ -52,7 +53,7 @@ public class ConsumerRunningInfo extends RemotingSerializable { String property = prev.getProperties().getProperty(ConsumerRunningInfo.PROP_CONSUME_TYPE); if (property == null) { - property = ((ConsumeType) prev.getProperties().get(ConsumerRunningInfo.PROP_CONSUME_TYPE)).name(); + property = ((ConsumeType)prev.getProperties().get(ConsumerRunningInfo.PROP_CONSUME_TYPE)).name(); } push = ConsumeType.valueOf(property) == ConsumeType.CONSUME_PASSIVELY; } @@ -97,22 +98,6 @@ public class ConsumerRunningInfo extends RemotingSerializable { return true; } - public Properties getProperties() { - return properties; - } - - public void setProperties(Properties properties) { - this.properties = properties; - } - - public TreeSet getSubscriptionSet() { - return subscriptionSet; - } - - public void setSubscriptionSet(TreeSet subscriptionSet) { - this.subscriptionSet = subscriptionSet; - } - public static boolean analyzeRebalance(final TreeMap criTable) { return true; } @@ -124,7 +109,7 @@ public class ConsumerRunningInfo extends RemotingSerializable { String property = info.getProperties().getProperty(ConsumerRunningInfo.PROP_CONSUME_TYPE); if (property == null) { - property = ((ConsumeType) info.getProperties().get(ConsumerRunningInfo.PROP_CONSUME_TYPE)).name(); + property = ((ConsumeType)info.getProperties().get(ConsumerRunningInfo.PROP_CONSUME_TYPE)).name(); } push = ConsumeType.valueOf(property) == ConsumeType.CONSUME_PASSIVELY; } @@ -142,32 +127,30 @@ public class ConsumerRunningInfo extends RemotingSerializable { MessageQueue mq = next.getKey(); ProcessQueueInfo pq = next.getValue(); - if (orderMsg) { if (!pq.isLocked()) { sb.append(String.format("%s %s can't lock for a while, %dms%n", // - clientId, // - mq, // - System.currentTimeMillis() - pq.getLastLockTimestamp())); + clientId, // + mq, // + System.currentTimeMillis() - pq.getLastLockTimestamp())); } else { if (pq.isDroped() && (pq.getTryUnlockTimes() > 0)) { sb.append(String.format("%s %s unlock %d times, still failed%n", // - clientId, // - mq, // - pq.getTryUnlockTimes())); + clientId, // + mq, // + pq.getTryUnlockTimes())); } } - } else { long diff = System.currentTimeMillis() - pq.getLastConsumeTimestamp(); if (diff > (1000 * 60) && pq.getCachedMsgCount() > 0) { sb.append(String.format("%s %s can't consume for a while, maybe blocked, %dms%n", // - clientId, // - mq, // - diff)); + clientId, // + mq, // + diff)); } } } @@ -176,6 +159,22 @@ public class ConsumerRunningInfo extends RemotingSerializable { return sb.toString(); } + public Properties getProperties() { + return properties; + } + + public void setProperties(Properties properties) { + this.properties = properties; + } + + public TreeSet getSubscriptionSet() { + return subscriptionSet; + } + + public void setSubscriptionSet(TreeSet subscriptionSet) { + this.subscriptionSet = subscriptionSet; + } + public TreeMap getMqTable() { return mqTable; } @@ -213,10 +212,10 @@ public class ConsumerRunningInfo extends RemotingSerializable { while (it.hasNext()) { SubscriptionData next = it.next(); String item = String.format("%03d Topic: %-40s ClassFilter: %-8s SubExpression: %s%n", // - ++i, // - next.getTopic(), // - next.isClassFilterMode(), // - next.getSubString()); + ++i, // + next.getTopic(), // + next.isClassFilterMode(), // + next.getSubString()); sb.append(item); } @@ -225,20 +224,20 @@ public class ConsumerRunningInfo extends RemotingSerializable { { sb.append("\n\n#Consumer Offset#\n"); sb.append(String.format("%-32s %-32s %-4s %-20s%n", // - "#Topic", // - "#Broker Name", // - "#QID", // - "#Consumer Offset"// + "#Topic", // + "#Broker Name", // + "#QID", // + "#Consumer Offset"// )); Iterator> it = this.mqTable.entrySet().iterator(); while (it.hasNext()) { Entry next = it.next(); String item = String.format("%-32s %-32s %-4d %-20d%n", // - next.getKey().getTopic(), // - next.getKey().getBrokerName(), // - next.getKey().getQueueId(), // - next.getValue().getCommitOffset()); + next.getKey().getTopic(), // + next.getKey().getBrokerName(), // + next.getKey().getQueueId(), // + next.getValue().getCommitOffset()); sb.append(item); } @@ -247,20 +246,20 @@ public class ConsumerRunningInfo extends RemotingSerializable { { sb.append("\n\n#Consumer MQ Detail#\n"); sb.append(String.format("%-32s %-32s %-4s %-20s%n", // - "#Topic", // - "#Broker Name", // - "#QID", // - "#ProcessQueueInfo"// + "#Topic", // + "#Broker Name", // + "#QID", // + "#ProcessQueueInfo"// )); Iterator> it = this.mqTable.entrySet().iterator(); while (it.hasNext()) { Entry next = it.next(); String item = String.format("%-32s %-32s %-4d %s%n", // - next.getKey().getTopic(), // - next.getKey().getBrokerName(), // - next.getKey().getQueueId(), // - next.getValue().toString()); + next.getKey().getTopic(), // + next.getKey().getBrokerName(), // + next.getKey().getQueueId(), // + next.getValue().toString()); sb.append(item); } @@ -269,26 +268,26 @@ public class ConsumerRunningInfo extends RemotingSerializable { { sb.append("\n\n#Consumer RT&TPS#\n"); sb.append(String.format("%-32s %14s %14s %14s %14s %18s %25s%n", // - "#Topic", // - "#Pull RT", // - "#Pull TPS", // - "#Consume RT", // - "#ConsumeOK TPS", // - "#ConsumeFailed TPS", // - "#ConsumeFailedMsgsInHour"// + "#Topic", // + "#Pull RT", // + "#Pull TPS", // + "#Consume RT", // + "#ConsumeOK TPS", // + "#ConsumeFailed TPS", // + "#ConsumeFailedMsgsInHour"// )); Iterator> it = this.statusTable.entrySet().iterator(); while (it.hasNext()) { Entry next = it.next(); String item = String.format("%-32s %14.2f %14.2f %14.2f %14.2f %18.2f %25d%n", // - next.getKey(), // - next.getValue().getPullRT(), // - next.getValue().getPullTPS(), // - next.getValue().getConsumeRT(), // - next.getValue().getConsumeOKTPS(), // - next.getValue().getConsumeFailedTPS(), // - next.getValue().getConsumeFailedMsgs()// + next.getKey(), // + next.getValue().getPullRT(), // + next.getValue().getPullTPS(), // + next.getValue().getConsumeRT(), // + next.getValue().getConsumeOKTPS(), // + next.getValue().getConsumeFailedTPS(), // + next.getValue().getConsumeFailedMsgs()// ); sb.append(item); @@ -307,7 +306,6 @@ public class ConsumerRunningInfo extends RemotingSerializable { return jstack; } - public void setJstack(String jstack) { this.jstack = jstack; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/body/GetConsumerStatusBody.java b/common/src/main/java/org/apache/rocketmq/common/protocol/body/GetConsumerStatusBody.java index d37116ce..1bbd631c 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/body/GetConsumerStatusBody.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/body/GetConsumerStatusBody.java @@ -6,46 +6,40 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.body; -import org.apache.rocketmq.common.message.MessageQueue; -import org.apache.rocketmq.remoting.protocol.RemotingSerializable; - import java.util.HashMap; import java.util.Map; - +import org.apache.rocketmq.common.message.MessageQueue; +import org.apache.rocketmq.remoting.protocol.RemotingSerializable; @Deprecated public class GetConsumerStatusBody extends RemotingSerializable { private Map messageQueueTable = new HashMap(); private Map> consumerTable = - new HashMap>(); - + new HashMap>(); public Map getMessageQueueTable() { return messageQueueTable; } - public void setMessageQueueTable(Map messageQueueTable) { this.messageQueueTable = messageQueueTable; } - public Map> getConsumerTable() { return consumerTable; } - public void setConsumerTable(Map> consumerTable) { this.consumerTable = consumerTable; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/body/GroupList.java b/common/src/main/java/org/apache/rocketmq/common/protocol/body/GroupList.java index e67dd8c3..9f4918bd 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/body/GroupList.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/body/GroupList.java @@ -6,20 +6,18 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.body; -import org.apache.rocketmq.remoting.protocol.RemotingSerializable; - import java.util.HashSet; - +import org.apache.rocketmq.remoting.protocol.RemotingSerializable; /** * @@ -27,12 +25,10 @@ import java.util.HashSet; public class GroupList extends RemotingSerializable { private HashSet groupList = new HashSet(); - public HashSet getGroupList() { return groupList; } - public void setGroupList(HashSet groupList) { this.groupList = groupList; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/body/KVTable.java b/common/src/main/java/org/apache/rocketmq/common/protocol/body/KVTable.java index 18b20a22..7904f763 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/body/KVTable.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/body/KVTable.java @@ -6,20 +6,18 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.body; -import org.apache.rocketmq.remoting.protocol.RemotingSerializable; - import java.util.HashMap; - +import org.apache.rocketmq.remoting.protocol.RemotingSerializable; /** * @@ -27,12 +25,10 @@ import java.util.HashMap; public class KVTable extends RemotingSerializable { private HashMap table = new HashMap(); - public HashMap getTable() { return table; } - public void setTable(HashMap table) { this.table = table; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/body/LockBatchRequestBody.java b/common/src/main/java/org/apache/rocketmq/common/protocol/body/LockBatchRequestBody.java index 59768ff8..97fac5aa 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/body/LockBatchRequestBody.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/body/LockBatchRequestBody.java @@ -6,23 +6,21 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.body; -import org.apache.rocketmq.common.message.MessageQueue; -import org.apache.rocketmq.remoting.protocol.RemotingSerializable; - import java.util.HashSet; import java.util.Set; - +import org.apache.rocketmq.common.message.MessageQueue; +import org.apache.rocketmq.remoting.protocol.RemotingSerializable; /** * @@ -32,32 +30,26 @@ public class LockBatchRequestBody extends RemotingSerializable { private String clientId; private Set mqSet = new HashSet(); - public String getConsumerGroup() { return consumerGroup; } - public void setConsumerGroup(String consumerGroup) { this.consumerGroup = consumerGroup; } - public String getClientId() { return clientId; } - public void setClientId(String clientId) { this.clientId = clientId; } - public Set getMqSet() { return mqSet; } - public void setMqSet(Set mqSet) { this.mqSet = mqSet; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/body/LockBatchResponseBody.java b/common/src/main/java/org/apache/rocketmq/common/protocol/body/LockBatchResponseBody.java index e1a51179..51084381 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/body/LockBatchResponseBody.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/body/LockBatchResponseBody.java @@ -6,23 +6,21 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.body; -import org.apache.rocketmq.common.message.MessageQueue; -import org.apache.rocketmq.remoting.protocol.RemotingSerializable; - import java.util.HashSet; import java.util.Set; - +import org.apache.rocketmq.common.message.MessageQueue; +import org.apache.rocketmq.remoting.protocol.RemotingSerializable; /** * @@ -31,12 +29,10 @@ public class LockBatchResponseBody extends RemotingSerializable { private Set lockOKMQSet = new HashSet(); - public Set getLockOKMQSet() { return lockOKMQSet; } - public void setLockOKMQSet(Set lockOKMQSet) { this.lockOKMQSet = lockOKMQSet; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/body/ProcessQueueInfo.java b/common/src/main/java/org/apache/rocketmq/common/protocol/body/ProcessQueueInfo.java index 0ceaa692..65703f30 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/body/ProcessQueueInfo.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/body/ProcessQueueInfo.java @@ -6,20 +6,19 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.body; import org.apache.rocketmq.common.UtilAll; - public class ProcessQueueInfo { private long commitOffset; @@ -39,147 +38,120 @@ public class ProcessQueueInfo { private long lastPullTimestamp; private long lastConsumeTimestamp; - public long getCommitOffset() { return commitOffset; } - public void setCommitOffset(long commitOffset) { this.commitOffset = commitOffset; } - public long getCachedMsgMinOffset() { return cachedMsgMinOffset; } - public void setCachedMsgMinOffset(long cachedMsgMinOffset) { this.cachedMsgMinOffset = cachedMsgMinOffset; } - public long getCachedMsgMaxOffset() { return cachedMsgMaxOffset; } - public void setCachedMsgMaxOffset(long cachedMsgMaxOffset) { this.cachedMsgMaxOffset = cachedMsgMaxOffset; } - public int getCachedMsgCount() { return cachedMsgCount; } - public void setCachedMsgCount(int cachedMsgCount) { this.cachedMsgCount = cachedMsgCount; } - public long getTransactionMsgMinOffset() { return transactionMsgMinOffset; } - public void setTransactionMsgMinOffset(long transactionMsgMinOffset) { this.transactionMsgMinOffset = transactionMsgMinOffset; } - public long getTransactionMsgMaxOffset() { return transactionMsgMaxOffset; } - public void setTransactionMsgMaxOffset(long transactionMsgMaxOffset) { this.transactionMsgMaxOffset = transactionMsgMaxOffset; } - public int getTransactionMsgCount() { return transactionMsgCount; } - public void setTransactionMsgCount(int transactionMsgCount) { this.transactionMsgCount = transactionMsgCount; } - public boolean isLocked() { return locked; } - public void setLocked(boolean locked) { this.locked = locked; } - public long getTryUnlockTimes() { return tryUnlockTimes; } - public void setTryUnlockTimes(long tryUnlockTimes) { this.tryUnlockTimes = tryUnlockTimes; } - public long getLastLockTimestamp() { return lastLockTimestamp; } - public void setLastLockTimestamp(long lastLockTimestamp) { this.lastLockTimestamp = lastLockTimestamp; } - public boolean isDroped() { return droped; } - public void setDroped(boolean droped) { this.droped = droped; } - public long getLastPullTimestamp() { return lastPullTimestamp; } - public void setLastPullTimestamp(long lastPullTimestamp) { this.lastPullTimestamp = lastPullTimestamp; } - public long getLastConsumeTimestamp() { return lastConsumeTimestamp; } - public void setLastConsumeTimestamp(long lastConsumeTimestamp) { this.lastConsumeTimestamp = lastConsumeTimestamp; } - @Override public String toString() { return "ProcessQueueInfo [commitOffset=" + commitOffset + ", cachedMsgMinOffset=" - + cachedMsgMinOffset + ", cachedMsgMaxOffset=" + cachedMsgMaxOffset + ", cachedMsgCount=" - + cachedMsgCount + ", transactionMsgMinOffset=" + transactionMsgMinOffset - + ", transactionMsgMaxOffset=" + transactionMsgMaxOffset + ", transactionMsgCount=" - + transactionMsgCount + ", locked=" + locked + ", tryUnlockTimes=" + tryUnlockTimes - + ", lastLockTimestamp=" + UtilAll.timeMillisToHumanString(lastLockTimestamp) + ", droped=" - + droped + ", lastPullTimestamp=" + UtilAll.timeMillisToHumanString(lastPullTimestamp) - + ", lastConsumeTimestamp=" + UtilAll.timeMillisToHumanString(lastConsumeTimestamp) + "]"; + + cachedMsgMinOffset + ", cachedMsgMaxOffset=" + cachedMsgMaxOffset + ", cachedMsgCount=" + + cachedMsgCount + ", transactionMsgMinOffset=" + transactionMsgMinOffset + + ", transactionMsgMaxOffset=" + transactionMsgMaxOffset + ", transactionMsgCount=" + + transactionMsgCount + ", locked=" + locked + ", tryUnlockTimes=" + tryUnlockTimes + + ", lastLockTimestamp=" + UtilAll.timeMillisToHumanString(lastLockTimestamp) + ", droped=" + + droped + ", lastPullTimestamp=" + UtilAll.timeMillisToHumanString(lastPullTimestamp) + + ", lastConsumeTimestamp=" + UtilAll.timeMillisToHumanString(lastConsumeTimestamp) + "]"; } } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/body/ProducerConnection.java b/common/src/main/java/org/apache/rocketmq/common/protocol/body/ProducerConnection.java index 99ac6ba9..bc043376 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/body/ProducerConnection.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/body/ProducerConnection.java @@ -6,31 +6,27 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.body; -import org.apache.rocketmq.remoting.protocol.RemotingSerializable; - import java.util.HashSet; - +import org.apache.rocketmq.remoting.protocol.RemotingSerializable; public class ProducerConnection extends RemotingSerializable { private HashSet connectionSet = new HashSet(); - public HashSet getConnectionSet() { return connectionSet; } - public void setConnectionSet(HashSet connectionSet) { this.connectionSet = connectionSet; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/body/QueryConsumeTimeSpanBody.java b/common/src/main/java/org/apache/rocketmq/common/protocol/body/QueryConsumeTimeSpanBody.java index 9daff003..8b95d73f 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/body/QueryConsumeTimeSpanBody.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/body/QueryConsumeTimeSpanBody.java @@ -6,32 +6,28 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.body; -import org.apache.rocketmq.remoting.protocol.RemotingSerializable; - import java.util.ArrayList; import java.util.List; - +import org.apache.rocketmq.remoting.protocol.RemotingSerializable; public class QueryConsumeTimeSpanBody extends RemotingSerializable { List consumeTimeSpanSet = new ArrayList(); - public List getConsumeTimeSpanSet() { return consumeTimeSpanSet; } - public void setConsumeTimeSpanSet(List consumeTimeSpanSet) { this.consumeTimeSpanSet = consumeTimeSpanSet; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/body/QueryCorrectionOffsetBody.java b/common/src/main/java/org/apache/rocketmq/common/protocol/body/QueryCorrectionOffsetBody.java index 18b1ff42..f2be75cf 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/body/QueryCorrectionOffsetBody.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/body/QueryCorrectionOffsetBody.java @@ -6,31 +6,27 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.body; -import org.apache.rocketmq.remoting.protocol.RemotingSerializable; - import java.util.HashMap; import java.util.Map; - +import org.apache.rocketmq.remoting.protocol.RemotingSerializable; public class QueryCorrectionOffsetBody extends RemotingSerializable { private Map correctionOffsets = new HashMap(); - public Map getCorrectionOffsets() { return correctionOffsets; } - public void setCorrectionOffsets(Map correctionOffsets) { this.correctionOffsets = correctionOffsets; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/body/QueueTimeSpan.java b/common/src/main/java/org/apache/rocketmq/common/protocol/body/QueueTimeSpan.java index df1daf92..5d416646 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/body/QueueTimeSpan.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/body/QueueTimeSpan.java @@ -6,23 +6,21 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.body; +import java.util.Date; import org.apache.rocketmq.common.UtilAll; import org.apache.rocketmq.common.message.MessageQueue; -import java.util.Date; - - public class QueueTimeSpan { private MessageQueue messageQueue; private long minTimeStamp; @@ -30,67 +28,54 @@ public class QueueTimeSpan { private long consumeTimeStamp; private long delayTime; - public MessageQueue getMessageQueue() { return messageQueue; } - public void setMessageQueue(MessageQueue messageQueue) { this.messageQueue = messageQueue; } - public long getMinTimeStamp() { return minTimeStamp; } - public void setMinTimeStamp(long minTimeStamp) { this.minTimeStamp = minTimeStamp; } - public long getMaxTimeStamp() { return maxTimeStamp; } - public void setMaxTimeStamp(long maxTimeStamp) { this.maxTimeStamp = maxTimeStamp; } - public long getConsumeTimeStamp() { return consumeTimeStamp; } - public void setConsumeTimeStamp(long consumeTimeStamp) { this.consumeTimeStamp = consumeTimeStamp; } - public String getMinTimeStampStr() { return UtilAll.formatDate(new Date(minTimeStamp), UtilAll.YYYY_MM_DD_HH_MM_SS_SSS); } - public String getMaxTimeStampStr() { return UtilAll.formatDate(new Date(maxTimeStamp), UtilAll.YYYY_MM_DD_HH_MM_SS_SSS); } - public String getConsumeTimeStampStr() { return UtilAll.formatDate(new Date(consumeTimeStamp), UtilAll.YYYY_MM_DD_HH_MM_SS_SSS); } - public long getDelayTime() { return delayTime; } - public void setDelayTime(long delayTime) { this.delayTime = delayTime; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/body/RegisterBrokerBody.java b/common/src/main/java/org/apache/rocketmq/common/protocol/body/RegisterBrokerBody.java index 45a4a298..dfb6f101 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/body/RegisterBrokerBody.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/body/RegisterBrokerBody.java @@ -6,43 +6,37 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.body; -import org.apache.rocketmq.remoting.protocol.RemotingSerializable; - import java.util.ArrayList; import java.util.List; - +import org.apache.rocketmq.remoting.protocol.RemotingSerializable; public class RegisterBrokerBody extends RemotingSerializable { private TopicConfigSerializeWrapper topicConfigSerializeWrapper = new TopicConfigSerializeWrapper(); private List filterServerList = new ArrayList(); - public TopicConfigSerializeWrapper getTopicConfigSerializeWrapper() { return topicConfigSerializeWrapper; } - public void setTopicConfigSerializeWrapper(TopicConfigSerializeWrapper topicConfigSerializeWrapper) { this.topicConfigSerializeWrapper = topicConfigSerializeWrapper; } - public List getFilterServerList() { return filterServerList; } - public void setFilterServerList(List filterServerList) { this.filterServerList = filterServerList; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/body/ResetOffsetBody.java b/common/src/main/java/org/apache/rocketmq/common/protocol/body/ResetOffsetBody.java index cefaa1f1..3a249f07 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/body/ResetOffsetBody.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/body/ResetOffsetBody.java @@ -6,35 +6,31 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.body; +import java.util.Map; import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.remoting.protocol.RemotingSerializable; -import java.util.Map; - - /** * */ public class ResetOffsetBody extends RemotingSerializable { private Map offsetTable; - public Map getOffsetTable() { return offsetTable; } - public void setOffsetTable(Map offsetTable) { this.offsetTable = offsetTable; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/body/ResetOffsetBodyForC.java b/common/src/main/java/org/apache/rocketmq/common/protocol/body/ResetOffsetBodyForC.java index 35026054..f566a5ad 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/body/ResetOffsetBodyForC.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/body/ResetOffsetBodyForC.java @@ -6,32 +6,29 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.body; +import java.util.List; import org.apache.rocketmq.common.message.MessageQueueForC; import org.apache.rocketmq.remoting.protocol.RemotingSerializable; -import java.util.List; - public class ResetOffsetBodyForC extends RemotingSerializable { private List offsetTable; - public List getOffsetTable() { return offsetTable; } - public void setOffsetTable(List offsetTable) { this.offsetTable = offsetTable; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/body/SubscriptionGroupWrapper.java b/common/src/main/java/org/apache/rocketmq/common/protocol/body/SubscriptionGroupWrapper.java index 88b863e1..bc6a326c 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/body/SubscriptionGroupWrapper.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/body/SubscriptionGroupWrapper.java @@ -6,46 +6,40 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.body; +import java.util.concurrent.ConcurrentHashMap; import org.apache.rocketmq.common.DataVersion; import org.apache.rocketmq.common.subscription.SubscriptionGroupConfig; import org.apache.rocketmq.remoting.protocol.RemotingSerializable; -import java.util.concurrent.ConcurrentHashMap; - - public class SubscriptionGroupWrapper extends RemotingSerializable { private ConcurrentHashMap subscriptionGroupTable = - new ConcurrentHashMap(1024); + new ConcurrentHashMap(1024); private DataVersion dataVersion = new DataVersion(); - public ConcurrentHashMap getSubscriptionGroupTable() { return subscriptionGroupTable; } - public void setSubscriptionGroupTable( - ConcurrentHashMap subscriptionGroupTable) { + ConcurrentHashMap subscriptionGroupTable) { this.subscriptionGroupTable = subscriptionGroupTable; } - public DataVersion getDataVersion() { return dataVersion; } - public void setDataVersion(DataVersion dataVersion) { this.dataVersion = dataVersion; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/body/TopicConfigSerializeWrapper.java b/common/src/main/java/org/apache/rocketmq/common/protocol/body/TopicConfigSerializeWrapper.java index f91caa61..bc4df0cd 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/body/TopicConfigSerializeWrapper.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/body/TopicConfigSerializeWrapper.java @@ -6,45 +6,39 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.body; +import java.util.concurrent.ConcurrentHashMap; import org.apache.rocketmq.common.DataVersion; import org.apache.rocketmq.common.TopicConfig; import org.apache.rocketmq.remoting.protocol.RemotingSerializable; -import java.util.concurrent.ConcurrentHashMap; - - public class TopicConfigSerializeWrapper extends RemotingSerializable { private ConcurrentHashMap topicConfigTable = - new ConcurrentHashMap(); + new ConcurrentHashMap(); private DataVersion dataVersion = new DataVersion(); - public ConcurrentHashMap getTopicConfigTable() { return topicConfigTable; } - public void setTopicConfigTable(ConcurrentHashMap topicConfigTable) { this.topicConfigTable = topicConfigTable; } - public DataVersion getDataVersion() { return dataVersion; } - public void setDataVersion(DataVersion dataVersion) { this.dataVersion = dataVersion; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/body/TopicList.java b/common/src/main/java/org/apache/rocketmq/common/protocol/body/TopicList.java index 4be52ee6..80ebb858 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/body/TopicList.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/body/TopicList.java @@ -6,42 +6,36 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.body; -import org.apache.rocketmq.remoting.protocol.RemotingSerializable; - import java.util.HashSet; import java.util.Set; - +import org.apache.rocketmq.remoting.protocol.RemotingSerializable; public class TopicList extends RemotingSerializable { private Set topicList = new HashSet(); private String brokerAddr; - public Set getTopicList() { return topicList; } - public void setTopicList(Set topicList) { this.topicList = topicList; } - public String getBrokerAddr() { return brokerAddr; } - public void setBrokerAddr(String brokerAddr) { this.brokerAddr = brokerAddr; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/body/UnlockBatchRequestBody.java b/common/src/main/java/org/apache/rocketmq/common/protocol/body/UnlockBatchRequestBody.java index 8142b12a..741c4730 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/body/UnlockBatchRequestBody.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/body/UnlockBatchRequestBody.java @@ -6,55 +6,47 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.body; -import org.apache.rocketmq.common.message.MessageQueue; -import org.apache.rocketmq.remoting.protocol.RemotingSerializable; - import java.util.HashSet; import java.util.Set; - +import org.apache.rocketmq.common.message.MessageQueue; +import org.apache.rocketmq.remoting.protocol.RemotingSerializable; public class UnlockBatchRequestBody extends RemotingSerializable { private String consumerGroup; private String clientId; private Set mqSet = new HashSet(); - public String getConsumerGroup() { return consumerGroup; } - public void setConsumerGroup(String consumerGroup) { this.consumerGroup = consumerGroup; } - public String getClientId() { return clientId; } - public void setClientId(String clientId) { this.clientId = clientId; } - public Set getMqSet() { return mqSet; } - public void setMqSet(Set mqSet) { this.mqSet = mqSet; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/CheckTransactionStateRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/CheckTransactionStateRequestHeader.java index 5b6e67fc..eb08c19d 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/CheckTransactionStateRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/CheckTransactionStateRequestHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: EndTransactionRequestHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -24,7 +26,6 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class CheckTransactionStateRequestHeader implements CommandCustomHeader { @CFNotNull private Long tranStateTableOffset; @@ -33,27 +34,22 @@ public class CheckTransactionStateRequestHeader implements CommandCustomHeader { private String msgId; private String transactionId; - @Override public void checkFields() throws RemotingCommandException { } - public Long getTranStateTableOffset() { return tranStateTableOffset; } - public void setTranStateTableOffset(Long tranStateTableOffset) { this.tranStateTableOffset = tranStateTableOffset; } - public Long getCommitLogOffset() { return commitLogOffset; } - public void setCommitLogOffset(Long commitLogOffset) { this.commitLogOffset = commitLogOffset; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/CheckTransactionStateResponseHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/CheckTransactionStateResponseHeader.java index 805e3aca..7ad665f2 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/CheckTransactionStateResponseHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/CheckTransactionStateResponseHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: EndTransactionResponseHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -25,7 +27,6 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class CheckTransactionStateResponseHeader implements CommandCustomHeader { @CFNotNull private String producerGroup; @@ -36,7 +37,6 @@ public class CheckTransactionStateResponseHeader implements CommandCustomHeader @CFNotNull private Integer commitOrRollback; // TRANSACTION_COMMIT_TYPE - // TRANSACTION_ROLLBACK_TYPE @Override @@ -52,42 +52,34 @@ public class CheckTransactionStateResponseHeader implements CommandCustomHeader throw new RemotingCommandException("commitOrRollback field wrong"); } - public String getProducerGroup() { return producerGroup; } - public void setProducerGroup(String producerGroup) { this.producerGroup = producerGroup; } - public Long getTranStateTableOffset() { return tranStateTableOffset; } - public void setTranStateTableOffset(Long tranStateTableOffset) { this.tranStateTableOffset = tranStateTableOffset; } - public Long getCommitLogOffset() { return commitLogOffset; } - public void setCommitLogOffset(Long commitLogOffset) { this.commitLogOffset = commitLogOffset; } - public Integer getCommitOrRollback() { return commitOrRollback; } - public void setCommitOrRollback(Integer commitOrRollback) { this.commitOrRollback = commitOrRollback; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/CloneGroupOffsetRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/CloneGroupOffsetRequestHeader.java index 1752b88c..46c183ec 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/CloneGroupOffsetRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/CloneGroupOffsetRequestHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: DeleteTopicRequestHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -24,7 +26,6 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class CloneGroupOffsetRequestHeader implements CommandCustomHeader { @CFNotNull private String srcGroup; @@ -33,48 +34,39 @@ public class CloneGroupOffsetRequestHeader implements CommandCustomHeader { private String topic; private boolean offline; - @Override public void checkFields() throws RemotingCommandException { } - public String getDestGroup() { return destGroup; } - public void setDestGroup(String destGroup) { this.destGroup = destGroup; } - public String getTopic() { return topic; } - public void setTopic(String topic) { this.topic = topic; } - public String getSrcGroup() { return srcGroup; } - public void setSrcGroup(String srcGroup) { this.srcGroup = srcGroup; } - public boolean isOffline() { return offline; } - public void setOffline(boolean offline) { this.offline = offline; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/ConsumeMessageDirectlyResultRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/ConsumeMessageDirectlyResultRequestHeader.java index aea30925..917d69fd 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/ConsumeMessageDirectlyResultRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/ConsumeMessageDirectlyResultRequestHeader.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.header; @@ -22,7 +22,6 @@ import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.annotation.CFNullable; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class ConsumeMessageDirectlyResultRequestHeader implements CommandCustomHeader { @CFNotNull private String consumerGroup; @@ -33,47 +32,38 @@ public class ConsumeMessageDirectlyResultRequestHeader implements CommandCustomH @CFNullable private String brokerName; - @Override public void checkFields() throws RemotingCommandException { } - public String getConsumerGroup() { return consumerGroup; } - public void setConsumerGroup(String consumerGroup) { this.consumerGroup = consumerGroup; } - public String getBrokerName() { return brokerName; } - public void setBrokerName(String brokerName) { this.brokerName = brokerName; } - public String getClientId() { return clientId; } - public void setClientId(String clientId) { this.clientId = clientId; } - public String getMsgId() { return msgId; } - public void setMsgId(String msgId) { this.msgId = msgId; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/ConsumerSendMsgBackRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/ConsumerSendMsgBackRequestHeader.java index d108f022..ffde8f70 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/ConsumerSendMsgBackRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/ConsumerSendMsgBackRequestHeader.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.header; @@ -22,7 +22,6 @@ import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.annotation.CFNullable; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - /** * */ @@ -39,86 +38,70 @@ public class ConsumerSendMsgBackRequestHeader implements CommandCustomHeader { private boolean unitMode = false; private Integer maxReconsumeTimes; - @Override public void checkFields() throws RemotingCommandException { } - public Long getOffset() { return offset; } - public void setOffset(Long offset) { this.offset = offset; } - public String getGroup() { return group; } - public void setGroup(String group) { this.group = group; } - public Integer getDelayLevel() { return delayLevel; } - public void setDelayLevel(Integer delayLevel) { this.delayLevel = delayLevel; } - public String getOriginMsgId() { return originMsgId; } - public void setOriginMsgId(String originMsgId) { this.originMsgId = originMsgId; } - public String getOriginTopic() { return originTopic; } - public void setOriginTopic(String originTopic) { this.originTopic = originTopic; } - public boolean isUnitMode() { return unitMode; } - public void setUnitMode(boolean unitMode) { this.unitMode = unitMode; } - public Integer getMaxReconsumeTimes() { return maxReconsumeTimes; } - public void setMaxReconsumeTimes(final Integer maxReconsumeTimes) { this.maxReconsumeTimes = maxReconsumeTimes; } - @Override public String toString() { return "ConsumerSendMsgBackRequestHeader [group=" + group + ", originTopic=" + originTopic + ", originMsgId=" + originMsgId - + ", delayLevel=" + delayLevel + ", unitMode=" + unitMode + ", maxReconsumeTimes=" + maxReconsumeTimes + "]"; + + ", delayLevel=" + delayLevel + ", unitMode=" + unitMode + ", maxReconsumeTimes=" + maxReconsumeTimes + "]"; } } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/CreateTopicRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/CreateTopicRequestHeader.java index fff2b99c..609d46db 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/CreateTopicRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/CreateTopicRequestHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: CreateTopicRequestHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -25,7 +27,6 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class CreateTopicRequestHeader implements CommandCustomHeader { @CFNotNull private String topic; @@ -43,7 +44,6 @@ public class CreateTopicRequestHeader implements CommandCustomHeader { @CFNotNull private Boolean order = false; - @Override public void checkFields() throws RemotingCommandException { try { @@ -53,87 +53,70 @@ public class CreateTopicRequestHeader implements CommandCustomHeader { } } - public TopicFilterType getTopicFilterTypeEnum() { return TopicFilterType.valueOf(this.topicFilterType); } - public String getTopic() { return topic; } - public void setTopic(String topic) { this.topic = topic; } - public String getDefaultTopic() { return defaultTopic; } - public void setDefaultTopic(String defaultTopic) { this.defaultTopic = defaultTopic; } - public Integer getReadQueueNums() { return readQueueNums; } - public void setReadQueueNums(Integer readQueueNums) { this.readQueueNums = readQueueNums; } - public Integer getWriteQueueNums() { return writeQueueNums; } - public void setWriteQueueNums(Integer writeQueueNums) { this.writeQueueNums = writeQueueNums; } - public Integer getPerm() { return perm; } - public void setPerm(Integer perm) { this.perm = perm; } - public String getTopicFilterType() { return topicFilterType; } - public void setTopicFilterType(String topicFilterType) { this.topicFilterType = topicFilterType; } - public Integer getTopicSysFlag() { return topicSysFlag; } - public void setTopicSysFlag(Integer topicSysFlag) { this.topicSysFlag = topicSysFlag; } - public Boolean getOrder() { return order; } - public void setOrder(Boolean order) { this.order = order; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/DeleteSubscriptionGroupRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/DeleteSubscriptionGroupRequestHeader.java index cdb43585..a9f6aa35 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/DeleteSubscriptionGroupRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/DeleteSubscriptionGroupRequestHeader.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.header; @@ -21,22 +21,18 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class DeleteSubscriptionGroupRequestHeader implements CommandCustomHeader { @CFNotNull private String groupName; - @Override public void checkFields() throws RemotingCommandException { } - public String getGroupName() { return groupName; } - public void setGroupName(String groupName) { this.groupName = groupName; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/DeleteTopicRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/DeleteTopicRequestHeader.java index 93e2dd4a..73d65562 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/DeleteTopicRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/DeleteTopicRequestHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: DeleteTopicRequestHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -24,22 +26,18 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class DeleteTopicRequestHeader implements CommandCustomHeader { @CFNotNull private String topic; - @Override public void checkFields() throws RemotingCommandException { } - public String getTopic() { return topic; } - public void setTopic(String topic) { this.topic = topic; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/EndTransactionRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/EndTransactionRequestHeader.java index 2d93e62a..e21016a7 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/EndTransactionRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/EndTransactionRequestHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: EndTransactionRequestHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -26,7 +28,6 @@ import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.annotation.CFNullable; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class EndTransactionRequestHeader implements CommandCustomHeader { @CFNotNull private String producerGroup; @@ -64,62 +65,50 @@ public class EndTransactionRequestHeader implements CommandCustomHeader { throw new RemotingCommandException("commitOrRollback field wrong"); } - public String getProducerGroup() { return producerGroup; } - public void setProducerGroup(String producerGroup) { this.producerGroup = producerGroup; } - public Long getTranStateTableOffset() { return tranStateTableOffset; } - public void setTranStateTableOffset(Long tranStateTableOffset) { this.tranStateTableOffset = tranStateTableOffset; } - public Long getCommitLogOffset() { return commitLogOffset; } - public void setCommitLogOffset(Long commitLogOffset) { this.commitLogOffset = commitLogOffset; } - public Integer getCommitOrRollback() { return commitOrRollback; } - public void setCommitOrRollback(Integer commitOrRollback) { this.commitOrRollback = commitOrRollback; } - public Boolean getFromTransactionCheck() { return fromTransactionCheck; } - public void setFromTransactionCheck(Boolean fromTransactionCheck) { this.fromTransactionCheck = fromTransactionCheck; } - public String getMsgId() { return msgId; } - public void setMsgId(String msgId) { this.msgId = msgId; } @@ -135,8 +124,8 @@ public class EndTransactionRequestHeader implements CommandCustomHeader { @Override public String toString() { return "EndTransactionRequestHeader [producerGroup=" + producerGroup + ", tranStateTableOffset=" - + tranStateTableOffset + ", commitLogOffset=" + commitLogOffset + ", commitOrRollback=" - + commitOrRollback + ", fromTransactionCheck=" + fromTransactionCheck + ", msgId=" + msgId - + "]"; + + tranStateTableOffset + ", commitLogOffset=" + commitLogOffset + ", commitOrRollback=" + + commitOrRollback + ", fromTransactionCheck=" + fromTransactionCheck + ", msgId=" + msgId + + "]"; } } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/EndTransactionResponseHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/EndTransactionResponseHeader.java index 85ad2e40..377a73cf 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/EndTransactionResponseHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/EndTransactionResponseHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: EndTransactionResponseHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -23,7 +25,6 @@ package org.apache.rocketmq.common.protocol.header; import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class EndTransactionResponseHeader implements CommandCustomHeader { @Override diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetAllTopicConfigResponseHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetAllTopicConfigResponseHeader.java index 96030e5c..c8de6417 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetAllTopicConfigResponseHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetAllTopicConfigResponseHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: GetAllTopicConfigResponseHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -23,7 +25,6 @@ package org.apache.rocketmq.common.protocol.header; import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class GetAllTopicConfigResponseHeader implements CommandCustomHeader { @Override diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetBrokerConfigResponseHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetBrokerConfigResponseHeader.java index d15b1e9d..a6b6bc0b 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetBrokerConfigResponseHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetBrokerConfigResponseHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: GetBrokerConfigResponseHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -24,22 +26,18 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class GetBrokerConfigResponseHeader implements CommandCustomHeader { @CFNotNull private String version; - @Override public void checkFields() throws RemotingCommandException { } - public String getVersion() { return version; } - public void setVersion(String version) { this.version = version; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumeStatsInBrokerHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumeStatsInBrokerHeader.java index b17a5589..cc2c2dad 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumeStatsInBrokerHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumeStatsInBrokerHeader.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.header; @@ -21,7 +21,6 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class GetConsumeStatsInBrokerHeader implements CommandCustomHeader { @CFNotNull private boolean isOrder; diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumeStatsRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumeStatsRequestHeader.java index 25d8041f..43bd8a74 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumeStatsRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumeStatsRequestHeader.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.header; @@ -20,35 +20,29 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class GetConsumeStatsRequestHeader implements CommandCustomHeader { @CFNotNull private String consumerGroup; private String topic; - @Override public void checkFields() throws RemotingCommandException { // TODO Auto-generated method stub } - public String getConsumerGroup() { return consumerGroup; } - public void setConsumerGroup(String consumerGroup) { this.consumerGroup = consumerGroup; } - public String getTopic() { return topic; } - public void setTopic(String topic) { this.topic = topic; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumerConnectionListRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumerConnectionListRequestHeader.java index a31b8abb..8f12c79a 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumerConnectionListRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumerConnectionListRequestHeader.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.header; @@ -21,7 +21,6 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - /** * * @@ -30,19 +29,16 @@ public class GetConsumerConnectionListRequestHeader implements CommandCustomHead @CFNotNull private String consumerGroup; - @Override public void checkFields() throws RemotingCommandException { // To change body of implemented methods use File | Settings | File // Templates. } - public String getConsumerGroup() { return consumerGroup; } - public void setConsumerGroup(String consumerGroup) { this.consumerGroup = consumerGroup; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumerListByGroupRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumerListByGroupRequestHeader.java index 0a7e4e4a..ecd224d0 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumerListByGroupRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumerListByGroupRequestHeader.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.header; @@ -21,22 +21,18 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class GetConsumerListByGroupRequestHeader implements CommandCustomHeader { @CFNotNull private String consumerGroup; - @Override public void checkFields() throws RemotingCommandException { } - public String getConsumerGroup() { return consumerGroup; } - public void setConsumerGroup(String consumerGroup) { this.consumerGroup = consumerGroup; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumerListByGroupResponseBody.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumerListByGroupResponseBody.java index 09348310..23e24a85 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumerListByGroupResponseBody.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumerListByGroupResponseBody.java @@ -6,31 +6,27 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.header; -import org.apache.rocketmq.remoting.protocol.RemotingSerializable; - import java.util.List; - +import org.apache.rocketmq.remoting.protocol.RemotingSerializable; public class GetConsumerListByGroupResponseBody extends RemotingSerializable { private List consumerIdList; - public List getConsumerIdList() { return consumerIdList; } - public void setConsumerIdList(List consumerIdList) { this.consumerIdList = consumerIdList; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumerListByGroupResponseHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumerListByGroupResponseHeader.java index 7e2a1747..5d90e893 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumerListByGroupResponseHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumerListByGroupResponseHeader.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.header; @@ -20,7 +20,6 @@ package org.apache.rocketmq.common.protocol.header; import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class GetConsumerListByGroupResponseHeader implements CommandCustomHeader { @Override diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumerRunningInfoRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumerRunningInfoRequestHeader.java index e44a5ac0..f1144e95 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumerRunningInfoRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumerRunningInfoRequestHeader.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.header; @@ -22,7 +22,6 @@ import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.annotation.CFNullable; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class GetConsumerRunningInfoRequestHeader implements CommandCustomHeader { @CFNotNull private String consumerGroup; @@ -31,37 +30,30 @@ public class GetConsumerRunningInfoRequestHeader implements CommandCustomHeader @CFNullable private boolean jstackEnable; - @Override public void checkFields() throws RemotingCommandException { } - public String getConsumerGroup() { return consumerGroup; } - public void setConsumerGroup(String consumerGroup) { this.consumerGroup = consumerGroup; } - public String getClientId() { return clientId; } - public void setClientId(String clientId) { this.clientId = clientId; } - public boolean isJstackEnable() { return jstackEnable; } - public void setJstackEnable(boolean jstackEnable) { this.jstackEnable = jstackEnable; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumerStatusRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumerStatusRequestHeader.java index b577ac89..954df8fe 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumerStatusRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumerStatusRequestHeader.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.header; @@ -22,7 +22,6 @@ import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.annotation.CFNullable; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - /** * */ @@ -34,38 +33,31 @@ public class GetConsumerStatusRequestHeader implements CommandCustomHeader { @CFNullable private String clientAddr; - @Override public void checkFields() throws RemotingCommandException { // TODO Auto-generated method stub } - public String getTopic() { return topic; } - public void setTopic(String topic) { this.topic = topic; } - public String getGroup() { return group; } - public void setGroup(String group) { this.group = group; } - public String getClientAddr() { return clientAddr; } - public void setClientAddr(String clientAddr) { this.clientAddr = clientAddr; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetEarliestMsgStoretimeRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetEarliestMsgStoretimeRequestHeader.java index 9d5b75dd..a99bbc61 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetEarliestMsgStoretimeRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetEarliestMsgStoretimeRequestHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: GetEarliestMsgStoretimeRequestHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -24,35 +26,29 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class GetEarliestMsgStoretimeRequestHeader implements CommandCustomHeader { @CFNotNull private String topic; @CFNotNull private Integer queueId; - @Override public void checkFields() throws RemotingCommandException { // TODO Auto-generated method stub } - public String getTopic() { return topic; } - public void setTopic(String topic) { this.topic = topic; } - public Integer getQueueId() { return queueId; } - public void setQueueId(Integer queueId) { this.queueId = queueId; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetEarliestMsgStoretimeResponseHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetEarliestMsgStoretimeResponseHeader.java index 658388a2..d074a91b 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetEarliestMsgStoretimeResponseHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetEarliestMsgStoretimeResponseHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: GetEarliestMsgStoretimeResponseHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -24,22 +26,18 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class GetEarliestMsgStoretimeResponseHeader implements CommandCustomHeader { @CFNotNull private Long timestamp; - @Override public void checkFields() throws RemotingCommandException { } - public Long getTimestamp() { return timestamp; } - public void setTimestamp(Long timestamp) { this.timestamp = timestamp; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetMaxOffsetRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetMaxOffsetRequestHeader.java index 6d33dcbb..714d1b56 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetMaxOffsetRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetMaxOffsetRequestHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: GetMaxOffsetRequestHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -24,34 +26,28 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class GetMaxOffsetRequestHeader implements CommandCustomHeader { @CFNotNull private String topic; @CFNotNull private Integer queueId; - @Override public void checkFields() throws RemotingCommandException { } - public String getTopic() { return topic; } - public void setTopic(String topic) { this.topic = topic; } - public Integer getQueueId() { return queueId; } - public void setQueueId(Integer queueId) { this.queueId = queueId; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetMaxOffsetResponseHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetMaxOffsetResponseHeader.java index 0143ef8a..e89ef213 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetMaxOffsetResponseHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetMaxOffsetResponseHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: GetMaxOffsetResponseHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -24,22 +26,18 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class GetMaxOffsetResponseHeader implements CommandCustomHeader { @CFNotNull private Long offset; - @Override public void checkFields() throws RemotingCommandException { } - public Long getOffset() { return offset; } - public void setOffset(Long offset) { this.offset = offset; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetMinOffsetRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetMinOffsetRequestHeader.java index ce097271..eef99e27 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetMinOffsetRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetMinOffsetRequestHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: GetMinOffsetRequestHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -24,34 +26,28 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class GetMinOffsetRequestHeader implements CommandCustomHeader { @CFNotNull private String topic; @CFNotNull private Integer queueId; - @Override public void checkFields() throws RemotingCommandException { } - public String getTopic() { return topic; } - public void setTopic(String topic) { this.topic = topic; } - public Integer getQueueId() { return queueId; } - public void setQueueId(Integer queueId) { this.queueId = queueId; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetMinOffsetResponseHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetMinOffsetResponseHeader.java index 366b5138..67b7a018 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetMinOffsetResponseHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetMinOffsetResponseHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: GetMinOffsetResponseHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -24,22 +26,18 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class GetMinOffsetResponseHeader implements CommandCustomHeader { @CFNotNull private Long offset; - @Override public void checkFields() throws RemotingCommandException { } - public Long getOffset() { return offset; } - public void setOffset(Long offset) { this.offset = offset; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetProducerConnectionListRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetProducerConnectionListRequestHeader.java index d6da4a76..62fe94d3 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetProducerConnectionListRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetProducerConnectionListRequestHeader.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.header; @@ -21,24 +21,20 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class GetProducerConnectionListRequestHeader implements CommandCustomHeader { @CFNotNull private String producerGroup; - @Override public void checkFields() throws RemotingCommandException { // To change body of implemented methods use File | Settings | File // Templates. } - public String getProducerGroup() { return producerGroup; } - public void setProducerGroup(String producerGroup) { this.producerGroup = producerGroup; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetTopicStatsInfoRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetTopicStatsInfoRequestHeader.java index f49dee08..3ef4eb3b 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetTopicStatsInfoRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetTopicStatsInfoRequestHeader.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.header; @@ -21,7 +21,6 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - /** * */ @@ -29,17 +28,14 @@ public class GetTopicStatsInfoRequestHeader implements CommandCustomHeader { @CFNotNull private String topic; - @Override public void checkFields() throws RemotingCommandException { } - public String getTopic() { return topic; } - public void setTopic(String topic) { this.topic = topic; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetTopicsByClusterRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetTopicsByClusterRequestHeader.java index 37f5ffae..80ee8f13 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetTopicsByClusterRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetTopicsByClusterRequestHeader.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.header; @@ -21,7 +21,6 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - /** * */ @@ -29,17 +28,14 @@ public class GetTopicsByClusterRequestHeader implements CommandCustomHeader { @CFNotNull private String cluster; - @Override public void checkFields() throws RemotingCommandException { } - public String getCluster() { return cluster; } - public void setCluster(String cluster) { this.cluster = cluster; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/NotifyConsumerIdsChangedRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/NotifyConsumerIdsChangedRequestHeader.java index 35ac787e..c8bfdb74 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/NotifyConsumerIdsChangedRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/NotifyConsumerIdsChangedRequestHeader.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.header; @@ -21,22 +21,18 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class NotifyConsumerIdsChangedRequestHeader implements CommandCustomHeader { @CFNotNull private String consumerGroup; - @Override public void checkFields() throws RemotingCommandException { } - public String getConsumerGroup() { return consumerGroup; } - public void setConsumerGroup(String consumerGroup) { this.consumerGroup = consumerGroup; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/PullMessageRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/PullMessageRequestHeader.java index 7e72ca10..b0e65adf 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/PullMessageRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/PullMessageRequestHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: PullMessageRequestHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -25,7 +27,6 @@ import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.annotation.CFNullable; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class PullMessageRequestHeader implements CommandCustomHeader { @CFNotNull private String consumerGroup; @@ -48,107 +49,86 @@ public class PullMessageRequestHeader implements CommandCustomHeader { @CFNotNull private Long subVersion; - @Override public void checkFields() throws RemotingCommandException { } - public String getConsumerGroup() { return consumerGroup; } - public void setConsumerGroup(String consumerGroup) { this.consumerGroup = consumerGroup; } - public String getTopic() { return topic; } - public void setTopic(String topic) { this.topic = topic; } - public Integer getQueueId() { return queueId; } - public void setQueueId(Integer queueId) { this.queueId = queueId; } - public Long getQueueOffset() { return queueOffset; } - public void setQueueOffset(Long queueOffset) { this.queueOffset = queueOffset; } - public Integer getMaxMsgNums() { return maxMsgNums; } - public void setMaxMsgNums(Integer maxMsgNums) { this.maxMsgNums = maxMsgNums; } - public Integer getSysFlag() { return sysFlag; } - public void setSysFlag(Integer sysFlag) { this.sysFlag = sysFlag; } - public Long getCommitOffset() { return commitOffset; } - public void setCommitOffset(Long commitOffset) { this.commitOffset = commitOffset; } - public Long getSuspendTimeoutMillis() { return suspendTimeoutMillis; } - public void setSuspendTimeoutMillis(Long suspendTimeoutMillis) { this.suspendTimeoutMillis = suspendTimeoutMillis; } - public String getSubscription() { return subscription; } - public void setSubscription(String subscription) { this.subscription = subscription; } - public Long getSubVersion() { return subVersion; } - public void setSubVersion(Long subVersion) { this.subVersion = subVersion; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/PullMessageResponseHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/PullMessageResponseHeader.java index 576a1b47..6907068f 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/PullMessageResponseHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/PullMessageResponseHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: PullMessageResponseHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -24,7 +26,6 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class PullMessageResponseHeader implements CommandCustomHeader { @CFNotNull private Long suggestWhichBrokerId; @@ -35,47 +36,38 @@ public class PullMessageResponseHeader implements CommandCustomHeader { @CFNotNull private Long maxOffset; - @Override public void checkFields() throws RemotingCommandException { } - public Long getNextBeginOffset() { return nextBeginOffset; } - public void setNextBeginOffset(Long nextBeginOffset) { this.nextBeginOffset = nextBeginOffset; } - public Long getMinOffset() { return minOffset; } - public void setMinOffset(Long minOffset) { this.minOffset = minOffset; } - public Long getMaxOffset() { return maxOffset; } - public void setMaxOffset(Long maxOffset) { this.maxOffset = maxOffset; } - public Long getSuggestWhichBrokerId() { return suggestWhichBrokerId; } - public void setSuggestWhichBrokerId(Long suggestWhichBrokerId) { this.suggestWhichBrokerId = suggestWhichBrokerId; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/QueryConsumeTimeSpanRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/QueryConsumeTimeSpanRequestHeader.java index 2afdbd52..83253a33 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/QueryConsumeTimeSpanRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/QueryConsumeTimeSpanRequestHeader.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.header; @@ -21,7 +21,6 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - /** * */ @@ -31,27 +30,22 @@ public class QueryConsumeTimeSpanRequestHeader implements CommandCustomHeader { @CFNotNull private String group; - @Override public void checkFields() throws RemotingCommandException { } - public String getTopic() { return topic; } - public void setTopic(String topic) { this.topic = topic; } - public String getGroup() { return group; } - public void setGroup(String group) { this.group = group; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/QueryConsumerOffsetRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/QueryConsumerOffsetRequestHeader.java index f38f9129..9cbfaa2f 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/QueryConsumerOffsetRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/QueryConsumerOffsetRequestHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: QueryConsumerOffsetRequestHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -24,7 +26,6 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class QueryConsumerOffsetRequestHeader implements CommandCustomHeader { @CFNotNull private String consumerGroup; @@ -33,37 +34,30 @@ public class QueryConsumerOffsetRequestHeader implements CommandCustomHeader { @CFNotNull private Integer queueId; - @Override public void checkFields() throws RemotingCommandException { } - public String getConsumerGroup() { return consumerGroup; } - public void setConsumerGroup(String consumerGroup) { this.consumerGroup = consumerGroup; } - public String getTopic() { return topic; } - public void setTopic(String topic) { this.topic = topic; } - public Integer getQueueId() { return queueId; } - public void setQueueId(Integer queueId) { this.queueId = queueId; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/QueryConsumerOffsetResponseHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/QueryConsumerOffsetResponseHeader.java index db13a39a..51b50ea0 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/QueryConsumerOffsetResponseHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/QueryConsumerOffsetResponseHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: QueryConsumerOffsetResponseHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -24,22 +26,18 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class QueryConsumerOffsetResponseHeader implements CommandCustomHeader { @CFNotNull private Long offset; - @Override public void checkFields() throws RemotingCommandException { } - public Long getOffset() { return offset; } - public void setOffset(Long offset) { this.offset = offset; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/QueryCorrectionOffsetHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/QueryCorrectionOffsetHeader.java index da2b200c..04926fad 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/QueryCorrectionOffsetHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/QueryCorrectionOffsetHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: GetMinOffsetRequestHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -24,7 +26,6 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - /** * * @@ -36,38 +37,31 @@ public class QueryCorrectionOffsetHeader implements CommandCustomHeader { @CFNotNull private String topic; - @Override public void checkFields() throws RemotingCommandException { // TODO Auto-generated method stub } - public String getFilterGroups() { return filterGroups; } - public void setFilterGroups(String filterGroups) { this.filterGroups = filterGroups; } - public String getCompareGroup() { return compareGroup; } - public void setCompareGroup(String compareGroup) { this.compareGroup = compareGroup; } - public String getTopic() { return topic; } - public void setTopic(String topic) { this.topic = topic; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/QueryMessageRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/QueryMessageRequestHeader.java index f7ab8655..5aed5f3d 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/QueryMessageRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/QueryMessageRequestHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: QueryMessageRequestHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -24,7 +26,6 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class QueryMessageRequestHeader implements CommandCustomHeader { @CFNotNull private String topic; @@ -37,58 +38,47 @@ public class QueryMessageRequestHeader implements CommandCustomHeader { @CFNotNull private Long endTimestamp; - @Override public void checkFields() throws RemotingCommandException { } - public String getTopic() { return topic; } - public void setTopic(String topic) { this.topic = topic; } - public String getKey() { return key; } - public void setKey(String key) { this.key = key; } - public Integer getMaxNum() { return maxNum; } - public void setMaxNum(Integer maxNum) { this.maxNum = maxNum; } - public Long getBeginTimestamp() { return beginTimestamp; } - public void setBeginTimestamp(Long beginTimestamp) { this.beginTimestamp = beginTimestamp; } - public Long getEndTimestamp() { return endTimestamp; } - public void setEndTimestamp(Long endTimestamp) { this.endTimestamp = endTimestamp; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/QueryMessageResponseHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/QueryMessageResponseHeader.java index 8e34c73e..14d4d54f 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/QueryMessageResponseHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/QueryMessageResponseHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: QueryMessageResponseHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -24,34 +26,28 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class QueryMessageResponseHeader implements CommandCustomHeader { @CFNotNull private Long indexLastUpdateTimestamp; @CFNotNull private Long indexLastUpdatePhyoffset; - @Override public void checkFields() throws RemotingCommandException { } - public Long getIndexLastUpdateTimestamp() { return indexLastUpdateTimestamp; } - public void setIndexLastUpdateTimestamp(Long indexLastUpdateTimestamp) { this.indexLastUpdateTimestamp = indexLastUpdateTimestamp; } - public Long getIndexLastUpdatePhyoffset() { return indexLastUpdatePhyoffset; } - public void setIndexLastUpdatePhyoffset(Long indexLastUpdatePhyoffset) { this.indexLastUpdatePhyoffset = indexLastUpdatePhyoffset; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/QueryTopicConsumeByWhoRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/QueryTopicConsumeByWhoRequestHeader.java index 0d3e7f4c..a58de58d 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/QueryTopicConsumeByWhoRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/QueryTopicConsumeByWhoRequestHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: QueryMessageRequestHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -24,23 +26,19 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class QueryTopicConsumeByWhoRequestHeader implements CommandCustomHeader { @CFNotNull private String topic; - @Override public void checkFields() throws RemotingCommandException { } - public String getTopic() { return topic; } - public void setTopic(String topic) { this.topic = topic; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/ResetOffsetRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/ResetOffsetRequestHeader.java index 678e85f3..920760bf 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/ResetOffsetRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/ResetOffsetRequestHeader.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.header; @@ -21,7 +21,6 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - /** * * @@ -36,47 +35,38 @@ public class ResetOffsetRequestHeader implements CommandCustomHeader { @CFNotNull private boolean isForce; - public String getTopic() { return topic; } - public void setTopic(String topic) { this.topic = topic; } - public String getGroup() { return group; } - public void setGroup(String group) { this.group = group; } - public long getTimestamp() { return timestamp; } - public void setTimestamp(long timestamp) { this.timestamp = timestamp; } - public boolean isForce() { return isForce; } - public void setForce(boolean isForce) { this.isForce = isForce; } - @Override public void checkFields() throws RemotingCommandException { diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/SearchOffsetRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/SearchOffsetRequestHeader.java index b355aec7..e686f902 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/SearchOffsetRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/SearchOffsetRequestHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: SearchOffsetRequestHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -24,7 +26,6 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class SearchOffsetRequestHeader implements CommandCustomHeader { @CFNotNull private String topic; @@ -33,39 +34,32 @@ public class SearchOffsetRequestHeader implements CommandCustomHeader { @CFNotNull private Long timestamp; - @Override public void checkFields() throws RemotingCommandException { // TODO Auto-generated method stub } - public String getTopic() { return topic; } - public void setTopic(String topic) { this.topic = topic; } - public Integer getQueueId() { return queueId; } - public void setQueueId(Integer queueId) { this.queueId = queueId; } - public Long getTimestamp() { return timestamp; } - public void setTimestamp(Long timestamp) { this.timestamp = timestamp; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/SearchOffsetResponseHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/SearchOffsetResponseHeader.java index 9a74180b..bbac8442 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/SearchOffsetResponseHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/SearchOffsetResponseHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: SearchOffsetResponseHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -24,22 +26,18 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class SearchOffsetResponseHeader implements CommandCustomHeader { @CFNotNull private Long offset; - @Override public void checkFields() throws RemotingCommandException { } - public Long getOffset() { return offset; } - public void setOffset(Long offset) { this.offset = offset; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/SendMessageRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/SendMessageRequestHeader.java index d5af1048..937a86e9 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/SendMessageRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/SendMessageRequestHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: SendMessageRequestHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -25,7 +27,6 @@ import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.annotation.CFNullable; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class SendMessageRequestHeader implements CommandCustomHeader { @CFNotNull private String producerGroup; @@ -51,127 +52,102 @@ public class SendMessageRequestHeader implements CommandCustomHeader { private boolean unitMode = false; private Integer maxReconsumeTimes; - @Override public void checkFields() throws RemotingCommandException { } - public String getProducerGroup() { return producerGroup; } - public void setProducerGroup(String producerGroup) { this.producerGroup = producerGroup; } - public String getTopic() { return topic; } - public void setTopic(String topic) { this.topic = topic; } - public String getDefaultTopic() { return defaultTopic; } - public void setDefaultTopic(String defaultTopic) { this.defaultTopic = defaultTopic; } - public Integer getDefaultTopicQueueNums() { return defaultTopicQueueNums; } - public void setDefaultTopicQueueNums(Integer defaultTopicQueueNums) { this.defaultTopicQueueNums = defaultTopicQueueNums; } - public Integer getQueueId() { return queueId; } - public void setQueueId(Integer queueId) { this.queueId = queueId; } - public Integer getSysFlag() { return sysFlag; } - public void setSysFlag(Integer sysFlag) { this.sysFlag = sysFlag; } - public Long getBornTimestamp() { return bornTimestamp; } - public void setBornTimestamp(Long bornTimestamp) { this.bornTimestamp = bornTimestamp; } - public Integer getFlag() { return flag; } - public void setFlag(Integer flag) { this.flag = flag; } - public String getProperties() { return properties; } - public void setProperties(String properties) { this.properties = properties; } - public Integer getReconsumeTimes() { return reconsumeTimes; } - public void setReconsumeTimes(Integer reconsumeTimes) { this.reconsumeTimes = reconsumeTimes; } - public boolean isUnitMode() { return unitMode; } - public void setUnitMode(boolean isUnitMode) { this.unitMode = isUnitMode; } - public Integer getMaxReconsumeTimes() { return maxReconsumeTimes; } - public void setMaxReconsumeTimes(final Integer maxReconsumeTimes) { this.maxReconsumeTimes = maxReconsumeTimes; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/SendMessageRequestHeaderV2.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/SendMessageRequestHeaderV2.java index 8bf956dc..fe5a12bf 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/SendMessageRequestHeaderV2.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/SendMessageRequestHeaderV2.java @@ -22,7 +22,6 @@ import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.annotation.CFNullable; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - /** * Use short variable name to speed up FastJson deserialization process. */ @@ -94,117 +93,94 @@ public class SendMessageRequestHeaderV2 implements CommandCustomHeader { return a; } - public void setA(String a) { this.a = a; } - public String getB() { return b; } - public void setB(String b) { this.b = b; } - public String getC() { return c; } - public void setC(String c) { this.c = c; } - public Integer getD() { return d; } - public void setD(Integer d) { this.d = d; } - public Integer getE() { return e; } - public void setE(Integer e) { this.e = e; } - public Integer getF() { return f; } - public void setF(Integer f) { this.f = f; } - public Long getG() { return g; } - public void setG(Long g) { this.g = g; } - public Integer getH() { return h; } - public void setH(Integer h) { this.h = h; } - public String getI() { return i; } - public void setI(String i) { this.i = i; } - public Integer getJ() { return j; } - public void setJ(Integer j) { this.j = j; } - public boolean isK() { return k; } - public void setK(boolean k) { this.k = k; } - public Integer getL() { return l; } - public void setL(final Integer l) { this.l = l; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/SendMessageResponseHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/SendMessageResponseHeader.java index 3457ea71..b6a8fa59 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/SendMessageResponseHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/SendMessageResponseHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: SendMessageResponseHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -24,7 +26,6 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class SendMessageResponseHeader implements CommandCustomHeader { @CFNotNull private String msgId; @@ -34,37 +35,30 @@ public class SendMessageResponseHeader implements CommandCustomHeader { private Long queueOffset; private String transactionId; - @Override public void checkFields() throws RemotingCommandException { } - public String getMsgId() { return msgId; } - public void setMsgId(String msgId) { this.msgId = msgId; } - public Integer getQueueId() { return queueId; } - public void setQueueId(Integer queueId) { this.queueId = queueId; } - public Long getQueueOffset() { return queueOffset; } - public void setQueueOffset(Long queueOffset) { this.queueOffset = queueOffset; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/UnregisterClientRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/UnregisterClientRequestHeader.java index 4c5e6f16..106580e7 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/UnregisterClientRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/UnregisterClientRequestHeader.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ /** @@ -25,7 +25,6 @@ import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.annotation.CFNullable; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class UnregisterClientRequestHeader implements CommandCustomHeader { @CFNotNull private String clientID; @@ -35,37 +34,30 @@ public class UnregisterClientRequestHeader implements CommandCustomHeader { @CFNullable private String consumerGroup; - public String getClientID() { return clientID; } - public void setClientID(String clientID) { this.clientID = clientID; } - public String getProducerGroup() { return producerGroup; } - public void setProducerGroup(String producerGroup) { this.producerGroup = producerGroup; } - public String getConsumerGroup() { return consumerGroup; } - public void setConsumerGroup(String consumerGroup) { this.consumerGroup = consumerGroup; } - @Override public void checkFields() throws RemotingCommandException { // TODO Auto-generated method stub diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/UnregisterClientResponseHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/UnregisterClientResponseHeader.java index 92758a1d..68d1c7b3 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/UnregisterClientResponseHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/UnregisterClientResponseHeader.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ /** @@ -23,7 +23,6 @@ package org.apache.rocketmq.common.protocol.header; import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class UnregisterClientResponseHeader implements CommandCustomHeader { @Override diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/UpdateConsumerOffsetRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/UpdateConsumerOffsetRequestHeader.java index 40861c18..5822d8e9 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/UpdateConsumerOffsetRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/UpdateConsumerOffsetRequestHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: UpdateConsumerOffsetRequestHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -24,7 +26,6 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class UpdateConsumerOffsetRequestHeader implements CommandCustomHeader { @CFNotNull private String consumerGroup; @@ -35,47 +36,38 @@ public class UpdateConsumerOffsetRequestHeader implements CommandCustomHeader { @CFNotNull private Long commitOffset; - @Override public void checkFields() throws RemotingCommandException { } - public String getConsumerGroup() { return consumerGroup; } - public void setConsumerGroup(String consumerGroup) { this.consumerGroup = consumerGroup; } - public String getTopic() { return topic; } - public void setTopic(String topic) { this.topic = topic; } - public Integer getQueueId() { return queueId; } - public void setQueueId(Integer queueId) { this.queueId = queueId; } - public Long getCommitOffset() { return commitOffset; } - public void setCommitOffset(Long commitOffset) { this.commitOffset = commitOffset; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/UpdateConsumerOffsetResponseHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/UpdateConsumerOffsetResponseHeader.java index d24c5ad8..c8b60838 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/UpdateConsumerOffsetResponseHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/UpdateConsumerOffsetResponseHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: UpdateConsumerOffsetResponseHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -23,7 +25,6 @@ package org.apache.rocketmq.common.protocol.header; import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class UpdateConsumerOffsetResponseHeader implements CommandCustomHeader { @Override public void checkFields() throws RemotingCommandException { diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/ViewBrokerStatsDataRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/ViewBrokerStatsDataRequestHeader.java index 6d11cd81..3fc0ce48 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/ViewBrokerStatsDataRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/ViewBrokerStatsDataRequestHeader.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.header; @@ -21,35 +21,29 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class ViewBrokerStatsDataRequestHeader implements CommandCustomHeader { @CFNotNull private String statsName; @CFNotNull private String statsKey; - @Override public void checkFields() throws RemotingCommandException { } - public String getStatsName() { return statsName; } - public void setStatsName(String statsName) { this.statsName = statsName; } - public String getStatsKey() { return statsKey; } - public void setStatsKey(String statsKey) { this.statsKey = statsKey; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/ViewMessageRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/ViewMessageRequestHeader.java index 4e8d4029..f1c76227 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/ViewMessageRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/ViewMessageRequestHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: ViewMessageRequestHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -24,22 +26,18 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class ViewMessageRequestHeader implements CommandCustomHeader { @CFNotNull private Long offset; - @Override public void checkFields() throws RemotingCommandException { } - public Long getOffset() { return offset; } - public void setOffset(Long offset) { this.offset = offset; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/ViewMessageResponseHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/ViewMessageResponseHeader.java index 6c92dc0c..b2d97d42 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/ViewMessageResponseHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/ViewMessageResponseHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: ViewMessageResponseHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -23,7 +25,6 @@ package org.apache.rocketmq.common.protocol.header; import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class ViewMessageResponseHeader implements CommandCustomHeader { @Override diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/filtersrv/RegisterFilterServerRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/filtersrv/RegisterFilterServerRequestHeader.java index 480e528a..5a45d29c 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/filtersrv/RegisterFilterServerRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/filtersrv/RegisterFilterServerRequestHeader.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.header.filtersrv; @@ -21,22 +21,18 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class RegisterFilterServerRequestHeader implements CommandCustomHeader { @CFNotNull private String filterServerAddr; - @Override public void checkFields() throws RemotingCommandException { } - public String getFilterServerAddr() { return filterServerAddr; } - public void setFilterServerAddr(String filterServerAddr) { this.filterServerAddr = filterServerAddr; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/filtersrv/RegisterFilterServerResponseHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/filtersrv/RegisterFilterServerResponseHeader.java index a2a52f00..56067ee6 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/filtersrv/RegisterFilterServerResponseHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/filtersrv/RegisterFilterServerResponseHeader.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.header.filtersrv; @@ -21,34 +21,28 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class RegisterFilterServerResponseHeader implements CommandCustomHeader { @CFNotNull private String brokerName; @CFNotNull private long brokerId; - @Override public void checkFields() throws RemotingCommandException { } - public long getBrokerId() { return brokerId; } - public void setBrokerId(long brokerId) { this.brokerId = brokerId; } - public String getBrokerName() { return brokerName; } - public void setBrokerName(String brokerName) { this.brokerName = brokerName; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/filtersrv/RegisterMessageFilterClassRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/filtersrv/RegisterMessageFilterClassRequestHeader.java index 1fc94a97..3b1601e4 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/filtersrv/RegisterMessageFilterClassRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/filtersrv/RegisterMessageFilterClassRequestHeader.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.header.filtersrv; @@ -21,7 +21,6 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class RegisterMessageFilterClassRequestHeader implements CommandCustomHeader { @CFNotNull private String consumerGroup; @@ -32,47 +31,38 @@ public class RegisterMessageFilterClassRequestHeader implements CommandCustomHea @CFNotNull private Integer classCRC; - @Override public void checkFields() throws RemotingCommandException { } - public String getConsumerGroup() { return consumerGroup; } - public void setConsumerGroup(String consumerGroup) { this.consumerGroup = consumerGroup; } - public String getTopic() { return topic; } - public void setTopic(String topic) { this.topic = topic; } - public String getClassName() { return className; } - public void setClassName(String className) { this.className = className; } - public Integer getClassCRC() { return classCRC; } - public void setClassCRC(Integer classCRC) { this.classCRC = classCRC; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/DeleteKVConfigRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/DeleteKVConfigRequestHeader.java index ff196233..f423b116 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/DeleteKVConfigRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/DeleteKVConfigRequestHeader.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.header.namesrv; @@ -21,7 +21,6 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - /** * */ @@ -31,27 +30,22 @@ public class DeleteKVConfigRequestHeader implements CommandCustomHeader { @CFNotNull private String key; - @Override public void checkFields() throws RemotingCommandException { } - public String getNamespace() { return namespace; } - public void setNamespace(String namespace) { this.namespace = namespace; } - public String getKey() { return key; } - public void setKey(String key) { this.key = key; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/DeleteTopicInNamesrvRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/DeleteTopicInNamesrvRequestHeader.java index 44e8cb66..3fd9bb37 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/DeleteTopicInNamesrvRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/DeleteTopicInNamesrvRequestHeader.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.header.namesrv; @@ -20,7 +20,6 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - /** * */ @@ -28,17 +27,14 @@ public class DeleteTopicInNamesrvRequestHeader implements CommandCustomHeader { @CFNotNull private String topic; - @Override public void checkFields() throws RemotingCommandException { } - public String getTopic() { return topic; } - public void setTopic(String topic) { this.topic = topic; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/GetKVConfigRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/GetKVConfigRequestHeader.java index b68976a1..e60163b4 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/GetKVConfigRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/GetKVConfigRequestHeader.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.header.namesrv; @@ -21,7 +21,6 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - /** * */ @@ -31,27 +30,22 @@ public class GetKVConfigRequestHeader implements CommandCustomHeader { @CFNotNull private String key; - @Override public void checkFields() throws RemotingCommandException { } - public String getNamespace() { return namespace; } - public void setNamespace(String namespace) { this.namespace = namespace; } - public String getKey() { return key; } - public void setKey(String key) { this.key = key; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/GetKVConfigResponseHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/GetKVConfigResponseHeader.java index 88e20d9b..71ff698d 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/GetKVConfigResponseHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/GetKVConfigResponseHeader.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.header.namesrv; @@ -21,7 +21,6 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNullable; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - /** * */ @@ -29,17 +28,14 @@ public class GetKVConfigResponseHeader implements CommandCustomHeader { @CFNullable private String value; - @Override public void checkFields() throws RemotingCommandException { } - public String getValue() { return value; } - public void setValue(String value) { this.value = value; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/GetKVListByNamespaceRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/GetKVListByNamespaceRequestHeader.java index eea086e3..32a37481 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/GetKVListByNamespaceRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/GetKVListByNamespaceRequestHeader.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.header.namesrv; @@ -21,7 +21,6 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - /** * */ @@ -29,17 +28,14 @@ public class GetKVListByNamespaceRequestHeader implements CommandCustomHeader { @CFNotNull private String namespace; - @Override public void checkFields() throws RemotingCommandException { } - public String getNamespace() { return namespace; } - public void setNamespace(String namespace) { this.namespace = namespace; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/GetRouteInfoRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/GetRouteInfoRequestHeader.java index 4c01d531..62abaecf 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/GetRouteInfoRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/GetRouteInfoRequestHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: GetRouteInfoRequestHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -24,22 +26,18 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class GetRouteInfoRequestHeader implements CommandCustomHeader { @CFNotNull private String topic; - @Override public void checkFields() throws RemotingCommandException { } - public String getTopic() { return topic; } - public void setTopic(String topic) { this.topic = topic; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/GetRouteInfoResponseHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/GetRouteInfoResponseHeader.java index 9b192d38..a122ceab 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/GetRouteInfoResponseHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/GetRouteInfoResponseHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: GetRouteInfoResponseHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -23,7 +25,6 @@ package org.apache.rocketmq.common.protocol.header.namesrv; import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class GetRouteInfoResponseHeader implements CommandCustomHeader { @Override diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/PutKVConfigRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/PutKVConfigRequestHeader.java index 01e9a5e9..bdc35bba 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/PutKVConfigRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/PutKVConfigRequestHeader.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.header.namesrv; @@ -21,7 +21,6 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class PutKVConfigRequestHeader implements CommandCustomHeader { @CFNotNull private String namespace; @@ -30,37 +29,30 @@ public class PutKVConfigRequestHeader implements CommandCustomHeader { @CFNotNull private String value; - @Override public void checkFields() throws RemotingCommandException { } - public String getNamespace() { return namespace; } - public void setNamespace(String namespace) { this.namespace = namespace; } - public String getKey() { return key; } - public void setKey(String key) { this.key = key; } - public String getValue() { return value; } - public void setValue(String value) { this.value = value; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/RegisterBrokerRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/RegisterBrokerRequestHeader.java index 2ac0102c..dbfecb1d 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/RegisterBrokerRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/RegisterBrokerRequestHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: RegisterBrokerRequestHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -24,7 +26,6 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class RegisterBrokerRequestHeader implements CommandCustomHeader { @CFNotNull private String brokerName; @@ -37,57 +38,46 @@ public class RegisterBrokerRequestHeader implements CommandCustomHeader { @CFNotNull private Long brokerId; - @Override public void checkFields() throws RemotingCommandException { } - public String getBrokerName() { return brokerName; } - public void setBrokerName(String brokerName) { this.brokerName = brokerName; } - public String getBrokerAddr() { return brokerAddr; } - public void setBrokerAddr(String brokerAddr) { this.brokerAddr = brokerAddr; } - public String getClusterName() { return clusterName; } - public void setClusterName(String clusterName) { this.clusterName = clusterName; } - public String getHaServerAddr() { return haServerAddr; } - public void setHaServerAddr(String haServerAddr) { this.haServerAddr = haServerAddr; } - public Long getBrokerId() { return brokerId; } - public void setBrokerId(Long brokerId) { this.brokerId = brokerId; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/RegisterBrokerResponseHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/RegisterBrokerResponseHeader.java index 68b26ecd..2e440468 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/RegisterBrokerResponseHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/RegisterBrokerResponseHeader.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.header.namesrv; @@ -21,7 +21,6 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNullable; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - /** * */ @@ -31,27 +30,22 @@ public class RegisterBrokerResponseHeader implements CommandCustomHeader { @CFNullable private String masterAddr; - @Override public void checkFields() throws RemotingCommandException { } - public String getHaServerAddr() { return haServerAddr; } - public void setHaServerAddr(String haServerAddr) { this.haServerAddr = haServerAddr; } - public String getMasterAddr() { return masterAddr; } - public void setMasterAddr(String masterAddr) { this.masterAddr = masterAddr; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/RegisterOrderTopicRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/RegisterOrderTopicRequestHeader.java index 9381fa9f..0e04c790 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/RegisterOrderTopicRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/RegisterOrderTopicRequestHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: RegisterOrderTopicRequestHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -24,35 +26,29 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class RegisterOrderTopicRequestHeader implements CommandCustomHeader { @CFNotNull private String topic; @CFNotNull private String orderTopicString; - @Override public void checkFields() throws RemotingCommandException { // TODO Auto-generated method stub } - public String getTopic() { return topic; } - public void setTopic(String topic) { this.topic = topic; } - public String getOrderTopicString() { return orderTopicString; } - public void setOrderTopicString(String orderTopicString) { this.orderTopicString = orderTopicString; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/UnRegisterBrokerRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/UnRegisterBrokerRequestHeader.java index e5bdd930..9f6fd27c 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/UnRegisterBrokerRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/UnRegisterBrokerRequestHeader.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: UnRegisterBrokerRequestHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -24,7 +26,6 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public class UnRegisterBrokerRequestHeader implements CommandCustomHeader { @CFNotNull private String brokerName; @@ -35,47 +36,38 @@ public class UnRegisterBrokerRequestHeader implements CommandCustomHeader { @CFNotNull private Long brokerId; - @Override public void checkFields() throws RemotingCommandException { } - public String getBrokerName() { return brokerName; } - public void setBrokerName(String brokerName) { this.brokerName = brokerName; } - public String getBrokerAddr() { return brokerAddr; } - public void setBrokerAddr(String brokerAddr) { this.brokerAddr = brokerAddr; } - public String getClusterName() { return clusterName; } - public void setClusterName(String clusterName) { this.clusterName = clusterName; } - public Long getBrokerId() { return brokerId; } - public void setBrokerId(Long brokerId) { this.brokerId = brokerId; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/WipeWritePermOfBrokerRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/WipeWritePermOfBrokerRequestHeader.java index 3f943d77..b94146b8 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/WipeWritePermOfBrokerRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/WipeWritePermOfBrokerRequestHeader.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.header.namesrv; @@ -20,7 +20,6 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - /** * */ @@ -28,18 +27,15 @@ public class WipeWritePermOfBrokerRequestHeader implements CommandCustomHeader { @CFNotNull private String brokerName; - @Override public void checkFields() throws RemotingCommandException { } - public String getBrokerName() { return brokerName; } - public void setBrokerName(String brokerName) { this.brokerName = brokerName; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/WipeWritePermOfBrokerResponseHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/WipeWritePermOfBrokerResponseHeader.java index 83d28b6a..fd223938 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/WipeWritePermOfBrokerResponseHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/WipeWritePermOfBrokerResponseHeader.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.header.namesrv; @@ -20,7 +20,6 @@ import org.apache.rocketmq.remoting.CommandCustomHeader; import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - /** * */ @@ -28,17 +27,14 @@ public class WipeWritePermOfBrokerResponseHeader implements CommandCustomHeader @CFNotNull private Integer wipeTopicCount; - @Override public void checkFields() throws RemotingCommandException { } - public Integer getWipeTopicCount() { return wipeTopicCount; } - public void setWipeTopicCount(Integer wipeTopicCount) { this.wipeTopicCount = wipeTopicCount; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/heartbeat/ConsumeType.java b/common/src/main/java/org/apache/rocketmq/common/protocol/heartbeat/ConsumeType.java index 923053b6..49fe045e 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/heartbeat/ConsumeType.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/heartbeat/ConsumeType.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: ConsumeType.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -32,7 +34,6 @@ public enum ConsumeType { this.typeCN = typeCN; } - public String getTypeCN() { return typeCN; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/heartbeat/ConsumerData.java b/common/src/main/java/org/apache/rocketmq/common/protocol/heartbeat/ConsumerData.java index 88d99729..c2a0107e 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/heartbeat/ConsumerData.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/heartbeat/ConsumerData.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: ConsumerData.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -20,11 +22,9 @@ */ package org.apache.rocketmq.common.protocol.heartbeat; -import org.apache.rocketmq.common.consumer.ConsumeFromWhere; - import java.util.HashSet; import java.util.Set; - +import org.apache.rocketmq.common.consumer.ConsumeFromWhere; public class ConsumerData { private String groupName; @@ -34,71 +34,58 @@ public class ConsumerData { private Set subscriptionDataSet = new HashSet(); private boolean unitMode; - public String getGroupName() { return groupName; } - public void setGroupName(String groupName) { this.groupName = groupName; } - public ConsumeType getConsumeType() { return consumeType; } - public void setConsumeType(ConsumeType consumeType) { this.consumeType = consumeType; } - public MessageModel getMessageModel() { return messageModel; } - public void setMessageModel(MessageModel messageModel) { this.messageModel = messageModel; } - public ConsumeFromWhere getConsumeFromWhere() { return consumeFromWhere; } - public void setConsumeFromWhere(ConsumeFromWhere consumeFromWhere) { this.consumeFromWhere = consumeFromWhere; } - public Set getSubscriptionDataSet() { return subscriptionDataSet; } - public void setSubscriptionDataSet(Set subscriptionDataSet) { this.subscriptionDataSet = subscriptionDataSet; } - public boolean isUnitMode() { return unitMode; } - public void setUnitMode(boolean isUnitMode) { this.unitMode = isUnitMode; } - @Override public String toString() { return "ConsumerData [groupName=" + groupName + ", consumeType=" + consumeType + ", messageModel=" - + messageModel + ", consumeFromWhere=" + consumeFromWhere + ", unitMode=" + unitMode - + ", subscriptionDataSet=" + subscriptionDataSet + "]"; + + messageModel + ", consumeFromWhere=" + consumeFromWhere + ", unitMode=" + unitMode + + ", subscriptionDataSet=" + subscriptionDataSet + "]"; } } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/heartbeat/HeartbeatData.java b/common/src/main/java/org/apache/rocketmq/common/protocol/heartbeat/HeartbeatData.java index 20a19274..52571743 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/heartbeat/HeartbeatData.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/heartbeat/HeartbeatData.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: HeartbeatData.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -20,51 +22,42 @@ */ package org.apache.rocketmq.common.protocol.heartbeat; -import org.apache.rocketmq.remoting.protocol.RemotingSerializable; - import java.util.HashSet; import java.util.Set; - +import org.apache.rocketmq.remoting.protocol.RemotingSerializable; public class HeartbeatData extends RemotingSerializable { private String clientID; private Set producerDataSet = new HashSet(); private Set consumerDataSet = new HashSet(); - public String getClientID() { return clientID; } - public void setClientID(String clientID) { this.clientID = clientID; } - public Set getProducerDataSet() { return producerDataSet; } - public void setProducerDataSet(Set producerDataSet) { this.producerDataSet = producerDataSet; } - public Set getConsumerDataSet() { return consumerDataSet; } - public void setConsumerDataSet(Set consumerDataSet) { this.consumerDataSet = consumerDataSet; } - @Override public String toString() { return "HeartbeatData [clientID=" + clientID + ", producerDataSet=" + producerDataSet - + ", consumerDataSet=" + consumerDataSet + "]"; + + ", consumerDataSet=" + consumerDataSet + "]"; } } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/heartbeat/MessageModel.java b/common/src/main/java/org/apache/rocketmq/common/protocol/heartbeat/MessageModel.java index 858df3fe..d710502d 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/heartbeat/MessageModel.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/heartbeat/MessageModel.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: MessageModel.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -40,7 +42,6 @@ public enum MessageModel { this.modeCN = modeCN; } - public String getModeCN() { return modeCN; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/heartbeat/ProducerData.java b/common/src/main/java/org/apache/rocketmq/common/protocol/heartbeat/ProducerData.java index 7d3d054d..b7d4c95a 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/heartbeat/ProducerData.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/heartbeat/ProducerData.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: ProducerData.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -23,17 +25,14 @@ package org.apache.rocketmq.common.protocol.heartbeat; public class ProducerData { private String groupName; - public String getGroupName() { return groupName; } - public void setGroupName(String groupName) { this.groupName = groupName; } - @Override public String toString() { return "ProducerData [groupName=" + groupName + "]"; diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/heartbeat/SubscriptionData.java b/common/src/main/java/org/apache/rocketmq/common/protocol/heartbeat/SubscriptionData.java index c1c9f849..8c4292af 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/heartbeat/SubscriptionData.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/heartbeat/SubscriptionData.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: SubscriptionData.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -21,11 +23,9 @@ package org.apache.rocketmq.common.protocol.heartbeat; import com.alibaba.fastjson.annotation.JSONField; - import java.util.HashSet; import java.util.Set; - public class SubscriptionData implements Comparable { public final static String SUB_ALL = "*"; private boolean classFilterMode = false; @@ -38,12 +38,10 @@ public class SubscriptionData implements Comparable { @JSONField(serialize = false) private String filterClassSource; - public SubscriptionData() { } - public SubscriptionData(String topic, String subString) { super(); this.topic = topic; @@ -62,62 +60,50 @@ public class SubscriptionData implements Comparable { return topic; } - public void setTopic(String topic) { this.topic = topic; } - public String getSubString() { return subString; } - public void setSubString(String subString) { this.subString = subString; } - public Set getTagsSet() { return tagsSet; } - public void setTagsSet(Set tagsSet) { this.tagsSet = tagsSet; } - public long getSubVersion() { return subVersion; } - public void setSubVersion(long subVersion) { this.subVersion = subVersion; } - public Set getCodeSet() { return codeSet; } - public void setCodeSet(Set codeSet) { this.codeSet = codeSet; } - public boolean isClassFilterMode() { return classFilterMode; } - public void setClassFilterMode(boolean classFilterMode) { this.classFilterMode = classFilterMode; } - @Override public int hashCode() { final int prime = 31; @@ -130,7 +116,6 @@ public class SubscriptionData implements Comparable { return result; } - @Override public boolean equals(Object obj) { if (this == obj) @@ -139,7 +124,7 @@ public class SubscriptionData implements Comparable { return false; if (getClass() != obj.getClass()) return false; - SubscriptionData other = (SubscriptionData) obj; + SubscriptionData other = (SubscriptionData)obj; if (classFilterMode != other.classFilterMode) return false; if (codeSet == null) { @@ -167,15 +152,13 @@ public class SubscriptionData implements Comparable { return true; } - @Override public String toString() { return "SubscriptionData [classFilterMode=" + classFilterMode + ", topic=" + topic + ", subString=" - + subString + ", tagsSet=" + tagsSet + ", codeSet=" + codeSet + ", subVersion=" + subVersion - + "]"; + + subString + ", tagsSet=" + tagsSet + ", codeSet=" + codeSet + ", subVersion=" + subVersion + + "]"; } - @Override public int compareTo(SubscriptionData other) { String thisValue = this.topic + "@" + this.subString; diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/route/BrokerData.java b/common/src/main/java/org/apache/rocketmq/common/protocol/route/BrokerData.java index 08e82b1a..f79bdb56 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/route/BrokerData.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/route/BrokerData.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: BrokerData.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -20,11 +22,9 @@ */ package org.apache.rocketmq.common.protocol.route; -import org.apache.rocketmq.common.MixAll; - import java.util.HashMap; import java.util.Map; - +import org.apache.rocketmq.common.MixAll; /** * @@ -78,7 +78,7 @@ public class BrokerData implements Comparable { return false; if (getClass() != obj.getClass()) return false; - BrokerData other = (BrokerData) obj; + BrokerData other = (BrokerData)obj; if (brokerAddrs == null) { if (other.brokerAddrs != null) return false; diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/route/QueueData.java b/common/src/main/java/org/apache/rocketmq/common/protocol/route/QueueData.java index 3c72565b..3fe3e2c0 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/route/QueueData.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/route/QueueData.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: QueueData.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -79,7 +81,7 @@ public class QueueData implements Comparable { return false; if (getClass() != obj.getClass()) return false; - QueueData other = (QueueData) obj; + QueueData other = (QueueData)obj; if (brokerName == null) { if (other.brokerName != null) return false; @@ -99,8 +101,8 @@ public class QueueData implements Comparable { @Override public String toString() { return "QueueData [brokerName=" + brokerName + ", readQueueNums=" + readQueueNums - + ", writeQueueNums=" + writeQueueNums + ", perm=" + perm + ", topicSynFlag=" + topicSynFlag - + "]"; + + ", writeQueueNums=" + writeQueueNums + ", perm=" + perm + ", topicSynFlag=" + topicSynFlag + + "]"; } @Override diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/route/TopicRouteData.java b/common/src/main/java/org/apache/rocketmq/common/protocol/route/TopicRouteData.java index 0061c258..64d97264 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/route/TopicRouteData.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/route/TopicRouteData.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: TopicRouteData.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ */ /** @@ -20,12 +22,10 @@ */ package org.apache.rocketmq.common.protocol.route; -import org.apache.rocketmq.remoting.protocol.RemotingSerializable; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; - +import org.apache.rocketmq.remoting.protocol.RemotingSerializable; public class TopicRouteData extends RemotingSerializable { private String orderTopicConf; @@ -33,7 +33,6 @@ public class TopicRouteData extends RemotingSerializable { private List brokerDatas; private HashMap/* Filter Server */> filterServerTable; - public TopicRouteData cloneTopicRouteData() { TopicRouteData topicRouteData = new TopicRouteData(); topicRouteData.setQueueDatas(new ArrayList()); @@ -56,22 +55,18 @@ public class TopicRouteData extends RemotingSerializable { return topicRouteData; } - public List getQueueDatas() { return queueDatas; } - public void setQueueDatas(List queueDatas) { this.queueDatas = queueDatas; } - public List getBrokerDatas() { return brokerDatas; } - public void setBrokerDatas(List brokerDatas) { this.brokerDatas = brokerDatas; } @@ -111,7 +106,7 @@ public class TopicRouteData extends RemotingSerializable { return false; if (getClass() != obj.getClass()) return false; - TopicRouteData other = (TopicRouteData) obj; + TopicRouteData other = (TopicRouteData)obj; if (brokerDatas == null) { if (other.brokerDatas != null) return false; @@ -138,6 +133,6 @@ public class TopicRouteData extends RemotingSerializable { @Override public String toString() { return "TopicRouteData [orderTopicConf=" + orderTopicConf + ", queueDatas=" + queueDatas - + ", brokerDatas=" + brokerDatas + ", filterServerTable=" + filterServerTable + "]"; + + ", brokerDatas=" + brokerDatas + ", filterServerTable=" + filterServerTable + "]"; } } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/topic/OffsetMovedEvent.java b/common/src/main/java/org/apache/rocketmq/common/protocol/topic/OffsetMovedEvent.java index df5ec71c..920685ce 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/topic/OffsetMovedEvent.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/topic/OffsetMovedEvent.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol.topic; @@ -20,57 +20,47 @@ package org.apache.rocketmq.common.protocol.topic; import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.remoting.protocol.RemotingSerializable; - public class OffsetMovedEvent extends RemotingSerializable { private String consumerGroup; private MessageQueue messageQueue; private long offsetRequest; private long offsetNew; - public String getConsumerGroup() { return consumerGroup; } - public void setConsumerGroup(String consumerGroup) { this.consumerGroup = consumerGroup; } - public MessageQueue getMessageQueue() { return messageQueue; } - public void setMessageQueue(MessageQueue messageQueue) { this.messageQueue = messageQueue; } - public long getOffsetRequest() { return offsetRequest; } - public void setOffsetRequest(long offsetRequest) { this.offsetRequest = offsetRequest; } - public long getOffsetNew() { return offsetNew; } - public void setOffsetNew(long offsetNew) { this.offsetNew = offsetNew; } - @Override public String toString() { return "OffsetMovedEvent [consumerGroup=" + consumerGroup + ", messageQueue=" + messageQueue - + ", offsetRequest=" + offsetRequest + ", offsetNew=" + offsetNew + "]"; + + ", offsetRequest=" + offsetRequest + ", offsetNew=" + offsetNew + "]"; } } diff --git a/common/src/main/java/org/apache/rocketmq/common/queue/ConcurrentTreeMap.java b/common/src/main/java/org/apache/rocketmq/common/queue/ConcurrentTreeMap.java index 897988f3..021ba834 100644 --- a/common/src/main/java/org/apache/rocketmq/common/queue/ConcurrentTreeMap.java +++ b/common/src/main/java/org/apache/rocketmq/common/queue/ConcurrentTreeMap.java @@ -6,26 +6,24 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.queue; -import org.apache.rocketmq.common.constant.LoggerName; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.util.Comparator; import java.util.Map; import java.util.TreeMap; import java.util.concurrent.locks.ReentrantLock; - +import org.apache.rocketmq.common.constant.LoggerName; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * thread safe @@ -37,14 +35,12 @@ public class ConcurrentTreeMap { private TreeMap tree; private RoundQueue roundQueue; - public ConcurrentTreeMap(int capacity, Comparator comparator) { tree = new TreeMap(comparator); roundQueue = new RoundQueue(capacity); lock = new ReentrantLock(true); } - public Map.Entry pollFirstEntry() { lock.lock(); try { @@ -54,7 +50,6 @@ public class ConcurrentTreeMap { } } - public V putIfAbsentAndRetExsit(K key, V value) { lock.lock(); try { @@ -66,9 +61,7 @@ public class ConcurrentTreeMap { } log.warn("putIfAbsentAndRetExsit success. {}", key); return exsit; - } - - else { + } else { V exsit = tree.get(key); return exsit; } diff --git a/common/src/main/java/org/apache/rocketmq/common/queue/RoundQueue.java b/common/src/main/java/org/apache/rocketmq/common/queue/RoundQueue.java index 11168e6a..e9f2177b 100644 --- a/common/src/main/java/org/apache/rocketmq/common/queue/RoundQueue.java +++ b/common/src/main/java/org/apache/rocketmq/common/queue/RoundQueue.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.queue; @@ -20,7 +20,6 @@ package org.apache.rocketmq.common.queue; import java.util.LinkedList; import java.util.Queue; - /** * not thread safe * @@ -30,13 +29,11 @@ public class RoundQueue { private Queue queue; private int capacity; - public RoundQueue(int capacity) { this.capacity = capacity; queue = new LinkedList(); } - public boolean put(E e) { boolean ok = false; if (!queue.contains(e)) { diff --git a/common/src/main/java/org/apache/rocketmq/common/running/RunningStats.java b/common/src/main/java/org/apache/rocketmq/common/running/RunningStats.java index 106d1114..6cfd4bf4 100644 --- a/common/src/main/java/org/apache/rocketmq/common/running/RunningStats.java +++ b/common/src/main/java/org/apache/rocketmq/common/running/RunningStats.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.running; diff --git a/common/src/main/java/org/apache/rocketmq/common/stats/MomentStatsItem.java b/common/src/main/java/org/apache/rocketmq/common/stats/MomentStatsItem.java index 58eedb2d..b9fcfb8b 100644 --- a/common/src/main/java/org/apache/rocketmq/common/stats/MomentStatsItem.java +++ b/common/src/main/java/org/apache/rocketmq/common/stats/MomentStatsItem.java @@ -17,13 +17,11 @@ package org.apache.rocketmq.common.stats; -import org.apache.rocketmq.common.UtilAll; -import org.slf4j.Logger; - import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; - +import org.apache.rocketmq.common.UtilAll; +import org.slf4j.Logger; public class MomentStatsItem { @@ -34,16 +32,14 @@ public class MomentStatsItem { private final ScheduledExecutorService scheduledExecutorService; private final Logger log; - public MomentStatsItem(String statsName, String statsKey, - ScheduledExecutorService scheduledExecutorService, Logger log) { + ScheduledExecutorService scheduledExecutorService, Logger log) { this.statsName = statsName; this.statsKey = statsKey; this.scheduledExecutorService = scheduledExecutorService; this.log = log; } - public void init() { this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() { @Override @@ -58,24 +54,21 @@ public class MomentStatsItem { }, Math.abs(UtilAll.computNextMinutesTimeMillis() - System.currentTimeMillis()), 1000 * 60 * 5, TimeUnit.MILLISECONDS); } - public void printAtMinutes() { log.info(String.format("[%s] [%s] Stats Every 5 Minutes, Value: %d", - this.statsName, - this.statsKey, - this.value.get())); + this.statsName, + this.statsKey, + this.value.get())); } public AtomicLong getValue() { return value; } - public String getStatsKey() { return statsKey; } - public String getStatsName() { return statsName; } diff --git a/common/src/main/java/org/apache/rocketmq/common/stats/MomentStatsItemSet.java b/common/src/main/java/org/apache/rocketmq/common/stats/MomentStatsItemSet.java index aba61c76..44cc6039 100644 --- a/common/src/main/java/org/apache/rocketmq/common/stats/MomentStatsItemSet.java +++ b/common/src/main/java/org/apache/rocketmq/common/stats/MomentStatsItemSet.java @@ -17,24 +17,21 @@ package org.apache.rocketmq.common.stats; -import org.apache.rocketmq.common.UtilAll; -import org.slf4j.Logger; - import java.util.Iterator; import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; - +import org.apache.rocketmq.common.UtilAll; +import org.slf4j.Logger; public class MomentStatsItemSet { private final ConcurrentHashMap statsItemTable = - new ConcurrentHashMap(128); + new ConcurrentHashMap(128); private final String statsName; private final ScheduledExecutorService scheduledExecutorService; private final Logger log; - public MomentStatsItemSet(String statsName, ScheduledExecutorService scheduledExecutorService, Logger log) { this.statsName = statsName; this.scheduledExecutorService = scheduledExecutorService; @@ -80,7 +77,7 @@ public class MomentStatsItemSet { MomentStatsItem statsItem = this.statsItemTable.get(statsKey); if (null == statsItem) { statsItem = - new MomentStatsItem(this.statsName, statsKey, this.scheduledExecutorService, this.log); + new MomentStatsItem(this.statsName, statsKey, this.scheduledExecutorService, this.log); MomentStatsItem prev = this.statsItemTable.put(statsKey, statsItem); if (null == prev) { diff --git a/common/src/main/java/org/apache/rocketmq/common/stats/StatsItem.java b/common/src/main/java/org/apache/rocketmq/common/stats/StatsItem.java index 42bb5613..b1703b1c 100644 --- a/common/src/main/java/org/apache/rocketmq/common/stats/StatsItem.java +++ b/common/src/main/java/org/apache/rocketmq/common/stats/StatsItem.java @@ -17,14 +17,12 @@ package org.apache.rocketmq.common.stats; -import org.apache.rocketmq.common.UtilAll; -import org.slf4j.Logger; - import java.util.LinkedList; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; - +import org.apache.rocketmq.common.UtilAll; +import org.slf4j.Logger; public class StatsItem { @@ -34,10 +32,8 @@ public class StatsItem { private final LinkedList csListMinute = new LinkedList(); - private final LinkedList csListHour = new LinkedList(); - private final LinkedList csListDay = new LinkedList(); private final String statsName; @@ -45,19 +41,14 @@ public class StatsItem { private final ScheduledExecutorService scheduledExecutorService; private final Logger log; - public StatsItem(String statsName, String statsKey, ScheduledExecutorService scheduledExecutorService, - Logger log) { + Logger log) { this.statsName = statsName; this.statsKey = statsKey; this.scheduledExecutorService = scheduledExecutorService; this.log = log; } - public StatsSnapshot getStatsDataInMinute() { - return computeStatsData(this.csListMinute); - } - private static StatsSnapshot computeStatsData(final LinkedList csList) { StatsSnapshot statsSnapshot = new StatsSnapshot(); synchronized (csList) { @@ -84,6 +75,10 @@ public class StatsItem { return statsSnapshot; } + public StatsSnapshot getStatsDataInMinute() { + return computeStatsData(this.csListMinute); + } + public StatsSnapshot getStatsDataInHour() { return computeStatsData(this.csListHour); } @@ -104,7 +99,6 @@ public class StatsItem { } }, 0, 10, TimeUnit.SECONDS); - this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() { @Override public void run() { @@ -115,7 +109,6 @@ public class StatsItem { } }, 0, 10, TimeUnit.MINUTES); - this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() { @Override public void run() { @@ -126,7 +119,6 @@ public class StatsItem { } }, 0, 1, TimeUnit.HOURS); - this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() { @Override public void run() { @@ -137,7 +129,6 @@ public class StatsItem { } }, Math.abs(UtilAll.computNextMinutesTimeMillis() - System.currentTimeMillis()), 1000 * 60, TimeUnit.MILLISECONDS); - this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() { @Override public void run() { @@ -148,7 +139,6 @@ public class StatsItem { } }, Math.abs(UtilAll.computNextHourTimeMillis() - System.currentTimeMillis()), 1000 * 60 * 60, TimeUnit.MILLISECONDS); - this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() { @Override public void run() { @@ -163,7 +153,7 @@ public class StatsItem { public void samplingInSeconds() { synchronized (this.csListMinute) { this.csListMinute.add(new CallSnapshot(System.currentTimeMillis(), this.times.get(), this.value - .get())); + .get())); if (this.csListMinute.size() > 7) { this.csListMinute.removeFirst(); } @@ -173,7 +163,7 @@ public class StatsItem { public void samplingInMinutes() { synchronized (this.csListHour) { this.csListHour.add(new CallSnapshot(System.currentTimeMillis(), this.times.get(), this.value - .get())); + .get())); if (this.csListHour.size() > 7) { this.csListHour.removeFirst(); } @@ -183,7 +173,7 @@ public class StatsItem { public void samplingInHour() { synchronized (this.csListDay) { this.csListDay.add(new CallSnapshot(System.currentTimeMillis(), this.times.get(), this.value - .get())); + .get())); if (this.csListDay.size() > 25) { this.csListDay.removeFirst(); } @@ -193,61 +183,56 @@ public class StatsItem { public void printAtMinutes() { StatsSnapshot ss = computeStatsData(this.csListMinute); log.info(String.format("[%s] [%s] Stats In One Minute, SUM: %d TPS: %.2f AVGPT: %.2f", - this.statsName, - this.statsKey, - ss.getSum(), - ss.getTps(), - ss.getAvgpt())); + this.statsName, + this.statsKey, + ss.getSum(), + ss.getTps(), + ss.getAvgpt())); } public void printAtHour() { StatsSnapshot ss = computeStatsData(this.csListHour); log.info(String.format("[%s] [%s] Stats In One Hour, SUM: %d TPS: %.2f AVGPT: %.2f", - this.statsName, - this.statsKey, - ss.getSum(), - ss.getTps(), - ss.getAvgpt())); + this.statsName, + this.statsKey, + ss.getSum(), + ss.getTps(), + ss.getAvgpt())); } public void printAtDay() { StatsSnapshot ss = computeStatsData(this.csListDay); log.info(String.format("[%s] [%s] Stats In One Day, SUM: %d TPS: %.2f AVGPT: %.2f", - this.statsName, - this.statsKey, - ss.getSum(), - ss.getTps(), - ss.getAvgpt())); + this.statsName, + this.statsKey, + ss.getSum(), + ss.getTps(), + ss.getAvgpt())); } public AtomicLong getValue() { return value; } - public String getStatsKey() { return statsKey; } - public String getStatsName() { return statsName; } - public AtomicLong getTimes() { return times; } } - class CallSnapshot { private final long timestamp; private final long times; private final long value; - public CallSnapshot(long timestamp, long times, long value) { super(); this.timestamp = timestamp; @@ -255,17 +240,14 @@ class CallSnapshot { this.value = value; } - public long getTimestamp() { return timestamp; } - public long getTimes() { return times; } - public long getValue() { return value; } diff --git a/common/src/main/java/org/apache/rocketmq/common/stats/StatsItemSet.java b/common/src/main/java/org/apache/rocketmq/common/stats/StatsItemSet.java index 919745d3..726bf6ae 100644 --- a/common/src/main/java/org/apache/rocketmq/common/stats/StatsItemSet.java +++ b/common/src/main/java/org/apache/rocketmq/common/stats/StatsItemSet.java @@ -17,25 +17,22 @@ package org.apache.rocketmq.common.stats; -import org.apache.rocketmq.common.UtilAll; -import org.slf4j.Logger; - import java.util.Iterator; import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; - +import org.apache.rocketmq.common.UtilAll; +import org.slf4j.Logger; public class StatsItemSet { private final ConcurrentHashMap statsItemTable = - new ConcurrentHashMap(128); + new ConcurrentHashMap(128); private final String statsName; private final ScheduledExecutorService scheduledExecutorService; private final Logger log; - public StatsItemSet(String statsName, ScheduledExecutorService scheduledExecutorService, Logger log) { this.statsName = statsName; this.scheduledExecutorService = scheduledExecutorService; @@ -55,7 +52,6 @@ public class StatsItemSet { } }, 0, 10, TimeUnit.SECONDS); - this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() { @Override public void run() { @@ -66,7 +62,6 @@ public class StatsItemSet { } }, 0, 10, TimeUnit.MINUTES); - this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() { @Override public void run() { @@ -77,7 +72,6 @@ public class StatsItemSet { } }, 0, 1, TimeUnit.HOURS); - this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() { @Override public void run() { @@ -88,7 +82,6 @@ public class StatsItemSet { } }, Math.abs(UtilAll.computNextMinutesTimeMillis() - System.currentTimeMillis()), 1000 * 60, TimeUnit.MILLISECONDS); - this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() { @Override public void run() { @@ -99,7 +92,6 @@ public class StatsItemSet { } }, Math.abs(UtilAll.computNextHourTimeMillis() - System.currentTimeMillis()), 1000 * 60 * 60, TimeUnit.MILLISECONDS); - this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() { @Override public void run() { diff --git a/common/src/main/java/org/apache/rocketmq/common/stats/StatsSnapshot.java b/common/src/main/java/org/apache/rocketmq/common/stats/StatsSnapshot.java index 652d2149..4df39d10 100644 --- a/common/src/main/java/org/apache/rocketmq/common/stats/StatsSnapshot.java +++ b/common/src/main/java/org/apache/rocketmq/common/stats/StatsSnapshot.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.stats; @@ -22,32 +22,26 @@ public class StatsSnapshot { private double tps; private double avgpt; - public long getSum() { return sum; } - public void setSum(long sum) { this.sum = sum; } - public double getTps() { return tps; } - public void setTps(double tps) { this.tps = tps; } - public double getAvgpt() { return avgpt; } - public void setAvgpt(double avgpt) { this.avgpt = avgpt; } diff --git a/common/src/main/java/org/apache/rocketmq/common/subscription/SubscriptionGroupConfig.java b/common/src/main/java/org/apache/rocketmq/common/subscription/SubscriptionGroupConfig.java index 8fc14cd3..9bf97fbf 100644 --- a/common/src/main/java/org/apache/rocketmq/common/subscription/SubscriptionGroupConfig.java +++ b/common/src/main/java/org/apache/rocketmq/common/subscription/SubscriptionGroupConfig.java @@ -19,7 +19,6 @@ package org.apache.rocketmq.common.subscription; import org.apache.rocketmq.common.MixAll; - public class SubscriptionGroupConfig { private String groupName; @@ -39,82 +38,66 @@ public class SubscriptionGroupConfig { private boolean notifyConsumerIdsChangedEnable = true; - public String getGroupName() { return groupName; } - public void setGroupName(String groupName) { this.groupName = groupName; } - public boolean isConsumeEnable() { return consumeEnable; } - public void setConsumeEnable(boolean consumeEnable) { this.consumeEnable = consumeEnable; } - public boolean isConsumeFromMinEnable() { return consumeFromMinEnable; } - public void setConsumeFromMinEnable(boolean consumeFromMinEnable) { this.consumeFromMinEnable = consumeFromMinEnable; } - public boolean isConsumeBroadcastEnable() { return consumeBroadcastEnable; } - public void setConsumeBroadcastEnable(boolean consumeBroadcastEnable) { this.consumeBroadcastEnable = consumeBroadcastEnable; } - public int getRetryQueueNums() { return retryQueueNums; } - public void setRetryQueueNums(int retryQueueNums) { this.retryQueueNums = retryQueueNums; } - public int getRetryMaxTimes() { return retryMaxTimes; } - public void setRetryMaxTimes(int retryMaxTimes) { this.retryMaxTimes = retryMaxTimes; } - public long getBrokerId() { return brokerId; } - public void setBrokerId(long brokerId) { this.brokerId = brokerId; } - public long getWhichBrokerWhenConsumeSlowly() { return whichBrokerWhenConsumeSlowly; } - public void setWhichBrokerWhenConsumeSlowly(long whichBrokerWhenConsumeSlowly) { this.whichBrokerWhenConsumeSlowly = whichBrokerWhenConsumeSlowly; } @@ -131,7 +114,7 @@ public class SubscriptionGroupConfig { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + (int) (brokerId ^ (brokerId >>> 32)); + result = prime * result + (int)(brokerId ^ (brokerId >>> 32)); result = prime * result + (consumeBroadcastEnable ? 1231 : 1237); result = prime * result + (consumeEnable ? 1231 : 1237); result = prime * result + (consumeFromMinEnable ? 1231 : 1237); @@ -140,11 +123,10 @@ public class SubscriptionGroupConfig { result = prime * result + retryMaxTimes; result = prime * result + retryQueueNums; result = - prime * result + (int) (whichBrokerWhenConsumeSlowly ^ (whichBrokerWhenConsumeSlowly >>> 32)); + prime * result + (int)(whichBrokerWhenConsumeSlowly ^ (whichBrokerWhenConsumeSlowly >>> 32)); return result; } - @Override public boolean equals(Object obj) { if (this == obj) @@ -153,7 +135,7 @@ public class SubscriptionGroupConfig { return false; if (getClass() != obj.getClass()) return false; - SubscriptionGroupConfig other = (SubscriptionGroupConfig) obj; + SubscriptionGroupConfig other = (SubscriptionGroupConfig)obj; if (brokerId != other.brokerId) return false; if (consumeBroadcastEnable != other.consumeBroadcastEnable) @@ -178,14 +160,13 @@ public class SubscriptionGroupConfig { return true; } - @Override public String toString() { return "SubscriptionGroupConfig [groupName=" + groupName + ", consumeEnable=" + consumeEnable - + ", consumeFromMinEnable=" + consumeFromMinEnable + ", consumeBroadcastEnable=" - + consumeBroadcastEnable + ", retryQueueNums=" + retryQueueNums + ", retryMaxTimes=" - + retryMaxTimes + ", brokerId=" + brokerId + ", whichBrokerWhenConsumeSlowly=" - + whichBrokerWhenConsumeSlowly + ", notifyConsumerIdsChangedEnable=" - + notifyConsumerIdsChangedEnable + "]"; + + ", consumeFromMinEnable=" + consumeFromMinEnable + ", consumeBroadcastEnable=" + + consumeBroadcastEnable + ", retryQueueNums=" + retryQueueNums + ", retryMaxTimes=" + + retryMaxTimes + ", brokerId=" + brokerId + ", whichBrokerWhenConsumeSlowly=" + + whichBrokerWhenConsumeSlowly + ", notifyConsumerIdsChangedEnable=" + + notifyConsumerIdsChangedEnable + "]"; } } diff --git a/common/src/main/java/org/apache/rocketmq/common/sysflag/MessageSysFlag.java b/common/src/main/java/org/apache/rocketmq/common/sysflag/MessageSysFlag.java index 4ccfef7e..c2135437 100644 --- a/common/src/main/java/org/apache/rocketmq/common/sysflag/MessageSysFlag.java +++ b/common/src/main/java/org/apache/rocketmq/common/sysflag/MessageSysFlag.java @@ -24,17 +24,14 @@ public class MessageSysFlag { public final static int TRANSACTION_COMMIT_TYPE = 0x2 << 2; public final static int TRANSACTION_ROLLBACK_TYPE = 0x3 << 2; - public static int getTransactionValue(final int flag) { return flag & TRANSACTION_ROLLBACK_TYPE; } - public static int resetTransactionValue(final int flag, final int type) { return (flag & (~TRANSACTION_ROLLBACK_TYPE)) | type; } - public static int clearCompressedFlag(final int flag) { return flag & (~COMPRESSED_FLAG); } diff --git a/common/src/main/java/org/apache/rocketmq/common/sysflag/PullSysFlag.java b/common/src/main/java/org/apache/rocketmq/common/sysflag/PullSysFlag.java index 193459c0..b659c522 100644 --- a/common/src/main/java/org/apache/rocketmq/common/sysflag/PullSysFlag.java +++ b/common/src/main/java/org/apache/rocketmq/common/sysflag/PullSysFlag.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.sysflag; @@ -22,9 +22,8 @@ public class PullSysFlag { private final static int FLAG_SUBSCRIPTION = 0x1 << 2; private final static int FLAG_CLASS_FILTER = 0x1 << 3; - public static int buildSysFlag(final boolean commitOffset, final boolean suspend, - final boolean subscription, final boolean classFilter) { + final boolean subscription, final boolean classFilter) { int flag = 0; if (commitOffset) { @@ -46,27 +45,22 @@ public class PullSysFlag { return flag; } - public static int clearCommitOffsetFlag(final int sysFlag) { return sysFlag & (~FLAG_COMMIT_OFFSET); } - public static boolean hasCommitOffsetFlag(final int sysFlag) { return (sysFlag & FLAG_COMMIT_OFFSET) == FLAG_COMMIT_OFFSET; } - public static boolean hasSuspendFlag(final int sysFlag) { return (sysFlag & FLAG_SUSPEND) == FLAG_SUSPEND; } - public static boolean hasSubscriptionFlag(final int sysFlag) { return (sysFlag & FLAG_SUBSCRIPTION) == FLAG_SUBSCRIPTION; } - public static boolean hasClassFilterFlag(final int sysFlag) { return (sysFlag & FLAG_CLASS_FILTER) == FLAG_CLASS_FILTER; } diff --git a/common/src/main/java/org/apache/rocketmq/common/sysflag/SubscriptionSysFlag.java b/common/src/main/java/org/apache/rocketmq/common/sysflag/SubscriptionSysFlag.java index da6401e0..cf7cdcd2 100644 --- a/common/src/main/java/org/apache/rocketmq/common/sysflag/SubscriptionSysFlag.java +++ b/common/src/main/java/org/apache/rocketmq/common/sysflag/SubscriptionSysFlag.java @@ -20,7 +20,6 @@ public class SubscriptionSysFlag { private final static int FLAG_UNIT = 0x1 << 0; - public static int buildSysFlag(final boolean unit) { int sysFlag = 0; @@ -31,22 +30,18 @@ public class SubscriptionSysFlag { return sysFlag; } - public static int setUnitFlag(final int sysFlag) { return sysFlag | FLAG_UNIT; } - public static int clearUnitFlag(final int sysFlag) { return sysFlag & (~FLAG_UNIT); } - public static boolean hasUnitFlag(final int sysFlag) { return (sysFlag & FLAG_UNIT) == FLAG_UNIT; } - public static void main(String[] args) { } } diff --git a/common/src/main/java/org/apache/rocketmq/common/sysflag/TopicSysFlag.java b/common/src/main/java/org/apache/rocketmq/common/sysflag/TopicSysFlag.java index 1d804dbc..2c45150b 100644 --- a/common/src/main/java/org/apache/rocketmq/common/sysflag/TopicSysFlag.java +++ b/common/src/main/java/org/apache/rocketmq/common/sysflag/TopicSysFlag.java @@ -27,7 +27,6 @@ public class TopicSysFlag { private final static int FLAG_UNIT_SUB = 0x1 << 1; - public static int buildSysFlag(final boolean unit, final boolean hasUnitSub) { int sysFlag = 0; @@ -42,37 +41,30 @@ public class TopicSysFlag { return sysFlag; } - public static int setUnitFlag(final int sysFlag) { return sysFlag | FLAG_UNIT; } - public static int clearUnitFlag(final int sysFlag) { return sysFlag & (~FLAG_UNIT); } - public static boolean hasUnitFlag(final int sysFlag) { return (sysFlag & FLAG_UNIT) == FLAG_UNIT; } - public static int setUnitSubFlag(final int sysFlag) { return sysFlag | FLAG_UNIT_SUB; } - public static int clearUnitSubFlag(final int sysFlag) { return sysFlag & (~FLAG_UNIT_SUB); } - public static boolean hasUnitSubFlag(final int sysFlag) { return (sysFlag & FLAG_UNIT_SUB) == FLAG_UNIT_SUB; } - public static void main(String[] args) { } } diff --git a/common/src/main/java/org/apache/rocketmq/common/utils/ChannelUtil.java b/common/src/main/java/org/apache/rocketmq/common/utils/ChannelUtil.java index ab017f22..dcb9187c 100644 --- a/common/src/main/java/org/apache/rocketmq/common/utils/ChannelUtil.java +++ b/common/src/main/java/org/apache/rocketmq/common/utils/ChannelUtil.java @@ -6,25 +6,24 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.utils; import io.netty.channel.Channel; - import java.net.InetAddress; import java.net.InetSocketAddress; public class ChannelUtil { public static String getRemoteIp(Channel channel) { - InetSocketAddress inetSocketAddress = (InetSocketAddress) channel.remoteAddress(); + InetSocketAddress inetSocketAddress = (InetSocketAddress)channel.remoteAddress(); if (inetSocketAddress == null) { return ""; } diff --git a/common/src/main/java/org/apache/rocketmq/common/utils/HttpTinyClient.java b/common/src/main/java/org/apache/rocketmq/common/utils/HttpTinyClient.java index fcd002cd..0cc34635 100755 --- a/common/src/main/java/org/apache/rocketmq/common/utils/HttpTinyClient.java +++ b/common/src/main/java/org/apache/rocketmq/common/utils/HttpTinyClient.java @@ -6,20 +6,17 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.utils; -import org.apache.rocketmq.common.MQVersion; -import org.apache.rocketmq.common.MixAll; - import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; @@ -27,21 +24,22 @@ import java.net.URL; import java.net.URLEncoder; import java.util.Iterator; import java.util.List; - +import org.apache.rocketmq.common.MQVersion; +import org.apache.rocketmq.common.MixAll; public class HttpTinyClient { static public HttpResult httpGet(String url, List headers, List paramValues, - String encoding, long readTimeoutMs) throws IOException { + String encoding, long readTimeoutMs) throws IOException { String encodedContent = encodingParams(paramValues, encoding); url += (null == encodedContent) ? "" : ("?" + encodedContent); HttpURLConnection conn = null; try { - conn = (HttpURLConnection) new URL(url).openConnection(); + conn = (HttpURLConnection)new URL(url).openConnection(); conn.setRequestMethod("GET"); - conn.setConnectTimeout((int) readTimeoutMs); - conn.setReadTimeout((int) readTimeoutMs); + conn.setConnectTimeout((int)readTimeoutMs); + conn.setReadTimeout((int)readTimeoutMs); setHeaders(conn, headers, encoding); conn.connect(); @@ -62,7 +60,7 @@ public class HttpTinyClient { } static private String encodingParams(List paramValues, String encoding) - throws UnsupportedEncodingException { + throws UnsupportedEncodingException { StringBuilder sb = new StringBuilder(); if (null == paramValues) { return null; @@ -87,7 +85,6 @@ public class HttpTinyClient { conn.addRequestProperty("Client-Version", MQVersion.getVersionDesc(MQVersion.CURRENT_VERSION)); conn.addRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + encoding); - String ts = String.valueOf(System.currentTimeMillis()); conn.addRequestProperty("Metaq-Client-RequestTS", ts); } @@ -110,15 +107,15 @@ public class HttpTinyClient { * @throws java.io.IOException */ static public HttpResult httpPost(String url, List headers, List paramValues, - String encoding, long readTimeoutMs) throws IOException { + String encoding, long readTimeoutMs) throws IOException { String encodedContent = encodingParams(paramValues, encoding); HttpURLConnection conn = null; try { - conn = (HttpURLConnection) new URL(url).openConnection(); + conn = (HttpURLConnection)new URL(url).openConnection(); conn.setRequestMethod("POST"); conn.setConnectTimeout(3000); - conn.setReadTimeout((int) readTimeoutMs); + conn.setReadTimeout((int)readTimeoutMs); conn.setDoOutput(true); conn.setDoInput(true); setHeaders(conn, headers, encoding); @@ -145,7 +142,6 @@ public class HttpTinyClient { final public int code; final public String content; - public HttpResult(int code, String content) { this.code = code; this.content = content; diff --git a/common/src/main/java/org/apache/rocketmq/common/utils/IOTinyUtils.java b/common/src/main/java/org/apache/rocketmq/common/utils/IOTinyUtils.java index a5152f89..b569c24b 100644 --- a/common/src/main/java/org/apache/rocketmq/common/utils/IOTinyUtils.java +++ b/common/src/main/java/org/apache/rocketmq/common/utils/IOTinyUtils.java @@ -6,40 +6,46 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.utils; -import org.apache.rocketmq.remoting.common.RemotingHelper; - -import java.io.*; +import java.io.BufferedReader; +import java.io.CharArrayWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.Reader; +import java.io.Writer; import java.nio.channels.FileChannel; import java.util.ArrayList; import java.util.List; - +import org.apache.rocketmq.remoting.common.RemotingHelper; public class IOTinyUtils { static public String toString(InputStream input, String encoding) throws IOException { return (null == encoding) ? toString(new InputStreamReader(input, RemotingHelper.DEFAULT_CHARSET)) : toString(new InputStreamReader( - input, encoding)); + input, encoding)); } - static public String toString(Reader reader) throws IOException { CharArrayWriter sw = new CharArrayWriter(); copy(reader, sw); return sw.toString(); } - static public long copy(Reader input, Writer output) throws IOException { char[] buffer = new char[1 << 12]; long count = 0; @@ -50,7 +56,6 @@ public class IOTinyUtils { return count; } - /** */ @@ -58,7 +63,7 @@ public class IOTinyUtils { BufferedReader reader = toBufferedReader(input); List list = new ArrayList(); String line = null; - for (;;) { + for (; ; ) { line = reader.readLine(); if (null != line) { list.add(line); @@ -69,12 +74,10 @@ public class IOTinyUtils { return list; } - static private BufferedReader toBufferedReader(Reader reader) { - return reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader); + return reader instanceof BufferedReader ? (BufferedReader)reader : new BufferedReader(reader); } - static public void copyFile(String source, String target) throws IOException { File sf = new File(source); if (!sf.exists()) { @@ -102,7 +105,6 @@ public class IOTinyUtils { } } - public static void delete(File fileOrDir) throws IOException { if (fileOrDir == null) { return; @@ -115,7 +117,6 @@ public class IOTinyUtils { fileOrDir.delete(); } - /** */ @@ -149,7 +150,6 @@ public class IOTinyUtils { } } - public static void writeStringToFile(File file, String data, String encoding) throws IOException { OutputStream os = null; try { diff --git a/common/src/test/java/org/apache/rocketmq/common/MixAllTest.java b/common/src/test/java/org/apache/rocketmq/common/MixAllTest.java index 0006f749..3205c645 100644 --- a/common/src/test/java/org/apache/rocketmq/common/MixAllTest.java +++ b/common/src/test/java/org/apache/rocketmq/common/MixAllTest.java @@ -6,23 +6,21 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common; -import junit.framework.Assert; -import org.junit.Test; - import java.net.InetAddress; import java.util.List; - +import junit.framework.Assert; +import org.junit.Test; public class MixAllTest { diff --git a/common/src/test/java/org/apache/rocketmq/common/RemotingUtilTest.java b/common/src/test/java/org/apache/rocketmq/common/RemotingUtilTest.java index b7509b14..9211d377 100644 --- a/common/src/test/java/org/apache/rocketmq/common/RemotingUtilTest.java +++ b/common/src/test/java/org/apache/rocketmq/common/RemotingUtilTest.java @@ -6,20 +6,19 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common; import org.apache.rocketmq.remoting.common.RemotingUtil; import org.junit.Test; - public class RemotingUtilTest { @Test public void test() throws Exception { diff --git a/common/src/test/java/org/apache/rocketmq/common/UtilAllTest.java b/common/src/test/java/org/apache/rocketmq/common/UtilAllTest.java index decd3d0f..b21d65b3 100644 --- a/common/src/test/java/org/apache/rocketmq/common/UtilAllTest.java +++ b/common/src/test/java/org/apache/rocketmq/common/UtilAllTest.java @@ -6,25 +6,23 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common; -import org.junit.Test; - import java.net.URL; import java.util.Properties; +import org.junit.Test; import static org.junit.Assert.assertTrue; - public class UtilAllTest { @Test @@ -32,7 +30,6 @@ public class UtilAllTest { System.out.println(UtilAll.currentStackTrace()); } - @Test public void test_a() { URL url = this.getClass().getProtectionDomain().getCodeSource().getLocation(); @@ -40,14 +37,12 @@ public class UtilAllTest { System.out.println(url.getPath()); } - @Test public void test_resetClassProperties() { DemoConfig demoConfig = new DemoConfig(); MixAll.properties2Object(new Properties(), demoConfig); } - @Test public void test_properties2String() { DemoConfig demoConfig = new DemoConfig(); @@ -55,13 +50,11 @@ public class UtilAllTest { System.out.println(MixAll.properties2String(properties)); } - @Test public void test_timeMillisToHumanString() { System.out.println(UtilAll.timeMillisToHumanString()); } - @Test public void test_isPropertiesEqual() { final Properties p1 = new Properties(); @@ -77,7 +70,6 @@ public class UtilAllTest { assertTrue(MixAll.isPropertiesEqual(p1, p2)); } - @Test public void test_getpid() { int pid = UtilAll.getPid(); @@ -86,7 +78,6 @@ public class UtilAllTest { assertTrue(pid > 0); } - @Test public void test_isBlank() { { @@ -121,42 +112,34 @@ public class UtilAllTest { private boolean demoOK = false; private String demoName = "haha"; - public int getDemoWidth() { return demoWidth; } - public void setDemoWidth(int demoWidth) { this.demoWidth = demoWidth; } - public int getDemoLength() { return demoLength; } - public void setDemoLength(int demoLength) { this.demoLength = demoLength; } - public boolean isDemoOK() { return demoOK; } - public void setDemoOK(boolean demoOK) { this.demoOK = demoOK; } - public String getDemoName() { return demoName; } - public void setDemoNfieldame(String demoName) { this.demoName = demoName; } diff --git a/common/src/test/java/org/apache/rocketmq/common/filter/FilterAPITest.java b/common/src/test/java/org/apache/rocketmq/common/filter/FilterAPITest.java index cf26efd3..5a97db93 100644 --- a/common/src/test/java/org/apache/rocketmq/common/filter/FilterAPITest.java +++ b/common/src/test/java/org/apache/rocketmq/common/filter/FilterAPITest.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.filter; @@ -21,7 +21,6 @@ import org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData; import org.apache.rocketmq.remoting.protocol.RemotingSerializable; import org.junit.Test; - /** * */ @@ -30,14 +29,14 @@ public class FilterAPITest { @Test public void testBuildSubscriptionData() throws Exception { SubscriptionData subscriptionData = - FilterAPI.buildSubscriptionData("ConsumerGroup1", "TestTopic", "TAG1 || Tag2 || tag3"); + FilterAPI.buildSubscriptionData("ConsumerGroup1", "TestTopic", "TAG1 || Tag2 || tag3"); System.out.println(subscriptionData); } @Test public void testSubscriptionData() throws Exception { SubscriptionData subscriptionData = - FilterAPI.buildSubscriptionData("ConsumerGroup1", "TestTopic", "TAG1 || Tag2 || tag3"); + FilterAPI.buildSubscriptionData("ConsumerGroup1", "TestTopic", "TAG1 || Tag2 || tag3"); subscriptionData.setFilterClassSource("java hello"); String json = RemotingSerializable.toJson(subscriptionData, true); System.out.println(json); diff --git a/common/src/test/java/org/apache/rocketmq/common/protocol/ConsumeStatusTest.java b/common/src/test/java/org/apache/rocketmq/common/protocol/ConsumeStatusTest.java index 79c6bbfa..b5115376 100644 --- a/common/src/test/java/org/apache/rocketmq/common/protocol/ConsumeStatusTest.java +++ b/common/src/test/java/org/apache/rocketmq/common/protocol/ConsumeStatusTest.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.protocol; @@ -21,7 +21,6 @@ import org.apache.rocketmq.common.protocol.body.ConsumeStatus; import org.apache.rocketmq.remoting.protocol.RemotingSerializable; import org.junit.Test; - public class ConsumeStatusTest { @Test diff --git a/conf/2m-2s-async/broker-a-s.properties b/conf/2m-2s-async/broker-a-s.properties index a4401f88..60fddf9b 100644 --- a/conf/2m-2s-async/broker-a-s.properties +++ b/conf/2m-2s-async/broker-a-s.properties @@ -12,7 +12,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - brokerClusterName=DefaultCluster brokerName=broker-a brokerId=1 diff --git a/conf/2m-2s-async/broker-a.properties b/conf/2m-2s-async/broker-a.properties index 6ca12f1d..367f9744 100644 --- a/conf/2m-2s-async/broker-a.properties +++ b/conf/2m-2s-async/broker-a.properties @@ -12,7 +12,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - brokerClusterName=DefaultCluster brokerName=broker-a brokerId=0 diff --git a/conf/2m-2s-async/broker-b-s.properties b/conf/2m-2s-async/broker-b-s.properties index 51f8daf9..bcd5a16a 100644 --- a/conf/2m-2s-async/broker-b-s.properties +++ b/conf/2m-2s-async/broker-b-s.properties @@ -12,7 +12,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - brokerClusterName=DefaultCluster brokerName=broker-b brokerId=1 diff --git a/conf/2m-2s-async/broker-b.properties b/conf/2m-2s-async/broker-b.properties index f7f3791f..33b68fee 100644 --- a/conf/2m-2s-async/broker-b.properties +++ b/conf/2m-2s-async/broker-b.properties @@ -12,7 +12,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - brokerClusterName=DefaultCluster brokerName=broker-b brokerId=0 diff --git a/conf/2m-2s-sync/broker-a-s.properties b/conf/2m-2s-sync/broker-a-s.properties index a4401f88..60fddf9b 100644 --- a/conf/2m-2s-sync/broker-a-s.properties +++ b/conf/2m-2s-sync/broker-a-s.properties @@ -12,7 +12,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - brokerClusterName=DefaultCluster brokerName=broker-a brokerId=1 diff --git a/conf/2m-2s-sync/broker-a.properties b/conf/2m-2s-sync/broker-a.properties index 135552d2..b916f88e 100644 --- a/conf/2m-2s-sync/broker-a.properties +++ b/conf/2m-2s-sync/broker-a.properties @@ -12,7 +12,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - brokerClusterName=DefaultCluster brokerName=broker-a brokerId=0 diff --git a/conf/2m-2s-sync/broker-b-s.properties b/conf/2m-2s-sync/broker-b-s.properties index 51f8daf9..bcd5a16a 100644 --- a/conf/2m-2s-sync/broker-b-s.properties +++ b/conf/2m-2s-sync/broker-b-s.properties @@ -12,7 +12,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - brokerClusterName=DefaultCluster brokerName=broker-b brokerId=1 diff --git a/conf/2m-2s-sync/broker-b.properties b/conf/2m-2s-sync/broker-b.properties index 97162a75..44fcea70 100644 --- a/conf/2m-2s-sync/broker-b.properties +++ b/conf/2m-2s-sync/broker-b.properties @@ -12,7 +12,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - brokerClusterName=DefaultCluster brokerName=broker-b brokerId=0 diff --git a/conf/2m-noslave/broker-a.properties b/conf/2m-noslave/broker-a.properties index 6ca12f1d..367f9744 100644 --- a/conf/2m-noslave/broker-a.properties +++ b/conf/2m-noslave/broker-a.properties @@ -12,7 +12,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - brokerClusterName=DefaultCluster brokerName=broker-a brokerId=0 diff --git a/conf/2m-noslave/broker-b.properties b/conf/2m-noslave/broker-b.properties index f7f3791f..33b68fee 100644 --- a/conf/2m-noslave/broker-b.properties +++ b/conf/2m-noslave/broker-b.properties @@ -12,7 +12,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - brokerClusterName=DefaultCluster brokerName=broker-b brokerId=0 diff --git a/conf/broker.conf b/conf/broker.conf index 6ca12f1d..0c0b28b7 100644 --- a/conf/broker.conf +++ b/conf/broker.conf @@ -13,10 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -brokerClusterName=DefaultCluster -brokerName=broker-a -brokerId=0 -deleteWhen=04 -fileReservedTime=48 -brokerRole=ASYNC_MASTER -flushDiskType=ASYNC_FLUSH +brokerClusterName = DefaultCluster +brokerName = broker-a +brokerId = 0 +deleteWhen = 04 +fileReservedTime = 48 +brokerRole = ASYNC_MASTER +flushDiskType = ASYNC_FLUSH diff --git a/conf/logback_broker.xml b/conf/logback_broker.xml index 49e9d12e..7a8f83b4 100644 --- a/conf/logback_broker.xml +++ b/conf/logback_broker.xml @@ -28,7 +28,7 @@ 10 + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> 100MB @@ -48,7 +48,7 @@ 20 + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> 128MB @@ -71,7 +71,7 @@ 10 + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> 100MB @@ -94,7 +94,7 @@ 10 + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> 100MB @@ -117,7 +117,7 @@ 10 + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> 128MB @@ -140,7 +140,7 @@ 10 + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> 100MB @@ -163,7 +163,7 @@ 10 + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> 100MB @@ -187,7 +187,7 @@ 10 + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> 100MB @@ -210,7 +210,7 @@ 5 + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> 100MB @@ -233,7 +233,7 @@ 5 + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> 100MB @@ -253,7 +253,7 @@ 10 + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> 500MB diff --git a/conf/logback_filtersrv.xml b/conf/logback_filtersrv.xml index 8de4e084..9668795d 100644 --- a/conf/logback_filtersrv.xml +++ b/conf/logback_filtersrv.xml @@ -28,7 +28,7 @@ 5 + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> 100MB @@ -48,7 +48,7 @@ 5 + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> 100MB diff --git a/conf/logback_namesrv.xml b/conf/logback_namesrv.xml index 7a60c764..45ccf4f0 100644 --- a/conf/logback_namesrv.xml +++ b/conf/logback_namesrv.xml @@ -28,7 +28,7 @@ 5 + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> 100MB @@ -48,7 +48,7 @@ 5 + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> 100MB diff --git a/conf/logback_tools.xml b/conf/logback_tools.xml index addf211c..35d33a5e 100644 --- a/conf/logback_tools.xml +++ b/conf/logback_tools.xml @@ -28,7 +28,7 @@ 5 + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> 100MB @@ -48,7 +48,7 @@ 5 + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> 100MB diff --git a/example/pom.xml b/example/pom.xml index 53aa6a69..efb1aa57 100644 --- a/example/pom.xml +++ b/example/pom.xml @@ -15,7 +15,7 @@ limitations under the License. --> - org.apache.rocketmq diff --git a/example/src/main/java/org/apache/rocketmq/example/benchmark/Consumer.java b/example/src/main/java/org/apache/rocketmq/example/benchmark/Consumer.java index 1fbb8a4b..f810f5a8 100644 --- a/example/src/main/java/org/apache/rocketmq/example/benchmark/Consumer.java +++ b/example/src/main/java/org/apache/rocketmq/example/benchmark/Consumer.java @@ -17,6 +17,15 @@ package org.apache.rocketmq.example.benchmark; +import java.util.LinkedList; +import java.util.List; +import java.util.Timer; +import java.util.TimerTask; +import java.util.concurrent.atomic.AtomicLong; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.PosixParser; import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext; import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; @@ -24,16 +33,6 @@ import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently; import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.common.message.MessageExt; import org.apache.rocketmq.srvutil.ServerUtil; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.PosixParser; - -import java.util.LinkedList; -import java.util.List; -import java.util.Timer; -import java.util.TimerTask; -import java.util.concurrent.atomic.AtomicLong; public class Consumer { @@ -77,17 +76,16 @@ public class Consumer { Long[] end = snapshotList.getLast(); final long consumeTps = - (long) (((end[1] - begin[1]) / (double) (end[0] - begin[0])) * 1000L); - final double averageB2CRT = (end[2] - begin[2]) / (double) (end[1] - begin[1]); - final double averageS2CRT = (end[3] - begin[3]) / (double) (end[1] - begin[1]); + (long)(((end[1] - begin[1]) / (double)(end[0] - begin[0])) * 1000L); + final double averageB2CRT = (end[2] - begin[2]) / (double)(end[1] - begin[1]); + final double averageS2CRT = (end[3] - begin[3]) / (double)(end[1] - begin[1]); System.out.printf("Consume TPS: %d Average(B2C) RT: %7.3f Average(S2C) RT: %7.3f MAX(B2C) RT: %d MAX(S2C) RT: %d%n", - consumeTps, averageB2CRT, averageS2CRT, end[4], end[5] + consumeTps, averageB2CRT, averageS2CRT, end[4], end[5] ); } } - @Override public void run() { try { @@ -106,7 +104,7 @@ public class Consumer { consumer.registerMessageListener(new MessageListenerConcurrently() { @Override public ConsumeConcurrentlyStatus consumeMessage(List msgs, - ConsumeConcurrentlyContext context) { + ConsumeConcurrentlyContext context) { MessageExt msg = msgs.get(0); long now = System.currentTimeMillis(); @@ -140,7 +138,6 @@ public class Consumer { opt.setRequired(false); options.addOption(opt); - opt = new Option("p", "group prefix enable", true, "Consumer group name, Default: false"); opt.setRequired(false); options.addOption(opt); @@ -148,7 +145,6 @@ public class Consumer { return options; } - public static void compareAndSetMax(final AtomicLong target, final long value) { long prev = target.get(); while (value > prev) { @@ -161,7 +157,6 @@ public class Consumer { } } - class StatsBenchmarkConsumer { private final AtomicLong receiveMessageTotalCount = new AtomicLong(0L); @@ -173,41 +168,35 @@ class StatsBenchmarkConsumer { private final AtomicLong store2ConsumerMaxRT = new AtomicLong(0L); - public Long[] createSnapshot() { - Long[] snap = new Long[]{ - System.currentTimeMillis(), - this.receiveMessageTotalCount.get(), - this.born2ConsumerTotalRT.get(), - this.store2ConsumerTotalRT.get(), - this.born2ConsumerMaxRT.get(), - this.store2ConsumerMaxRT.get(), + Long[] snap = new Long[] { + System.currentTimeMillis(), + this.receiveMessageTotalCount.get(), + this.born2ConsumerTotalRT.get(), + this.store2ConsumerTotalRT.get(), + this.born2ConsumerMaxRT.get(), + this.store2ConsumerMaxRT.get(), }; return snap; } - public AtomicLong getReceiveMessageTotalCount() { return receiveMessageTotalCount; } - public AtomicLong getBorn2ConsumerTotalRT() { return born2ConsumerTotalRT; } - public AtomicLong getStore2ConsumerTotalRT() { return store2ConsumerTotalRT; } - public AtomicLong getBorn2ConsumerMaxRT() { return born2ConsumerMaxRT; } - public AtomicLong getStore2ConsumerMaxRT() { return store2ConsumerMaxRT; } diff --git a/example/src/main/java/org/apache/rocketmq/example/benchmark/Producer.java b/example/src/main/java/org/apache/rocketmq/example/benchmark/Producer.java index 3b13f94f..88e9a4fa 100644 --- a/example/src/main/java/org/apache/rocketmq/example/benchmark/Producer.java +++ b/example/src/main/java/org/apache/rocketmq/example/benchmark/Producer.java @@ -16,6 +16,17 @@ */ package org.apache.rocketmq.example.benchmark; +import java.io.UnsupportedEncodingException; +import java.util.LinkedList; +import java.util.Timer; +import java.util.TimerTask; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.atomic.AtomicLong; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.PosixParser; import org.apache.rocketmq.client.exception.MQBrokerException; import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.client.log.ClientLogger; @@ -24,20 +35,8 @@ import org.apache.rocketmq.common.message.Message; import org.apache.rocketmq.remoting.common.RemotingHelper; import org.apache.rocketmq.remoting.exception.RemotingException; import org.apache.rocketmq.srvutil.ServerUtil; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.PosixParser; import org.slf4j.Logger; -import java.io.UnsupportedEncodingException; -import java.util.LinkedList; -import java.util.Timer; -import java.util.TimerTask; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.atomic.AtomicLong; - public class Producer { public static void main(String[] args) throws MQClientException, UnsupportedEncodingException { @@ -82,15 +81,14 @@ public class Producer { Long[] begin = snapshotList.getFirst(); Long[] end = snapshotList.getLast(); - final long sendTps = (long) (((end[3] - begin[3]) / (double) (end[0] - begin[0])) * 1000L); - final double averageRT = (end[5] - begin[5]) / (double) (end[3] - begin[3]); + final long sendTps = (long)(((end[3] - begin[3]) / (double)(end[0] - begin[0])) * 1000L); + final double averageRT = (end[5] - begin[5]) / (double)(end[3] - begin[3]); System.out.printf("Send TPS: %d Max RT: %d Average RT: %7.3f Send Failed: %d Response Failed: %d%n", - sendTps, statsBenchmark.getSendMessageMaxRT().get(), averageRT, end[2], end[4]); + sendTps, statsBenchmark.getSendMessageMaxRT().get(), averageRT, end[2], end[4]); } } - @Override public void run() { try { @@ -202,7 +200,6 @@ public class Producer { } } - class StatsBenchmarkProducer { private final AtomicLong sendRequestSuccessCount = new AtomicLong(0L); @@ -216,46 +213,39 @@ class StatsBenchmarkProducer { private final AtomicLong sendMessageMaxRT = new AtomicLong(0L); - public Long[] createSnapshot() { - Long[] snap = new Long[]{ - System.currentTimeMillis(), - this.sendRequestSuccessCount.get(), - this.sendRequestFailedCount.get(), - this.receiveResponseSuccessCount.get(), - this.receiveResponseFailedCount.get(), - this.sendMessageSuccessTimeTotal.get(), + Long[] snap = new Long[] { + System.currentTimeMillis(), + this.sendRequestSuccessCount.get(), + this.sendRequestFailedCount.get(), + this.receiveResponseSuccessCount.get(), + this.receiveResponseFailedCount.get(), + this.sendMessageSuccessTimeTotal.get(), }; return snap; } - public AtomicLong getSendRequestSuccessCount() { return sendRequestSuccessCount; } - public AtomicLong getSendRequestFailedCount() { return sendRequestFailedCount; } - public AtomicLong getReceiveResponseSuccessCount() { return receiveResponseSuccessCount; } - public AtomicLong getReceiveResponseFailedCount() { return receiveResponseFailedCount; } - public AtomicLong getSendMessageSuccessTimeTotal() { return sendMessageSuccessTimeTotal; } - public AtomicLong getSendMessageMaxRT() { return sendMessageMaxRT; } diff --git a/example/src/main/java/org/apache/rocketmq/example/benchmark/TransactionProducer.java b/example/src/main/java/org/apache/rocketmq/example/benchmark/TransactionProducer.java index 43f159bd..ce4b1ab7 100644 --- a/example/src/main/java/org/apache/rocketmq/example/benchmark/TransactionProducer.java +++ b/example/src/main/java/org/apache/rocketmq/example/benchmark/TransactionProducer.java @@ -17,12 +17,6 @@ package org.apache.rocketmq.example.benchmark; -import org.apache.rocketmq.client.exception.MQClientException; -import org.apache.rocketmq.common.message.Message; -import org.apache.rocketmq.common.message.MessageExt; -import org.apache.rocketmq.remoting.common.RemotingHelper; -import org.apache.rocketmq.client.producer.*; - import java.io.UnsupportedEncodingException; import java.util.LinkedList; import java.util.Timer; @@ -30,6 +24,15 @@ import java.util.TimerTask; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicLong; +import org.apache.rocketmq.client.exception.MQClientException; +import org.apache.rocketmq.client.producer.LocalTransactionExecuter; +import org.apache.rocketmq.client.producer.LocalTransactionState; +import org.apache.rocketmq.client.producer.SendResult; +import org.apache.rocketmq.client.producer.TransactionCheckListener; +import org.apache.rocketmq.client.producer.TransactionMQProducer; +import org.apache.rocketmq.common.message.Message; +import org.apache.rocketmq.common.message.MessageExt; +import org.apache.rocketmq.remoting.common.RemotingHelper; public class TransactionProducer { private static int threadCount; @@ -37,7 +40,6 @@ public class TransactionProducer { private static boolean ischeck; private static boolean ischeckffalse; - public static void main(String[] args) throws MQClientException, UnsupportedEncodingException { threadCount = args.length >= 1 ? Integer.parseInt(args[0]) : 32; messageSize = args.length >= 2 ? Integer.parseInt(args[1]) : 1024 * 2; @@ -71,16 +73,15 @@ public class TransactionProducer { Long[] end = snapshotList.getLast(); final long sendTps = - (long) (((end[3] - begin[3]) / (double) (end[0] - begin[0])) * 1000L); - final double averageRT = (end[5] - begin[5]) / (double) (end[3] - begin[3]); + (long)(((end[3] - begin[3]) / (double)(end[0] - begin[0])) * 1000L); + final double averageRT = (end[5] - begin[5]) / (double)(end[3] - begin[3]); System.out.printf( - "Send TPS: %d Max RT: %d Average RT: %7.3f Send Failed: %d Response Failed: %d transaction checkCount: %d %n", - sendTps, statsBenchmark.getSendMessageMaxRT().get(), averageRT, end[2], end[4], end[6]); + "Send TPS: %d Max RT: %d Average RT: %7.3f Send Failed: %d Response Failed: %d transaction checkCount: %d %n", + sendTps, statsBenchmark.getSendMessageMaxRT().get(), averageRT, end[2], end[4], end[6]); } } - @Override public void run() { try { @@ -92,7 +93,7 @@ public class TransactionProducer { }, 10000, 10000); final TransactionCheckListener transactionCheckListener = - new TransactionCheckListenerBImpl(ischeckffalse, statsBenchmark); + new TransactionCheckListenerBImpl(ischeckffalse, statsBenchmark); final TransactionMQProducer producer = new TransactionMQProducer("benchmark_transaction_producer"); producer.setInstanceName(Long.toString(System.currentTimeMillis())); producer.setTransactionCheckListener(transactionCheckListener); @@ -110,7 +111,7 @@ public class TransactionProducer { // Thread.sleep(1000); final long beginTimestamp = System.currentTimeMillis(); SendResult sendResult = - producer.sendMessageInTransaction(msg, tranExecuter, null); + producer.sendMessageInTransaction(msg, tranExecuter, null); if (sendResult != null) { statsBenchmark.getSendRequestSuccessCount().incrementAndGet(); statsBenchmark.getReceiveResponseSuccessCount().incrementAndGet(); @@ -121,8 +122,8 @@ public class TransactionProducer { long prevMaxRT = statsBenchmark.getSendMessageMaxRT().get(); while (currentRT > prevMaxRT) { boolean updated = - statsBenchmark.getSendMessageMaxRT().compareAndSet(prevMaxRT, - currentRT); + statsBenchmark.getSendMessageMaxRT().compareAndSet(prevMaxRT, + currentRT); if (updated) break; @@ -137,7 +138,6 @@ public class TransactionProducer { } } - private static Message buildMessage(final int messageSize) throws UnsupportedEncodingException { Message msg = new Message(); msg.setTopic("BenchmarkTest"); @@ -153,17 +153,14 @@ public class TransactionProducer { } } - class TransactionExecuterBImpl implements LocalTransactionExecuter { private boolean ischeck; - public TransactionExecuterBImpl(boolean ischeck) { this.ischeck = ischeck; } - @Override public LocalTransactionState executeLocalTransactionBranch(final Message msg, final Object arg) { if (ischeck) { @@ -173,19 +170,16 @@ class TransactionExecuterBImpl implements LocalTransactionExecuter { } } - class TransactionCheckListenerBImpl implements TransactionCheckListener { private boolean ischeckffalse; private StatsBenchmarkTProducer statsBenchmarkTProducer; - public TransactionCheckListenerBImpl(boolean ischeckffalse, - StatsBenchmarkTProducer statsBenchmarkTProducer) { + StatsBenchmarkTProducer statsBenchmarkTProducer) { this.ischeckffalse = ischeckffalse; this.statsBenchmarkTProducer = statsBenchmarkTProducer; } - @Override public LocalTransactionState checkLocalTransactionState(MessageExt msg) { statsBenchmarkTProducer.getCheckRequestSuccessCount().incrementAndGet(); @@ -198,7 +192,6 @@ class TransactionCheckListenerBImpl implements TransactionCheckListener { } } - class StatsBenchmarkTProducer { private final AtomicLong sendRequestSuccessCount = new AtomicLong(0L); @@ -214,51 +207,43 @@ class StatsBenchmarkTProducer { private final AtomicLong checkRequestSuccessCount = new AtomicLong(0L); - public Long[] createSnapshot() { - Long[] snap = new Long[]{ - System.currentTimeMillis(), - this.sendRequestSuccessCount.get(), - this.sendRequestFailedCount.get(), - this.receiveResponseSuccessCount.get(), - this.receiveResponseFailedCount.get(), - this.sendMessageSuccessTimeTotal.get(), - this.checkRequestSuccessCount.get()}; + Long[] snap = new Long[] { + System.currentTimeMillis(), + this.sendRequestSuccessCount.get(), + this.sendRequestFailedCount.get(), + this.receiveResponseSuccessCount.get(), + this.receiveResponseFailedCount.get(), + this.sendMessageSuccessTimeTotal.get(), + this.checkRequestSuccessCount.get()}; return snap; } - public AtomicLong getSendRequestSuccessCount() { return sendRequestSuccessCount; } - public AtomicLong getSendRequestFailedCount() { return sendRequestFailedCount; } - public AtomicLong getReceiveResponseSuccessCount() { return receiveResponseSuccessCount; } - public AtomicLong getReceiveResponseFailedCount() { return receiveResponseFailedCount; } - public AtomicLong getSendMessageSuccessTimeTotal() { return sendMessageSuccessTimeTotal; } - public AtomicLong getSendMessageMaxRT() { return sendMessageMaxRT; } - public AtomicLong getCheckRequestSuccessCount() { return checkRequestSuccessCount; } diff --git a/example/src/main/java/org/apache/rocketmq/example/broadcast/PushConsumer.java b/example/src/main/java/org/apache/rocketmq/example/broadcast/PushConsumer.java index aa62a1e3..6301b3b4 100644 --- a/example/src/main/java/org/apache/rocketmq/example/broadcast/PushConsumer.java +++ b/example/src/main/java/org/apache/rocketmq/example/broadcast/PushConsumer.java @@ -16,6 +16,7 @@ */ package org.apache.rocketmq.example.broadcast; +import java.util.List; import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext; import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; @@ -25,8 +26,6 @@ import org.apache.rocketmq.common.consumer.ConsumeFromWhere; import org.apache.rocketmq.common.message.MessageExt; import org.apache.rocketmq.common.protocol.heartbeat.MessageModel; -import java.util.List; - public class PushConsumer { public static void main(String[] args) throws InterruptedException, MQClientException { @@ -42,7 +41,7 @@ public class PushConsumer { @Override public ConsumeConcurrentlyStatus consumeMessage(List msgs, - ConsumeConcurrentlyContext context) { + ConsumeConcurrentlyContext context) { System.out.printf(Thread.currentThread().getName() + " Receive New Messages: " + msgs + "%n"); return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; } diff --git a/example/src/main/java/org/apache/rocketmq/example/filter/Consumer.java b/example/src/main/java/org/apache/rocketmq/example/filter/Consumer.java index d0a41f15..8d0fbe45 100644 --- a/example/src/main/java/org/apache/rocketmq/example/filter/Consumer.java +++ b/example/src/main/java/org/apache/rocketmq/example/filter/Consumer.java @@ -16,6 +16,7 @@ */ package org.apache.rocketmq.example.filter; +import java.util.List; import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext; import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; @@ -24,9 +25,6 @@ import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.common.MixAll; import org.apache.rocketmq.common.message.MessageExt; -import java.util.List; - - public class Consumer { public static void main(String[] args) throws InterruptedException, MQClientException { @@ -34,13 +32,13 @@ public class Consumer { String filterCode = MixAll.file2String("/home/admin/MessageFilterImpl.java"); consumer.subscribe("TopicFilter7", "org.apache.rocketmq.example.filter.MessageFilterImpl", - filterCode); + filterCode); consumer.registerMessageListener(new MessageListenerConcurrently() { @Override public ConsumeConcurrentlyStatus consumeMessage(List msgs, - ConsumeConcurrentlyContext context) { + ConsumeConcurrentlyContext context) { System.out.printf(Thread.currentThread().getName() + " Receive New Messages: " + msgs + "%n"); return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; } diff --git a/example/src/main/java/org/apache/rocketmq/example/filter/Producer.java b/example/src/main/java/org/apache/rocketmq/example/filter/Producer.java index d58c28db..a2dba6cf 100644 --- a/example/src/main/java/org/apache/rocketmq/example/filter/Producer.java +++ b/example/src/main/java/org/apache/rocketmq/example/filter/Producer.java @@ -30,9 +30,9 @@ public class Producer { try { for (int i = 0; i < 6000000; i++) { Message msg = new Message("TopicFilter7", - "TagA", - "OrderID001", - "Hello world".getBytes(RemotingHelper.DEFAULT_CHARSET)); + "TagA", + "OrderID001", + "Hello world".getBytes(RemotingHelper.DEFAULT_CHARSET)); msg.putUserProperty("SequenceId", String.valueOf(i)); SendResult sendResult = producer.send(msg); diff --git a/example/src/main/java/org/apache/rocketmq/example/operation/Consumer.java b/example/src/main/java/org/apache/rocketmq/example/operation/Consumer.java index a6a3aca0..ec7d6eff 100644 --- a/example/src/main/java/org/apache/rocketmq/example/operation/Consumer.java +++ b/example/src/main/java/org/apache/rocketmq/example/operation/Consumer.java @@ -16,22 +16,20 @@ */ package org.apache.rocketmq.example.operation; -import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; -import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext; -import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; -import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently; -import org.apache.rocketmq.client.exception.MQClientException; -import org.apache.rocketmq.common.message.MessageExt; +import java.util.List; +import java.util.concurrent.atomic.AtomicLong; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; import org.apache.commons.cli.PosixParser; - -import java.util.List; -import java.util.concurrent.atomic.AtomicLong; - +import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; +import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext; +import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; +import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently; +import org.apache.rocketmq.client.exception.MQClientException; +import org.apache.rocketmq.common.message.MessageExt; public class Consumer { @@ -51,10 +49,9 @@ public class Consumer { consumer.registerMessageListener(new MessageListenerConcurrently() { AtomicLong consumeTimes = new AtomicLong(0); - @Override public ConsumeConcurrentlyStatus consumeMessage(List msgs, - ConsumeConcurrentlyContext context) { + ConsumeConcurrentlyContext context) { long currentTimes = this.consumeTimes.incrementAndGet(); System.out.printf("%-8d %s%n", currentTimes, msgs); if (Boolean.parseBoolean(returnFailedHalf)) { diff --git a/example/src/main/java/org/apache/rocketmq/example/operation/Producer.java b/example/src/main/java/org/apache/rocketmq/example/operation/Producer.java index 54e256be..663acd0c 100644 --- a/example/src/main/java/org/apache/rocketmq/example/operation/Producer.java +++ b/example/src/main/java/org/apache/rocketmq/example/operation/Producer.java @@ -6,22 +6,27 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.example.operation; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.HelpFormatter; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.apache.commons.cli.PosixParser; import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.client.producer.DefaultMQProducer; import org.apache.rocketmq.client.producer.SendResult; import org.apache.rocketmq.common.message.Message; import org.apache.rocketmq.remoting.common.RemotingHelper; -import org.apache.commons.cli.*; public class Producer { @@ -42,10 +47,10 @@ public class Producer { for (int i = 0; i < Integer.parseInt(msgCount); i++) { try { Message msg = new Message( - topic, - tags, - keys, - ("Hello RocketMQ " + i).getBytes(RemotingHelper.DEFAULT_CHARSET)); + topic, + tags, + keys, + ("Hello RocketMQ " + i).getBytes(RemotingHelper.DEFAULT_CHARSET)); SendResult sendResult = producer.send(msg); System.out.printf("%-8d %s%n", i, sendResult); } catch (Exception e) { diff --git a/example/src/main/java/org/apache/rocketmq/example/ordermessage/Consumer.java b/example/src/main/java/org/apache/rocketmq/example/ordermessage/Consumer.java index 7ddfbf7e..0a25402b 100644 --- a/example/src/main/java/org/apache/rocketmq/example/ordermessage/Consumer.java +++ b/example/src/main/java/org/apache/rocketmq/example/ordermessage/Consumer.java @@ -16,6 +16,8 @@ */ package org.apache.rocketmq.example.ordermessage; +import java.util.List; +import java.util.concurrent.atomic.AtomicLong; import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyContext; import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyStatus; @@ -24,10 +26,6 @@ import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.common.consumer.ConsumeFromWhere; import org.apache.rocketmq.common.message.MessageExt; -import java.util.List; -import java.util.concurrent.atomic.AtomicLong; - - public class Consumer { public static void main(String[] args) throws MQClientException { diff --git a/example/src/main/java/org/apache/rocketmq/example/ordermessage/Producer.java b/example/src/main/java/org/apache/rocketmq/example/ordermessage/Producer.java index 84c1da4a..7abbb5ae 100644 --- a/example/src/main/java/org/apache/rocketmq/example/ordermessage/Producer.java +++ b/example/src/main/java/org/apache/rocketmq/example/ordermessage/Producer.java @@ -16,6 +16,8 @@ */ package org.apache.rocketmq.example.ordermessage; +import java.io.UnsupportedEncodingException; +import java.util.List; import org.apache.rocketmq.client.exception.MQBrokerException; import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.client.producer.DefaultMQProducer; @@ -27,25 +29,22 @@ import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.remoting.common.RemotingHelper; import org.apache.rocketmq.remoting.exception.RemotingException; -import java.io.UnsupportedEncodingException; -import java.util.List; - public class Producer { public static void main(String[] args) throws UnsupportedEncodingException { try { MQProducer producer = new DefaultMQProducer("please_rename_unique_group_name"); producer.start(); - String[] tags = new String[]{"TagA", "TagB", "TagC", "TagD", "TagE"}; + String[] tags = new String[] {"TagA", "TagB", "TagC", "TagD", "TagE"}; for (int i = 0; i < 100; i++) { int orderId = i % 10; Message msg = - new Message("TopicTestjjj", tags[i % tags.length], "KEY" + i, - ("Hello RocketMQ " + i).getBytes(RemotingHelper.DEFAULT_CHARSET)); + new Message("TopicTestjjj", tags[i % tags.length], "KEY" + i, + ("Hello RocketMQ " + i).getBytes(RemotingHelper.DEFAULT_CHARSET)); SendResult sendResult = producer.send(msg, new MessageQueueSelector() { @Override public MessageQueue select(List mqs, Message msg, Object arg) { - Integer id = (Integer) arg; + Integer id = (Integer)arg; int index = id % mqs.size(); return mqs.get(index); } diff --git a/example/src/main/java/org/apache/rocketmq/example/quickstart/Consumer.java b/example/src/main/java/org/apache/rocketmq/example/quickstart/Consumer.java index 43566f0d..513c2690 100644 --- a/example/src/main/java/org/apache/rocketmq/example/quickstart/Consumer.java +++ b/example/src/main/java/org/apache/rocketmq/example/quickstart/Consumer.java @@ -16,6 +16,7 @@ */ package org.apache.rocketmq.example.quickstart; +import java.util.List; import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext; import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; @@ -24,8 +25,6 @@ import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.common.consumer.ConsumeFromWhere; import org.apache.rocketmq.common.message.MessageExt; -import java.util.List; - public class Consumer { public static void main(String[] args) throws InterruptedException, MQClientException { @@ -39,7 +38,7 @@ public class Consumer { @Override public ConsumeConcurrentlyStatus consumeMessage(List msgs, - ConsumeConcurrentlyContext context) { + ConsumeConcurrentlyContext context) { System.out.printf(Thread.currentThread().getName() + " Receive New Messages: " + msgs + "%n"); return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; } diff --git a/example/src/main/java/org/apache/rocketmq/example/quickstart/Producer.java b/example/src/main/java/org/apache/rocketmq/example/quickstart/Producer.java index f6bd5df0..a74d9dfe 100644 --- a/example/src/main/java/org/apache/rocketmq/example/quickstart/Producer.java +++ b/example/src/main/java/org/apache/rocketmq/example/quickstart/Producer.java @@ -32,8 +32,8 @@ public class Producer { for (int i = 0; i < 1000; i++) { try { Message msg = new Message("TopicTest", - "TagA", - ("Hello RocketMQ " + i).getBytes(RemotingHelper.DEFAULT_CHARSET) + "TagA", + ("Hello RocketMQ " + i).getBytes(RemotingHelper.DEFAULT_CHARSET) ); SendResult sendResult = producer.send(msg); LocalTransactionExecuter tranExecuter = new LocalTransactionExecuter() { diff --git a/example/src/main/java/org/apache/rocketmq/example/simple/AsyncProducer.java b/example/src/main/java/org/apache/rocketmq/example/simple/AsyncProducer.java index 68dbb679..d4d9975e 100644 --- a/example/src/main/java/org/apache/rocketmq/example/simple/AsyncProducer.java +++ b/example/src/main/java/org/apache/rocketmq/example/simple/AsyncProducer.java @@ -16,6 +16,7 @@ */ package org.apache.rocketmq.example.simple; +import java.io.UnsupportedEncodingException; import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.client.producer.DefaultMQProducer; import org.apache.rocketmq.client.producer.SendCallback; @@ -23,9 +24,6 @@ import org.apache.rocketmq.client.producer.SendResult; import org.apache.rocketmq.common.message.Message; import org.apache.rocketmq.remoting.common.RemotingHelper; -import java.io.UnsupportedEncodingException; - - public class AsyncProducer { public static void main(String[] args) throws MQClientException, InterruptedException, UnsupportedEncodingException { @@ -37,9 +35,9 @@ public class AsyncProducer { try { final int index = i; Message msg = new Message("Jodie_topic_1023", - "TagA", - "OrderID188", - "Hello world".getBytes(RemotingHelper.DEFAULT_CHARSET)); + "TagA", + "OrderID188", + "Hello world".getBytes(RemotingHelper.DEFAULT_CHARSET)); producer.send(msg, new SendCallback() { @Override public void onSuccess(SendResult sendResult) { diff --git a/example/src/main/java/org/apache/rocketmq/example/simple/CachedQueue.java b/example/src/main/java/org/apache/rocketmq/example/simple/CachedQueue.java index 2b4ce236..54bf54f6 100644 --- a/example/src/main/java/org/apache/rocketmq/example/simple/CachedQueue.java +++ b/example/src/main/java/org/apache/rocketmq/example/simple/CachedQueue.java @@ -6,26 +6,23 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.example.simple; -import org.apache.rocketmq.common.message.MessageExt; - import java.util.TreeMap; - +import org.apache.rocketmq.common.message.MessageExt; public class CachedQueue { private final TreeMap msgCachedTable = new TreeMap(); - public TreeMap getMsgCachedTable() { return msgCachedTable; } diff --git a/example/src/main/java/org/apache/rocketmq/example/simple/Producer.java b/example/src/main/java/org/apache/rocketmq/example/simple/Producer.java index b035d57a..590bcee3 100644 --- a/example/src/main/java/org/apache/rocketmq/example/simple/Producer.java +++ b/example/src/main/java/org/apache/rocketmq/example/simple/Producer.java @@ -22,7 +22,6 @@ import org.apache.rocketmq.client.producer.SendResult; import org.apache.rocketmq.common.message.Message; import org.apache.rocketmq.remoting.common.RemotingHelper; - public class Producer { public static void main(String[] args) throws MQClientException, InterruptedException { @@ -34,9 +33,9 @@ public class Producer { try { { Message msg = new Message("TopicTest", - "TagA", - "OrderID188", - "Hello world".getBytes(RemotingHelper.DEFAULT_CHARSET)); + "TagA", + "OrderID188", + "Hello world".getBytes(RemotingHelper.DEFAULT_CHARSET)); SendResult sendResult = producer.send(msg); System.out.printf("%s%n", sendResult); } diff --git a/example/src/main/java/org/apache/rocketmq/example/simple/PullConsumer.java b/example/src/main/java/org/apache/rocketmq/example/simple/PullConsumer.java index 8c9ba152..c468f3ae 100644 --- a/example/src/main/java/org/apache/rocketmq/example/simple/PullConsumer.java +++ b/example/src/main/java/org/apache/rocketmq/example/simple/PullConsumer.java @@ -16,19 +16,17 @@ */ package org.apache.rocketmq.example.simple; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; import org.apache.rocketmq.client.consumer.DefaultMQPullConsumer; import org.apache.rocketmq.client.consumer.PullResult; import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.common.message.MessageQueue; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - public class PullConsumer { private static final Map OFFSE_TABLE = new HashMap(); - public static void main(String[] args) throws MQClientException { DefaultMQPullConsumer consumer = new DefaultMQPullConsumer("please_rename_unique_group_name_5"); @@ -41,7 +39,7 @@ public class PullConsumer { while (true) { try { PullResult pullResult = - consumer.pullBlockIfNotFound(mq, null, getMessageQueueOffset(mq), 32); + consumer.pullBlockIfNotFound(mq, null, getMessageQueueOffset(mq), 32); System.out.printf("%s%n", pullResult); putMessageQueueOffset(mq, pullResult.getNextBeginOffset()); switch (pullResult.getPullStatus()) { diff --git a/example/src/main/java/org/apache/rocketmq/example/simple/PullScheduleService.java b/example/src/main/java/org/apache/rocketmq/example/simple/PullScheduleService.java index d38d6799..b6bc8d25 100644 --- a/example/src/main/java/org/apache/rocketmq/example/simple/PullScheduleService.java +++ b/example/src/main/java/org/apache/rocketmq/example/simple/PullScheduleService.java @@ -26,7 +26,6 @@ import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.common.protocol.heartbeat.MessageModel; - public class PullScheduleService { public static void main(String[] args) throws MQClientException { @@ -59,7 +58,6 @@ public class PullScheduleService { } consumer.updateConsumeOffset(mq, pullResult.getNextBeginOffset()); - context.setPullNextDelayTimeMillis(100); } catch (Exception e) { e.printStackTrace(); diff --git a/example/src/main/java/org/apache/rocketmq/example/simple/PushConsumer.java b/example/src/main/java/org/apache/rocketmq/example/simple/PushConsumer.java index 5929affa..78bb9220 100644 --- a/example/src/main/java/org/apache/rocketmq/example/simple/PushConsumer.java +++ b/example/src/main/java/org/apache/rocketmq/example/simple/PushConsumer.java @@ -16,6 +16,7 @@ */ package org.apache.rocketmq.example.simple; +import java.util.List; import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext; import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; @@ -24,9 +25,6 @@ import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.common.consumer.ConsumeFromWhere; import org.apache.rocketmq.common.message.MessageExt; -import java.util.List; - - public class PushConsumer { public static void main(String[] args) throws InterruptedException, MQClientException { diff --git a/example/src/main/java/org/apache/rocketmq/example/simple/RandomAsyncCommit.java b/example/src/main/java/org/apache/rocketmq/example/simple/RandomAsyncCommit.java index cda79523..1e13d39e 100644 --- a/example/src/main/java/org/apache/rocketmq/example/simple/RandomAsyncCommit.java +++ b/example/src/main/java/org/apache/rocketmq/example/simple/RandomAsyncCommit.java @@ -6,28 +6,25 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.example.simple; -import org.apache.rocketmq.common.message.MessageExt; -import org.apache.rocketmq.common.message.MessageQueue; - import java.util.List; import java.util.concurrent.ConcurrentHashMap; - +import org.apache.rocketmq.common.message.MessageExt; +import org.apache.rocketmq.common.message.MessageQueue; public class RandomAsyncCommit { private final ConcurrentHashMap mqCachedTable = - new ConcurrentHashMap(); - + new ConcurrentHashMap(); public void putMessages(final MessageQueue mq, final List msgs) { CachedQueue cachedQueue = this.mqCachedTable.get(mq); @@ -40,7 +37,6 @@ public class RandomAsyncCommit { } } - public void removeMessage(final MessageQueue mq, long offset) { CachedQueue cachedQueue = this.mqCachedTable.get(mq); if (null != cachedQueue) { @@ -48,7 +44,6 @@ public class RandomAsyncCommit { } } - public long commitableOffset(final MessageQueue mq) { CachedQueue cachedQueue = this.mqCachedTable.get(mq); if (null != cachedQueue) { diff --git a/example/src/main/java/org/apache/rocketmq/example/simple/TestProducer.java b/example/src/main/java/org/apache/rocketmq/example/simple/TestProducer.java index 0304a639..8787fa8b 100644 --- a/example/src/main/java/org/apache/rocketmq/example/simple/TestProducer.java +++ b/example/src/main/java/org/apache/rocketmq/example/simple/TestProducer.java @@ -33,14 +33,14 @@ public class TestProducer { try { { Message msg = new Message("TopicTest1", - "TagA", - "key113", - "Hello world".getBytes(RemotingHelper.DEFAULT_CHARSET)); + "TagA", + "key113", + "Hello world".getBytes(RemotingHelper.DEFAULT_CHARSET)); SendResult sendResult = producer.send(msg); System.out.printf("%s%n", sendResult); QueryResult queryMessage = - producer.queryMessage("TopicTest1", "key113", 10, 0, System.currentTimeMillis()); + producer.queryMessage("TopicTest1", "key113", 10, 0, System.currentTimeMillis()); for (MessageExt m : queryMessage.getMessageList()) { System.out.printf("%s%n", m); } diff --git a/example/src/main/java/org/apache/rocketmq/example/transaction/TransactionCheckListenerImpl.java b/example/src/main/java/org/apache/rocketmq/example/transaction/TransactionCheckListenerImpl.java index fea93a84..1beed713 100644 --- a/example/src/main/java/org/apache/rocketmq/example/transaction/TransactionCheckListenerImpl.java +++ b/example/src/main/java/org/apache/rocketmq/example/transaction/TransactionCheckListenerImpl.java @@ -16,17 +16,14 @@ */ package org.apache.rocketmq.example.transaction; +import java.util.concurrent.atomic.AtomicInteger; import org.apache.rocketmq.client.producer.LocalTransactionState; import org.apache.rocketmq.client.producer.TransactionCheckListener; import org.apache.rocketmq.common.message.MessageExt; -import java.util.concurrent.atomic.AtomicInteger; - - public class TransactionCheckListenerImpl implements TransactionCheckListener { private AtomicInteger transactionIndex = new AtomicInteger(0); - @Override public LocalTransactionState checkLocalTransactionState(MessageExt msg) { System.out.printf("server checking TrMsg " + msg.toString() + "%n"); diff --git a/example/src/main/java/org/apache/rocketmq/example/transaction/TransactionExecuterImpl.java b/example/src/main/java/org/apache/rocketmq/example/transaction/TransactionExecuterImpl.java index eb787fd5..b767a4a5 100644 --- a/example/src/main/java/org/apache/rocketmq/example/transaction/TransactionExecuterImpl.java +++ b/example/src/main/java/org/apache/rocketmq/example/transaction/TransactionExecuterImpl.java @@ -6,26 +6,24 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.example.transaction; +import java.util.concurrent.atomic.AtomicInteger; import org.apache.rocketmq.client.producer.LocalTransactionExecuter; import org.apache.rocketmq.client.producer.LocalTransactionState; import org.apache.rocketmq.common.message.Message; -import java.util.concurrent.atomic.AtomicInteger; - public class TransactionExecuterImpl implements LocalTransactionExecuter { private AtomicInteger transactionIndex = new AtomicInteger(1); - @Override public LocalTransactionState executeLocalTransactionBranch(final Message msg, final Object arg) { int value = transactionIndex.getAndIncrement(); diff --git a/example/src/main/java/org/apache/rocketmq/example/transaction/TransactionProducer.java b/example/src/main/java/org/apache/rocketmq/example/transaction/TransactionProducer.java index 5a868c64..1609a811 100644 --- a/example/src/main/java/org/apache/rocketmq/example/transaction/TransactionProducer.java +++ b/example/src/main/java/org/apache/rocketmq/example/transaction/TransactionProducer.java @@ -16,6 +16,7 @@ */ package org.apache.rocketmq.example.transaction; +import java.io.UnsupportedEncodingException; import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.client.producer.SendResult; import org.apache.rocketmq.client.producer.TransactionCheckListener; @@ -23,8 +24,6 @@ import org.apache.rocketmq.client.producer.TransactionMQProducer; import org.apache.rocketmq.common.message.Message; import org.apache.rocketmq.remoting.common.RemotingHelper; -import java.io.UnsupportedEncodingException; - public class TransactionProducer { public static void main(String[] args) throws MQClientException, InterruptedException { TransactionCheckListener transactionCheckListener = new TransactionCheckListenerImpl(); @@ -35,13 +34,13 @@ public class TransactionProducer { producer.setTransactionCheckListener(transactionCheckListener); producer.start(); - String[] tags = new String[]{"TagA", "TagB", "TagC", "TagD", "TagE"}; + String[] tags = new String[] {"TagA", "TagB", "TagC", "TagD", "TagE"}; TransactionExecuterImpl tranExecuter = new TransactionExecuterImpl(); for (int i = 0; i < 100; i++) { try { Message msg = - new Message("TopicTest", tags[i % tags.length], "KEY" + i, - ("Hello RocketMQ " + i).getBytes(RemotingHelper.DEFAULT_CHARSET)); + new Message("TopicTest", tags[i % tags.length], "KEY" + i, + ("Hello RocketMQ " + i).getBytes(RemotingHelper.DEFAULT_CHARSET)); SendResult sendResult = producer.sendMessageInTransaction(msg, tranExecuter, null); System.out.printf("%s%n", sendResult); diff --git a/example/src/main/resources/MessageFilterImpl.java b/example/src/main/resources/MessageFilterImpl.java index 3ff3f48b..83ca00ef 100644 --- a/example/src/main/resources/MessageFilterImpl.java +++ b/example/src/main/resources/MessageFilterImpl.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.example.filter; @@ -20,7 +20,6 @@ package org.apache.rocketmq.example.filter; import org.apache.rocketmq.common.filter.MessageFilter; import org.apache.rocketmq.common.message.MessageExt; - public class MessageFilterImpl implements MessageFilter { @Override @@ -29,7 +28,7 @@ public class MessageFilterImpl implements MessageFilter { if (property != null) { int id = Integer.parseInt(property); if (((id % 10) == 0) && // - (id > 100)) { + (id > 100)) { return true; } } diff --git a/filtersrv/pom.xml b/filtersrv/pom.xml index bebd10a1..cf5388db 100644 --- a/filtersrv/pom.xml +++ b/filtersrv/pom.xml @@ -15,7 +15,7 @@ limitations under the License. --> - org.apache.rocketmq diff --git a/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/FilterServerOuterAPI.java b/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/FilterServerOuterAPI.java index bd16e0d1..32b8bad4 100644 --- a/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/FilterServerOuterAPI.java +++ b/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/FilterServerOuterAPI.java @@ -30,43 +30,38 @@ import org.apache.rocketmq.remoting.netty.NettyClientConfig; import org.apache.rocketmq.remoting.netty.NettyRemotingClient; import org.apache.rocketmq.remoting.protocol.RemotingCommand; - public class FilterServerOuterAPI { private final RemotingClient remotingClient; - public FilterServerOuterAPI() { this.remotingClient = new NettyRemotingClient(new NettyClientConfig()); } - public void start() { this.remotingClient.start(); } - public void shutdown() { this.remotingClient.shutdown(); } - public RegisterFilterServerResponseHeader registerFilterServerToBroker( - final String brokerAddr, - final String filterServerAddr + final String brokerAddr, + final String filterServerAddr ) throws RemotingCommandException, RemotingConnectException, RemotingSendRequestException, - RemotingTimeoutException, InterruptedException, MQBrokerException { + RemotingTimeoutException, InterruptedException, MQBrokerException { RegisterFilterServerRequestHeader requestHeader = new RegisterFilterServerRequestHeader(); requestHeader.setFilterServerAddr(filterServerAddr); RemotingCommand request = - RemotingCommand.createRequestCommand(RequestCode.REGISTER_FILTER_SERVER, requestHeader); + RemotingCommand.createRequestCommand(RequestCode.REGISTER_FILTER_SERVER, requestHeader); RemotingCommand response = this.remotingClient.invokeSync(brokerAddr, request, 3000); assert response != null; switch (response.getCode()) { case ResponseCode.SUCCESS: { RegisterFilterServerResponseHeader responseHeader = - (RegisterFilterServerResponseHeader) response - .decodeCommandCustomHeader(RegisterFilterServerResponseHeader.class); + (RegisterFilterServerResponseHeader)response + .decodeCommandCustomHeader(RegisterFilterServerResponseHeader.class); return responseHeader; } diff --git a/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/FiltersrvConfig.java b/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/FiltersrvConfig.java index ec0381d3..ee2ebee1 100644 --- a/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/FiltersrvConfig.java +++ b/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/FiltersrvConfig.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.filtersrv; @@ -21,14 +21,13 @@ import org.apache.rocketmq.common.MixAll; import org.apache.rocketmq.common.annotation.ImportantField; import org.apache.rocketmq.remoting.common.RemotingUtil; - public class FiltersrvConfig { private String rocketmqHome = System.getProperty(MixAll.ROCKETMQ_HOME_PROPERTY, - System.getenv(MixAll.ROCKETMQ_HOME_ENV)); + System.getenv(MixAll.ROCKETMQ_HOME_ENV)); @ImportantField private String namesrvAddr = System.getProperty(MixAll.NAMESRV_ADDR_PROPERTY, - System.getenv(MixAll.NAMESRV_ADDR_ENV)); + System.getenv(MixAll.NAMESRV_ADDR_ENV)); private String connectWhichBroker = "127.0.0.1:10911"; private String filterServerIP = RemotingUtil.getLocalAddress(); @@ -36,122 +35,98 @@ public class FiltersrvConfig { private int compressMsgBodyOverHowmuch = 1024 * 8; private int zipCompressLevel = 5; - private boolean clientUploadFilterClassEnable = true; - private String filterClassRepertoryUrl = "http://fsrep.tbsite.net/filterclass"; private int fsServerAsyncSemaphoreValue = 2048; private int fsServerCallbackExecutorThreads = 64; private int fsServerWorkerThreads = 64; - public String getRocketmqHome() { return rocketmqHome; } - public void setRocketmqHome(String rocketmqHome) { this.rocketmqHome = rocketmqHome; } - public String getNamesrvAddr() { return namesrvAddr; } - public void setNamesrvAddr(String namesrvAddr) { this.namesrvAddr = namesrvAddr; } - public String getConnectWhichBroker() { return connectWhichBroker; } - public void setConnectWhichBroker(String connectWhichBroker) { this.connectWhichBroker = connectWhichBroker; } - public String getFilterServerIP() { return filterServerIP; } - public void setFilterServerIP(String filterServerIP) { this.filterServerIP = filterServerIP; } - public int getCompressMsgBodyOverHowmuch() { return compressMsgBodyOverHowmuch; } - public void setCompressMsgBodyOverHowmuch(int compressMsgBodyOverHowmuch) { this.compressMsgBodyOverHowmuch = compressMsgBodyOverHowmuch; } - public int getZipCompressLevel() { return zipCompressLevel; } - public void setZipCompressLevel(int zipCompressLevel) { this.zipCompressLevel = zipCompressLevel; } - public boolean isClientUploadFilterClassEnable() { return clientUploadFilterClassEnable; } - public void setClientUploadFilterClassEnable(boolean clientUploadFilterClassEnable) { this.clientUploadFilterClassEnable = clientUploadFilterClassEnable; } - public String getFilterClassRepertoryUrl() { return filterClassRepertoryUrl; } - public void setFilterClassRepertoryUrl(String filterClassRepertoryUrl) { this.filterClassRepertoryUrl = filterClassRepertoryUrl; } - public int getFsServerAsyncSemaphoreValue() { return fsServerAsyncSemaphoreValue; } - public void setFsServerAsyncSemaphoreValue(int fsServerAsyncSemaphoreValue) { this.fsServerAsyncSemaphoreValue = fsServerAsyncSemaphoreValue; } - public int getFsServerCallbackExecutorThreads() { return fsServerCallbackExecutorThreads; } - public void setFsServerCallbackExecutorThreads(int fsServerCallbackExecutorThreads) { this.fsServerCallbackExecutorThreads = fsServerCallbackExecutorThreads; } - public int getFsServerWorkerThreads() { return fsServerWorkerThreads; } - public void setFsServerWorkerThreads(int fsServerWorkerThreads) { this.fsServerWorkerThreads = fsServerWorkerThreads; } diff --git a/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/FiltersrvController.java b/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/FiltersrvController.java index ca136e05..c46b6132 100644 --- a/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/FiltersrvController.java +++ b/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/FiltersrvController.java @@ -16,6 +16,10 @@ */ package org.apache.rocketmq.filtersrv; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; import org.apache.rocketmq.client.consumer.DefaultMQPullConsumer; import org.apache.rocketmq.common.MixAll; import org.apache.rocketmq.common.ThreadFactoryImpl; @@ -31,12 +35,6 @@ import org.apache.rocketmq.remoting.netty.NettyServerConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; - - public class FiltersrvController { private static final Logger log = LoggerFactory.getLogger(LoggerName.FILTERSRV_LOGGER_NAME); @@ -47,10 +45,10 @@ public class FiltersrvController { private final FilterServerOuterAPI filterServerOuterAPI = new FilterServerOuterAPI(); private final DefaultMQPullConsumer defaultMQPullConsumer = new DefaultMQPullConsumer( - MixAll.FILTERSRV_CONSUMER_GROUP); + MixAll.FILTERSRV_CONSUMER_GROUP); private final ScheduledExecutorService scheduledExecutorService = Executors - .newSingleThreadScheduledExecutor(new ThreadFactoryImpl("FSScheduledThread")); + .newSingleThreadScheduledExecutor(new ThreadFactoryImpl("FSScheduledThread")); private final FilterServerStatsManager filterServerStatsManager = new FilterServerStatsManager(); private RemotingServer remotingServer; @@ -58,29 +56,24 @@ public class FiltersrvController { private ExecutorService remotingExecutor; private volatile String brokerName = null; - public FiltersrvController(FiltersrvConfig filtersrvConfig, NettyServerConfig nettyServerConfig) { this.filtersrvConfig = filtersrvConfig; this.nettyServerConfig = nettyServerConfig; this.filterClassManager = new FilterClassManager(this); } - public boolean initialize() { MixAll.printObjectProperties(log, this.filtersrvConfig); - this.remotingServer = new NettyRemotingServer(this.nettyServerConfig); - this.remotingExecutor = - Executors.newFixedThreadPool(nettyServerConfig.getServerWorkerThreads(), - new ThreadFactoryImpl("RemotingExecutorThread_")); + Executors.newFixedThreadPool(nettyServerConfig.getServerWorkerThreads(), + new ThreadFactoryImpl("RemotingExecutorThread_")); this.registerProcessor(); - this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() { @Override @@ -90,9 +83,9 @@ public class FiltersrvController { }, 3, 10, TimeUnit.SECONDS); this.defaultMQPullConsumer.setBrokerSuspendMaxTimeMillis(this.defaultMQPullConsumer - .getBrokerSuspendMaxTimeMillis() - 1000); + .getBrokerSuspendMaxTimeMillis() - 1000); this.defaultMQPullConsumer.setConsumerTimeoutMillisWhenSuspend(this.defaultMQPullConsumer - .getConsumerTimeoutMillisWhenSuspend() - 1000); + .getConsumerTimeoutMillisWhenSuspend() - 1000); this.defaultMQPullConsumer.setNamesrvAddr(this.filtersrvConfig.getNamesrvAddr()); this.defaultMQPullConsumer.setInstanceName(String.valueOf(UtilAll.getPid())); @@ -102,26 +95,26 @@ public class FiltersrvController { private void registerProcessor() { this.remotingServer - .registerDefaultProcessor(new DefaultRequestProcessor(this), this.remotingExecutor); + .registerDefaultProcessor(new DefaultRequestProcessor(this), this.remotingExecutor); } public void registerFilterServerToBroker() { try { RegisterFilterServerResponseHeader responseHeader = - this.filterServerOuterAPI.registerFilterServerToBroker( - this.filtersrvConfig.getConnectWhichBroker(), this.localAddr()); + this.filterServerOuterAPI.registerFilterServerToBroker( + this.filtersrvConfig.getConnectWhichBroker(), this.localAddr()); this.defaultMQPullConsumer.getDefaultMQPullConsumerImpl().getPullAPIWrapper() - .setDefaultBrokerId(responseHeader.getBrokerId()); + .setDefaultBrokerId(responseHeader.getBrokerId()); if (null == this.brokerName) { this.brokerName = responseHeader.getBrokerName(); } log.info("register filter server<{}> to broker<{}> OK, Return: {} {}", - this.localAddr(), - this.filtersrvConfig.getConnectWhichBroker(), - responseHeader.getBrokerName(), - responseHeader.getBrokerId()); + this.localAddr(), + this.filtersrvConfig.getConnectWhichBroker(), + responseHeader.getBrokerName(), + responseHeader.getBrokerId()); } catch (Exception e) { log.warn("register filter server Exception", e); @@ -132,7 +125,7 @@ public class FiltersrvController { public String localAddr() { return String.format("%s:%d", this.filtersrvConfig.getFilterServerIP(), - this.remotingServer.localListenPort()); + this.remotingServer.localListenPort()); } public void start() throws Exception { @@ -140,12 +133,11 @@ public class FiltersrvController { this.remotingServer.start(); this.filterServerOuterAPI.start(); this.defaultMQPullConsumer.getDefaultMQPullConsumerImpl().getPullAPIWrapper() - .setConnectBrokerByUser(true); + .setConnectBrokerByUser(true); this.filterClassManager.start(); this.filterServerStatsManager.start(); } - public void shutdown() { this.remotingServer.shutdown(); this.remotingExecutor.shutdown(); @@ -156,67 +148,54 @@ public class FiltersrvController { this.filterServerStatsManager.shutdown(); } - public RemotingServer getRemotingServer() { return remotingServer; } - public void setRemotingServer(RemotingServer remotingServer) { this.remotingServer = remotingServer; } - public ExecutorService getRemotingExecutor() { return remotingExecutor; } - public void setRemotingExecutor(ExecutorService remotingExecutor) { this.remotingExecutor = remotingExecutor; } - public FiltersrvConfig getFiltersrvConfig() { return filtersrvConfig; } - public NettyServerConfig getNettyServerConfig() { return nettyServerConfig; } - public ScheduledExecutorService getScheduledExecutorService() { return scheduledExecutorService; } - public FilterServerOuterAPI getFilterServerOuterAPI() { return filterServerOuterAPI; } - public FilterClassManager getFilterClassManager() { return filterClassManager; } - public DefaultMQPullConsumer getDefaultMQPullConsumer() { return defaultMQPullConsumer; } - public String getBrokerName() { return brokerName; } - public void setBrokerName(String brokerName) { this.brokerName = brokerName; } - public FilterServerStatsManager getFilterServerStatsManager() { return filterServerStatsManager; } diff --git a/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/FiltersrvStartup.java b/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/FiltersrvStartup.java index 461c79c0..f239caf1 100644 --- a/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/FiltersrvStartup.java +++ b/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/FiltersrvStartup.java @@ -18,6 +18,15 @@ package org.apache.rocketmq.filtersrv; import ch.qos.logback.classic.LoggerContext; import ch.qos.logback.classic.joran.JoranConfigurator; +import java.io.BufferedInputStream; +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.Properties; +import java.util.concurrent.atomic.AtomicInteger; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.PosixParser; import org.apache.rocketmq.common.MQVersion; import org.apache.rocketmq.common.MixAll; import org.apache.rocketmq.common.constant.LoggerName; @@ -25,20 +34,9 @@ import org.apache.rocketmq.remoting.netty.NettyServerConfig; import org.apache.rocketmq.remoting.netty.NettySystemConfig; import org.apache.rocketmq.remoting.protocol.RemotingCommand; import org.apache.rocketmq.srvutil.ServerUtil; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.PosixParser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.BufferedInputStream; -import java.io.FileInputStream; -import java.io.InputStream; -import java.util.Properties; -import java.util.concurrent.atomic.AtomicInteger; - - public class FiltersrvStartup { public static Logger log; @@ -65,12 +63,10 @@ public class FiltersrvStartup { public static FiltersrvController createController(String[] args) { System.setProperty(RemotingCommand.REMOTING_VERSION_KEY, Integer.toString(MQVersion.CURRENT_VERSION)); - if (null == System.getProperty(NettySystemConfig.COM_ROCKETMQ_REMOTING_SOCKET_SNDBUF_SIZE)) { NettySystemConfig.socketSndbufSize = 65535; } - if (null == System.getProperty(NettySystemConfig.COM_ROCKETMQ_REMOTING_SOCKET_RCVBUF_SIZE)) { NettySystemConfig.socketRcvbufSize = 1024; } @@ -78,8 +74,8 @@ public class FiltersrvStartup { try { Options options = ServerUtil.buildCommandlineOptions(new Options()); final CommandLine commandLine = - ServerUtil.parseCmdLine("mqfiltersrv", args, buildCommandlineOptions(options), - new PosixParser()); + ServerUtil.parseCmdLine("mqfiltersrv", args, buildCommandlineOptions(options), + new PosixParser()); if (null == commandLine) { System.exit(-1); return null; @@ -108,7 +104,7 @@ public class FiltersrvStartup { nettyServerConfig.setListenPort(0); nettyServerConfig.setServerAsyncSemaphoreValue(filtersrvConfig.getFsServerAsyncSemaphoreValue()); nettyServerConfig.setServerCallbackExecutorThreads(filtersrvConfig - .getFsServerCallbackExecutorThreads()); + .getFsServerCallbackExecutorThreads()); nettyServerConfig.setServerWorkerThreads(filtersrvConfig.getFsServerWorkerThreads()); if (commandLine.hasOption('p')) { @@ -120,11 +116,11 @@ public class FiltersrvStartup { MixAll.properties2Object(ServerUtil.commandLine2Properties(commandLine), filtersrvConfig); if (null == filtersrvConfig.getRocketmqHome()) { System.out.printf("Please set the " + MixAll.ROCKETMQ_HOME_ENV - + " variable in your environment to match the location of the RocketMQ installation%n"); + + " variable in your environment to match the location of the RocketMQ installation%n"); System.exit(-2); } - LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); + LoggerContext lc = (LoggerContext)LoggerFactory.getILoggerFactory(); JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(lc); lc.reset(); @@ -132,7 +128,7 @@ public class FiltersrvStartup { log = LoggerFactory.getLogger(LoggerName.FILTERSRV_LOGGER_NAME); final FiltersrvController controller = - new FiltersrvController(filtersrvConfig, nettyServerConfig); + new FiltersrvController(filtersrvConfig, nettyServerConfig); boolean initResult = controller.initialize(); if (!initResult) { controller.shutdown(); diff --git a/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/filter/DynaCode.java b/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/filter/DynaCode.java index fd956856..11102d08 100644 --- a/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/filter/DynaCode.java +++ b/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/filter/DynaCode.java @@ -6,35 +6,43 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.filtersrv.filter; +import java.io.BufferedWriter; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.OutputStreamWriter; +import java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.net.URLDecoder; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import javax.tools.JavaCompiler; +import javax.tools.ToolProvider; +import org.apache.commons.lang3.StringUtils; import org.apache.rocketmq.common.UtilAll; import org.apache.rocketmq.common.constant.LoggerName; import org.apache.rocketmq.common.filter.FilterAPI; import org.apache.rocketmq.remoting.common.RemotingHelper; -import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.tools.JavaCompiler; -import javax.tools.ToolProvider; -import java.io.*; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.net.URLDecoder; -import java.util.*; - - public class DynaCode { private static final Logger LOGGER = LoggerFactory.getLogger(LoggerName.FILTERSRV_LOGGER_NAME); @@ -43,46 +51,35 @@ public class DynaCode { private static final String LINE_SP = System.getProperty("line.separator"); private String sourcePath = System.getProperty("user.home") + FILE_SP + "rocketmq_filter_class" + FILE_SP - + UtilAll.getPid(); + + UtilAll.getPid(); private String outPutClassPath = sourcePath; - private ClassLoader parentClassLoader; - private List codeStrs; - private Map/* class */> loadClass; - private String classpath; - private String bootclasspath; - private String extdirs; - private String encoding = "UTF-8"; - private String target; - @SuppressWarnings("unchecked") public DynaCode(String code) { this(Thread.currentThread().getContextClassLoader(), Arrays.asList(code)); } - public DynaCode(ClassLoader parentClassLoader, List codeStrs) { this(extractClasspath(parentClassLoader), parentClassLoader, codeStrs); } - public DynaCode(String classpath, ClassLoader parentClassLoader, List codeStrs) { this.classpath = classpath; this.parentClassLoader = parentClassLoader; @@ -90,12 +87,15 @@ public class DynaCode { this.loadClass = new HashMap>(codeStrs.size()); } + public DynaCode(List codeStrs) { + this(Thread.currentThread().getContextClassLoader(), codeStrs); + } private static String extractClasspath(ClassLoader cl) { StringBuffer buf = new StringBuffer(); while (cl != null) { if (cl instanceof URLClassLoader) { - URL urls[] = ((URLClassLoader) cl).getURLs(); + URL urls[] = ((URLClassLoader)cl).getURLs(); for (int i = 0; i < urls.length; i++) { if (buf.length() > 0) { buf.append(File.pathSeparatorChar); @@ -115,13 +115,8 @@ public class DynaCode { return buf.toString(); } - - public DynaCode(List codeStrs) { - this(Thread.currentThread().getContextClassLoader(), codeStrs); - } - public static Class compileAndLoadClass(final String className, final String javaSource) - throws Exception { + throws Exception { String classSimpleName = FilterAPI.simpleClassName(className); String javaCode = javaSource; @@ -138,16 +133,6 @@ public class DynaCode { return clazz; } - public void compileAndLoadClass() throws Exception { - String[] sourceFiles = this.uploadSrcFile(); - this.compile(sourceFiles); - this.loadClass(this.loadClass.keySet()); - } - - public Map> getLoadClass() { - return loadClass; - } - public static String getQualifiedName(String code) { StringBuilder sb = new StringBuilder(); String className = getClassName(code); @@ -162,6 +147,57 @@ public class DynaCode { return sb.toString(); } + public static String getClassName(String code) { + String className = StringUtils.substringBefore(code, "{"); + if (StringUtils.isBlank(className)) { + return className; + } + if (StringUtils.contains(code, " class ")) { + className = StringUtils.substringAfter(className, " class "); + if (StringUtils.contains(className, " extends ")) { + className = StringUtils.substringBefore(className, " extends ").trim(); + } else if (StringUtils.contains(className, " implements ")) { + className = StringUtils.trim(StringUtils.substringBefore(className, " implements ")); + } else { + className = StringUtils.trim(className); + } + } else if (StringUtils.contains(code, " interface ")) { + className = StringUtils.substringAfter(className, " interface "); + if (StringUtils.contains(className, " extends ")) { + className = StringUtils.substringBefore(className, " extends ").trim(); + } else { + className = StringUtils.trim(className); + } + } else if (StringUtils.contains(code, " enum ")) { + className = StringUtils.trim(StringUtils.substringAfter(className, " enum ")); + } else { + return StringUtils.EMPTY; + } + return className; + } + + public static String getPackageName(String code) { + String packageName = + StringUtils.substringBefore(StringUtils.substringAfter(code, "package "), ";").trim(); + return packageName; + } + + public static String getFullClassName(String code) { + String packageName = getPackageName(code); + String className = getClassName(code); + return StringUtils.isBlank(packageName) ? className : packageName + "." + className; + } + + public void compileAndLoadClass() throws Exception { + String[] sourceFiles = this.uploadSrcFile(); + this.compile(sourceFiles); + this.loadClass(this.loadClass.keySet()); + } + + public Map> getLoadClass() { + return loadClass; + } + private String[] uploadSrcFile() throws Exception { List srcFileAbsolutePaths = new ArrayList(codeStrs.size()); for (String code : codeStrs) { @@ -201,7 +237,7 @@ public class DynaCode { srcFile.deleteOnExit(); } OutputStreamWriter outputStreamWriter = - new OutputStreamWriter(new FileOutputStream(srcFile), encoding); + new OutputStreamWriter(new FileOutputStream(srcFile), encoding); bufferWriter = new BufferedWriter(outputStreamWriter); for (String lineCode : code.split(LINE_SP)) { bufferWriter.write(lineCode); @@ -225,7 +261,7 @@ public class DynaCode { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); if (compiler == null) { throw new NullPointerException( - "ToolProvider.getSystemJavaCompiler() return null,please use JDK replace JRE!"); + "ToolProvider.getSystemJavaCompiler() return null,please use JDK replace JRE!"); } int resultCode = compiler.run(null, null, err, args); if (resultCode != 0) { @@ -236,8 +272,8 @@ public class DynaCode { private void loadClass(Set classFullNames) throws ClassNotFoundException, MalformedURLException { synchronized (loadClass) { ClassLoader classLoader = - new URLClassLoader(new URL[]{new File(outPutClassPath).toURI().toURL()}, - parentClassLoader); + new URLClassLoader(new URL[] {new File(outPutClassPath).toURI().toURL()}, + parentClassLoader); for (String key : classFullNames) { Class classz = classLoader.loadClass(key); if (null != classz) { @@ -250,47 +286,6 @@ public class DynaCode { } } - public static String getClassName(String code) { - String className = StringUtils.substringBefore(code, "{"); - if (StringUtils.isBlank(className)) { - return className; - } - if (StringUtils.contains(code, " class ")) { - className = StringUtils.substringAfter(className, " class "); - if (StringUtils.contains(className, " extends ")) { - className = StringUtils.substringBefore(className, " extends ").trim(); - } else if (StringUtils.contains(className, " implements ")) { - className = StringUtils.trim(StringUtils.substringBefore(className, " implements ")); - } else { - className = StringUtils.trim(className); - } - } else if (StringUtils.contains(code, " interface ")) { - className = StringUtils.substringAfter(className, " interface "); - if (StringUtils.contains(className, " extends ")) { - className = StringUtils.substringBefore(className, " extends ").trim(); - } else { - className = StringUtils.trim(className); - } - } else if (StringUtils.contains(code, " enum ")) { - className = StringUtils.trim(StringUtils.substringAfter(className, " enum ")); - } else { - return StringUtils.EMPTY; - } - return className; - } - - public static String getPackageName(String code) { - String packageName = - StringUtils.substringBefore(StringUtils.substringAfter(code, "package "), ";").trim(); - return packageName; - } - - public static String getFullClassName(String code) { - String packageName = getPackageName(code); - String className = getClassName(code); - return StringUtils.isBlank(packageName) ? className : packageName + "." + className; - } - private String[] buildCompileJavacArgs(String srcFiles[]) { ArrayList args = new ArrayList(); if (StringUtils.isNotBlank(classpath)) { diff --git a/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/filter/FilterClassFetchMethod.java b/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/filter/FilterClassFetchMethod.java index 36d6b7ec..89f1883b 100644 --- a/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/filter/FilterClassFetchMethod.java +++ b/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/filter/FilterClassFetchMethod.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.filtersrv.filter; diff --git a/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/filter/FilterClassInfo.java b/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/filter/FilterClassInfo.java index d278fe39..1cb0e962 100644 --- a/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/filter/FilterClassInfo.java +++ b/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/filter/FilterClassInfo.java @@ -6,51 +6,44 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.filtersrv.filter; import org.apache.rocketmq.common.filter.MessageFilter; - public class FilterClassInfo { private String className; private int classCRC; private MessageFilter messageFilter; - public int getClassCRC() { return classCRC; } - public void setClassCRC(int classCRC) { this.classCRC = classCRC; } - public MessageFilter getMessageFilter() { return messageFilter; } - public void setMessageFilter(MessageFilter messageFilter) { this.messageFilter = messageFilter; } - public String getClassName() { return className; } - public void setClassName(String className) { this.className = className; } diff --git a/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/filter/FilterClassLoader.java b/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/filter/FilterClassLoader.java index 32698525..32f5ac21 100644 --- a/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/filter/FilterClassLoader.java +++ b/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/filter/FilterClassLoader.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.filtersrv.filter; diff --git a/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/filter/FilterClassManager.java b/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/filter/FilterClassManager.java index fab4d7d5..66389e0f 100644 --- a/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/filter/FilterClassManager.java +++ b/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/filter/FilterClassManager.java @@ -6,17 +6,23 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.filtersrv.filter; +import java.util.Iterator; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; import org.apache.rocketmq.common.MixAll; import org.apache.rocketmq.common.ThreadFactoryImpl; import org.apache.rocketmq.common.UtilAll; @@ -26,14 +32,6 @@ import org.apache.rocketmq.filtersrv.FiltersrvController; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Iterator; -import java.util.Map.Entry; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; - - public class FilterClassManager { private static final Logger log = LoggerFactory.getLogger(LoggerName.FILTERSRV_LOGGER_NAME); @@ -41,19 +39,21 @@ public class FilterClassManager { private final FiltersrvController filtersrvController; private final ScheduledExecutorService scheduledExecutorService = Executors - .newSingleThreadScheduledExecutor(new ThreadFactoryImpl("FSGetClassScheduledThread")); + .newSingleThreadScheduledExecutor(new ThreadFactoryImpl("FSGetClassScheduledThread")); private ConcurrentHashMap filterClassTable = - new ConcurrentHashMap(128); + new ConcurrentHashMap(128); private FilterClassFetchMethod filterClassFetchMethod; - public FilterClassManager(FiltersrvController filtersrvController) { this.filtersrvController = filtersrvController; this.filterClassFetchMethod = - new HttpFilterClassFetchMethod(this.filtersrvController.getFiltersrvConfig() - .getFilterClassRepertoryUrl()); + new HttpFilterClassFetchMethod(this.filtersrvController.getFiltersrvConfig() + .getFilterClassRepertoryUrl()); } + private static String buildKey(final String consumerGroup, final String topic) { + return topic + "@" + consumerGroup; + } public void start() { if (!this.filtersrvController.getFiltersrvConfig().isClientUploadFilterClassEnable()) { @@ -75,20 +75,20 @@ public class FilterClassManager { FilterClassInfo filterClassInfo = next.getValue(); String[] topicAndGroup = next.getKey().split("@"); String responseStr = - this.filterClassFetchMethod.fetch(topicAndGroup[0], topicAndGroup[1], - filterClassInfo.getClassName()); + this.filterClassFetchMethod.fetch(topicAndGroup[0], topicAndGroup[1], + filterClassInfo.getClassName()); byte[] filterSourceBinary = responseStr.getBytes("UTF-8"); int classCRC = UtilAll.crc32(responseStr.getBytes("UTF-8")); if (classCRC != filterClassInfo.getClassCRC()) { String javaSource = new String(filterSourceBinary, MixAll.DEFAULT_CHARSET); Class newClass = - DynaCode.compileAndLoadClass(filterClassInfo.getClassName(), javaSource); + DynaCode.compileAndLoadClass(filterClassInfo.getClassName(), javaSource); Object newInstance = newClass.newInstance(); - filterClassInfo.setMessageFilter((MessageFilter) newInstance); + filterClassInfo.setMessageFilter((MessageFilter)newInstance); filterClassInfo.setClassCRC(classCRC); log.info("fetch Remote class File OK, {} {}", next.getKey(), - filterClassInfo.getClassName()); + filterClassInfo.getClassName()); } } catch (Exception e) { log.error("fetchClassFromRemoteHost Exception", e); @@ -101,10 +101,9 @@ public class FilterClassManager { } public boolean registerFilterClass(final String consumerGroup, final String topic, - final String className, final int classCRC, final byte[] filterSourceBinary) { + final String className, final int classCRC, final byte[] filterSourceBinary) { final String key = buildKey(consumerGroup, topic); - boolean registerNew = false; FilterClassInfo filterClassInfoPrev = this.filterClassTable.get(key); if (null == filterClassInfoPrev) { @@ -135,17 +134,17 @@ public class FilterClassManager { String javaSource = new String(filterSourceBinary, MixAll.DEFAULT_CHARSET); Class newClass = DynaCode.compileAndLoadClass(className, javaSource); Object newInstance = newClass.newInstance(); - filterClassInfoNew.setMessageFilter((MessageFilter) newInstance); + filterClassInfoNew.setMessageFilter((MessageFilter)newInstance); filterClassInfoNew.setClassCRC(classCRC); } this.filterClassTable.put(key, filterClassInfoNew); } catch (Throwable e) { String info = - String - .format( - "FilterServer, registerFilterClass Exception, consumerGroup: %s topic: %s className: %s", - consumerGroup, topic, className); + String + .format( + "FilterServer, registerFilterClass Exception, consumerGroup: %s topic: %s className: %s", + consumerGroup, topic, className); log.error(info, e); return false; } @@ -155,20 +154,14 @@ public class FilterClassManager { return true; } - private static String buildKey(final String consumerGroup, final String topic) { - return topic + "@" + consumerGroup; - } - public FilterClassInfo findFilterClass(final String consumerGroup, final String topic) { return this.filterClassTable.get(buildKey(consumerGroup, topic)); } - public FilterClassFetchMethod getFilterClassFetchMethod() { return filterClassFetchMethod; } - public void setFilterClassFetchMethod(FilterClassFetchMethod filterClassFetchMethod) { this.filterClassFetchMethod = filterClassFetchMethod; } diff --git a/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/filter/HttpFilterClassFetchMethod.java b/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/filter/HttpFilterClassFetchMethod.java index c8b15151..99bfad03 100644 --- a/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/filter/HttpFilterClassFetchMethod.java +++ b/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/filter/HttpFilterClassFetchMethod.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.filtersrv.filter; @@ -23,17 +23,14 @@ import org.apache.rocketmq.common.utils.HttpTinyClient.HttpResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - public class HttpFilterClassFetchMethod implements FilterClassFetchMethod { private static final Logger log = LoggerFactory.getLogger(LoggerName.FILTERSRV_LOGGER_NAME); private final String url; - public HttpFilterClassFetchMethod(String url) { this.url = url; } - @Override public String fetch(String topic, String consumerGroup, String className) { String thisUrl = String.format("%s/%s.java", this.url, className); @@ -45,7 +42,7 @@ public class HttpFilterClassFetchMethod implements FilterClassFetchMethod { } } catch (Exception e) { log.error( - String.format("call <%s> exception, Topic: %s Group: %s", thisUrl, topic, consumerGroup), e); + String.format("call <%s> exception, Topic: %s Group: %s", thisUrl, topic, consumerGroup), e); } return null; diff --git a/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/processor/DefaultRequestProcessor.java b/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/processor/DefaultRequestProcessor.java index f2c98ae9..1d56ac17 100644 --- a/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/processor/DefaultRequestProcessor.java +++ b/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/processor/DefaultRequestProcessor.java @@ -16,6 +16,13 @@ */ package org.apache.rocketmq.filtersrv.processor; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelFutureListener; +import io.netty.channel.ChannelHandlerContext; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.List; import org.apache.rocketmq.client.consumer.DefaultMQPullConsumer; import org.apache.rocketmq.client.consumer.PullCallback; import org.apache.rocketmq.client.consumer.PullResult; @@ -39,36 +46,25 @@ import org.apache.rocketmq.remoting.exception.RemotingCommandException; import org.apache.rocketmq.remoting.netty.NettyRequestProcessor; import org.apache.rocketmq.remoting.protocol.RemotingCommand; import org.apache.rocketmq.store.CommitLog; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelFutureListener; -import io.netty.channel.ChannelHandlerContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.List; - - public class DefaultRequestProcessor implements NettyRequestProcessor { private static final Logger log = LoggerFactory.getLogger(LoggerName.FILTERSRV_LOGGER_NAME); private final FiltersrvController filtersrvController; - public DefaultRequestProcessor(FiltersrvController filtersrvController) { this.filtersrvController = filtersrvController; } - @Override public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) throws Exception { if (log.isDebugEnabled()) { log.debug("receive request, {} {} {}", - request.getCode(), - RemotingHelper.parseChannelRemoteAddr(ctx.channel()), - request); + request.getCode(), + RemotingHelper.parseChannelRemoteAddr(ctx.channel()), + request); } switch (request.getCode()) { @@ -89,14 +85,14 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { private RemotingCommand registerMessageFilterClass(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final RegisterMessageFilterClassRequestHeader requestHeader = - (RegisterMessageFilterClassRequestHeader) request.decodeCommandCustomHeader(RegisterMessageFilterClassRequestHeader.class); + (RegisterMessageFilterClassRequestHeader)request.decodeCommandCustomHeader(RegisterMessageFilterClassRequestHeader.class); try { boolean ok = this.filtersrvController.getFilterClassManager().registerFilterClass(requestHeader.getConsumerGroup(), - requestHeader.getTopic(), - requestHeader.getClassName(), - requestHeader.getClassCRC(), - request.getBody()); + requestHeader.getTopic(), + requestHeader.getClassName(), + requestHeader.getClassCRC(), + request.getBody()); if (!ok) { throw new Exception("registerFilterClass error"); } @@ -113,20 +109,19 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { private RemotingCommand pullMessageForward(final ChannelHandlerContext ctx, final RemotingCommand request) throws Exception { final RemotingCommand response = RemotingCommand.createResponseCommand(PullMessageResponseHeader.class); - final PullMessageResponseHeader responseHeader = (PullMessageResponseHeader) response.readCustomHeader(); + final PullMessageResponseHeader responseHeader = (PullMessageResponseHeader)response.readCustomHeader(); final PullMessageRequestHeader requestHeader = - (PullMessageRequestHeader) request.decodeCommandCustomHeader(PullMessageRequestHeader.class); + (PullMessageRequestHeader)request.decodeCommandCustomHeader(PullMessageRequestHeader.class); final FilterContext filterContext = new FilterContext(); filterContext.setConsumerGroup(requestHeader.getConsumerGroup()); - response.setOpaque(request.getOpaque()); DefaultMQPullConsumer pullConsumer = this.filtersrvController.getDefaultMQPullConsumer(); final FilterClassInfo findFilterClass = - this.filtersrvController.getFilterClassManager() - .findFilterClass(requestHeader.getConsumerGroup(), requestHeader.getTopic()); + this.filtersrvController.getFilterClassManager() + .findFilterClass(requestHeader.getConsumerGroup(), requestHeader.getTopic()); if (null == findFilterClass) { response.setCode(ResponseCode.SYSTEM_ERROR); response.setRemark("Find Filter class failed, not registered"); @@ -141,7 +136,6 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { responseHeader.setSuggestWhichBrokerId(MixAll.MASTER_ID); - MessageQueue mq = new MessageQueue(); mq.setTopic(requestHeader.getTopic()); mq.setQueueId(requestHeader.getQueueId()); @@ -171,7 +165,6 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { } } - if (!msgListOK.isEmpty()) { returnResponse(requestHeader.getConsumerGroup(), requestHeader.getTopic(), ctx, response, msgListOK); return; @@ -180,8 +173,8 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { } } catch (Throwable e) { final String error = - String.format("do Message Filter Exception, ConsumerGroup: %s Topic: %s ", - requestHeader.getConsumerGroup(), requestHeader.getTopic()); + String.format("do Message Filter Exception, ConsumerGroup: %s Topic: %s ", + requestHeader.getConsumerGroup(), requestHeader.getTopic()); log.error(error, e); response.setCode(ResponseCode.SYSTEM_ERROR); @@ -207,7 +200,6 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { returnResponse(requestHeader.getConsumerGroup(), requestHeader.getTopic(), ctx, response, null); } - @Override public void onException(Throwable e) { response.setCode(ResponseCode.SYSTEM_ERROR); @@ -223,7 +215,7 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { } private void returnResponse(final String group, final String topic, ChannelHandlerContext ctx, final RemotingCommand response, - final List msgList) { + final List msgList) { if (null != msgList) { ByteBuffer[] msgBufferList = new ByteBuffer[msgList.size()]; int bodyTotalSize = 0; @@ -244,7 +236,6 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { response.setBody(body.array()); - this.filtersrvController.getFilterServerStatsManager().incGroupGetNums(group, topic, msgList.size()); this.filtersrvController.getFilterServerStatsManager().incGroupGetSize(group, topic, bodyTotalSize); @@ -285,23 +276,23 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { byte[] propertiesData = properties.getBytes(MixAll.DEFAULT_CHARSET); final int propertiesLength = propertiesData.length; final int msgLen = 4 // 1 TOTALSIZE - + 4 // 2 MAGICCODE - + 4 // 3 BODYCRC - + 4 // 4 QUEUEID - + 4 // 5 FLAG - + 8 // 6 QUEUEOFFSET - + 8 // 7 PHYSICALOFFSET - + 4 // 8 SYSFLAG - + 8 // 9 BORNTIMESTAMP - + 8 // 10 BORNHOST - + 8 // 11 STORETIMESTAMP - + 8 // 12 STOREHOSTADDRESS - + 4 // 13 RECONSUMETIMES - + 8 // 14 Prepared Transaction Offset - + 4 + bodyLength // 14 BODY - + 1 + topicLength // 15 TOPIC - + 2 + propertiesLength // 16 propertiesLength - + 0; + + 4 // 2 MAGICCODE + + 4 // 3 BODYCRC + + 4 // 4 QUEUEID + + 4 // 5 FLAG + + 8 // 6 QUEUEOFFSET + + 8 // 7 PHYSICALOFFSET + + 4 // 8 SYSFLAG + + 8 // 9 BORNTIMESTAMP + + 8 // 10 BORNHOST + + 8 // 11 STORETIMESTAMP + + 8 // 12 STOREHOSTADDRESS + + 4 // 13 RECONSUMETIMES + + 8 // 14 Prepared Transaction Offset + + 4 + bodyLength // 14 BODY + + 1 + topicLength // 15 TOPIC + + 2 + propertiesLength // 16 propertiesLength + + 0; ByteBuffer msgStoreItemMemory = ByteBuffer.allocate(msgLen); @@ -340,10 +331,10 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { if (bodyLength > 0) msgStoreItemMemory.put(msgInner.getBody()); // 16 TOPIC - msgStoreItemMemory.put((byte) topicLength); + msgStoreItemMemory.put((byte)topicLength); msgStoreItemMemory.put(topicData); // 17 PROPERTIES - msgStoreItemMemory.putShort((short) propertiesLength); + msgStoreItemMemory.putShort((short)propertiesLength); if (propertiesLength > 0) msgStoreItemMemory.put(propertiesData); diff --git a/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/stats/FilterServerStatsManager.java b/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/stats/FilterServerStatsManager.java index 8665fbd6..4f44e991 100644 --- a/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/stats/FilterServerStatsManager.java +++ b/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/stats/FilterServerStatsManager.java @@ -6,59 +6,52 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.filtersrv.stats; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; import org.apache.rocketmq.common.ThreadFactoryImpl; import org.apache.rocketmq.common.constant.LoggerName; import org.apache.rocketmq.common.stats.StatsItemSet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; - - public class FilterServerStatsManager { private static final Logger log = LoggerFactory.getLogger(LoggerName.FILTERSRV_LOGGER_NAME); private final ScheduledExecutorService scheduledExecutorService = Executors - .newSingleThreadScheduledExecutor(new ThreadFactoryImpl("FSStatsThread")); + .newSingleThreadScheduledExecutor(new ThreadFactoryImpl("FSStatsThread")); // ConsumerGroup Get Nums private final StatsItemSet groupGetNums = new StatsItemSet("GROUP_GET_NUMS", - this.scheduledExecutorService, log); + this.scheduledExecutorService, log); // ConsumerGroup Get Size private final StatsItemSet groupGetSize = new StatsItemSet("GROUP_GET_SIZE", - this.scheduledExecutorService, log); - + this.scheduledExecutorService, log); public FilterServerStatsManager() { } - public void start() { } - public void shutdown() { this.scheduledExecutorService.shutdown(); } - public void incGroupGetNums(final String group, final String topic, final int incValue) { this.groupGetNums.addValue(topic + "@" + group, incValue, 1); } - public void incGroupGetSize(final String group, final String topic, final int incValue) { this.groupGetSize.addValue(topic + "@" + group, incValue, 1); } diff --git a/namesrv/pom.xml b/namesrv/pom.xml index 2ec2f5f4..27a1c84e 100644 --- a/namesrv/pom.xml +++ b/namesrv/pom.xml @@ -15,7 +15,7 @@ limitations under the License. --> - org.apache.rocketmq diff --git a/namesrv/src/main/java/org/apache/rocketmq/namesrv/NamesrvController.java b/namesrv/src/main/java/org/apache/rocketmq/namesrv/NamesrvController.java index 4c286e0b..b212adbd 100644 --- a/namesrv/src/main/java/org/apache/rocketmq/namesrv/NamesrvController.java +++ b/namesrv/src/main/java/org/apache/rocketmq/namesrv/NamesrvController.java @@ -6,16 +6,20 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.namesrv; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; import org.apache.rocketmq.common.Configuration; import org.apache.rocketmq.common.ThreadFactoryImpl; import org.apache.rocketmq.common.constant.LoggerName; @@ -31,12 +35,6 @@ import org.apache.rocketmq.remoting.netty.NettyServerConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; - - public class NamesrvController { private static final Logger log = LoggerFactory.getLogger(LoggerName.NAMESRV_LOGGER_NAME); @@ -45,7 +43,7 @@ public class NamesrvController { private final NettyServerConfig nettyServerConfig; private final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryImpl( - "NSScheduledThread")); + "NSScheduledThread")); private final KVConfigManager kvConfigManager; private final RouteInfoManager routeInfoManager; @@ -57,7 +55,6 @@ public class NamesrvController { private Configuration configuration; - public NamesrvController(NamesrvConfig namesrvConfig, NettyServerConfig nettyServerConfig) { this.namesrvConfig = namesrvConfig; this.nettyServerConfig = nettyServerConfig; @@ -65,26 +62,23 @@ public class NamesrvController { this.routeInfoManager = new RouteInfoManager(); this.brokerHousekeepingService = new BrokerHousekeepingService(this); this.configuration = new Configuration( - log, - this.namesrvConfig, this.nettyServerConfig + log, + this.namesrvConfig, this.nettyServerConfig ); this.configuration.setStorePathFromConfig(this.namesrvConfig, "configStorePath"); } - public boolean initialize() { this.kvConfigManager.load(); this.remotingServer = new NettyRemotingServer(this.nettyServerConfig, this.brokerHousekeepingService); - this.remotingExecutor = - Executors.newFixedThreadPool(nettyServerConfig.getServerWorkerThreads(), new ThreadFactoryImpl("RemotingExecutorThread_")); + Executors.newFixedThreadPool(nettyServerConfig.getServerWorkerThreads(), new ThreadFactoryImpl("RemotingExecutorThread_")); this.registerProcessor(); - this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() { @Override @@ -104,56 +98,47 @@ public class NamesrvController { return true; } - private void registerProcessor() { if (namesrvConfig.isClusterTest()) { this.remotingServer.registerDefaultProcessor(new ClusterTestRequestProcessor(this, namesrvConfig.getProductEnvName()), - this.remotingExecutor); + this.remotingExecutor); } else { this.remotingServer.registerDefaultProcessor(new DefaultRequestProcessor(this), this.remotingExecutor); } } - public void start() throws Exception { this.remotingServer.start(); } - public void shutdown() { this.remotingServer.shutdown(); this.remotingExecutor.shutdown(); this.scheduledExecutorService.shutdown(); } - public NamesrvConfig getNamesrvConfig() { return namesrvConfig; } - public NettyServerConfig getNettyServerConfig() { return nettyServerConfig; } - public KVConfigManager getKvConfigManager() { return kvConfigManager; } - public RouteInfoManager getRouteInfoManager() { return routeInfoManager; } - public RemotingServer getRemotingServer() { return remotingServer; } - public void setRemotingServer(RemotingServer remotingServer) { this.remotingServer = remotingServer; } diff --git a/namesrv/src/main/java/org/apache/rocketmq/namesrv/NamesrvStartup.java b/namesrv/src/main/java/org/apache/rocketmq/namesrv/NamesrvStartup.java index be824cd3..0eb9a52e 100644 --- a/namesrv/src/main/java/org/apache/rocketmq/namesrv/NamesrvStartup.java +++ b/namesrv/src/main/java/org/apache/rocketmq/namesrv/NamesrvStartup.java @@ -18,6 +18,15 @@ package org.apache.rocketmq.namesrv; import ch.qos.logback.classic.LoggerContext; import ch.qos.logback.classic.joran.JoranConfigurator; +import java.io.BufferedInputStream; +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.Properties; +import java.util.concurrent.atomic.AtomicInteger; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.PosixParser; import org.apache.rocketmq.common.MQVersion; import org.apache.rocketmq.common.MixAll; import org.apache.rocketmq.common.constant.LoggerName; @@ -26,20 +35,9 @@ import org.apache.rocketmq.remoting.netty.NettyServerConfig; import org.apache.rocketmq.remoting.netty.NettySystemConfig; import org.apache.rocketmq.remoting.protocol.RemotingCommand; import org.apache.rocketmq.srvutil.ServerUtil; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.PosixParser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.BufferedInputStream; -import java.io.FileInputStream; -import java.io.InputStream; -import java.util.Properties; -import java.util.concurrent.atomic.AtomicInteger; - - public class NamesrvStartup { public static Properties properties = null; public static CommandLine commandLine = null; @@ -51,12 +49,10 @@ public class NamesrvStartup { public static NamesrvController main0(String[] args) { System.setProperty(RemotingCommand.REMOTING_VERSION_KEY, Integer.toString(MQVersion.CURRENT_VERSION)); - if (null == System.getProperty(NettySystemConfig.COM_ROCKETMQ_REMOTING_SOCKET_SNDBUF_SIZE)) { NettySystemConfig.socketSndbufSize = 4096; } - if (null == System.getProperty(NettySystemConfig.COM_ROCKETMQ_REMOTING_SOCKET_RCVBUF_SIZE)) { NettySystemConfig.socketRcvbufSize = 4096; } @@ -66,14 +62,13 @@ public class NamesrvStartup { Options options = ServerUtil.buildCommandlineOptions(new Options()); commandLine = - ServerUtil.parseCmdLine("mqnamesrv", args, buildCommandlineOptions(options), - new PosixParser()); + ServerUtil.parseCmdLine("mqnamesrv", args, buildCommandlineOptions(options), + new PosixParser()); if (null == commandLine) { System.exit(-1); return null; } - final NamesrvConfig namesrvConfig = new NamesrvConfig(); final NettyServerConfig nettyServerConfig = new NettyServerConfig(); nettyServerConfig.setListenPort(9876); @@ -93,7 +88,6 @@ public class NamesrvStartup { } } - if (commandLine.hasOption('p')) { MixAll.printObjectProperties(null, namesrvConfig); MixAll.printObjectProperties(null, nettyServerConfig); @@ -104,22 +98,20 @@ public class NamesrvStartup { if (null == namesrvConfig.getRocketmqHome()) { System.out.printf("Please set the " + MixAll.ROCKETMQ_HOME_ENV - + " variable in your environment to match the location of the RocketMQ installation%n"); + + " variable in your environment to match the location of the RocketMQ installation%n"); System.exit(-2); } - LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); + LoggerContext lc = (LoggerContext)LoggerFactory.getILoggerFactory(); JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(lc); lc.reset(); configurator.doConfigure(namesrvConfig.getRocketmqHome() + "/conf/logback_namesrv.xml"); final Logger log = LoggerFactory.getLogger(LoggerName.NAMESRV_LOGGER_NAME); - MixAll.printObjectProperties(log, namesrvConfig); MixAll.printObjectProperties(log, nettyServerConfig); - final NamesrvController controller = new NamesrvController(namesrvConfig, nettyServerConfig); // remember all configs to prevent discard @@ -135,7 +127,6 @@ public class NamesrvStartup { private volatile boolean hasShutdown = false; private AtomicInteger shutdownTimes = new AtomicInteger(0); - @Override public void run() { synchronized (this) { @@ -151,7 +142,6 @@ public class NamesrvStartup { } }, "ShutdownHook")); - controller.start(); String tip = "The Name Server boot success. serializeType=" + RemotingCommand.getSerializeTypeConfigInThisServer(); diff --git a/namesrv/src/main/java/org/apache/rocketmq/namesrv/kvconfig/KVConfigManager.java b/namesrv/src/main/java/org/apache/rocketmq/namesrv/kvconfig/KVConfigManager.java index c9e534f6..4705bed0 100644 --- a/namesrv/src/main/java/org/apache/rocketmq/namesrv/kvconfig/KVConfigManager.java +++ b/namesrv/src/main/java/org/apache/rocketmq/namesrv/kvconfig/KVConfigManager.java @@ -6,30 +6,28 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.namesrv.kvconfig; -import org.apache.rocketmq.common.MixAll; -import org.apache.rocketmq.common.constant.LoggerName; -import org.apache.rocketmq.common.protocol.body.KVTable; -import org.apache.rocketmq.namesrv.NamesrvController; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.io.IOException; import java.util.HashMap; import java.util.Iterator; import java.util.Map.Entry; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; - +import org.apache.rocketmq.common.MixAll; +import org.apache.rocketmq.common.constant.LoggerName; +import org.apache.rocketmq.common.protocol.body.KVTable; +import org.apache.rocketmq.namesrv.NamesrvController; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class KVConfigManager { private static final Logger log = LoggerFactory.getLogger(LoggerName.NAMESRV_LOGGER_NAME); @@ -38,19 +36,17 @@ public class KVConfigManager { private final ReadWriteLock lock = new ReentrantReadWriteLock(); private final HashMap> configTable = - new HashMap>(); - + new HashMap>(); public KVConfigManager(NamesrvController namesrvController) { this.namesrvController = namesrvController; } - public void load() { String content = MixAll.file2String(this.namesrvController.getNamesrvConfig().getKvConfigPath()); if (content != null) { KVConfigSerializeWrapper kvConfigSerializeWrapper = - KVConfigSerializeWrapper.fromJson(content, KVConfigSerializeWrapper.class); + KVConfigSerializeWrapper.fromJson(content, KVConfigSerializeWrapper.class); if (null != kvConfigSerializeWrapper) { this.configTable.putAll(kvConfigSerializeWrapper.getConfigTable()); log.info("load KV config table OK"); @@ -58,7 +54,6 @@ public class KVConfigManager { } } - public void putKVConfig(final String namespace, final String key, final String value) { try { this.lock.writeLock().lockInterruptibly(); @@ -73,10 +68,10 @@ public class KVConfigManager { final String prev = kvTable.put(key, value); if (null != prev) { log.info("putKVConfig update config item, Namespace: {} Key: {} Value: {}", // - namespace, key, value); + namespace, key, value); } else { log.info("putKVConfig create new config item, Namespace: {} Key: {} Value: {}", // - namespace, key, value); + namespace, key, value); } } finally { this.lock.writeLock().unlock(); @@ -102,7 +97,7 @@ public class KVConfigManager { } } catch (IOException e) { log.error("persist kvconfig Exception, " - + this.namesrvController.getNamesrvConfig().getKvConfigPath(), e); + + this.namesrvController.getNamesrvConfig().getKvConfigPath(), e); } finally { this.lock.readLock().unlock(); } @@ -120,7 +115,7 @@ public class KVConfigManager { if (null != kvTable) { String value = kvTable.remove(key); log.info("deleteKVConfig delete a config item, Namespace: {} Key: {} Value: {}", // - namespace, key, value); + namespace, key, value); } } finally { this.lock.writeLock().unlock(); @@ -179,14 +174,14 @@ public class KVConfigManager { { log.info("configTable SIZE: {}", this.configTable.size()); Iterator>> it = - this.configTable.entrySet().iterator(); + this.configTable.entrySet().iterator(); while (it.hasNext()) { Entry> next = it.next(); Iterator> itSub = next.getValue().entrySet().iterator(); while (itSub.hasNext()) { Entry nextSub = itSub.next(); log.info("configTable NS: {} Key: {} Value: {}", next.getKey(), nextSub.getKey(), - nextSub.getValue()); + nextSub.getValue()); } } } diff --git a/namesrv/src/main/java/org/apache/rocketmq/namesrv/kvconfig/KVConfigSerializeWrapper.java b/namesrv/src/main/java/org/apache/rocketmq/namesrv/kvconfig/KVConfigSerializeWrapper.java index 64659279..e35a37c9 100644 --- a/namesrv/src/main/java/org/apache/rocketmq/namesrv/kvconfig/KVConfigSerializeWrapper.java +++ b/namesrv/src/main/java/org/apache/rocketmq/namesrv/kvconfig/KVConfigSerializeWrapper.java @@ -6,30 +6,26 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.namesrv.kvconfig; -import org.apache.rocketmq.remoting.protocol.RemotingSerializable; - import java.util.HashMap; - +import org.apache.rocketmq.remoting.protocol.RemotingSerializable; public class KVConfigSerializeWrapper extends RemotingSerializable { private HashMap> configTable; - public HashMap> getConfigTable() { return configTable; } - public void setConfigTable(HashMap> configTable) { this.configTable = configTable; } diff --git a/namesrv/src/main/java/org/apache/rocketmq/namesrv/processor/ClusterTestRequestProcessor.java b/namesrv/src/main/java/org/apache/rocketmq/namesrv/processor/ClusterTestRequestProcessor.java index 9ee56a40..95410fa1 100644 --- a/namesrv/src/main/java/org/apache/rocketmq/namesrv/processor/ClusterTestRequestProcessor.java +++ b/namesrv/src/main/java/org/apache/rocketmq/namesrv/processor/ClusterTestRequestProcessor.java @@ -6,16 +6,17 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.namesrv.processor; +import io.netty.channel.ChannelHandlerContext; import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.common.constant.LoggerName; import org.apache.rocketmq.common.help.FAQUrl; @@ -27,17 +28,14 @@ import org.apache.rocketmq.namesrv.NamesrvController; import org.apache.rocketmq.remoting.exception.RemotingCommandException; import org.apache.rocketmq.remoting.protocol.RemotingCommand; import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; -import io.netty.channel.ChannelHandlerContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - public class ClusterTestRequestProcessor extends DefaultRequestProcessor { private static final Logger log = LoggerFactory.getLogger(LoggerName.NAMESRV_LOGGER_NAME); private final DefaultMQAdminExt adminExt; private final String productEnvName; - public ClusterTestRequestProcessor(NamesrvController namesrvController, String productEnvName) { super(namesrvController); this.productEnvName = productEnvName; @@ -51,18 +49,17 @@ public class ClusterTestRequestProcessor extends DefaultRequestProcessor { } } - @Override public RemotingCommand getRouteInfoByTopic(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetRouteInfoRequestHeader requestHeader = - (GetRouteInfoRequestHeader) request.decodeCommandCustomHeader(GetRouteInfoRequestHeader.class); + (GetRouteInfoRequestHeader)request.decodeCommandCustomHeader(GetRouteInfoRequestHeader.class); TopicRouteData topicRouteData = this.namesrvController.getRouteInfoManager().pickupTopicRouteData(requestHeader.getTopic()); if (topicRouteData != null) { String orderTopicConf = - this.namesrvController.getKvConfigManager().getKVConfig(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG, - requestHeader.getTopic()); + this.namesrvController.getKvConfigManager().getKVConfig(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG, + requestHeader.getTopic()); topicRouteData.setOrderTopicConf(orderTopicConf); } else { try { @@ -82,7 +79,7 @@ public class ClusterTestRequestProcessor extends DefaultRequestProcessor { response.setCode(ResponseCode.TOPIC_NOT_EXIST); response.setRemark("No topic route info in name server for the topic: " + requestHeader.getTopic() - + FAQUrl.suggestTodo(FAQUrl.APPLY_TOPIC_URL)); + + FAQUrl.suggestTodo(FAQUrl.APPLY_TOPIC_URL)); return response; } } diff --git a/namesrv/src/main/java/org/apache/rocketmq/namesrv/processor/DefaultRequestProcessor.java b/namesrv/src/main/java/org/apache/rocketmq/namesrv/processor/DefaultRequestProcessor.java index e47f300d..0135274b 100644 --- a/namesrv/src/main/java/org/apache/rocketmq/namesrv/processor/DefaultRequestProcessor.java +++ b/namesrv/src/main/java/org/apache/rocketmq/namesrv/processor/DefaultRequestProcessor.java @@ -6,16 +6,20 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.namesrv.processor; +import io.netty.channel.ChannelHandlerContext; +import java.io.UnsupportedEncodingException; +import java.util.Properties; +import java.util.concurrent.atomic.AtomicLong; import org.apache.rocketmq.common.MQVersion; import org.apache.rocketmq.common.MQVersion.Version; import org.apache.rocketmq.common.MixAll; @@ -28,40 +32,43 @@ import org.apache.rocketmq.common.protocol.ResponseCode; import org.apache.rocketmq.common.protocol.body.RegisterBrokerBody; import org.apache.rocketmq.common.protocol.body.TopicConfigSerializeWrapper; import org.apache.rocketmq.common.protocol.header.GetTopicsByClusterRequestHeader; -import org.apache.rocketmq.common.protocol.header.namesrv.*; +import org.apache.rocketmq.common.protocol.header.namesrv.DeleteKVConfigRequestHeader; +import org.apache.rocketmq.common.protocol.header.namesrv.DeleteTopicInNamesrvRequestHeader; +import org.apache.rocketmq.common.protocol.header.namesrv.GetKVConfigRequestHeader; +import org.apache.rocketmq.common.protocol.header.namesrv.GetKVConfigResponseHeader; +import org.apache.rocketmq.common.protocol.header.namesrv.GetKVListByNamespaceRequestHeader; +import org.apache.rocketmq.common.protocol.header.namesrv.GetRouteInfoRequestHeader; +import org.apache.rocketmq.common.protocol.header.namesrv.PutKVConfigRequestHeader; +import org.apache.rocketmq.common.protocol.header.namesrv.RegisterBrokerRequestHeader; +import org.apache.rocketmq.common.protocol.header.namesrv.RegisterBrokerResponseHeader; +import org.apache.rocketmq.common.protocol.header.namesrv.UnRegisterBrokerRequestHeader; +import org.apache.rocketmq.common.protocol.header.namesrv.WipeWritePermOfBrokerRequestHeader; +import org.apache.rocketmq.common.protocol.header.namesrv.WipeWritePermOfBrokerResponseHeader; import org.apache.rocketmq.common.protocol.route.TopicRouteData; import org.apache.rocketmq.namesrv.NamesrvController; import org.apache.rocketmq.remoting.common.RemotingHelper; import org.apache.rocketmq.remoting.exception.RemotingCommandException; import org.apache.rocketmq.remoting.netty.NettyRequestProcessor; import org.apache.rocketmq.remoting.protocol.RemotingCommand; -import io.netty.channel.ChannelHandlerContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.UnsupportedEncodingException; -import java.util.Properties; -import java.util.concurrent.atomic.AtomicLong; - - public class DefaultRequestProcessor implements NettyRequestProcessor { private static final Logger log = LoggerFactory.getLogger(LoggerName.NAMESRV_LOGGER_NAME); protected final NamesrvController namesrvController; - public DefaultRequestProcessor(NamesrvController namesrvController) { this.namesrvController = namesrvController; } - @Override public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { if (log.isDebugEnabled()) { log.debug("receive request, {} {} {}", - request.getCode(), - RemotingHelper.parseChannelRemoteAddr(ctx.channel()), - request); + request.getCode(), + RemotingHelper.parseChannelRemoteAddr(ctx.channel()), + request); } switch (request.getCode()) { @@ -75,8 +82,7 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { Version brokerVersion = MQVersion.value2Version(request.getVersion()); if (brokerVersion.ordinal() >= MQVersion.Version.V3_0_11.ordinal()) { return this.registerBrokerWithFilterServer(ctx, request); - } - else { + } else { return this.registerBroker(ctx, request); } case RequestCode.UNREGISTER_BROKER: @@ -121,12 +127,12 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { public RemotingCommand putKVConfig(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final PutKVConfigRequestHeader requestHeader = - (PutKVConfigRequestHeader) request.decodeCommandCustomHeader(PutKVConfigRequestHeader.class); + (PutKVConfigRequestHeader)request.decodeCommandCustomHeader(PutKVConfigRequestHeader.class); this.namesrvController.getKvConfigManager().putKVConfig( - requestHeader.getNamespace(), - requestHeader.getKey(), - requestHeader.getValue() + requestHeader.getNamespace(), + requestHeader.getKey(), + requestHeader.getValue() ); response.setCode(ResponseCode.SUCCESS); @@ -136,13 +142,13 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { public RemotingCommand getKVConfig(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(GetKVConfigResponseHeader.class); - final GetKVConfigResponseHeader responseHeader = (GetKVConfigResponseHeader) response.readCustomHeader(); + final GetKVConfigResponseHeader responseHeader = (GetKVConfigResponseHeader)response.readCustomHeader(); final GetKVConfigRequestHeader requestHeader = - (GetKVConfigRequestHeader) request.decodeCommandCustomHeader(GetKVConfigRequestHeader.class); + (GetKVConfigRequestHeader)request.decodeCommandCustomHeader(GetKVConfigRequestHeader.class); String value = this.namesrvController.getKvConfigManager().getKVConfig( - requestHeader.getNamespace(), - requestHeader.getKey() + requestHeader.getNamespace(), + requestHeader.getKey() ); if (value != null) { @@ -160,11 +166,11 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { public RemotingCommand deleteKVConfig(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final DeleteKVConfigRequestHeader requestHeader = - (DeleteKVConfigRequestHeader) request.decodeCommandCustomHeader(DeleteKVConfigRequestHeader.class); + (DeleteKVConfigRequestHeader)request.decodeCommandCustomHeader(DeleteKVConfigRequestHeader.class); this.namesrvController.getKvConfigManager().deleteKVConfig( - requestHeader.getNamespace(), - requestHeader.getKey() + requestHeader.getNamespace(), + requestHeader.getKey() ); response.setCode(ResponseCode.SUCCESS); @@ -173,11 +179,11 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { } public RemotingCommand registerBrokerWithFilterServer(ChannelHandlerContext ctx, RemotingCommand request) - throws RemotingCommandException { + throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(RegisterBrokerResponseHeader.class); - final RegisterBrokerResponseHeader responseHeader = (RegisterBrokerResponseHeader) response.readCustomHeader(); + final RegisterBrokerResponseHeader responseHeader = (RegisterBrokerResponseHeader)response.readCustomHeader(); final RegisterBrokerRequestHeader requestHeader = - (RegisterBrokerRequestHeader) request.decodeCommandCustomHeader(RegisterBrokerRequestHeader.class); + (RegisterBrokerRequestHeader)request.decodeCommandCustomHeader(RegisterBrokerRequestHeader.class); RegisterBrokerBody registerBrokerBody = new RegisterBrokerBody(); @@ -189,19 +195,18 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { } RegisterBrokerResult result = this.namesrvController.getRouteInfoManager().registerBroker( - requestHeader.getClusterName(), - requestHeader.getBrokerAddr(), - requestHeader.getBrokerName(), - requestHeader.getBrokerId(), - requestHeader.getHaServerAddr(), - registerBrokerBody.getTopicConfigSerializeWrapper(), - registerBrokerBody.getFilterServerList(), - ctx.channel()); + requestHeader.getClusterName(), + requestHeader.getBrokerAddr(), + requestHeader.getBrokerName(), + requestHeader.getBrokerId(), + requestHeader.getHaServerAddr(), + registerBrokerBody.getTopicConfigSerializeWrapper(), + registerBrokerBody.getFilterServerList(), + ctx.channel()); responseHeader.setHaServerAddr(result.getHaServerAddr()); responseHeader.setMasterAddr(result.getMasterAddr()); - byte[] jsonValue = this.namesrvController.getKvConfigManager().getKVListByNamespace(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG); response.setBody(jsonValue); @@ -212,9 +217,9 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { public RemotingCommand registerBroker(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(RegisterBrokerResponseHeader.class); - final RegisterBrokerResponseHeader responseHeader = (RegisterBrokerResponseHeader) response.readCustomHeader(); + final RegisterBrokerResponseHeader responseHeader = (RegisterBrokerResponseHeader)response.readCustomHeader(); final RegisterBrokerRequestHeader requestHeader = - (RegisterBrokerRequestHeader) request.decodeCommandCustomHeader(RegisterBrokerRequestHeader.class); + (RegisterBrokerRequestHeader)request.decodeCommandCustomHeader(RegisterBrokerRequestHeader.class); TopicConfigSerializeWrapper topicConfigWrapper; if (request.getBody() != null) { @@ -226,20 +231,19 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { } RegisterBrokerResult result = this.namesrvController.getRouteInfoManager().registerBroker( - requestHeader.getClusterName(), - requestHeader.getBrokerAddr(), - requestHeader.getBrokerName(), - requestHeader.getBrokerId(), - requestHeader.getHaServerAddr(), - topicConfigWrapper, - null, - ctx.channel() + requestHeader.getClusterName(), + requestHeader.getBrokerAddr(), + requestHeader.getBrokerName(), + requestHeader.getBrokerId(), + requestHeader.getHaServerAddr(), + topicConfigWrapper, + null, + ctx.channel() ); responseHeader.setHaServerAddr(result.getHaServerAddr()); responseHeader.setMasterAddr(result.getMasterAddr()); - byte[] jsonValue = this.namesrvController.getKvConfigManager().getKVListByNamespace(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG); response.setBody(jsonValue); response.setCode(ResponseCode.SUCCESS); @@ -250,13 +254,13 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { public RemotingCommand unregisterBroker(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final UnRegisterBrokerRequestHeader requestHeader = - (UnRegisterBrokerRequestHeader) request.decodeCommandCustomHeader(UnRegisterBrokerRequestHeader.class); + (UnRegisterBrokerRequestHeader)request.decodeCommandCustomHeader(UnRegisterBrokerRequestHeader.class); this.namesrvController.getRouteInfoManager().unregisterBroker( - requestHeader.getClusterName(), - requestHeader.getBrokerAddr(), - requestHeader.getBrokerName(), - requestHeader.getBrokerId()); + requestHeader.getClusterName(), + requestHeader.getBrokerAddr(), + requestHeader.getBrokerName(), + requestHeader.getBrokerId()); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); @@ -266,15 +270,15 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { public RemotingCommand getRouteInfoByTopic(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetRouteInfoRequestHeader requestHeader = - (GetRouteInfoRequestHeader) request.decodeCommandCustomHeader(GetRouteInfoRequestHeader.class); + (GetRouteInfoRequestHeader)request.decodeCommandCustomHeader(GetRouteInfoRequestHeader.class); TopicRouteData topicRouteData = this.namesrvController.getRouteInfoManager().pickupTopicRouteData(requestHeader.getTopic()); if (topicRouteData != null) { if (this.namesrvController.getNamesrvConfig().isOrderMessageEnable()) { String orderTopicConf = - this.namesrvController.getKvConfigManager().getKVConfig(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG, - requestHeader.getTopic()); + this.namesrvController.getKvConfigManager().getKVConfig(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG, + requestHeader.getTopic()); topicRouteData.setOrderTopicConf(orderTopicConf); } @@ -287,7 +291,7 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { response.setCode(ResponseCode.TOPIC_NOT_EXIST); response.setRemark("No topic route info in name server for the topic: " + requestHeader.getTopic() - + FAQUrl.suggestTodo(FAQUrl.APPLY_TOPIC_URL)); + + FAQUrl.suggestTodo(FAQUrl.APPLY_TOPIC_URL)); return response; } @@ -304,16 +308,16 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { private RemotingCommand wipeWritePermOfBroker(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(WipeWritePermOfBrokerResponseHeader.class); - final WipeWritePermOfBrokerResponseHeader responseHeader = (WipeWritePermOfBrokerResponseHeader) response.readCustomHeader(); + final WipeWritePermOfBrokerResponseHeader responseHeader = (WipeWritePermOfBrokerResponseHeader)response.readCustomHeader(); final WipeWritePermOfBrokerRequestHeader requestHeader = - (WipeWritePermOfBrokerRequestHeader) request.decodeCommandCustomHeader(WipeWritePermOfBrokerRequestHeader.class); + (WipeWritePermOfBrokerRequestHeader)request.decodeCommandCustomHeader(WipeWritePermOfBrokerRequestHeader.class); int wipeTopicCnt = this.namesrvController.getRouteInfoManager().wipeWritePermOfBrokerByLock(requestHeader.getBrokerName()); log.info("wipe write perm of broker[{}], client: {}, {}", - requestHeader.getBrokerName(), - RemotingHelper.parseChannelRemoteAddr(ctx.channel()), - wipeTopicCnt); + requestHeader.getBrokerName(), + RemotingHelper.parseChannelRemoteAddr(ctx.channel()), + wipeTopicCnt); responseHeader.setWipeTopicCount(wipeTopicCnt); response.setCode(ResponseCode.SUCCESS); @@ -335,7 +339,7 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { private RemotingCommand deleteTopicInNamesrv(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final DeleteTopicInNamesrvRequestHeader requestHeader = - (DeleteTopicInNamesrvRequestHeader) request.decodeCommandCustomHeader(DeleteTopicInNamesrvRequestHeader.class); + (DeleteTopicInNamesrvRequestHeader)request.decodeCommandCustomHeader(DeleteTopicInNamesrvRequestHeader.class); this.namesrvController.getRouteInfoManager().deleteTopic(requestHeader.getTopic()); @@ -347,10 +351,10 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { private RemotingCommand getKVListByNamespace(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetKVListByNamespaceRequestHeader requestHeader = - (GetKVListByNamespaceRequestHeader) request.decodeCommandCustomHeader(GetKVListByNamespaceRequestHeader.class); + (GetKVListByNamespaceRequestHeader)request.decodeCommandCustomHeader(GetKVListByNamespaceRequestHeader.class); byte[] jsonValue = this.namesrvController.getKvConfigManager().getKVListByNamespace( - requestHeader.getNamespace()); + requestHeader.getNamespace()); if (null != jsonValue) { response.setBody(jsonValue); response.setCode(ResponseCode.SUCCESS); @@ -366,7 +370,7 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { private RemotingCommand getTopicsByCluster(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetTopicsByClusterRequestHeader requestHeader = - (GetTopicsByClusterRequestHeader) request.decodeCommandCustomHeader(GetTopicsByClusterRequestHeader.class); + (GetTopicsByClusterRequestHeader)request.decodeCommandCustomHeader(GetTopicsByClusterRequestHeader.class); byte[] body = this.namesrvController.getRouteInfoManager().getTopicsByCluster(requestHeader.getCluster()); @@ -376,7 +380,6 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { return response; } - private RemotingCommand getSystemTopicListFromNs(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); @@ -388,7 +391,6 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { return response; } - private RemotingCommand getUnitTopicList(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); @@ -400,7 +402,6 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { return response; } - private RemotingCommand getHasUnitSubTopicList(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); @@ -412,9 +413,8 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { return response; } - private RemotingCommand getHasUnitSubUnUnitTopicList(ChannelHandlerContext ctx, RemotingCommand request) - throws RemotingCommandException { + throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); byte[] body = this.namesrvController.getRouteInfoManager().getHasUnitSubUnUnitTopicList(); diff --git a/namesrv/src/main/java/org/apache/rocketmq/namesrv/routeinfo/BrokerHousekeepingService.java b/namesrv/src/main/java/org/apache/rocketmq/namesrv/routeinfo/BrokerHousekeepingService.java index 47e1dc91..f4bbf24e 100644 --- a/namesrv/src/main/java/org/apache/rocketmq/namesrv/routeinfo/BrokerHousekeepingService.java +++ b/namesrv/src/main/java/org/apache/rocketmq/namesrv/routeinfo/BrokerHousekeepingService.java @@ -6,51 +6,45 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.namesrv.routeinfo; +import io.netty.channel.Channel; import org.apache.rocketmq.common.constant.LoggerName; import org.apache.rocketmq.namesrv.NamesrvController; import org.apache.rocketmq.remoting.ChannelEventListener; -import io.netty.channel.Channel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - public class BrokerHousekeepingService implements ChannelEventListener { private static final Logger log = LoggerFactory.getLogger(LoggerName.NAMESRV_LOGGER_NAME); private final NamesrvController namesrvController; - public BrokerHousekeepingService(NamesrvController namesrvController) { this.namesrvController = namesrvController; } - @Override public void onChannelConnect(String remoteAddr, Channel channel) { } - @Override public void onChannelClose(String remoteAddr, Channel channel) { this.namesrvController.getRouteInfoManager().onChannelDestroy(remoteAddr, channel); } - @Override public void onChannelException(String remoteAddr, Channel channel) { this.namesrvController.getRouteInfoManager().onChannelDestroy(remoteAddr, channel); } - @Override public void onChannelIdle(String remoteAddr, Channel channel) { this.namesrvController.getRouteInfoManager().onChannelDestroy(remoteAddr, channel); diff --git a/namesrv/src/main/java/org/apache/rocketmq/namesrv/routeinfo/RouteInfoManager.java b/namesrv/src/main/java/org/apache/rocketmq/namesrv/routeinfo/RouteInfoManager.java index 82b4cbff..e440e615 100644 --- a/namesrv/src/main/java/org/apache/rocketmq/namesrv/routeinfo/RouteInfoManager.java +++ b/namesrv/src/main/java/org/apache/rocketmq/namesrv/routeinfo/RouteInfoManager.java @@ -16,6 +16,18 @@ */ package org.apache.rocketmq.namesrv.routeinfo; +import io.netty.channel.Channel; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; import org.apache.rocketmq.common.DataVersion; import org.apache.rocketmq.common.MixAll; import org.apache.rocketmq.common.TopicConfig; @@ -30,17 +42,9 @@ import org.apache.rocketmq.common.protocol.route.QueueData; import org.apache.rocketmq.common.protocol.route.TopicRouteData; import org.apache.rocketmq.common.sysflag.TopicSysFlag; import org.apache.rocketmq.remoting.common.RemotingUtil; -import io.netty.channel.Channel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.*; -import java.util.Map.Entry; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.locks.ReadWriteLock; -import java.util.concurrent.locks.ReentrantReadWriteLock; - - public class RouteInfoManager { private static final Logger log = LoggerFactory.getLogger(LoggerName.NAMESRV_LOGGER_NAME); private final static long BROKER_CHANNEL_EXPIRED_TIME = 1000 * 60 * 2; @@ -51,7 +55,6 @@ public class RouteInfoManager { private final HashMap brokerLiveTable; private final HashMap/* Filter Server */> filterServerTable; - public RouteInfoManager() { this.topicQueueTable = new HashMap>(1024); this.brokerAddrTable = new HashMap(128); @@ -97,20 +100,19 @@ public class RouteInfoManager { } public RegisterBrokerResult registerBroker( - final String clusterName, - final String brokerAddr, - final String brokerName, - final long brokerId, - final String haServerAddr, - final TopicConfigSerializeWrapper topicConfigWrapper, - final List filterServerList, - final Channel channel) { + final String clusterName, + final String brokerAddr, + final String brokerName, + final long brokerId, + final String haServerAddr, + final TopicConfigSerializeWrapper topicConfigWrapper, + final List filterServerList, + final Channel channel) { RegisterBrokerResult result = new RegisterBrokerResult(); try { try { this.lock.writeLock().lockInterruptibly(); - Set brokerNames = this.clusterAddrTable.get(clusterName); if (null == brokerNames) { brokerNames = new HashSet(); @@ -120,7 +122,6 @@ public class RouteInfoManager { boolean registerFirst = false; - BrokerData brokerData = this.brokerAddrTable.get(brokerName); if (null == brokerData) { registerFirst = true; @@ -134,13 +135,12 @@ public class RouteInfoManager { String oldAddr = brokerData.getBrokerAddrs().put(brokerId, brokerAddr); registerFirst = registerFirst || (null == oldAddr); - if (null != topicConfigWrapper // - && MixAll.MASTER_ID == brokerId) { + && MixAll.MASTER_ID == brokerId) { if (this.isBrokerTopicConfigChanged(brokerAddr, topicConfigWrapper.getDataVersion())// - || registerFirst) { + || registerFirst) { ConcurrentHashMap tcTable = - topicConfigWrapper.getTopicConfigTable(); + topicConfigWrapper.getTopicConfigTable(); if (tcTable != null) { for (Map.Entry entry : tcTable.entrySet()) { this.createAndUpdateQueueData(brokerName, entry.getValue()); @@ -149,18 +149,16 @@ public class RouteInfoManager { } } - BrokerLiveInfo prevBrokerLiveInfo = this.brokerLiveTable.put(brokerAddr, - new BrokerLiveInfo( - System.currentTimeMillis(), - topicConfigWrapper.getDataVersion(), - channel, - haServerAddr)); + new BrokerLiveInfo( + System.currentTimeMillis(), + topicConfigWrapper.getDataVersion(), + channel, + haServerAddr)); if (null == prevBrokerLiveInfo) { log.info("new broker registerd, {} HAServer: {}", brokerAddr, haServerAddr); } - if (filterServerList != null) { if (filterServerList.isEmpty()) { this.filterServerTable.remove(brokerAddr); @@ -169,7 +167,6 @@ public class RouteInfoManager { } } - if (MixAll.MASTER_ID != brokerId) { String masterAddr = brokerData.getBrokerAddrs().get(MixAll.MASTER_ID); if (masterAddr != null) { @@ -224,7 +221,7 @@ public class RouteInfoManager { addNewOne = false; } else { log.info("topic changed, {} OLD: {} NEW: {}", topicConfig.getTopicName(), qd, - queueData); + queueData); it.remove(); } } @@ -274,18 +271,18 @@ public class RouteInfoManager { } public void unregisterBroker( - final String clusterName, - final String brokerAddr, - final String brokerName, - final long brokerId) { + final String clusterName, + final String brokerAddr, + final String brokerName, + final long brokerId) { try { try { this.lock.writeLock().lockInterruptibly(); BrokerLiveInfo brokerLiveInfo = this.brokerLiveTable.remove(brokerAddr); if (brokerLiveInfo != null) { log.info("unregisterBroker, remove from brokerLiveTable {}, {}", - brokerLiveInfo != null ? "OK" : "Failed", - brokerAddr + brokerLiveInfo != null ? "OK" : "Failed", + brokerAddr ); } @@ -296,14 +293,14 @@ public class RouteInfoManager { if (null != brokerData) { String addr = brokerData.getBrokerAddrs().remove(brokerId); log.info("unregisterBroker, remove addr from brokerAddrTable {}, {}", - addr != null ? "OK" : "Failed", - brokerAddr + addr != null ? "OK" : "Failed", + brokerAddr ); if (brokerData.getBrokerAddrs().isEmpty()) { this.brokerAddrTable.remove(brokerName); log.info("unregisterBroker, remove name from brokerAddrTable OK, {}", - brokerName + brokerName ); removeBrokerName = true; @@ -315,13 +312,13 @@ public class RouteInfoManager { if (nameSet != null) { boolean removed = nameSet.remove(brokerName); log.info("unregisterBroker, remove name from clusterAddrTable {}, {}", - removed ? "OK" : "Failed", - brokerName); + removed ? "OK" : "Failed", + brokerName); if (nameSet.isEmpty()) { this.clusterAddrTable.remove(clusterName); log.info("unregisterBroker, remove cluster from clusterAddrTable {}", - clusterName + clusterName ); } } @@ -377,7 +374,6 @@ public class RouteInfoManager { topicRouteData.setQueueDatas(queueDataList); foundQueueData = true; - Iterator it = queueDataList.iterator(); while (it.hasNext()) { QueueData qd = it.next(); @@ -389,8 +385,8 @@ public class RouteInfoManager { if (null != brokerData) { BrokerData brokerDataClone = new BrokerData(); brokerDataClone.setBrokerName(brokerData.getBrokerName()); - brokerDataClone.setBrokerAddrs((HashMap) brokerData - .getBrokerAddrs().clone()); + brokerDataClone.setBrokerAddrs((HashMap)brokerData + .getBrokerAddrs().clone()); brokerDataList.add(brokerDataClone); foundBrokerData = true; for (final String brokerAddr : brokerDataClone.getBrokerAddrs().values()) { @@ -439,7 +435,7 @@ public class RouteInfoManager { try { this.lock.readLock().lockInterruptibly(); Iterator> itBrokerLiveTable = - this.brokerLiveTable.entrySet().iterator(); + this.brokerLiveTable.entrySet().iterator(); while (itBrokerLiveTable.hasNext()) { Entry entry = itBrokerLiveTable.next(); if (entry.getValue().getChannel() == channel) { @@ -461,7 +457,6 @@ public class RouteInfoManager { log.info("the broker's channel destroyed, {}, clean it's data structure at once", brokerAddrFound); } - if (brokerAddrFound != null && brokerAddrFound.length() > 0) { try { @@ -472,7 +467,7 @@ public class RouteInfoManager { String brokerNameFound = null; boolean removeBrokerName = false; Iterator> itBrokerAddrTable = - this.brokerAddrTable.entrySet().iterator(); + this.brokerAddrTable.entrySet().iterator(); while (itBrokerAddrTable.hasNext() && (null == brokerNameFound)) { BrokerData brokerData = itBrokerAddrTable.next().getValue(); @@ -485,7 +480,7 @@ public class RouteInfoManager { brokerNameFound = brokerData.getBrokerName(); it.remove(); log.info("remove brokerAddr[{}, {}] from brokerAddrTable, because channel destroyed", - brokerId, brokerAddr); + brokerId, brokerAddr); break; } } @@ -494,7 +489,7 @@ public class RouteInfoManager { removeBrokerName = true; itBrokerAddrTable.remove(); log.info("remove brokerName[{}] from brokerAddrTable, because channel destroyed", - brokerData.getBrokerName()); + brokerData.getBrokerName()); } } @@ -507,12 +502,11 @@ public class RouteInfoManager { boolean removed = brokerNames.remove(brokerNameFound); if (removed) { log.info("remove brokerName[{}], clusterName[{}] from clusterAddrTable, because channel destroyed", - brokerNameFound, clusterName); - + brokerNameFound, clusterName); if (brokerNames.isEmpty()) { log.info("remove the clusterName[{}] from clusterAddrTable, because channel destroyed and no broker in this cluster", - clusterName); + clusterName); it.remove(); } @@ -523,7 +517,7 @@ public class RouteInfoManager { if (removeBrokerName) { Iterator>> itTopicQueueTable = - this.topicQueueTable.entrySet().iterator(); + this.topicQueueTable.entrySet().iterator(); while (itTopicQueueTable.hasNext()) { Entry> entry = itTopicQueueTable.next(); String topic = entry.getKey(); @@ -535,14 +529,14 @@ public class RouteInfoManager { if (queueData.getBrokerName().equals(brokerNameFound)) { itQueueData.remove(); log.info("remove topic[{} {}], from topicQueueTable, because channel destroyed", - topic, queueData); + topic, queueData); } } if (queueDataList.isEmpty()) { itTopicQueueTable.remove(); log.info("remove topic[{}] all queue, from topicQueueTable, because channel destroyed", - topic); + topic); } } } @@ -603,7 +597,6 @@ public class RouteInfoManager { } } - public byte[] getSystemTopicList() { TopicList topicList = new TopicList(); try { @@ -644,7 +637,7 @@ public class RouteInfoManager { Set brokerNameSet = this.clusterAddrTable.get(cluster); for (String brokerName : brokerNameSet) { Iterator>> topicTableIt = - this.topicQueueTable.entrySet().iterator(); + this.topicQueueTable.entrySet().iterator(); while (topicTableIt.hasNext()) { Entry> topicEntry = topicTableIt.next(); String topic = topicEntry.getKey(); @@ -673,13 +666,13 @@ public class RouteInfoManager { try { this.lock.readLock().lockInterruptibly(); Iterator>> topicTableIt = - this.topicQueueTable.entrySet().iterator(); + this.topicQueueTable.entrySet().iterator(); while (topicTableIt.hasNext()) { Entry> topicEntry = topicTableIt.next(); String topic = topicEntry.getKey(); List queueDatas = topicEntry.getValue(); if (queueDatas != null && queueDatas.size() > 0 - && TopicSysFlag.hasUnitFlag(queueDatas.get(0).getTopicSynFlag())) { + && TopicSysFlag.hasUnitFlag(queueDatas.get(0).getTopicSynFlag())) { topicList.getTopicList().add(topic); } } @@ -699,13 +692,13 @@ public class RouteInfoManager { try { this.lock.readLock().lockInterruptibly(); Iterator>> topicTableIt = - this.topicQueueTable.entrySet().iterator(); + this.topicQueueTable.entrySet().iterator(); while (topicTableIt.hasNext()) { Entry> topicEntry = topicTableIt.next(); String topic = topicEntry.getKey(); List queueDatas = topicEntry.getValue(); if (queueDatas != null && queueDatas.size() > 0 - && TopicSysFlag.hasUnitSubFlag(queueDatas.get(0).getTopicSynFlag())) { + && TopicSysFlag.hasUnitSubFlag(queueDatas.get(0).getTopicSynFlag())) { topicList.getTopicList().add(topic); } } @@ -725,14 +718,14 @@ public class RouteInfoManager { try { this.lock.readLock().lockInterruptibly(); Iterator>> topicTableIt = - this.topicQueueTable.entrySet().iterator(); + this.topicQueueTable.entrySet().iterator(); while (topicTableIt.hasNext()) { Entry> topicEntry = topicTableIt.next(); String topic = topicEntry.getKey(); List queueDatas = topicEntry.getValue(); if (queueDatas != null && queueDatas.size() > 0 - && !TopicSysFlag.hasUnitFlag(queueDatas.get(0).getTopicSynFlag()) - && TopicSysFlag.hasUnitSubFlag(queueDatas.get(0).getTopicSynFlag())) { + && !TopicSysFlag.hasUnitFlag(queueDatas.get(0).getTopicSynFlag()) + && TopicSysFlag.hasUnitSubFlag(queueDatas.get(0).getTopicSynFlag())) { topicList.getTopicList().add(topic); } } @@ -747,66 +740,55 @@ public class RouteInfoManager { } } - class BrokerLiveInfo { private long lastUpdateTimestamp; private DataVersion dataVersion; private Channel channel; private String haServerAddr; - public BrokerLiveInfo(long lastUpdateTimestamp, DataVersion dataVersion, Channel channel, - String haServerAddr) { + String haServerAddr) { this.lastUpdateTimestamp = lastUpdateTimestamp; this.dataVersion = dataVersion; this.channel = channel; this.haServerAddr = haServerAddr; } - public long getLastUpdateTimestamp() { return lastUpdateTimestamp; } - public void setLastUpdateTimestamp(long lastUpdateTimestamp) { this.lastUpdateTimestamp = lastUpdateTimestamp; } - public DataVersion getDataVersion() { return dataVersion; } - public void setDataVersion(DataVersion dataVersion) { this.dataVersion = dataVersion; } - public Channel getChannel() { return channel; } - public void setChannel(Channel channel) { this.channel = channel; } - public String getHaServerAddr() { return haServerAddr; } - public void setHaServerAddr(String haServerAddr) { this.haServerAddr = haServerAddr; } - @Override public String toString() { return "BrokerLiveInfo [lastUpdateTimestamp=" + lastUpdateTimestamp + ", dataVersion=" + dataVersion - + ", channel=" + channel + ", haServerAddr=" + haServerAddr + "]"; + + ", channel=" + channel + ", haServerAddr=" + haServerAddr + "]"; } } diff --git a/remoting/pom.xml b/remoting/pom.xml index 6e75c542..15f4443c 100644 --- a/remoting/pom.xml +++ b/remoting/pom.xml @@ -15,7 +15,7 @@ limitations under the License. --> - org.apache.rocketmq diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/ChannelEventListener.java b/remoting/src/main/java/org/apache/rocketmq/remoting/ChannelEventListener.java index ba93f090..98cbb538 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/ChannelEventListener.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/ChannelEventListener.java @@ -6,31 +6,27 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.remoting; import io.netty.channel.Channel; - /** * */ public interface ChannelEventListener { void onChannelConnect(final String remoteAddr, final Channel channel); - void onChannelClose(final String remoteAddr, final Channel channel); - void onChannelException(final String remoteAddr, final Channel channel); - void onChannelIdle(final String remoteAddr, final Channel channel); } diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/CommandCustomHeader.java b/remoting/src/main/java/org/apache/rocketmq/remoting/CommandCustomHeader.java index de7d3b05..bd1d1226 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/CommandCustomHeader.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/CommandCustomHeader.java @@ -6,19 +6,18 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.remoting; import org.apache.rocketmq.remoting.exception.RemotingCommandException; - public interface CommandCustomHeader { void checkFields() throws RemotingCommandException; } diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/InvokeCallback.java b/remoting/src/main/java/org/apache/rocketmq/remoting/InvokeCallback.java index 3db5f691..c3bcd87b 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/InvokeCallback.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/InvokeCallback.java @@ -6,19 +6,18 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.remoting; import org.apache.rocketmq.remoting.netty.ResponseFuture; - /** * */ diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/RPCHook.java b/remoting/src/main/java/org/apache/rocketmq/remoting/RPCHook.java index c489f1db..c118180b 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/RPCHook.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/RPCHook.java @@ -19,11 +19,9 @@ package org.apache.rocketmq.remoting; import org.apache.rocketmq.remoting.protocol.RemotingCommand; - public interface RPCHook { void doBeforeRequest(final String remoteAddr, final RemotingCommand request); - void doAfterResponse(final String remoteAddr, final RemotingCommand request, - final RemotingCommand response); + final RemotingCommand response); } diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/RemotingClient.java b/remoting/src/main/java/org/apache/rocketmq/remoting/RemotingClient.java index 5f96a343..6c7f7a99 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/RemotingClient.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/RemotingClient.java @@ -6,16 +6,18 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.remoting; +import java.util.List; +import java.util.concurrent.ExecutorService; import org.apache.rocketmq.remoting.exception.RemotingConnectException; import org.apache.rocketmq.remoting.exception.RemotingSendRequestException; import org.apache.rocketmq.remoting.exception.RemotingTimeoutException; @@ -23,10 +25,6 @@ import org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException; import org.apache.rocketmq.remoting.netty.NettyRequestProcessor; import org.apache.rocketmq.remoting.protocol.RemotingCommand; -import java.util.List; -import java.util.concurrent.ExecutorService; - - /** * */ @@ -34,28 +32,22 @@ public interface RemotingClient extends RemotingService { public void updateNameServerAddressList(final List addrs); - public List getNameServerAddressList(); - public RemotingCommand invokeSync(final String addr, final RemotingCommand request, - final long timeoutMillis) throws InterruptedException, RemotingConnectException, - RemotingSendRequestException, RemotingTimeoutException; - + final long timeoutMillis) throws InterruptedException, RemotingConnectException, + RemotingSendRequestException, RemotingTimeoutException; public void invokeAsync(final String addr, final RemotingCommand request, final long timeoutMillis, - final InvokeCallback invokeCallback) throws InterruptedException, RemotingConnectException, - RemotingTooMuchRequestException, RemotingTimeoutException, RemotingSendRequestException; - + final InvokeCallback invokeCallback) throws InterruptedException, RemotingConnectException, + RemotingTooMuchRequestException, RemotingTimeoutException, RemotingSendRequestException; public void invokeOneway(final String addr, final RemotingCommand request, final long timeoutMillis) - throws InterruptedException, RemotingConnectException, RemotingTooMuchRequestException, - RemotingTimeoutException, RemotingSendRequestException; - + throws InterruptedException, RemotingConnectException, RemotingTooMuchRequestException, + RemotingTimeoutException, RemotingSendRequestException; public void registerProcessor(final int requestCode, final NettyRequestProcessor processor, - final ExecutorService executor); - + final ExecutorService executor); public boolean isChannelWriteable(final String addr); } diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/RemotingServer.java b/remoting/src/main/java/org/apache/rocketmq/remoting/RemotingServer.java index 98270ecb..d0b13fca 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/RemotingServer.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/RemotingServer.java @@ -16,16 +16,14 @@ */ package org.apache.rocketmq.remoting; +import io.netty.channel.Channel; +import java.util.concurrent.ExecutorService; import org.apache.rocketmq.remoting.common.Pair; import org.apache.rocketmq.remoting.exception.RemotingSendRequestException; import org.apache.rocketmq.remoting.exception.RemotingTimeoutException; import org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException; import org.apache.rocketmq.remoting.netty.NettyRequestProcessor; import org.apache.rocketmq.remoting.protocol.RemotingCommand; -import io.netty.channel.Channel; - -import java.util.concurrent.ExecutorService; - /** * @@ -33,30 +31,24 @@ import java.util.concurrent.ExecutorService; public interface RemotingServer extends RemotingService { void registerProcessor(final int requestCode, final NettyRequestProcessor processor, - final ExecutorService executor); - + final ExecutorService executor); void registerDefaultProcessor(final NettyRequestProcessor processor, final ExecutorService executor); - int localListenPort(); - Pair getProcessorPair(final int requestCode); - RemotingCommand invokeSync(final Channel channel, final RemotingCommand request, - final long timeoutMillis) throws InterruptedException, RemotingSendRequestException, - RemotingTimeoutException; - + final long timeoutMillis) throws InterruptedException, RemotingSendRequestException, + RemotingTimeoutException; void invokeAsync(final Channel channel, final RemotingCommand request, final long timeoutMillis, - final InvokeCallback invokeCallback) throws InterruptedException, - RemotingTooMuchRequestException, RemotingTimeoutException, RemotingSendRequestException; - + final InvokeCallback invokeCallback) throws InterruptedException, + RemotingTooMuchRequestException, RemotingTimeoutException, RemotingSendRequestException; void invokeOneway(final Channel channel, final RemotingCommand request, final long timeoutMillis) - throws InterruptedException, RemotingTooMuchRequestException, RemotingTimeoutException, - RemotingSendRequestException; + throws InterruptedException, RemotingTooMuchRequestException, RemotingTimeoutException, + RemotingSendRequestException; } diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/RemotingService.java b/remoting/src/main/java/org/apache/rocketmq/remoting/RemotingService.java index 1af2b162..50e89d04 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/RemotingService.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/RemotingService.java @@ -20,9 +20,7 @@ package org.apache.rocketmq.remoting; public interface RemotingService { void start(); - void shutdown(); - void registerRPCHook(RPCHook rpcHook); } diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/annotation/CFNullable.java b/remoting/src/main/java/org/apache/rocketmq/remoting/annotation/CFNullable.java index b5520573..fabc06b4 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/annotation/CFNullable.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/annotation/CFNullable.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.remoting.annotation; diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/common/Pair.java b/remoting/src/main/java/org/apache/rocketmq/remoting/common/Pair.java index 180348c5..2f2fc77e 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/common/Pair.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/common/Pair.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.remoting.common; @@ -20,28 +20,23 @@ public class Pair { private T1 object1; private T2 object2; - public Pair(T1 object1, T2 object2) { this.object1 = object1; this.object2 = object2; } - public T1 getObject1() { return object1; } - public void setObject1(T1 object1) { this.object1 = object1; } - public T2 getObject2() { return object2; } - public void setObject2(T2 object2) { this.object2 = object2; } diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/common/RemotingHelper.java b/remoting/src/main/java/org/apache/rocketmq/remoting/common/RemotingHelper.java index 43005377..8d189e72 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/common/RemotingHelper.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/common/RemotingHelper.java @@ -6,28 +6,26 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.remoting.common; -import org.apache.rocketmq.remoting.exception.RemotingConnectException; -import org.apache.rocketmq.remoting.exception.RemotingSendRequestException; -import org.apache.rocketmq.remoting.exception.RemotingTimeoutException; -import org.apache.rocketmq.remoting.protocol.RemotingCommand; import io.netty.channel.Channel; - import java.io.IOException; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.nio.ByteBuffer; import java.nio.channels.SocketChannel; - +import org.apache.rocketmq.remoting.exception.RemotingConnectException; +import org.apache.rocketmq.remoting.exception.RemotingSendRequestException; +import org.apache.rocketmq.remoting.exception.RemotingTimeoutException; +import org.apache.rocketmq.remoting.protocol.RemotingCommand; public class RemotingHelper { public static final String ROCKETMQ_REMOTING = "RocketmqRemoting"; @@ -56,8 +54,8 @@ public class RemotingHelper { } public static RemotingCommand invokeSync(final String addr, final RemotingCommand request, - final long timeoutMillis) throws InterruptedException, RemotingConnectException, - RemotingSendRequestException, RemotingTimeoutException { + final long timeoutMillis) throws InterruptedException, RemotingConnectException, + RemotingSendRequestException, RemotingTimeoutException { long beginTime = System.currentTimeMillis(); SocketAddress socketAddress = RemotingUtil.string2SocketAddress(addr); SocketChannel socketChannel = RemotingUtil.connect(socketAddress); @@ -69,8 +67,7 @@ public class RemotingHelper { socketChannel.configureBlocking(true); //bugfix http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4614802 - socketChannel.socket().setSoTimeout((int) timeoutMillis); - + socketChannel.socket().setSoTimeout((int)timeoutMillis); ByteBuffer byteBufferRequest = request.encode(); while (byteBufferRequest.hasRemaining()) { @@ -86,7 +83,6 @@ public class RemotingHelper { throw new RemotingSendRequestException(addr); } - Thread.sleep(1); } @@ -106,7 +102,6 @@ public class RemotingHelper { throw new RemotingTimeoutException(addr, timeoutMillis); } - Thread.sleep(1); } @@ -125,11 +120,9 @@ public class RemotingHelper { throw new RemotingTimeoutException(addr, timeoutMillis); } - Thread.sleep(1); } - byteBufferBody.flip(); return RemotingCommand.decode(byteBufferBody); } catch (IOException e) { @@ -152,7 +145,6 @@ public class RemotingHelper { } } - public static String parseChannelRemoteAddr(final Channel channel) { if (null == channel) { return ""; @@ -172,19 +164,17 @@ public class RemotingHelper { return ""; } - public static String parseChannelRemoteName(final Channel channel) { if (null == channel) { return ""; } - final InetSocketAddress remote = (InetSocketAddress) channel.remoteAddress(); + final InetSocketAddress remote = (InetSocketAddress)channel.remoteAddress(); if (remote != null) { return remote.getAddress().getHostName(); } return ""; } - public static String parseSocketAddressAddr(SocketAddress socketAddress) { if (socketAddress != null) { final String addr = socketAddress.toString(); @@ -196,10 +186,9 @@ public class RemotingHelper { return ""; } - public static String parseSocketAddressName(SocketAddress socketAddress) { - final InetSocketAddress addrs = (InetSocketAddress) socketAddress; + final InetSocketAddress addrs = (InetSocketAddress)socketAddress; if (addrs != null) { return addrs.getAddress().getHostName(); } diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/common/RemotingUtil.java b/remoting/src/main/java/org/apache/rocketmq/remoting/common/RemotingUtil.java index 005471e0..bcc22327 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/common/RemotingUtil.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/common/RemotingUtil.java @@ -6,22 +6,19 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.remoting.common; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.io.IOException; import java.lang.reflect.Method; import java.net.Inet6Address; @@ -36,7 +33,8 @@ import java.nio.channels.SocketChannel; import java.nio.channels.spi.SelectorProvider; import java.util.ArrayList; import java.util.Enumeration; - +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class RemotingUtil { public static final String OS_NAME = System.getProperty("os.name"); @@ -69,7 +67,7 @@ public class RemotingUtil { try { final Method method = providerClazz.getMethod("provider"); if (method != null) { - final SelectorProvider selectorProvider = (SelectorProvider) method.invoke(null); + final SelectorProvider selectorProvider = (SelectorProvider)method.invoke(null); if (selectorProvider != null) { result = selectorProvider.openSelector(); } @@ -141,7 +139,6 @@ public class RemotingUtil { return null; } - public static String normalizeHostAddress(final InetAddress localHost) { if (localHost instanceof Inet6Address) { return "[" + localHost.getHostAddress() + "]"; @@ -156,22 +153,19 @@ public class RemotingUtil { return isa; } - public static String socketAddress2String(final SocketAddress addr) { StringBuilder sb = new StringBuilder(); - InetSocketAddress inetSocketAddress = (InetSocketAddress) addr; + InetSocketAddress inetSocketAddress = (InetSocketAddress)addr; sb.append(inetSocketAddress.getAddress().getHostAddress()); sb.append(":"); sb.append(inetSocketAddress.getPort()); return sb.toString(); } - public static SocketChannel connect(SocketAddress remote) { return connect(remote, 1000 * 5); } - public static SocketChannel connect(SocketAddress remote, final int timeoutMillis) { SocketChannel sc = null; try { @@ -197,14 +191,13 @@ public class RemotingUtil { return null; } - public static void closeChannel(Channel channel) { final String addrRemote = RemotingHelper.parseChannelRemoteAddr(channel); channel.close().addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { log.info("closeChannel: close the connection to remote address[{}] result: {}", addrRemote, - future.isSuccess()); + future.isSuccess()); } }); } diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/common/SemaphoreReleaseOnlyOnce.java b/remoting/src/main/java/org/apache/rocketmq/remoting/common/SemaphoreReleaseOnlyOnce.java index 7734f860..c8d594ef 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/common/SemaphoreReleaseOnlyOnce.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/common/SemaphoreReleaseOnlyOnce.java @@ -6,30 +6,27 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.remoting.common; import java.util.concurrent.Semaphore; import java.util.concurrent.atomic.AtomicBoolean; - public class SemaphoreReleaseOnlyOnce { private final AtomicBoolean released = new AtomicBoolean(false); private final Semaphore semaphore; - public SemaphoreReleaseOnlyOnce(Semaphore semaphore) { this.semaphore = semaphore; } - public void release() { if (this.semaphore != null) { if (this.released.compareAndSet(false, true)) { @@ -38,7 +35,6 @@ public class SemaphoreReleaseOnlyOnce { } } - public Semaphore getSemaphore() { return semaphore; } diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/common/ServiceThread.java b/remoting/src/main/java/org/apache/rocketmq/remoting/common/ServiceThread.java index c82cbdf1..9cccaaf8 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/common/ServiceThread.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/common/ServiceThread.java @@ -6,20 +6,19 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.remoting.common; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - /** * Base class for background thread * @@ -32,20 +31,16 @@ public abstract class ServiceThread implements Runnable { protected volatile boolean hasNotified = false; protected volatile boolean stopped = false; - public ServiceThread() { this.thread = new Thread(this, this.getServiceName()); } - public abstract String getServiceName(); - public void start() { this.thread.start(); } - public void shutdown() { this.shutdown(false); } @@ -69,7 +64,7 @@ public abstract class ServiceThread implements Runnable { this.thread.join(this.getJointime()); long eclipseTime = System.currentTimeMillis() - beginTime; STLOG.info("join thread " + this.getServiceName() + " eclipse time(ms) " + eclipseTime + " " - + this.getJointime()); + + this.getJointime()); } catch (InterruptedException e) { e.printStackTrace(); } diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/exception/RemotingCommandException.java b/remoting/src/main/java/org/apache/rocketmq/remoting/exception/RemotingCommandException.java index 72c52879..62a10a6f 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/exception/RemotingCommandException.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/exception/RemotingCommandException.java @@ -6,25 +6,23 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.remoting.exception; public class RemotingCommandException extends RemotingException { private static final long serialVersionUID = -6061365915274953096L; - public RemotingCommandException(String message) { super(message, null); } - public RemotingCommandException(String message, Throwable cause) { super(message, cause); } diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/exception/RemotingConnectException.java b/remoting/src/main/java/org/apache/rocketmq/remoting/exception/RemotingConnectException.java index 2fa4d692..c3e4777e 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/exception/RemotingConnectException.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/exception/RemotingConnectException.java @@ -6,25 +6,23 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.remoting.exception; public class RemotingConnectException extends RemotingException { private static final long serialVersionUID = -5565366231695911316L; - public RemotingConnectException(String addr) { this(addr, null); } - public RemotingConnectException(String addr, Throwable cause) { super("connect to <" + addr + "> failed", cause); } diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/exception/RemotingException.java b/remoting/src/main/java/org/apache/rocketmq/remoting/exception/RemotingException.java index f4a79ea6..cbc363b7 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/exception/RemotingException.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/exception/RemotingException.java @@ -6,25 +6,23 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.remoting.exception; public class RemotingException extends Exception { private static final long serialVersionUID = -5690687334570505110L; - public RemotingException(String message) { super(message); } - public RemotingException(String message, Throwable cause) { super(message, cause); } diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/exception/RemotingSendRequestException.java b/remoting/src/main/java/org/apache/rocketmq/remoting/exception/RemotingSendRequestException.java index 720ec1f8..4eb1b637 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/exception/RemotingSendRequestException.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/exception/RemotingSendRequestException.java @@ -6,25 +6,23 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.remoting.exception; public class RemotingSendRequestException extends RemotingException { private static final long serialVersionUID = 5391285827332471674L; - public RemotingSendRequestException(String addr) { this(addr, null); } - public RemotingSendRequestException(String addr, Throwable cause) { super("send request to <" + addr + "> failed", cause); } diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/exception/RemotingTimeoutException.java b/remoting/src/main/java/org/apache/rocketmq/remoting/exception/RemotingTimeoutException.java index 1190b493..e4cc69ed 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/exception/RemotingTimeoutException.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/exception/RemotingTimeoutException.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.remoting.exception; @@ -20,17 +20,14 @@ public class RemotingTimeoutException extends RemotingException { private static final long serialVersionUID = 4106899185095245979L; - public RemotingTimeoutException(String message) { super(message); } - public RemotingTimeoutException(String addr, long timeoutMillis) { this(addr, timeoutMillis, null); } - public RemotingTimeoutException(String addr, long timeoutMillis, Throwable cause) { super("wait response on the channel <" + addr + "> timeout, " + timeoutMillis + "(ms)", cause); } diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/exception/RemotingTooMuchRequestException.java b/remoting/src/main/java/org/apache/rocketmq/remoting/exception/RemotingTooMuchRequestException.java index 80d4418d..8ec5cf65 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/exception/RemotingTooMuchRequestException.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/exception/RemotingTooMuchRequestException.java @@ -6,20 +6,19 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.remoting.exception; public class RemotingTooMuchRequestException extends RemotingException { private static final long serialVersionUID = 4326919581254519654L; - public RemotingTooMuchRequestException(String message) { super(message); } diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyClientConfig.java b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyClientConfig.java index b7972720..7c017eb6 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyClientConfig.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyClientConfig.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.remoting.netty; @@ -53,97 +53,78 @@ public class NettyClientConfig { return clientWorkerThreads; } - public void setClientWorkerThreads(int clientWorkerThreads) { this.clientWorkerThreads = clientWorkerThreads; } - public int getClientOnewaySemaphoreValue() { return clientOnewaySemaphoreValue; } - public void setClientOnewaySemaphoreValue(int clientOnewaySemaphoreValue) { this.clientOnewaySemaphoreValue = clientOnewaySemaphoreValue; } - public int getConnectTimeoutMillis() { return connectTimeoutMillis; } - public void setConnectTimeoutMillis(int connectTimeoutMillis) { this.connectTimeoutMillis = connectTimeoutMillis; } - public int getClientCallbackExecutorThreads() { return clientCallbackExecutorThreads; } - public void setClientCallbackExecutorThreads(int clientCallbackExecutorThreads) { this.clientCallbackExecutorThreads = clientCallbackExecutorThreads; } - public long getChannelNotActiveInterval() { return channelNotActiveInterval; } - public void setChannelNotActiveInterval(long channelNotActiveInterval) { this.channelNotActiveInterval = channelNotActiveInterval; } - public int getClientAsyncSemaphoreValue() { return clientAsyncSemaphoreValue; } - public void setClientAsyncSemaphoreValue(int clientAsyncSemaphoreValue) { this.clientAsyncSemaphoreValue = clientAsyncSemaphoreValue; } - public int getClientChannelMaxIdleTimeSeconds() { return clientChannelMaxIdleTimeSeconds; } - public void setClientChannelMaxIdleTimeSeconds(int clientChannelMaxIdleTimeSeconds) { this.clientChannelMaxIdleTimeSeconds = clientChannelMaxIdleTimeSeconds; } - public int getClientSocketSndBufSize() { return clientSocketSndBufSize; } - public void setClientSocketSndBufSize(int clientSocketSndBufSize) { this.clientSocketSndBufSize = clientSocketSndBufSize; } - public int getClientSocketRcvBufSize() { return clientSocketRcvBufSize; } - public void setClientSocketRcvBufSize(int clientSocketRcvBufSize) { this.clientSocketRcvBufSize = clientSocketRcvBufSize; } - public boolean isClientPooledByteBufAllocatorEnable() { return clientPooledByteBufAllocatorEnable; } - public void setClientPooledByteBufAllocatorEnable(boolean clientPooledByteBufAllocatorEnable) { this.clientPooledByteBufAllocatorEnable = clientPooledByteBufAllocatorEnable; } diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyDecoder.java b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyDecoder.java index 0a8ba97f..73d7f2bd 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyDecoder.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyDecoder.java @@ -6,47 +6,43 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.remoting.netty; -import org.apache.rocketmq.remoting.common.RemotingHelper; -import org.apache.rocketmq.remoting.common.RemotingUtil; -import org.apache.rocketmq.remoting.protocol.RemotingCommand; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.LengthFieldBasedFrameDecoder; +import java.nio.ByteBuffer; +import org.apache.rocketmq.remoting.common.RemotingHelper; +import org.apache.rocketmq.remoting.common.RemotingUtil; +import org.apache.rocketmq.remoting.protocol.RemotingCommand; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.nio.ByteBuffer; - - /** * */ public class NettyDecoder extends LengthFieldBasedFrameDecoder { private static final Logger log = LoggerFactory.getLogger(RemotingHelper.ROCKETMQ_REMOTING); private static final int FRAME_MAX_LENGTH = // - Integer.parseInt(System.getProperty("com.rocketmq.remoting.frameMaxLength", "16777216")); - + Integer.parseInt(System.getProperty("com.rocketmq.remoting.frameMaxLength", "16777216")); public NettyDecoder() { super(FRAME_MAX_LENGTH, 0, 4, 0, 4); } - @Override public Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception { ByteBuf frame = null; try { - frame = (ByteBuf) super.decode(ctx, in); + frame = (ByteBuf)super.decode(ctx, in); if (null == frame) { return null; } diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyEncoder.java b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyEncoder.java index 35adcf2b..fdebcdc2 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyEncoder.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyEncoder.java @@ -6,28 +6,26 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.remoting.netty; -import org.apache.rocketmq.remoting.common.RemotingHelper; -import org.apache.rocketmq.remoting.common.RemotingUtil; -import org.apache.rocketmq.remoting.protocol.RemotingCommand; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToByteEncoder; +import java.nio.ByteBuffer; +import org.apache.rocketmq.remoting.common.RemotingHelper; +import org.apache.rocketmq.remoting.common.RemotingUtil; +import org.apache.rocketmq.remoting.protocol.RemotingCommand; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.nio.ByteBuffer; - - /** * */ @@ -36,7 +34,7 @@ public class NettyEncoder extends MessageToByteEncoder { @Override public void encode(ChannelHandlerContext ctx, RemotingCommand remotingCommand, ByteBuf out) - throws Exception { + throws Exception { try { ByteBuffer header = remotingCommand.encodeHeader(); out.writeBytes(header); diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyEvent.java b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyEvent.java index e0864098..825d1dae 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyEvent.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyEvent.java @@ -6,47 +6,41 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.remoting.netty; import io.netty.channel.Channel; - public class NettyEvent { private final NettyEventType type; private final String remoteAddr; private final Channel channel; - public NettyEvent(NettyEventType type, String remoteAddr, Channel channel) { this.type = type; this.remoteAddr = remoteAddr; this.channel = channel; } - public NettyEventType getType() { return type; } - public String getRemoteAddr() { return remoteAddr; } - public Channel getChannel() { return channel; } - @Override public String toString() { return "NettyEvent [type=" + type + ", remoteAddr=" + remoteAddr + ", channel=" + channel + "]"; diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyEventType.java b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyEventType.java index ae4b6479..b2135dae 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyEventType.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyEventType.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.remoting.netty; diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRemotingAbstract.java b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRemotingAbstract.java index 1034dd86..c0136d3f 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRemotingAbstract.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRemotingAbstract.java @@ -16,25 +16,10 @@ */ package org.apache.rocketmq.remoting.netty; -import org.apache.rocketmq.remoting.ChannelEventListener; -import org.apache.rocketmq.remoting.InvokeCallback; -import org.apache.rocketmq.remoting.RPCHook; -import org.apache.rocketmq.remoting.common.Pair; -import org.apache.rocketmq.remoting.common.RemotingHelper; -import org.apache.rocketmq.remoting.common.SemaphoreReleaseOnlyOnce; -import org.apache.rocketmq.remoting.common.ServiceThread; -import org.apache.rocketmq.remoting.exception.RemotingSendRequestException; -import org.apache.rocketmq.remoting.exception.RemotingTimeoutException; -import org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException; -import org.apache.rocketmq.remoting.protocol.RemotingCommand; -import org.apache.rocketmq.remoting.protocol.RemotingSysResponseCode; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandlerContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.net.SocketAddress; import java.util.HashMap; import java.util.Iterator; @@ -47,28 +32,37 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; - +import org.apache.rocketmq.remoting.ChannelEventListener; +import org.apache.rocketmq.remoting.InvokeCallback; +import org.apache.rocketmq.remoting.RPCHook; +import org.apache.rocketmq.remoting.common.Pair; +import org.apache.rocketmq.remoting.common.RemotingHelper; +import org.apache.rocketmq.remoting.common.SemaphoreReleaseOnlyOnce; +import org.apache.rocketmq.remoting.common.ServiceThread; +import org.apache.rocketmq.remoting.exception.RemotingSendRequestException; +import org.apache.rocketmq.remoting.exception.RemotingTimeoutException; +import org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException; +import org.apache.rocketmq.remoting.protocol.RemotingCommand; +import org.apache.rocketmq.remoting.protocol.RemotingSysResponseCode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public abstract class NettyRemotingAbstract { private static final Logger PLOG = LoggerFactory.getLogger(RemotingHelper.ROCKETMQ_REMOTING); - protected final Semaphore semaphoreOneway; - protected final Semaphore semaphoreAsync; - protected final ConcurrentHashMap responseTable = - new ConcurrentHashMap(256); + new ConcurrentHashMap(256); protected final HashMap> processorTable = - new HashMap>(64); + new HashMap>(64); protected final NettyEventExecuter nettyEventExecuter = new NettyEventExecuter(); protected Pair defaultRequestProcessor; - public NettyRemotingAbstract(final int permitsOneway, final int permitsAsync) { this.semaphoreOneway = new Semaphore(permitsOneway, true); this.semaphoreAsync = new Semaphore(permitsAsync, true); @@ -133,14 +127,14 @@ public abstract class NettyRemotingAbstract { } } catch (Throwable e) { if (!"com.aliyun.openservices.ons.api.impl.authority.exception.AuthenticationException" - .equals(e.getClass().getCanonicalName())) { + .equals(e.getClass().getCanonicalName())) { PLOG.error("process request exception", e); PLOG.error(cmd.toString()); } if (!cmd.isOnewayRPC()) { final RemotingCommand response = RemotingCommand.createResponseCommand(RemotingSysResponseCode.SYSTEM_ERROR, // - RemotingHelper.exceptionSimpleDesc(e)); + RemotingHelper.exceptionSimpleDesc(e)); response.setOpaque(opaque); ctx.writeAndFlush(response); } @@ -150,7 +144,7 @@ public abstract class NettyRemotingAbstract { if (pair.getObject1().rejectRequest()) { final RemotingCommand response = RemotingCommand.createResponseCommand(RemotingSysResponseCode.SYSTEM_BUSY, - "[REJECTREQUEST]system busy, start flow control for a while"); + "[REJECTREQUEST]system busy, start flow control for a while"); response.setOpaque(opaque); ctx.writeAndFlush(response); return; @@ -162,14 +156,14 @@ public abstract class NettyRemotingAbstract { } catch (RejectedExecutionException e) { if ((System.currentTimeMillis() % 10000) == 0) { PLOG.warn(RemotingHelper.parseChannelRemoteAddr(ctx.channel()) // - + ", too many requests and system thread pool busy, RejectedExecutionException " // - + pair.getObject2().toString() // - + " request code: " + cmd.getCode()); + + ", too many requests and system thread pool busy, RejectedExecutionException " // + + pair.getObject2().toString() // + + " request code: " + cmd.getCode()); } if (!cmd.isOnewayRPC()) { final RemotingCommand response = RemotingCommand.createResponseCommand(RemotingSysResponseCode.SYSTEM_BUSY, - "[OVERLOAD]system busy, start flow control for a while"); + "[OVERLOAD]system busy, start flow control for a while"); response.setOpaque(opaque); ctx.writeAndFlush(response); } @@ -177,7 +171,7 @@ public abstract class NettyRemotingAbstract { } else { String error = " request type " + cmd.getCode() + " not supported"; final RemotingCommand response = - RemotingCommand.createResponseCommand(RemotingSysResponseCode.REQUEST_CODE_NOT_SUPPORTED, error); + RemotingCommand.createResponseCommand(RemotingSysResponseCode.REQUEST_CODE_NOT_SUPPORTED, error); response.setOpaque(opaque); ctx.writeAndFlush(response); PLOG.error(RemotingHelper.parseChannelRemoteAddr(ctx.channel()) + error); @@ -267,7 +261,7 @@ public abstract class NettyRemotingAbstract { } public RemotingCommand invokeSyncImpl(final Channel channel, final RemotingCommand request, final long timeoutMillis) - throws InterruptedException, RemotingSendRequestException, RemotingTimeoutException { + throws InterruptedException, RemotingSendRequestException, RemotingTimeoutException { final int opaque = request.getOpaque(); try { @@ -295,7 +289,7 @@ public abstract class NettyRemotingAbstract { if (null == responseCommand) { if (responseFuture.isSendRequestOK()) { throw new RemotingTimeoutException(RemotingHelper.parseSocketAddressAddr(addr), timeoutMillis, - responseFuture.getCause()); + responseFuture.getCause()); } else { throw new RemotingSendRequestException(RemotingHelper.parseSocketAddressAddr(addr), responseFuture.getCause()); } @@ -308,8 +302,8 @@ public abstract class NettyRemotingAbstract { } public void invokeAsyncImpl(final Channel channel, final RemotingCommand request, final long timeoutMillis, - final InvokeCallback invokeCallback) - throws InterruptedException, RemotingTooMuchRequestException, RemotingTimeoutException, RemotingSendRequestException { + final InvokeCallback invokeCallback) + throws InterruptedException, RemotingTooMuchRequestException, RemotingTimeoutException, RemotingSendRequestException { final int opaque = request.getOpaque(); boolean acquired = this.semaphoreAsync.tryAcquire(timeoutMillis, TimeUnit.MILLISECONDS); if (acquired) { @@ -348,18 +342,18 @@ public abstract class NettyRemotingAbstract { } } else { String info = - String.format("invokeAsyncImpl tryAcquire semaphore timeout, %dms, waiting thread nums: %d semaphoreAsyncValue: %d", // - timeoutMillis, // - this.semaphoreAsync.getQueueLength(), // - this.semaphoreAsync.availablePermits()// - ); + String.format("invokeAsyncImpl tryAcquire semaphore timeout, %dms, waiting thread nums: %d semaphoreAsyncValue: %d", // + timeoutMillis, // + this.semaphoreAsync.getQueueLength(), // + this.semaphoreAsync.availablePermits()// + ); PLOG.warn(info); throw new RemotingTooMuchRequestException(info); } } public void invokeOnewayImpl(final Channel channel, final RemotingCommand request, final long timeoutMillis) - throws InterruptedException, RemotingTooMuchRequestException, RemotingTimeoutException, RemotingSendRequestException { + throws InterruptedException, RemotingTooMuchRequestException, RemotingTimeoutException, RemotingSendRequestException { request.markOnewayRPC(); boolean acquired = this.semaphoreOneway.tryAcquire(timeoutMillis, TimeUnit.MILLISECONDS); if (acquired) { @@ -384,10 +378,10 @@ public abstract class NettyRemotingAbstract { throw new RemotingTooMuchRequestException("invokeOnewayImpl invoke too fast"); } else { String info = String.format( - "invokeOnewayImpl tryAcquire semaphore timeout, %dms, waiting thread nums: %d semaphoreAsyncValue: %d", // - timeoutMillis, // - this.semaphoreOneway.getQueueLength(), // - this.semaphoreOneway.availablePermits()// + "invokeOnewayImpl tryAcquire semaphore timeout, %dms, waiting thread nums: %d semaphoreAsyncValue: %d", // + timeoutMillis, // + this.semaphoreOneway.getQueueLength(), // + this.semaphoreOneway.availablePermits()// ); PLOG.warn(info); throw new RemotingTimeoutException(info); @@ -399,7 +393,6 @@ public abstract class NettyRemotingAbstract { private final LinkedBlockingQueue eventQueue = new LinkedBlockingQueue(); private final int maxSize = 10000; - public void putNettyEvent(final NettyEvent event) { if (this.eventQueue.size() <= maxSize) { this.eventQueue.add(event); @@ -408,7 +401,6 @@ public abstract class NettyRemotingAbstract { } } - @Override public void run() { PLOG.info(this.getServiceName() + " service started"); @@ -445,7 +437,6 @@ public abstract class NettyRemotingAbstract { PLOG.info(this.getServiceName() + " service end"); } - @Override public String getServiceName() { return NettyEventExecuter.class.getSimpleName(); diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRemotingClient.java b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRemotingClient.java index 3b7013aa..db7815a8 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRemotingClient.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRemotingClient.java @@ -16,18 +16,6 @@ */ package org.apache.rocketmq.remoting.netty; -import org.apache.rocketmq.remoting.ChannelEventListener; -import org.apache.rocketmq.remoting.InvokeCallback; -import org.apache.rocketmq.remoting.RPCHook; -import org.apache.rocketmq.remoting.RemotingClient; -import org.apache.rocketmq.remoting.common.Pair; -import org.apache.rocketmq.remoting.common.RemotingHelper; -import org.apache.rocketmq.remoting.common.RemotingUtil; -import org.apache.rocketmq.remoting.exception.RemotingConnectException; -import org.apache.rocketmq.remoting.exception.RemotingSendRequestException; -import org.apache.rocketmq.remoting.exception.RemotingTimeoutException; -import org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException; -import org.apache.rocketmq.remoting.protocol.RemotingCommand; import io.netty.bootstrap.Bootstrap; import io.netty.channel.Channel; import io.netty.channel.ChannelDuplexHandler; @@ -45,9 +33,6 @@ import io.netty.handler.timeout.IdleState; import io.netty.handler.timeout.IdleStateEvent; import io.netty.handler.timeout.IdleStateHandler; import io.netty.util.concurrent.DefaultEventExecutorGroup; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.net.SocketAddress; import java.util.Collections; import java.util.List; @@ -64,7 +49,20 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; - +import org.apache.rocketmq.remoting.ChannelEventListener; +import org.apache.rocketmq.remoting.InvokeCallback; +import org.apache.rocketmq.remoting.RPCHook; +import org.apache.rocketmq.remoting.RemotingClient; +import org.apache.rocketmq.remoting.common.Pair; +import org.apache.rocketmq.remoting.common.RemotingHelper; +import org.apache.rocketmq.remoting.common.RemotingUtil; +import org.apache.rocketmq.remoting.exception.RemotingConnectException; +import org.apache.rocketmq.remoting.exception.RemotingSendRequestException; +import org.apache.rocketmq.remoting.exception.RemotingTimeoutException; +import org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException; +import org.apache.rocketmq.remoting.protocol.RemotingCommand; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class NettyRemotingClient extends NettyRemotingAbstract implements RemotingClient { private static final Logger log = LoggerFactory.getLogger(RemotingHelper.ROCKETMQ_REMOTING); @@ -94,7 +92,7 @@ public class NettyRemotingClient extends NettyRemotingAbstract implements Remoti } public NettyRemotingClient(final NettyClientConfig nettyClientConfig, // - final ChannelEventListener channelEventListener) { + final ChannelEventListener channelEventListener) { super(nettyClientConfig.getClientOnewaySemaphoreValue(), nettyClientConfig.getClientAsyncSemaphoreValue()); this.nettyClientConfig = nettyClientConfig; this.channelEventListener = channelEventListener; @@ -107,7 +105,6 @@ public class NettyRemotingClient extends NettyRemotingAbstract implements Remoti this.publicExecutor = Executors.newFixedThreadPool(publicThreadNums, new ThreadFactory() { private AtomicInteger threadIndex = new AtomicInteger(0); - @Override public Thread newThread(Runnable r) { return new Thread(r, "NettyClientPublicExecutor_" + this.threadIndex.incrementAndGet()); @@ -117,7 +114,6 @@ public class NettyRemotingClient extends NettyRemotingAbstract implements Remoti this.eventLoopGroupWorker = new NioEventLoopGroup(1, new ThreadFactory() { private AtomicInteger threadIndex = new AtomicInteger(0); - @Override public Thread newThread(Runnable r) { return new Thread(r, String.format("NettyClientSelector_%d", this.threadIndex.incrementAndGet())); @@ -134,36 +130,35 @@ public class NettyRemotingClient extends NettyRemotingAbstract implements Remoti @Override public void start() { this.defaultEventExecutorGroup = new DefaultEventExecutorGroup(// - nettyClientConfig.getClientWorkerThreads(), // - new ThreadFactory() { + nettyClientConfig.getClientWorkerThreads(), // + new ThreadFactory() { - private AtomicInteger threadIndex = new AtomicInteger(0); + private AtomicInteger threadIndex = new AtomicInteger(0); - - @Override - public Thread newThread(Runnable r) { - return new Thread(r, "NettyClientWorkerThread_" + this.threadIndex.incrementAndGet()); - } - }); + @Override + public Thread newThread(Runnable r) { + return new Thread(r, "NettyClientWorkerThread_" + this.threadIndex.incrementAndGet()); + } + }); Bootstrap handler = this.bootstrap.group(this.eventLoopGroupWorker).channel(NioSocketChannel.class)// - .option(ChannelOption.TCP_NODELAY, true) - .option(ChannelOption.SO_KEEPALIVE, false) - .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, nettyClientConfig.getConnectTimeoutMillis()) - .option(ChannelOption.SO_SNDBUF, nettyClientConfig.getClientSocketSndBufSize()) - .option(ChannelOption.SO_RCVBUF, nettyClientConfig.getClientSocketRcvBufSize()) - .handler(new ChannelInitializer() { - @Override - public void initChannel(SocketChannel ch) throws Exception { - ch.pipeline().addLast( - defaultEventExecutorGroup, - new NettyEncoder(), - new NettyDecoder(), - new IdleStateHandler(0, 0, nettyClientConfig.getClientChannelMaxIdleTimeSeconds()), - new NettyConnetManageHandler(), - new NettyClientHandler()); - } - }); + .option(ChannelOption.TCP_NODELAY, true) + .option(ChannelOption.SO_KEEPALIVE, false) + .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, nettyClientConfig.getConnectTimeoutMillis()) + .option(ChannelOption.SO_SNDBUF, nettyClientConfig.getClientSocketSndBufSize()) + .option(ChannelOption.SO_RCVBUF, nettyClientConfig.getClientSocketRcvBufSize()) + .handler(new ChannelInitializer() { + @Override + public void initChannel(SocketChannel ch) throws Exception { + ch.pipeline().addLast( + defaultEventExecutorGroup, + new NettyEncoder(), + new NettyDecoder(), + new IdleStateHandler(0, 0, nettyClientConfig.getClientChannelMaxIdleTimeSeconds()), + new NettyConnetManageHandler(), + new NettyClientHandler()); + } + }); this.timer.scheduleAtFixedRate(new TimerTask() { @Override @@ -233,7 +228,7 @@ public class NettyRemotingClient extends NettyRemotingAbstract implements Remoti removeItemFromTable = false; } else if (prevCW.getChannel() != channel) { log.info("closeChannel: the channel[{}] has been closed before, and has been created again, nothing to do.", - addrRemote); + addrRemote); removeItemFromTable = false; } @@ -338,7 +333,7 @@ public class NettyRemotingClient extends NettyRemotingAbstract implements Remoti @Override public RemotingCommand invokeSync(String addr, final RemotingCommand request, long timeoutMillis) - throws InterruptedException, RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException { + throws InterruptedException, RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException { final Channel channel = this.getAndCreateChannel(addr); if (channel != null && channel.isActive()) { try { @@ -431,7 +426,6 @@ public class NettyRemotingClient extends NettyRemotingAbstract implements Remoti return cw.getChannel(); } - if (this.lockChannelTables.tryLock(LOCK_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) { try { boolean createNewConnection = false; @@ -476,7 +470,7 @@ public class NettyRemotingClient extends NettyRemotingAbstract implements Remoti } } else { log.warn("createChannel: connect remote host[{}] timeout {}ms, {}", addr, this.nettyClientConfig.getConnectTimeoutMillis(), - channelFuture.toString()); + channelFuture.toString()); } } @@ -485,8 +479,8 @@ public class NettyRemotingClient extends NettyRemotingAbstract implements Remoti @Override public void invokeAsync(String addr, RemotingCommand request, long timeoutMillis, InvokeCallback invokeCallback) - throws InterruptedException, RemotingConnectException, RemotingTooMuchRequestException, RemotingTimeoutException, - RemotingSendRequestException { + throws InterruptedException, RemotingConnectException, RemotingTooMuchRequestException, RemotingTimeoutException, + RemotingSendRequestException { final Channel channel = this.getAndCreateChannel(addr); if (channel != null && channel.isActive()) { try { @@ -507,7 +501,7 @@ public class NettyRemotingClient extends NettyRemotingAbstract implements Remoti @Override public void invokeOneway(String addr, RemotingCommand request, long timeoutMillis) throws InterruptedException, - RemotingConnectException, RemotingTooMuchRequestException, RemotingTimeoutException, RemotingSendRequestException { + RemotingConnectException, RemotingTooMuchRequestException, RemotingTimeoutException, RemotingSendRequestException { final Channel channel = this.getAndCreateChannel(addr); if (channel != null && channel.isActive()) { try { @@ -572,27 +566,22 @@ public class NettyRemotingClient extends NettyRemotingAbstract implements Remoti static class ChannelWrapper { private final ChannelFuture channelFuture; - public ChannelWrapper(ChannelFuture channelFuture) { this.channelFuture = channelFuture; } - public boolean isOK() { return this.channelFuture.channel() != null && this.channelFuture.channel().isActive(); } - public boolean isWriteable() { return this.channelFuture.channel().isWritable(); } - private Channel getChannel() { return this.channelFuture.channel(); } - public ChannelFuture getChannelFuture() { return channelFuture; } @@ -610,7 +599,7 @@ public class NettyRemotingClient extends NettyRemotingAbstract implements Remoti class NettyConnetManageHandler extends ChannelDuplexHandler { @Override public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) - throws Exception { + throws Exception { final String local = localAddress == null ? "UNKNOW" : localAddress.toString(); final String remote = remoteAddress == null ? "UNKNOW" : remoteAddress.toString(); log.info("NETTY CLIENT PIPELINE: CONNECT {} => {}", local, remote); @@ -621,7 +610,6 @@ public class NettyRemotingClient extends NettyRemotingAbstract implements Remoti } } - @Override public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel()); @@ -634,7 +622,6 @@ public class NettyRemotingClient extends NettyRemotingAbstract implements Remoti } } - @Override public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel()); @@ -650,14 +637,14 @@ public class NettyRemotingClient extends NettyRemotingAbstract implements Remoti @Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof IdleStateEvent) { - IdleStateEvent evnet = (IdleStateEvent) evt; + IdleStateEvent evnet = (IdleStateEvent)evt; if (evnet.state().equals(IdleState.ALL_IDLE)) { final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel()); log.warn("NETTY CLIENT PIPELINE: IDLE exception [{}]", remoteAddress); closeChannel(ctx.channel()); if (NettyRemotingClient.this.channelEventListener != null) { NettyRemotingClient.this - .putNettyEvent(new NettyEvent(NettyEventType.IDLE, remoteAddress.toString(), ctx.channel())); + .putNettyEvent(new NettyEvent(NettyEventType.IDLE, remoteAddress.toString(), ctx.channel())); } } } diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRemotingServer.java b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRemotingServer.java index c6e2edae..f109086e 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRemotingServer.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRemotingServer.java @@ -6,27 +6,16 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.remoting.netty; -import org.apache.rocketmq.remoting.ChannelEventListener; -import org.apache.rocketmq.remoting.InvokeCallback; -import org.apache.rocketmq.remoting.RPCHook; -import org.apache.rocketmq.remoting.RemotingServer; -import org.apache.rocketmq.remoting.common.Pair; -import org.apache.rocketmq.remoting.common.RemotingHelper; -import org.apache.rocketmq.remoting.common.RemotingUtil; -import org.apache.rocketmq.remoting.exception.RemotingSendRequestException; -import org.apache.rocketmq.remoting.exception.RemotingTimeoutException; -import org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException; -import org.apache.rocketmq.remoting.protocol.RemotingCommand; import io.netty.bootstrap.ServerBootstrap; import io.netty.buffer.PooledByteBufAllocator; import io.netty.channel.Channel; @@ -45,9 +34,6 @@ import io.netty.handler.timeout.IdleState; import io.netty.handler.timeout.IdleStateEvent; import io.netty.handler.timeout.IdleStateHandler; import io.netty.util.concurrent.DefaultEventExecutorGroup; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.net.InetSocketAddress; import java.util.Timer; import java.util.TimerTask; @@ -55,7 +41,19 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicInteger; - +import org.apache.rocketmq.remoting.ChannelEventListener; +import org.apache.rocketmq.remoting.InvokeCallback; +import org.apache.rocketmq.remoting.RPCHook; +import org.apache.rocketmq.remoting.RemotingServer; +import org.apache.rocketmq.remoting.common.Pair; +import org.apache.rocketmq.remoting.common.RemotingHelper; +import org.apache.rocketmq.remoting.common.RemotingUtil; +import org.apache.rocketmq.remoting.exception.RemotingSendRequestException; +import org.apache.rocketmq.remoting.exception.RemotingTimeoutException; +import org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException; +import org.apache.rocketmq.remoting.protocol.RemotingCommand; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class NettyRemotingServer extends NettyRemotingAbstract implements RemotingServer { private static final Logger log = LoggerFactory.getLogger(RemotingHelper.ROCKETMQ_REMOTING); @@ -72,15 +70,12 @@ public class NettyRemotingServer extends NettyRemotingAbstract implements Remoti private RPCHook rpcHook; - private int port = 0; - public NettyRemotingServer(final NettyServerConfig nettyServerConfig) { this(nettyServerConfig, null); } - public NettyRemotingServer(final NettyServerConfig nettyServerConfig, final ChannelEventListener channelEventListener) { super(nettyServerConfig.getServerOnewaySemaphoreValue(), nettyServerConfig.getServerAsyncSemaphoreValue()); this.serverBootstrap = new ServerBootstrap(); @@ -95,7 +90,6 @@ public class NettyRemotingServer extends NettyRemotingAbstract implements Remoti this.publicExecutor = Executors.newFixedThreadPool(publicThreadNums, new ThreadFactory() { private AtomicInteger threadIndex = new AtomicInteger(0); - @Override public Thread newThread(Runnable r) { return new Thread(r, "NettyServerPublicExecutor_" + this.threadIndex.incrementAndGet()); @@ -105,7 +99,6 @@ public class NettyRemotingServer extends NettyRemotingAbstract implements Remoti this.eventLoopGroupBoss = new NioEventLoopGroup(1, new ThreadFactory() { private AtomicInteger threadIndex = new AtomicInteger(0); - @Override public Thread newThread(Runnable r) { return new Thread(r, String.format("NettyBoss_%d", this.threadIndex.incrementAndGet())); @@ -113,12 +106,11 @@ public class NettyRemotingServer extends NettyRemotingAbstract implements Remoti }); if (RemotingUtil.isLinuxPlatform() // - && nettyServerConfig.isUseEpollNativeSelector()) { + && nettyServerConfig.isUseEpollNativeSelector()) { this.eventLoopGroupSelector = new EpollEventLoopGroup(nettyServerConfig.getServerSelectorThreads(), new ThreadFactory() { private AtomicInteger threadIndex = new AtomicInteger(0); private int threadTotal = nettyServerConfig.getServerSelectorThreads(); - @Override public Thread newThread(Runnable r) { return new Thread(r, String.format("NettyServerEPOLLSelector_%d_%d", threadTotal, this.threadIndex.incrementAndGet())); @@ -129,7 +121,6 @@ public class NettyRemotingServer extends NettyRemotingAbstract implements Remoti private AtomicInteger threadIndex = new AtomicInteger(0); private int threadTotal = nettyServerConfig.getServerSelectorThreads(); - @Override public Thread newThread(Runnable r) { return new Thread(r, String.format("NettyServerNIOSelector_%d_%d", threadTotal, this.threadIndex.incrementAndGet())); @@ -138,51 +129,49 @@ public class NettyRemotingServer extends NettyRemotingAbstract implements Remoti } } - @Override public void start() { this.defaultEventExecutorGroup = new DefaultEventExecutorGroup(// - nettyServerConfig.getServerWorkerThreads(), // - new ThreadFactory() { + nettyServerConfig.getServerWorkerThreads(), // + new ThreadFactory() { - private AtomicInteger threadIndex = new AtomicInteger(0); + private AtomicInteger threadIndex = new AtomicInteger(0); + @Override + public Thread newThread(Runnable r) { + return new Thread(r, "NettyServerCodecThread_" + this.threadIndex.incrementAndGet()); + } + }); + ServerBootstrap childHandler = + this.serverBootstrap.group(this.eventLoopGroupBoss, this.eventLoopGroupSelector).channel(NioServerSocketChannel.class) + .option(ChannelOption.SO_BACKLOG, 1024) + .option(ChannelOption.SO_REUSEADDR, true) + .option(ChannelOption.SO_KEEPALIVE, false) + .childOption(ChannelOption.TCP_NODELAY, true) + .option(ChannelOption.SO_SNDBUF, nettyServerConfig.getServerSocketSndBufSize()) + .option(ChannelOption.SO_RCVBUF, nettyServerConfig.getServerSocketRcvBufSize()) + .localAddress(new InetSocketAddress(this.nettyServerConfig.getListenPort())) + .childHandler(new ChannelInitializer() { @Override - public Thread newThread(Runnable r) { - return new Thread(r, "NettyServerCodecThread_" + this.threadIndex.incrementAndGet()); + public void initChannel(SocketChannel ch) throws Exception { + ch.pipeline().addLast( + defaultEventExecutorGroup, + new NettyEncoder(), + new NettyDecoder(), + new IdleStateHandler(0, 0, nettyServerConfig.getServerChannelMaxIdleTimeSeconds()), + new NettyConnetManageHandler(), + new NettyServerHandler()); } }); - ServerBootstrap childHandler = - this.serverBootstrap.group(this.eventLoopGroupBoss, this.eventLoopGroupSelector).channel(NioServerSocketChannel.class) - .option(ChannelOption.SO_BACKLOG, 1024) - .option(ChannelOption.SO_REUSEADDR, true) - .option(ChannelOption.SO_KEEPALIVE, false) - .childOption(ChannelOption.TCP_NODELAY, true) - .option(ChannelOption.SO_SNDBUF, nettyServerConfig.getServerSocketSndBufSize()) - .option(ChannelOption.SO_RCVBUF, nettyServerConfig.getServerSocketRcvBufSize()) - .localAddress(new InetSocketAddress(this.nettyServerConfig.getListenPort())) - .childHandler(new ChannelInitializer() { - @Override - public void initChannel(SocketChannel ch) throws Exception { - ch.pipeline().addLast( - defaultEventExecutorGroup, - new NettyEncoder(), - new NettyDecoder(), - new IdleStateHandler(0, 0, nettyServerConfig.getServerChannelMaxIdleTimeSeconds()), - new NettyConnetManageHandler(), - new NettyServerHandler()); - } - }); - if (nettyServerConfig.isServerPooledByteBufAllocatorEnable()) { childHandler.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); } try { ChannelFuture sync = this.serverBootstrap.bind().sync(); - InetSocketAddress addr = (InetSocketAddress) sync.channel().localAddress(); + InetSocketAddress addr = (InetSocketAddress)sync.channel().localAddress(); this.port = addr.getPort(); } catch (InterruptedException e1) { throw new RuntimeException("this.serverBootstrap.bind().sync() InterruptedException", e1); @@ -269,19 +258,19 @@ public class NettyRemotingServer extends NettyRemotingAbstract implements Remoti @Override public RemotingCommand invokeSync(final Channel channel, final RemotingCommand request, final long timeoutMillis) - throws InterruptedException, RemotingSendRequestException, RemotingTimeoutException { + throws InterruptedException, RemotingSendRequestException, RemotingTimeoutException { return this.invokeSyncImpl(channel, request, timeoutMillis); } @Override public void invokeAsync(Channel channel, RemotingCommand request, long timeoutMillis, InvokeCallback invokeCallback) - throws InterruptedException, RemotingTooMuchRequestException, RemotingTimeoutException, RemotingSendRequestException { + throws InterruptedException, RemotingTooMuchRequestException, RemotingTimeoutException, RemotingSendRequestException { this.invokeAsyncImpl(channel, request, timeoutMillis, invokeCallback); } @Override public void invokeOneway(Channel channel, RemotingCommand request, long timeoutMillis) throws InterruptedException, - RemotingTooMuchRequestException, RemotingTimeoutException, RemotingSendRequestException { + RemotingTooMuchRequestException, RemotingTimeoutException, RemotingSendRequestException { this.invokeOnewayImpl(channel, request, timeoutMillis); } @@ -316,7 +305,6 @@ public class NettyRemotingServer extends NettyRemotingAbstract implements Remoti super.channelRegistered(ctx); } - @Override public void channelUnregistered(ChannelHandlerContext ctx) throws Exception { final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel()); @@ -324,7 +312,6 @@ public class NettyRemotingServer extends NettyRemotingAbstract implements Remoti super.channelUnregistered(ctx); } - @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel()); @@ -336,7 +323,6 @@ public class NettyRemotingServer extends NettyRemotingAbstract implements Remoti } } - @Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel()); @@ -348,18 +334,17 @@ public class NettyRemotingServer extends NettyRemotingAbstract implements Remoti } } - @Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof IdleStateEvent) { - IdleStateEvent evnet = (IdleStateEvent) evt; + IdleStateEvent evnet = (IdleStateEvent)evt; if (evnet.state().equals(IdleState.ALL_IDLE)) { final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel()); log.warn("NETTY SERVER PIPELINE: IDLE exception [{}]", remoteAddress); RemotingUtil.closeChannel(ctx.channel()); if (NettyRemotingServer.this.channelEventListener != null) { NettyRemotingServer.this - .putNettyEvent(new NettyEvent(NettyEventType.IDLE, remoteAddress.toString(), ctx.channel())); + .putNettyEvent(new NettyEvent(NettyEventType.IDLE, remoteAddress.toString(), ctx.channel())); } } } @@ -367,7 +352,6 @@ public class NettyRemotingServer extends NettyRemotingAbstract implements Remoti ctx.fireUserEventTriggered(evt); } - @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel()); diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRequestProcessor.java b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRequestProcessor.java index b8d20526..c6251e92 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRequestProcessor.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRequestProcessor.java @@ -6,19 +6,18 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.remoting.netty; -import org.apache.rocketmq.remoting.protocol.RemotingCommand; import io.netty.channel.ChannelHandlerContext; - +import org.apache.rocketmq.remoting.protocol.RemotingCommand; /** * Common remoting command processor @@ -27,6 +26,7 @@ import io.netty.channel.ChannelHandlerContext; */ public interface NettyRequestProcessor { RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) - throws Exception; + throws Exception; + boolean rejectRequest(); } diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyServerConfig.java b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyServerConfig.java index 0a53240f..f69fded6 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyServerConfig.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyServerConfig.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.remoting.netty; @@ -43,118 +43,96 @@ public class NettyServerConfig implements Cloneable { */ private boolean useEpollNativeSelector = false; - public int getListenPort() { return listenPort; } - public void setListenPort(int listenPort) { this.listenPort = listenPort; } - public int getServerWorkerThreads() { return serverWorkerThreads; } - public void setServerWorkerThreads(int serverWorkerThreads) { this.serverWorkerThreads = serverWorkerThreads; } - public int getServerSelectorThreads() { return serverSelectorThreads; } - public void setServerSelectorThreads(int serverSelectorThreads) { this.serverSelectorThreads = serverSelectorThreads; } - public int getServerOnewaySemaphoreValue() { return serverOnewaySemaphoreValue; } - public void setServerOnewaySemaphoreValue(int serverOnewaySemaphoreValue) { this.serverOnewaySemaphoreValue = serverOnewaySemaphoreValue; } - public int getServerCallbackExecutorThreads() { return serverCallbackExecutorThreads; } - public void setServerCallbackExecutorThreads(int serverCallbackExecutorThreads) { this.serverCallbackExecutorThreads = serverCallbackExecutorThreads; } - public int getServerAsyncSemaphoreValue() { return serverAsyncSemaphoreValue; } - public void setServerAsyncSemaphoreValue(int serverAsyncSemaphoreValue) { this.serverAsyncSemaphoreValue = serverAsyncSemaphoreValue; } - public int getServerChannelMaxIdleTimeSeconds() { return serverChannelMaxIdleTimeSeconds; } - public void setServerChannelMaxIdleTimeSeconds(int serverChannelMaxIdleTimeSeconds) { this.serverChannelMaxIdleTimeSeconds = serverChannelMaxIdleTimeSeconds; } - public int getServerSocketSndBufSize() { return serverSocketSndBufSize; } - public void setServerSocketSndBufSize(int serverSocketSndBufSize) { this.serverSocketSndBufSize = serverSocketSndBufSize; } - public int getServerSocketRcvBufSize() { return serverSocketRcvBufSize; } - public void setServerSocketRcvBufSize(int serverSocketRcvBufSize) { this.serverSocketRcvBufSize = serverSocketRcvBufSize; } - public boolean isServerPooledByteBufAllocatorEnable() { return serverPooledByteBufAllocatorEnable; } - public void setServerPooledByteBufAllocatorEnable(boolean serverPooledByteBufAllocatorEnable) { this.serverPooledByteBufAllocatorEnable = serverPooledByteBufAllocatorEnable; } - public boolean isUseEpollNativeSelector() { return useEpollNativeSelector; } - public void setUseEpollNativeSelector(boolean useEpollNativeSelector) { this.useEpollNativeSelector = useEpollNativeSelector; } @Override public Object clone() throws CloneNotSupportedException { - return (NettyServerConfig) super.clone(); + return (NettyServerConfig)super.clone(); } } diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettySystemConfig.java b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettySystemConfig.java index ca22df12..9409f92c 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettySystemConfig.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettySystemConfig.java @@ -19,24 +19,24 @@ package org.apache.rocketmq.remoting.netty; public class NettySystemConfig { public static final String COM_ROCKETMQ_REMOTING_NETTY_POOLED_BYTE_BUF_ALLOCATOR_ENABLE = - "com.rocketmq.remoting.nettyPooledByteBufAllocatorEnable"; + "com.rocketmq.remoting.nettyPooledByteBufAllocatorEnable"; public static final String COM_ROCKETMQ_REMOTING_SOCKET_SNDBUF_SIZE = // - "com.rocketmq.remoting.socket.sndbuf.size"; + "com.rocketmq.remoting.socket.sndbuf.size"; public static final String COM_ROCKETMQ_REMOTING_SOCKET_RCVBUF_SIZE = // - "com.rocketmq.remoting.socket.rcvbuf.size"; + "com.rocketmq.remoting.socket.rcvbuf.size"; public static final String COM_ROCKETMQ_REMOTING_CLIENT_ASYNC_SEMAPHORE_VALUE = // - "com.rocketmq.remoting.clientAsyncSemaphoreValue"; + "com.rocketmq.remoting.clientAsyncSemaphoreValue"; public static final String COM_ROCKETMQ_REMOTING_CLIENT_ONEWAY_SEMAPHORE_VALUE = // - "com.rocketmq.remoting.clientOnewaySemaphoreValue"; + "com.rocketmq.remoting.clientOnewaySemaphoreValue"; public static final boolean NETTY_POOLED_BYTE_BUF_ALLOCATOR_ENABLE = // - Boolean - .parseBoolean(System.getProperty(COM_ROCKETMQ_REMOTING_NETTY_POOLED_BYTE_BUF_ALLOCATOR_ENABLE, "false")); - public static int socketSndbufSize = // - Integer.parseInt(System.getProperty(COM_ROCKETMQ_REMOTING_SOCKET_SNDBUF_SIZE, "65535")); - public static int socketRcvbufSize = // - Integer.parseInt(System.getProperty(COM_ROCKETMQ_REMOTING_SOCKET_RCVBUF_SIZE, "65535")); + Boolean + .parseBoolean(System.getProperty(COM_ROCKETMQ_REMOTING_NETTY_POOLED_BYTE_BUF_ALLOCATOR_ENABLE, "false")); public static final int CLIENT_ASYNC_SEMAPHORE_VALUE = // - Integer.parseInt(System.getProperty(COM_ROCKETMQ_REMOTING_CLIENT_ASYNC_SEMAPHORE_VALUE, "65535")); + Integer.parseInt(System.getProperty(COM_ROCKETMQ_REMOTING_CLIENT_ASYNC_SEMAPHORE_VALUE, "65535")); public static final int CLIENT_ONEWAY_SEMAPHORE_VALUE = // - Integer.parseInt(System.getProperty(COM_ROCKETMQ_REMOTING_CLIENT_ONEWAY_SEMAPHORE_VALUE, "65535")); + Integer.parseInt(System.getProperty(COM_ROCKETMQ_REMOTING_CLIENT_ONEWAY_SEMAPHORE_VALUE, "65535")); + public static int socketSndbufSize = // + Integer.parseInt(System.getProperty(COM_ROCKETMQ_REMOTING_SOCKET_SNDBUF_SIZE, "65535")); + public static int socketRcvbufSize = // + Integer.parseInt(System.getProperty(COM_ROCKETMQ_REMOTING_SOCKET_RCVBUF_SIZE, "65535")); } diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/RequestTask.java b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/RequestTask.java index e1317a05..0443b435 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/RequestTask.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/RequestTask.java @@ -17,9 +17,8 @@ package org.apache.rocketmq.remoting.netty; - -import org.apache.rocketmq.remoting.protocol.RemotingCommand; import io.netty.channel.Channel; +import org.apache.rocketmq.remoting.protocol.RemotingCommand; public class RequestTask implements Runnable { private final Runnable runnable; @@ -37,7 +36,7 @@ public class RequestTask implements Runnable { @Override public int hashCode() { int result = runnable != null ? runnable.hashCode() : 0; - result = 31 * result + (int) (getCreateTimestamp() ^ (getCreateTimestamp() >>> 32)); + result = 31 * result + (int)(getCreateTimestamp() ^ (getCreateTimestamp() >>> 32)); result = 31 * result + (channel != null ? channel.hashCode() : 0); result = 31 * result + (request != null ? request.hashCode() : 0); result = 31 * result + (isStopRun() ? 1 : 0); @@ -46,14 +45,19 @@ public class RequestTask implements Runnable { @Override public boolean equals(final Object o) { - if (this == o) return true; - if (!(o instanceof RequestTask)) return false; + if (this == o) + return true; + if (!(o instanceof RequestTask)) + return false; - final RequestTask that = (RequestTask) o; + final RequestTask that = (RequestTask)o; - if (getCreateTimestamp() != that.getCreateTimestamp()) return false; - if (isStopRun() != that.isStopRun()) return false; - if (channel != null ? !channel.equals(that.channel) : that.channel != null) return false; + if (getCreateTimestamp() != that.getCreateTimestamp()) + return false; + if (isStopRun() != that.isStopRun()) + return false; + if (channel != null ? !channel.equals(that.channel) : that.channel != null) + return false; return request != null ? request.getOpaque() == that.request.getOpaque() : that.request == null; } @@ -72,7 +76,8 @@ public class RequestTask implements Runnable { @Override public void run() { - if (!this.stopRun) this.runnable.run(); + if (!this.stopRun) + this.runnable.run(); } public void returnResponse(int code, String remark) { diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/ResponseFuture.java b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/ResponseFuture.java index d564a3a5..fa792b24 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/ResponseFuture.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/ResponseFuture.java @@ -6,24 +6,22 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.remoting.netty; -import org.apache.rocketmq.remoting.InvokeCallback; -import org.apache.rocketmq.remoting.common.SemaphoreReleaseOnlyOnce; -import org.apache.rocketmq.remoting.protocol.RemotingCommand; - import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; - +import org.apache.rocketmq.remoting.InvokeCallback; +import org.apache.rocketmq.remoting.common.SemaphoreReleaseOnlyOnce; +import org.apache.rocketmq.remoting.protocol.RemotingCommand; public class ResponseFuture { private final int opaque; @@ -39,16 +37,14 @@ public class ResponseFuture { private volatile boolean sendRequestOK = true; private volatile Throwable cause; - public ResponseFuture(int opaque, long timeoutMillis, InvokeCallback invokeCallback, - SemaphoreReleaseOnlyOnce once) { + SemaphoreReleaseOnlyOnce once) { this.opaque = opaque; this.timeoutMillis = timeoutMillis; this.invokeCallback = invokeCallback; this.once = once; } - public void executeInvokeCallback() { if (invokeCallback != null) { if (this.executeCallbackOnlyOnce.compareAndSet(false, true)) { @@ -57,87 +53,72 @@ public class ResponseFuture { } } - public void release() { if (this.once != null) { this.once.release(); } } - public boolean isTimeout() { long diff = System.currentTimeMillis() - this.beginTimestamp; return diff > this.timeoutMillis; } - public RemotingCommand waitResponse(final long timeoutMillis) throws InterruptedException { this.countDownLatch.await(timeoutMillis, TimeUnit.MILLISECONDS); return this.responseCommand; } - public void putResponse(final RemotingCommand responseCommand) { this.responseCommand = responseCommand; this.countDownLatch.countDown(); } - public long getBeginTimestamp() { return beginTimestamp; } - public boolean isSendRequestOK() { return sendRequestOK; } - public void setSendRequestOK(boolean sendRequestOK) { this.sendRequestOK = sendRequestOK; } - public long getTimeoutMillis() { return timeoutMillis; } - public InvokeCallback getInvokeCallback() { return invokeCallback; } - public Throwable getCause() { return cause; } - public void setCause(Throwable cause) { this.cause = cause; } - public RemotingCommand getResponseCommand() { return responseCommand; } - public void setResponseCommand(RemotingCommand responseCommand) { this.responseCommand = responseCommand; } - public int getOpaque() { return opaque; } - @Override public String toString() { return "ResponseFuture [responseCommand=" + responseCommand + ", sendRequestOK=" + sendRequestOK - + ", cause=" + cause + ", opaque=" + opaque + ", timeoutMillis=" + timeoutMillis - + ", invokeCallback=" + invokeCallback + ", beginTimestamp=" + beginTimestamp - + ", countDownLatch=" + countDownLatch + "]"; + + ", cause=" + cause + ", opaque=" + opaque + ", timeoutMillis=" + timeoutMillis + + ", invokeCallback=" + invokeCallback + ", beginTimestamp=" + beginTimestamp + + ", countDownLatch=" + countDownLatch + "]"; } } diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/LanguageCode.java b/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/LanguageCode.java index 125fbd35..bdb02c60 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/LanguageCode.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/LanguageCode.java @@ -6,27 +6,27 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.remoting.protocol; public enum LanguageCode { - JAVA((byte) 0), - CPP((byte) 1), - DOTNET((byte) 2), - PYTHON((byte) 3), - DELPHI((byte) 4), - ERLANG((byte) 5), - RUBY((byte) 6), - OTHER((byte) 7), - HTTP((byte) 8); + JAVA((byte)0), + CPP((byte)1), + DOTNET((byte)2), + PYTHON((byte)3), + DELPHI((byte)4), + ERLANG((byte)5), + RUBY((byte)6), + OTHER((byte)7), + HTTP((byte)8); private byte code; diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RemotingCommand.java b/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RemotingCommand.java index 60dd4980..6b253dc6 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RemotingCommand.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RemotingCommand.java @@ -6,24 +6,17 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.remoting.protocol; import com.alibaba.fastjson.annotation.JSONField; -import org.apache.rocketmq.remoting.CommandCustomHeader; -import org.apache.rocketmq.remoting.annotation.CFNotNull; -import org.apache.rocketmq.remoting.common.RemotingHelper; -import org.apache.rocketmq.remoting.exception.RemotingCommandException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.lang.reflect.Modifier; @@ -31,22 +24,26 @@ import java.nio.ByteBuffer; import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; - +import org.apache.rocketmq.remoting.CommandCustomHeader; +import org.apache.rocketmq.remoting.annotation.CFNotNull; +import org.apache.rocketmq.remoting.common.RemotingHelper; +import org.apache.rocketmq.remoting.exception.RemotingCommandException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class RemotingCommand { public static final String SERIALIZE_TYPE_PROPERTY = "rocketmq.serialize.type"; public static final String SERIALIZE_TYPE_ENV = "ROCKETMQ_SERIALIZE_TYPE"; + public static final String REMOTING_VERSION_KEY = "rocketmq.remoting.version"; private static final Logger log = LoggerFactory.getLogger(RemotingHelper.ROCKETMQ_REMOTING); private static final int RPC_TYPE = 0; // 0, REQUEST_COMMAND private static final int RPC_ONEWAY = 1; // 0, RPC - private static final Map, Field[]> CLASS_HASH_MAP = - new HashMap, Field[]>(); + new HashMap, Field[]>(); private static final Map CANONICAL_NAME_CACHE = new HashMap(); + // 1, Oneway // 1, RESPONSE_COMMAND private static final Map NOT_NULL_ANNOTATION_CACHE = new HashMap(); - // 1, Oneway - private static final String STRING_CANONICAL_NAME = String.class.getCanonicalName(); private static final String DOUBLE_CANONICAL_NAME_1 = Double.class.getCanonicalName(); private static final String DOUBLE_CANONICAL_NAME_2 = double.class.getCanonicalName(); @@ -56,7 +53,6 @@ public class RemotingCommand { private static final String LONG_CANONICAL_NAME_2 = long.class.getCanonicalName(); private static final String BOOLEAN_CANONICAL_NAME_1 = Boolean.class.getCanonicalName(); private static final String BOOLEAN_CANONICAL_NAME_2 = boolean.class.getCanonicalName(); - public static final String REMOTING_VERSION_KEY = "rocketmq.remoting.version"; private static volatile int configVersion = -1; private static AtomicInteger requestId = new AtomicInteger(0); @@ -93,7 +89,6 @@ public class RemotingCommand { */ private transient byte[] body; - protected RemotingCommand() { } @@ -148,11 +143,6 @@ public class RemotingCommand { return cmd; } - public void markResponseType() { - int bits = 1 << RPC_TYPE; - this.flag |= bits; - } - public static RemotingCommand createResponseCommand(int code, String remark) { return createResponseCommand(code, remark, null); } @@ -205,7 +195,7 @@ public class RemotingCommand { } public static SerializeType getProtocolType(int source) { - return SerializeType.valueOf((byte) ((source >> 24) & 0xFF)); + return SerializeType.valueOf((byte)((source >> 24) & 0xFF)); } public static int createNewRequestId() { @@ -229,6 +219,21 @@ public class RemotingCommand { return true; } + public static byte[] markProtocolType(int source, SerializeType type) { + byte[] result = new byte[4]; + + result[0] = type.getCode(); + result[1] = (byte)((source >> 16) & 0xFF); + result[2] = (byte)((source >> 8) & 0xFF); + result[3] = (byte)(source & 0xFF); + return result; + } + + public void markResponseType() { + int bits = 1 << RPC_TYPE; + this.flag |= bits; + } + public CommandCustomHeader readCustomHeader() { return customHeader; } @@ -376,16 +381,6 @@ public class RemotingCommand { } } - public static byte[] markProtocolType(int source, SerializeType type) { - byte[] result = new byte[4]; - - result[0] = type.getCode(); - result[1] = (byte) ((source >> 16) & 0xFF); - result[2] = (byte) ((source >> 8) & 0xFF); - result[3] = (byte) (source & 0xFF); - return result; - } - public void makeCustomHeaderToNet() { if (this.customHeader != null) { Field[] fields = getClazzFields(customHeader.getClass()); @@ -550,16 +545,14 @@ public class RemotingCommand { @Override public String toString() { return "RemotingCommand [code=" + code + ", language=" + language + ", version=" + version + ", opaque=" + opaque + ", flag(B)=" - + Integer.toBinaryString(flag) + ", remark=" + remark + ", extFields=" + extFields + ", serializeTypeCurrentRPC=" - + serializeTypeCurrentRPC + "]"; + + Integer.toBinaryString(flag) + ", remark=" + remark + ", extFields=" + extFields + ", serializeTypeCurrentRPC=" + + serializeTypeCurrentRPC + "]"; } - public SerializeType getSerializeTypeCurrentRPC() { return serializeTypeCurrentRPC; } - public void setSerializeTypeCurrentRPC(SerializeType serializeTypeCurrentRPC) { this.serializeTypeCurrentRPC = serializeTypeCurrentRPC; } diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RemotingCommandType.java b/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RemotingCommandType.java index 3adf06f7..de4a5c91 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RemotingCommandType.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RemotingCommandType.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.remoting.protocol; diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RemotingSerializable.java b/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RemotingSerializable.java index e543ce12..8a5d76ee 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RemotingSerializable.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RemotingSerializable.java @@ -6,21 +6,19 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.remoting.protocol; import com.alibaba.fastjson.JSON; - import java.nio.charset.Charset; - /** * */ diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RemotingSysResponseCode.java b/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RemotingSysResponseCode.java index e92bc498..f2836fe9 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RemotingSysResponseCode.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RemotingSysResponseCode.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.remoting.protocol; diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RocketMQSerializable.java b/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RocketMQSerializable.java index 6b0d8258..64b37db8 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RocketMQSerializable.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RocketMQSerializable.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.remoting.protocol; @@ -22,7 +22,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; - /** * */ @@ -52,11 +51,11 @@ public class RocketMQSerializable { // ################### content ByteBuffer headerBuffer = ByteBuffer.allocate(totalLen); // int code(~32767) - headerBuffer.putShort((short) cmd.getCode()); + headerBuffer.putShort((short)cmd.getCode()); // LanguageCode language headerBuffer.put(cmd.getLanguage().getCode()); // int version(~32767) - headerBuffer.putShort((short) cmd.getVersion()); + headerBuffer.putShort((short)cmd.getVersion()); // int opaque headerBuffer.putInt(cmd.getOpaque()); // int flag @@ -92,10 +91,10 @@ public class RocketMQSerializable { Map.Entry entry = it.next(); if (entry.getKey() != null && entry.getValue() != null) { kvLength = - // keySize + Key - 2 + entry.getKey().getBytes(RemotingSerializable.CHARSET_UTF8).length - // valSize + val - + 4 + entry.getValue().getBytes(RemotingSerializable.CHARSET_UTF8).length; + // keySize + Key + 2 + entry.getKey().getBytes(RemotingSerializable.CHARSET_UTF8).length + // valSize + val + + 4 + entry.getValue().getBytes(RemotingSerializable.CHARSET_UTF8).length; totalLength += kvLength; } } @@ -110,7 +109,7 @@ public class RocketMQSerializable { key = entry.getKey().getBytes(RemotingSerializable.CHARSET_UTF8); val = entry.getValue().getBytes(RemotingSerializable.CHARSET_UTF8); - content.putShort((short) key.length); + content.putShort((short)key.length); content.put(key); content.putInt(val.length); @@ -124,18 +123,18 @@ public class RocketMQSerializable { private static int calTotalLen(int remark, int ext) { // int code(~32767) int length = 2 - // LanguageCode language - + 1 - // int version(~32767) - + 2 - // int opaque - + 4 - // int flag - + 4 - // String remark - + 4 + remark - // HashMap extFields - + 4 + ext; + // LanguageCode language + + 1 + // int version(~32767) + + 2 + // int opaque + + 4 + // int flag + + 4 + // String remark + + 4 + remark + // HashMap extFields + + 4 + ext; return length; } @@ -192,12 +191,11 @@ public class RocketMQSerializable { byteBuffer.get(valContent); map.put(new String(keyContent, RemotingSerializable.CHARSET_UTF8), new String(valContent, - RemotingSerializable.CHARSET_UTF8)); + RemotingSerializable.CHARSET_UTF8)); } return map; } - public static boolean isBlank(String str) { int strLen; if (str == null || (strLen = str.length()) == 0) { diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/SerializeType.java b/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/SerializeType.java index cebd48fe..6bfd42c2 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/SerializeType.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/SerializeType.java @@ -6,20 +6,20 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.remoting.protocol; public enum SerializeType { - JSON((byte) 0), - ROCKETMQ((byte) 1); + JSON((byte)0), + ROCKETMQ((byte)1); private byte code; diff --git a/remoting/src/test/java/org/apache/rocketmq/remoting/MixTest.java b/remoting/src/test/java/org/apache/rocketmq/remoting/MixTest.java index 3b73e467..984ecd1b 100644 --- a/remoting/src/test/java/org/apache/rocketmq/remoting/MixTest.java +++ b/remoting/src/test/java/org/apache/rocketmq/remoting/MixTest.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: MixTest.java 1831 2013-05-16 01:39:51Z vintagewang@apache.org $ */ /** @@ -22,7 +24,6 @@ package org.apache.rocketmq.remoting; import org.junit.Test; - public class MixTest { @Test public void test_extFieldsValue() { diff --git a/remoting/src/test/java/org/apache/rocketmq/remoting/NettyRPCTest.java b/remoting/src/test/java/org/apache/rocketmq/remoting/NettyRPCTest.java index 15330bc5..15a9aa31 100644 --- a/remoting/src/test/java/org/apache/rocketmq/remoting/NettyRPCTest.java +++ b/remoting/src/test/java/org/apache/rocketmq/remoting/NettyRPCTest.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: NettyRPCTest.java 1831 2013-05-16 01:39:51Z vintagewang@apache.org $ */ /** @@ -20,47 +22,32 @@ */ package org.apache.rocketmq.remoting; +import io.netty.channel.ChannelHandlerContext; +import java.util.concurrent.Executors; import org.apache.rocketmq.remoting.annotation.CFNullable; -import org.apache.rocketmq.remoting.exception.*; -import org.apache.rocketmq.remoting.netty.*; +import org.apache.rocketmq.remoting.exception.RemotingCommandException; +import org.apache.rocketmq.remoting.exception.RemotingConnectException; +import org.apache.rocketmq.remoting.exception.RemotingSendRequestException; +import org.apache.rocketmq.remoting.exception.RemotingTimeoutException; +import org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException; +import org.apache.rocketmq.remoting.netty.NettyClientConfig; +import org.apache.rocketmq.remoting.netty.NettyRemotingClient; +import org.apache.rocketmq.remoting.netty.NettyRemotingServer; +import org.apache.rocketmq.remoting.netty.NettyRequestProcessor; +import org.apache.rocketmq.remoting.netty.NettyServerConfig; +import org.apache.rocketmq.remoting.netty.ResponseFuture; import org.apache.rocketmq.remoting.protocol.RemotingCommand; -import io.netty.channel.ChannelHandlerContext; import org.junit.Test; -import java.util.concurrent.Executors; - import static org.junit.Assert.assertTrue; - public class NettyRPCTest { - @Test - public void test_RPC_Sync() throws InterruptedException, RemotingConnectException, - RemotingSendRequestException, RemotingTimeoutException { - RemotingServer server = createRemotingServer(); - RemotingClient client = createRemotingClient(); - - for (int i = 0; i < 100; i++) { - TestRequestHeader requestHeader = new TestRequestHeader(); - requestHeader.setCount(i); - requestHeader.setMessageTitle("HelloMessageTitle"); - RemotingCommand request = RemotingCommand.createRequestCommand(0, requestHeader); - RemotingCommand response = client.invokeSync("localhost:8888", request, 1000 * 3000); - System.out.println("invoke result = " + response); - assertTrue(response != null); - } - - client.shutdown(); - server.shutdown(); - System.out.println("-----------------------------------------------------------------"); - } - public static RemotingServer createRemotingServer() throws InterruptedException { NettyServerConfig config = new NettyServerConfig(); RemotingServer remotingServer = new NettyRemotingServer(config); remotingServer.registerProcessor(0, new NettyRequestProcessor() { private int i = 0; - @Override public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) { System.out.println("processRequest=" + request + " " + (i++)); @@ -84,9 +71,30 @@ public class NettyRPCTest { return client; } + @Test + public void test_RPC_Sync() throws InterruptedException, RemotingConnectException, + RemotingSendRequestException, RemotingTimeoutException { + RemotingServer server = createRemotingServer(); + RemotingClient client = createRemotingClient(); + + for (int i = 0; i < 100; i++) { + TestRequestHeader requestHeader = new TestRequestHeader(); + requestHeader.setCount(i); + requestHeader.setMessageTitle("HelloMessageTitle"); + RemotingCommand request = RemotingCommand.createRequestCommand(0, requestHeader); + RemotingCommand response = client.invokeSync("localhost:8888", request, 1000 * 3000); + System.out.println("invoke result = " + response); + assertTrue(response != null); + } + + client.shutdown(); + server.shutdown(); + System.out.println("-----------------------------------------------------------------"); + } + @Test public void test_RPC_Oneway() throws InterruptedException, RemotingConnectException, - RemotingTimeoutException, RemotingTooMuchRequestException, RemotingSendRequestException { + RemotingTimeoutException, RemotingTooMuchRequestException, RemotingSendRequestException { RemotingServer server = createRemotingServer(); RemotingClient client = createRemotingClient(); @@ -101,10 +109,9 @@ public class NettyRPCTest { System.out.println("-----------------------------------------------------------------"); } - @Test public void test_RPC_Async() throws InterruptedException, RemotingConnectException, - RemotingTimeoutException, RemotingTooMuchRequestException, RemotingSendRequestException { + RemotingTimeoutException, RemotingTooMuchRequestException, RemotingSendRequestException { RemotingServer server = createRemotingServer(); RemotingClient client = createRemotingClient(); @@ -126,10 +133,9 @@ public class NettyRPCTest { System.out.println("-----------------------------------------------------------------"); } - @Test public void test_server_call_client() throws InterruptedException, RemotingConnectException, - RemotingSendRequestException, RemotingTimeoutException { + RemotingSendRequestException, RemotingTimeoutException { final RemotingServer server = createRemotingServer(); final RemotingClient client = createRemotingClient(); @@ -183,7 +189,6 @@ public class NettyRPCTest { } - class TestRequestHeader implements CommandCustomHeader { @CFNullable private Integer count; @@ -191,33 +196,27 @@ class TestRequestHeader implements CommandCustomHeader { @CFNullable private String messageTitle; - @Override public void checkFields() throws RemotingCommandException { } - public Integer getCount() { return count; } - public void setCount(Integer count) { this.count = count; } - public String getMessageTitle() { return messageTitle; } - public void setMessageTitle(String messageTitle) { this.messageTitle = messageTitle; } } - class TestResponseHeader implements CommandCustomHeader { @CFNullable private Integer count; @@ -246,5 +245,4 @@ class TestResponseHeader implements CommandCustomHeader { this.messageTitle = messageTitle; } - } diff --git a/remoting/src/test/java/org/apache/rocketmq/subclass/TestSubClassAuto.java b/remoting/src/test/java/org/apache/rocketmq/subclass/TestSubClassAuto.java index 3c276975..16aa9b19 100644 --- a/remoting/src/test/java/org/apache/rocketmq/subclass/TestSubClassAuto.java +++ b/remoting/src/test/java/org/apache/rocketmq/subclass/TestSubClassAuto.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ /** @@ -22,7 +22,6 @@ package org.apache.rocketmq.subclass; import org.junit.Test; - public class TestSubClassAuto { @Test public void test_sub() { diff --git a/srvutil/pom.xml b/srvutil/pom.xml index 0873ee8d..af884cb5 100644 --- a/srvutil/pom.xml +++ b/srvutil/pom.xml @@ -15,7 +15,7 @@ limitations under the License. --> - org.apache.rocketmq diff --git a/srvutil/src/main/java/org/apache/rocketmq/srvutil/ServerUtil.java b/srvutil/src/main/java/org/apache/rocketmq/srvutil/ServerUtil.java index 0a25dd1e..1774150b 100644 --- a/srvutil/src/main/java/org/apache/rocketmq/srvutil/ServerUtil.java +++ b/srvutil/src/main/java/org/apache/rocketmq/srvutil/ServerUtil.java @@ -6,19 +6,23 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.srvutil; -import org.apache.commons.cli.*; - import java.util.Properties; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.CommandLineParser; +import org.apache.commons.cli.HelpFormatter; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; public class ServerUtil { @@ -28,17 +32,16 @@ public class ServerUtil { options.addOption(opt); opt = - new Option("n", "namesrvAddr", true, - "Name server address list, eg: 192.168.0.1:9876;192.168.0.2:9876"); + new Option("n", "namesrvAddr", true, + "Name server address list, eg: 192.168.0.1:9876;192.168.0.2:9876"); opt.setRequired(false); options.addOption(opt); return options; } - public static CommandLine parseCmdLine(final String appName, String[] args, Options options, - CommandLineParser parser) { + CommandLineParser parser) { HelpFormatter hf = new HelpFormatter(); hf.setWidth(110); CommandLine commandLine = null; @@ -55,14 +58,12 @@ public class ServerUtil { return commandLine; } - public static void printCommandLineHelp(final String appName, final Options options) { HelpFormatter hf = new HelpFormatter(); hf.setWidth(110); hf.printHelp(appName, options, true); } - public static Properties commandLine2Properties(final CommandLine commandLine) { Properties properties = new Properties(); Option[] opts = commandLine.getOptions(); diff --git a/store/pom.xml b/store/pom.xml index 10b13b99..29be589f 100644 --- a/store/pom.xml +++ b/store/pom.xml @@ -15,7 +15,7 @@ limitations under the License. --> - org.apache.rocketmq diff --git a/store/src/main/java/org/apache/rocketmq/store/AllocateMappedFileService.java b/store/src/main/java/org/apache/rocketmq/store/AllocateMappedFileService.java index 94362ea4..27b957f1 100644 --- a/store/src/main/java/org/apache/rocketmq/store/AllocateMappedFileService.java +++ b/store/src/main/java/org/apache/rocketmq/store/AllocateMappedFileService.java @@ -16,13 +16,6 @@ */ package org.apache.rocketmq.store; -import org.apache.rocketmq.common.ServiceThread; -import org.apache.rocketmq.common.UtilAll; -import org.apache.rocketmq.common.constant.LoggerName; -import org.apache.rocketmq.store.config.BrokerRole; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.io.File; import java.io.IOException; import java.util.ServiceLoader; @@ -30,33 +23,35 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CountDownLatch; import java.util.concurrent.PriorityBlockingQueue; import java.util.concurrent.TimeUnit; - +import org.apache.rocketmq.common.ServiceThread; +import org.apache.rocketmq.common.UtilAll; +import org.apache.rocketmq.common.constant.LoggerName; +import org.apache.rocketmq.store.config.BrokerRole; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Create MappedFile in advance - * */ public class AllocateMappedFileService extends ServiceThread { private static final Logger log = LoggerFactory.getLogger(LoggerName.STORE_LOGGER_NAME); private static int waitTimeOut = 1000 * 5; private ConcurrentHashMap requestTable = - new ConcurrentHashMap(); + new ConcurrentHashMap(); private PriorityBlockingQueue requestQueue = - new PriorityBlockingQueue(); + new PriorityBlockingQueue(); private volatile boolean hasException = false; private DefaultMessageStore messageStore; - public AllocateMappedFileService(DefaultMessageStore messageStore) { this.messageStore = messageStore; } - public MappedFile putRequestAndReturnMappedFile(String nextFilePath, String nextNextFilePath, int fileSize) { int canSubmitRequests = 2; if (this.messageStore.getMessageStoreConfig().isTransientStorePoolEnable()) { if (this.messageStore.getMessageStoreConfig().isFastFailIfNoBufferInStorePool() - && BrokerRole.SLAVE != this.messageStore.getMessageStoreConfig().getBrokerRole()) { //if broker is slave, don't fast fail even no buffer in pool + && BrokerRole.SLAVE != this.messageStore.getMessageStoreConfig().getBrokerRole()) { //if broker is slave, don't fast fail even no buffer in pool canSubmitRequests = this.messageStore.getTransientStorePool().remainBufferNumbs() - this.requestQueue.size(); } } @@ -67,7 +62,7 @@ public class AllocateMappedFileService extends ServiceThread { if (nextPutOK) { if (canSubmitRequests <= 0) { log.warn("[NOTIFYME]TransientStorePool is not enough, so create mapped file error, " + - "RequestQueueSize : {}, StorePoolSize: {}", this.requestQueue.size(), this.messageStore.getTransientStorePool().remainBufferNumbs()); + "RequestQueueSize : {}, StorePoolSize: {}", this.requestQueue.size(), this.messageStore.getTransientStorePool().remainBufferNumbs()); this.requestTable.remove(nextFilePath); return null; } @@ -83,7 +78,7 @@ public class AllocateMappedFileService extends ServiceThread { if (nextNextPutOK) { if (canSubmitRequests <= 0) { log.warn("[NOTIFYME]TransientStorePool is not enough, so skip preallocate mapped file, " + - "RequestQueueSize : {}, StorePoolSize: {}", this.requestQueue.size(), this.messageStore.getTransientStorePool().remainBufferNumbs()); + "RequestQueueSize : {}, StorePoolSize: {}", this.requestQueue.size(), this.messageStore.getTransientStorePool().remainBufferNumbs()); this.requestTable.remove(nextNextFilePath); } else { boolean offerOK = this.requestQueue.offer(nextNextReq); @@ -119,13 +114,11 @@ public class AllocateMappedFileService extends ServiceThread { return null; } - @Override public String getServiceName() { return AllocateMappedFileService.class.getSimpleName(); } - public void shutdown() { this.stopped = true; this.thread.interrupt(); @@ -144,7 +137,6 @@ public class AllocateMappedFileService extends ServiceThread { } } - public void run() { log.info(this.getServiceName() + " service started"); @@ -154,7 +146,6 @@ public class AllocateMappedFileService extends ServiceThread { log.info(this.getServiceName() + " service end"); } - /** * Only interrupted by the external thread, will return false */ @@ -166,12 +157,12 @@ public class AllocateMappedFileService extends ServiceThread { AllocateRequest expectedRequest = this.requestTable.get(req.getFilePath()); if (null == expectedRequest) { log.warn("this mmap request expired, maybe cause timeout " + req.getFilePath() + " " - + req.getFileSize()); + + req.getFileSize()); return true; } if (expectedRequest != req) { log.warn("never expected here, maybe cause timeout " + req.getFilePath() + " " - + req.getFileSize() + ", req:" + req + ", expectedRequest:" + expectedRequest); + + req.getFileSize() + ", req:" + req + ", expectedRequest:" + expectedRequest); return true; } @@ -195,16 +186,16 @@ public class AllocateMappedFileService extends ServiceThread { if (eclipseTime > 10) { int queueSize = this.requestQueue.size(); log.warn("create mappedFile spent time(ms) " + eclipseTime + " queue size " + queueSize - + " " + req.getFilePath() + " " + req.getFileSize()); + + " " + req.getFilePath() + " " + req.getFileSize()); } // pre write mappedFile if (mappedFile.getFileSize() >= this.messageStore.getMessageStoreConfig() - .getMapedFileSizeCommitLog() - && - this.messageStore.getMessageStoreConfig().isWarmMapedFileEnable()) { + .getMapedFileSizeCommitLog() + && + this.messageStore.getMessageStoreConfig().isWarmMapedFileEnable()) { mappedFile.warmMappedFile(this.messageStore.getMessageStoreConfig().getFlushDiskType(), - this.messageStore.getMessageStoreConfig().getFlushLeastPagesWhenWarmMapedFile()); + this.messageStore.getMessageStoreConfig().getFlushLeastPagesWhenWarmMapedFile()); } req.setMappedFile(mappedFile); @@ -239,53 +230,43 @@ public class AllocateMappedFileService extends ServiceThread { private CountDownLatch countDownLatch = new CountDownLatch(1); private volatile MappedFile mappedFile = null; - public AllocateRequest(String filePath, int fileSize) { this.filePath = filePath; this.fileSize = fileSize; } - public String getFilePath() { return filePath; } - public void setFilePath(String filePath) { this.filePath = filePath; } - public int getFileSize() { return fileSize; } - public void setFileSize(int fileSize) { this.fileSize = fileSize; } - public CountDownLatch getCountDownLatch() { return countDownLatch; } - public void setCountDownLatch(CountDownLatch countDownLatch) { this.countDownLatch = countDownLatch; } - public MappedFile getMappedFile() { return mappedFile; } - public void setMappedFile(MappedFile mappedFile) { this.mappedFile = mappedFile; } - public int compareTo(AllocateRequest other) { if (this.fileSize < other.fileSize) return 1; @@ -308,7 +289,6 @@ public class AllocateMappedFileService extends ServiceThread { // other.fileSize ? -1 : 0; } - @Override public int hashCode() { final int prime = 31; @@ -318,7 +298,6 @@ public class AllocateMappedFileService extends ServiceThread { return result; } - @Override public boolean equals(Object obj) { if (this == obj) @@ -327,7 +306,7 @@ public class AllocateMappedFileService extends ServiceThread { return false; if (getClass() != obj.getClass()) return false; - AllocateRequest other = (AllocateRequest) obj; + AllocateRequest other = (AllocateRequest)obj; if (filePath == null) { if (other.filePath != null) return false; diff --git a/store/src/main/java/org/apache/rocketmq/store/AppendMessageCallback.java b/store/src/main/java/org/apache/rocketmq/store/AppendMessageCallback.java index 0e8678c0..6d158d33 100644 --- a/store/src/main/java/org/apache/rocketmq/store/AppendMessageCallback.java +++ b/store/src/main/java/org/apache/rocketmq/store/AppendMessageCallback.java @@ -6,19 +6,18 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.store; import java.nio.ByteBuffer; - /** * Write messages callback interface * @@ -36,5 +35,5 @@ public interface AppendMessageCallback { * @return How many bytes to write */ AppendMessageResult doAppend(final long fileFromOffset, final ByteBuffer byteBuffer, - final int maxBlank, final MessageExtBrokerInner msg); + final int maxBlank, final MessageExtBrokerInner msg); } diff --git a/store/src/main/java/org/apache/rocketmq/store/AppendMessageResult.java b/store/src/main/java/org/apache/rocketmq/store/AppendMessageResult.java index 85412083..965097f1 100644 --- a/store/src/main/java/org/apache/rocketmq/store/AppendMessageResult.java +++ b/store/src/main/java/org/apache/rocketmq/store/AppendMessageResult.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.store; @@ -40,7 +40,7 @@ public class AppendMessageResult { } public AppendMessageResult(AppendMessageStatus status, long wroteOffset, int wroteBytes, String msgId, - long storeTimestamp, long logicsOffset, long pagecacheRT) { + long storeTimestamp, long logicsOffset, long pagecacheRT) { this.status = status; this.wroteOffset = wroteOffset; this.wroteBytes = wroteBytes; @@ -62,62 +62,50 @@ public class AppendMessageResult { return this.status == AppendMessageStatus.PUT_OK; } - public AppendMessageStatus getStatus() { return status; } - public void setStatus(AppendMessageStatus status) { this.status = status; } - public long getWroteOffset() { return wroteOffset; } - public void setWroteOffset(long wroteOffset) { this.wroteOffset = wroteOffset; } - public int getWroteBytes() { return wroteBytes; } - public void setWroteBytes(int wroteBytes) { this.wroteBytes = wroteBytes; } - public String getMsgId() { return msgId; } - public void setMsgId(String msgId) { this.msgId = msgId; } - public long getStoreTimestamp() { return storeTimestamp; } - public void setStoreTimestamp(long storeTimestamp) { this.storeTimestamp = storeTimestamp; } - public long getLogicsOffset() { return logicsOffset; } - public void setLogicsOffset(long logicsOffset) { this.logicsOffset = logicsOffset; } @@ -125,13 +113,13 @@ public class AppendMessageResult { @Override public String toString() { return "AppendMessageResult{" + - "status=" + status + - ", wroteOffset=" + wroteOffset + - ", wroteBytes=" + wroteBytes + - ", msgId='" + msgId + '\'' + - ", storeTimestamp=" + storeTimestamp + - ", logicsOffset=" + logicsOffset + - ", pagecacheRT=" + pagecacheRT + - '}'; + "status=" + status + + ", wroteOffset=" + wroteOffset + + ", wroteBytes=" + wroteBytes + + ", msgId='" + msgId + '\'' + + ", storeTimestamp=" + storeTimestamp + + ", logicsOffset=" + logicsOffset + + ", pagecacheRT=" + pagecacheRT + + '}'; } } diff --git a/store/src/main/java/org/apache/rocketmq/store/AppendMessageStatus.java b/store/src/main/java/org/apache/rocketmq/store/AppendMessageStatus.java index 34f70b1f..39cf9fa6 100644 --- a/store/src/main/java/org/apache/rocketmq/store/AppendMessageStatus.java +++ b/store/src/main/java/org/apache/rocketmq/store/AppendMessageStatus.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.store; diff --git a/store/src/main/java/org/apache/rocketmq/store/CommitLog.java b/store/src/main/java/org/apache/rocketmq/store/CommitLog.java index ddd6be35..17625f49 100644 --- a/store/src/main/java/org/apache/rocketmq/store/CommitLog.java +++ b/store/src/main/java/org/apache/rocketmq/store/CommitLog.java @@ -16,6 +16,15 @@ */ package org.apache.rocketmq.store; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.locks.ReentrantLock; import org.apache.rocketmq.common.ServiceThread; import org.apache.rocketmq.common.UtilAll; import org.apache.rocketmq.common.constant.LoggerName; @@ -31,20 +40,8 @@ import org.apache.rocketmq.store.schedule.ScheduleMessageService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.locks.ReentrantLock; - - /** * Store all metadata downtime for recovery, data protection reliability - * */ public class CommitLog { // Message's MAGIC CODE daa320a7 @@ -72,7 +69,7 @@ public class CommitLog { public CommitLog(final DefaultMessageStore defaultMessageStore) { this.mappedFileQueue = new MappedFileQueue(defaultMessageStore.getMessageStoreConfig().getStorePathCommitLog(), - defaultMessageStore.getMessageStoreConfig().getMapedFileSizeCommitLog(), defaultMessageStore.getAllocateMappedFileService()); + defaultMessageStore.getMessageStoreConfig().getMapedFileSizeCommitLog(), defaultMessageStore.getAllocateMappedFileService()); this.defaultMessageStore = defaultMessageStore; if (FlushDiskType.SYNC_FLUSH == defaultMessageStore.getMessageStoreConfig().getFlushDiskType()) { @@ -126,17 +123,15 @@ public class CommitLog { return this.mappedFileQueue.remainHowManyDataToFlush(); } - public int deleteExpiredFile(// - final long expiredTime, // - final int deleteFilesInterval, // - final long intervalForcibly, // - final boolean cleanImmediately// + final long expiredTime, // + final int deleteFilesInterval, // + final long intervalForcibly, // + final boolean cleanImmediately// ) { return this.mappedFileQueue.deleteExpiredFileByTime(expiredTime, deleteFilesInterval, intervalForcibly, cleanImmediately); } - /** * Read CommitLog data, use data replication */ @@ -144,12 +139,11 @@ public class CommitLog { return this.getData(offset, offset == 0); } - public SelectMappedBufferResult getData(final long offset, final boolean returnFirstOnNotFound) { int mappedFileSize = this.defaultMessageStore.getMessageStoreConfig().getMapedFileSizeCommitLog(); MappedFile mappedFile = this.mappedFileQueue.findMappedFileByOffset(offset, returnFirstOnNotFound); if (mappedFile != null) { - int pos = (int) (offset % mappedFileSize); + int pos = (int)(offset % mappedFileSize); SelectMappedBufferResult result = mappedFile.selectMappedBuffer(pos); return result; } @@ -157,7 +151,6 @@ public class CommitLog { return null; } - /** * When the normal exit, data recovery, all memory data have been flush */ @@ -227,8 +220,7 @@ public class CommitLog { /** * check the message and returns the message size * - * @return 0 Come the end of the file // >0 Normal messages // -1 Message - * checksum failure + * @return 0 Come the end of the file // >0 Normal messages // -1 Message checksum failure */ public DispatchRequest checkMessageAndReturnSize(java.nio.ByteBuffer byteBuffer, final boolean checkCRC, final boolean readBody) { try { @@ -340,7 +332,7 @@ public class CommitLog { if (delayLevel > 0) { tagsCode = this.defaultMessageStore.getScheduleMessageService().computeDeliverTimestamp(delayLevel, - storeTimestamp); + storeTimestamp); } } } @@ -354,23 +346,23 @@ public class CommitLog { doNothingForDeadCode(byteBuffer1); doNothingForDeadCode(byteBuffer2); log.error( - "[BUG]read total count not equals msg total size. totalSize={}, readTotalCount={}, bodyLen={}, topicLen={}, propertiesLength={}", - totalSize, readLength, bodyLen, topicLen, propertiesLength); + "[BUG]read total count not equals msg total size. totalSize={}, readTotalCount={}, bodyLen={}, topicLen={}, propertiesLength={}", + totalSize, readLength, bodyLen, topicLen, propertiesLength); return new DispatchRequest(totalSize, false/* success */); } return new DispatchRequest(// - topic, // 1 - queueId, // 2 - physicOffset, // 3 - totalSize, // 4 - tagsCode, // 5 - storeTimestamp, // 6 - queueOffset, // 7 - keys, // 8 - uniqKey, //9 - sysFlag, // 9 - preparedTransactionOffset// 10 + topic, // 1 + queueId, // 2 + physicOffset, // 3 + totalSize, // 4 + tagsCode, // 5 + storeTimestamp, // 6 + queueOffset, // 7 + keys, // 8 + uniqKey, //9 + sysFlag, // 9 + preparedTransactionOffset// 10 ); } catch (Exception e) { } @@ -380,24 +372,24 @@ public class CommitLog { private int calMsgLength(int bodyLength, int topicLength, int propertiesLength) { final int msgLen = 4 // 1 TOTALSIZE - + 4 // 2 MAGICCODE - + 4 // 3 BODYCRC - + 4 // 4 QUEUEID - + 4 // 5 FLAG - + 8 // 6 QUEUEOFFSET - + 8 // 7 PHYSICALOFFSET - + 4 // 8 SYSFLAG - + 8 // 9 BORNTIMESTAMP - + 8 // 10 BORNHOST - + 8 // 11 STORETIMESTAMP - + 8 // 12 STOREHOSTADDRESS - + 4 // 13 RECONSUMETIMES - + 8 // 14 Prepared Transaction Offset - + 4 + (bodyLength > 0 ? bodyLength : 0) // 14 BODY - + 1 + topicLength // 15 TOPIC - + 2 + (propertiesLength > 0 ? propertiesLength : 0) // 16 - // propertiesLength - + 0; + + 4 // 2 MAGICCODE + + 4 // 3 BODYCRC + + 4 // 4 QUEUEID + + 4 // 5 FLAG + + 8 // 6 QUEUEOFFSET + + 8 // 7 PHYSICALOFFSET + + 4 // 8 SYSFLAG + + 8 // 9 BORNTIMESTAMP + + 8 // 10 BORNHOST + + 8 // 11 STORETIMESTAMP + + 8 // 12 STOREHOSTADDRESS + + 4 // 13 RECONSUMETIMES + + 8 // 14 Prepared Transaction Offset + + 4 + (bodyLength > 0 ? bodyLength : 0) // 14 BODY + + 1 + topicLength // 15 TOPIC + + 2 + (propertiesLength > 0 ? propertiesLength : 0) // 16 + // propertiesLength + + 0; return msgLen; } @@ -441,7 +433,6 @@ public class CommitLog { if (size > 0) { mappedFileOffset += size; - if (this.defaultMessageStore.getMessageStoreConfig().isDuplicationEnable()) { if (dispatchRequest.getCommitLogOffset() < this.defaultMessageStore.getConfirmOffset()) { this.defaultMessageStore.doDispatch(dispatchRequest); @@ -505,18 +496,18 @@ public class CommitLog { } if (this.defaultMessageStore.getMessageStoreConfig().isMessageIndexEnable()// - && this.defaultMessageStore.getMessageStoreConfig().isMessageIndexSafe()) { + && this.defaultMessageStore.getMessageStoreConfig().isMessageIndexSafe()) { if (storeTimestamp <= this.defaultMessageStore.getStoreCheckpoint().getMinTimestampIndex()) { log.info("find check timestamp, {} {}", // - storeTimestamp, // - UtilAll.timeMillisToHumanString(storeTimestamp)); + storeTimestamp, // + UtilAll.timeMillisToHumanString(storeTimestamp)); return true; } } else { if (storeTimestamp <= this.defaultMessageStore.getStoreCheckpoint().getMinTimestamp()) { log.info("find check timestamp, {} {}", // - storeTimestamp, // - UtilAll.timeMillisToHumanString(storeTimestamp)); + storeTimestamp, // + UtilAll.timeMillisToHumanString(storeTimestamp)); return true; } } @@ -552,7 +543,7 @@ public class CommitLog { final int tranType = MessageSysFlag.getTransactionValue(msg.getSysFlag()); if (tranType == MessageSysFlag.TRANSACTION_NOT_TYPE// - || tranType == MessageSysFlag.TRANSACTION_COMMIT_TYPE) { + || tranType == MessageSysFlag.TRANSACTION_COMMIT_TYPE) { // Delay Delivery if (msg.getDelayTimeLevel() > 0) { if (msg.getDelayTimeLevel() > this.defaultMessageStore.getScheduleMessageService().getMaxDelayLevel()) { @@ -636,7 +627,6 @@ public class CommitLog { this.defaultMessageStore.unlockMappedFile(unlockMappedFile); } - PutMessageResult putMessageResult = new PutMessageResult(PutMessageStatus.PUT_OK, result); // Statistics @@ -647,14 +637,14 @@ public class CommitLog { // Synchronization flush if (FlushDiskType.SYNC_FLUSH == this.defaultMessageStore.getMessageStoreConfig().getFlushDiskType()) { - final GroupCommitService service = (GroupCommitService) this.flushCommitLogService; + final GroupCommitService service = (GroupCommitService)this.flushCommitLogService; if (msg.isWaitStoreMsgOK()) { request = new GroupCommitRequest(result.getWroteOffset() + result.getWroteBytes()); service.putRequest(request); boolean flushOK = request.waitForFlush(this.defaultMessageStore.getMessageStoreConfig().getSyncFlushTimeout()); if (!flushOK) { log.error("do groupcommit, wait for flush failed, topic: " + msg.getTopic() + " tags: " + msg.getTags() - + " client address: " + msg.getBornHostString()); + + " client address: " + msg.getBornHostString()); putMessageResult.setPutMessageStatus(PutMessageStatus.FLUSH_DISK_TIMEOUT); } } else { @@ -684,11 +674,11 @@ public class CommitLog { service.getWaitNotifyObject().wakeupAll(); boolean flushOK = - // TODO - request.waitForFlush(this.defaultMessageStore.getMessageStoreConfig().getSyncFlushTimeout()); + // TODO + request.waitForFlush(this.defaultMessageStore.getMessageStoreConfig().getSyncFlushTimeout()); if (!flushOK) { log.error("do sync transfer other node, wait return, but failed, topic: " + msg.getTopic() + " tags: " - + msg.getTags() + " client address: " + msg.getBornHostString()); + + msg.getTags() + " client address: " + msg.getBornHostString()); putMessageResult.setPutMessageStatus(PutMessageStatus.FLUSH_SLAVE_TIMEOUT); } } @@ -739,7 +729,7 @@ public class CommitLog { int mappedFileSize = this.defaultMessageStore.getMessageStoreConfig().getMapedFileSizeCommitLog(); MappedFile mappedFile = this.mappedFileQueue.findMappedFileByOffset(offset, offset == 0); if (mappedFile != null) { - int pos = (int) (offset % mappedFileSize); + int pos = (int)(offset % mappedFileSize); return mappedFile.selectMappedBuffer(pos, size); } return null; @@ -754,17 +744,14 @@ public class CommitLog { return topicQueueTable; } - public void setTopicQueueTable(HashMap topicQueueTable) { this.topicQueueTable = topicQueueTable; } - public void destroy() { this.mappedFileQueue.destroy(); } - public boolean appendData(long startOffset, byte[] data) { lockForPutMessage(); //spin... try { @@ -780,7 +767,6 @@ public class CommitLog { } } - public boolean retryDeleteFirstFile(final long intervalForcibly) { return this.mappedFileQueue.retryDeleteFirstFile(intervalForcibly); } @@ -798,6 +784,72 @@ public class CommitLog { mappedFileQueue.checkSelf(); } + public long lockTimeMills() { + long diff = 0; + long begin = this.beginTimeInLock; + if (begin > 0) { + diff = this.defaultMessageStore.now() - begin; + } + + if (diff < 0) { + diff = 0; + } + + return diff; + } + + /** + * Spin util acquired the lock. + */ + private void lockForPutMessage() { + if (this.defaultMessageStore.getMessageStoreConfig().isUseReentrantLockWhenPutMessage()) { + putMessageNormalLock.lock(); + } else { + boolean flag; + do { + flag = this.putMessageSpinLock.compareAndSet(true, false); + } + while (!flag); + } + } + + private void releasePutMessageLock() { + if (this.defaultMessageStore.getMessageStoreConfig().isUseReentrantLockWhenPutMessage()) { + putMessageNormalLock.unlock(); + } else { + this.putMessageSpinLock.compareAndSet(false, true); + } + } + + public static class GroupCommitRequest { + private final long nextOffset; + private final CountDownLatch countDownLatch = new CountDownLatch(1); + private volatile boolean flushOK = false; + + public GroupCommitRequest(long nextOffset) { + this.nextOffset = nextOffset; + } + + public long getNextOffset() { + return nextOffset; + } + + public void wakeupCustomer(final boolean flushOK) { + this.flushOK = flushOK; + this.countDownLatch.countDown(); + } + + public boolean waitForFlush(long timeout) { + try { + this.countDownLatch.await(timeout, TimeUnit.MILLISECONDS); + return this.flushOK; + } catch (InterruptedException e) { + e.printStackTrace(); + return false; + } + } + } + abstract class FlushCommitLogService extends ServiceThread { protected static final int RETRY_TIMES_OVER = 10; } @@ -820,7 +872,7 @@ public class CommitLog { int commitDataLeastPages = CommitLog.this.defaultMessageStore.getMessageStoreConfig().getCommitCommitLogLeastPages(); int commitDataThoroughInterval = - CommitLog.this.defaultMessageStore.getMessageStoreConfig().getCommitCommitLogThoroughInterval(); + CommitLog.this.defaultMessageStore.getMessageStoreConfig().getCommitCommitLogThoroughInterval(); long begin = System.currentTimeMillis(); if (begin >= (this.lastCommitTimestamp + commitDataThoroughInterval)) { @@ -859,7 +911,6 @@ public class CommitLog { private long lastFlushTimestamp = 0; private long printTimes = 0; - public void run() { CommitLog.log.info(this.getServiceName() + " service started"); @@ -870,7 +921,7 @@ public class CommitLog { int flushPhysicQueueLeastPages = CommitLog.this.defaultMessageStore.getMessageStoreConfig().getFlushCommitLogLeastPages(); int flushPhysicQueueThoroughInterval = - CommitLog.this.defaultMessageStore.getMessageStoreConfig().getFlushCommitLogThoroughInterval(); + CommitLog.this.defaultMessageStore.getMessageStoreConfig().getFlushCommitLogThoroughInterval(); boolean printFlushProgress = false; @@ -921,58 +972,22 @@ public class CommitLog { CommitLog.log.info(this.getServiceName() + " service end"); } - @Override public String getServiceName() { return FlushRealTimeService.class.getSimpleName(); } - private void printFlushProgress() { // CommitLog.log.info("how much disk fall behind memory, " // + CommitLog.this.mappedFileQueue.howMuchFallBehind()); } - @Override public long getJointime() { return 1000 * 60 * 5; } } - public static class GroupCommitRequest { - private final long nextOffset; - private final CountDownLatch countDownLatch = new CountDownLatch(1); - private volatile boolean flushOK = false; - - - public GroupCommitRequest(long nextOffset) { - this.nextOffset = nextOffset; - } - - - public long getNextOffset() { - return nextOffset; - } - - - public void wakeupCustomer(final boolean flushOK) { - this.flushOK = flushOK; - this.countDownLatch.countDown(); - } - - - public boolean waitForFlush(long timeout) { - try { - this.countDownLatch.await(timeout, TimeUnit.MILLISECONDS); - return this.flushOK; - } catch (InterruptedException e) { - e.printStackTrace(); - return false; - } - } - } - /** * GroupCommit Service */ @@ -980,7 +995,6 @@ public class CommitLog { private volatile List requestsWrite = new ArrayList(); private volatile List requestsRead = new ArrayList(); - public void putRequest(final GroupCommitRequest request) { synchronized (this) { this.requestsWrite.add(request); @@ -990,14 +1004,12 @@ public class CommitLog { } } - private void swapRequests() { List tmp = this.requestsWrite; this.requestsWrite = this.requestsRead; this.requestsRead = tmp; } - private void doCommit() { if (!this.requestsRead.isEmpty()) { for (GroupCommitRequest req : this.requestsRead) { @@ -1028,7 +1040,6 @@ public class CommitLog { } } - public void run() { CommitLog.log.info(this.getServiceName() + " service started"); @@ -1058,19 +1069,16 @@ public class CommitLog { CommitLog.log.info(this.getServiceName() + " service end"); } - @Override protected void onWaitEnd() { this.swapRequests(); } - @Override public String getServiceName() { return GroupCommitService.class.getSimpleName(); } - @Override public long getJointime() { return 1000 * 60 * 5; @@ -1090,19 +1098,16 @@ public class CommitLog { private final ByteBuffer hostHolder = ByteBuffer.allocate(8); - DefaultAppendMessageCallback(final int size) { this.msgIdMemory = ByteBuffer.allocate(MessageDecoder.MSG_ID_LENGTH); this.msgStoreItemMemory = ByteBuffer.allocate(size + END_FILE_MIN_BLANK_LENGTH); this.maxMessageSize = size; } - public ByteBuffer getMsgStoreItemMemory() { return msgStoreItemMemory; } - public AppendMessageResult doAppend(final long fileFromOffset, final ByteBuffer byteBuffer, final int maxBlank, final MessageExtBrokerInner msgInner) { // STORETIMESTAMP + STOREHOSTADDRESS + OFFSET
@@ -1143,9 +1148,9 @@ public class CommitLog { * Serialize message */ final byte[] propertiesData = - msgInner.getPropertiesString() == null ? null : msgInner.getPropertiesString().getBytes(MessageDecoder.CHARSET_UTF8); + msgInner.getPropertiesString() == null ? null : msgInner.getPropertiesString().getBytes(MessageDecoder.CHARSET_UTF8); - final short propertiesLength = propertiesData == null ? 0 : (short) propertiesData.length; + final short propertiesLength = propertiesData == null ? 0 : (short)propertiesData.length; if (propertiesLength > Short.MAX_VALUE) { log.warn("putMessage message properties length too long. length={}", propertiesData.length); @@ -1162,7 +1167,7 @@ public class CommitLog { // Exceeds the maximum message if (msgLen > this.maxMessageSize) { CommitLog.log.warn("message size exceeded, msg total size: " + msgLen + ", msg body size: " + bodyLength - + ", maxMessageSize: " + this.maxMessageSize); + + ", maxMessageSize: " + this.maxMessageSize); return new AppendMessageResult(AppendMessageStatus.MESSAGE_SIZE_EXCEEDED); } @@ -1180,7 +1185,7 @@ public class CommitLog { final long beginTimeMills = CommitLog.this.defaultMessageStore.now(); byteBuffer.put(this.msgStoreItemMemory.array(), 0, maxBlank); return new AppendMessageResult(AppendMessageStatus.END_OF_FILE, wroteOffset, maxBlank, msgId, msgInner.getStoreTimestamp(), - queueOffset, CommitLog.this.defaultMessageStore.now() - beginTimeMills); + queueOffset, CommitLog.this.defaultMessageStore.now() - beginTimeMills); } // Initialization of storage space @@ -1221,7 +1226,7 @@ public class CommitLog { if (bodyLength > 0) this.msgStoreItemMemory.put(msgInner.getBody()); // 16 TOPIC - this.msgStoreItemMemory.put((byte) topicLength); + this.msgStoreItemMemory.put((byte)topicLength); this.msgStoreItemMemory.put(topicData); // 17 PROPERTIES this.msgStoreItemMemory.putShort(propertiesLength); @@ -1233,7 +1238,7 @@ public class CommitLog { byteBuffer.put(this.msgStoreItemMemory.array(), 0, msgLen); AppendMessageResult result = new AppendMessageResult(AppendMessageStatus.PUT_OK, wroteOffset, msgLen, msgId, - msgInner.getStoreTimestamp(), queueOffset, CommitLog.this.defaultMessageStore.now() - beginTimeMills); + msgInner.getStoreTimestamp(), queueOffset, CommitLog.this.defaultMessageStore.now() - beginTimeMills); switch (tranType) { case MessageSysFlag.TRANSACTION_PREPARED_TYPE: @@ -1250,46 +1255,9 @@ public class CommitLog { return result; } - private void resetByteBuffer(final ByteBuffer byteBuffer, final int limit) { byteBuffer.flip(); byteBuffer.limit(limit); } } - - public long lockTimeMills() { - long diff = 0; - long begin = this.beginTimeInLock; - if (begin > 0) { - diff = this.defaultMessageStore.now() - begin; - } - - if (diff < 0) { - diff = 0; - } - - return diff; - } - - /** - * Spin util acquired the lock. - */ - private void lockForPutMessage() { - if (this.defaultMessageStore.getMessageStoreConfig().isUseReentrantLockWhenPutMessage()) { - putMessageNormalLock.lock(); - } else { - boolean flag; - do { - flag = this.putMessageSpinLock.compareAndSet(true, false); - } while (!flag); - } - } - - private void releasePutMessageLock() { - if (this.defaultMessageStore.getMessageStoreConfig().isUseReentrantLockWhenPutMessage()) { - putMessageNormalLock.unlock(); - } else { - this.putMessageSpinLock.compareAndSet(false, true); - } - } } diff --git a/store/src/main/java/org/apache/rocketmq/store/ConsumeQueue.java b/store/src/main/java/org/apache/rocketmq/store/ConsumeQueue.java index 6326d4b5..d9e2f031 100644 --- a/store/src/main/java/org/apache/rocketmq/store/ConsumeQueue.java +++ b/store/src/main/java/org/apache/rocketmq/store/ConsumeQueue.java @@ -16,14 +16,12 @@ */ package org.apache.rocketmq.store; -import org.apache.rocketmq.common.constant.LoggerName; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.io.File; import java.nio.ByteBuffer; import java.util.List; - +import org.apache.rocketmq.common.constant.LoggerName; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class ConsumeQueue { @@ -43,13 +41,12 @@ public class ConsumeQueue { private long maxPhysicOffset = -1; private volatile long minLogicOffset = 0; - public ConsumeQueue( - final String topic, - final int queueId, - final String storePath, - final int mappedFileSize, - final DefaultMessageStore defaultMessageStore) { + final String topic, + final int queueId, + final String storePath, + final int mappedFileSize, + final DefaultMessageStore defaultMessageStore) { this.storePath = storePath; this.mappedFileSize = mappedFileSize; this.defaultMessageStore = defaultMessageStore; @@ -58,22 +55,20 @@ public class ConsumeQueue { this.queueId = queueId; String queueDir = this.storePath - + File.separator + topic - + File.separator + queueId; + + File.separator + topic + + File.separator + queueId; this.mappedFileQueue = new MappedFileQueue(queueDir, mappedFileSize, null); this.byteBufferIndex = ByteBuffer.allocate(CQ_STORE_UNIT_SIZE); } - public boolean load() { boolean result = this.mappedFileQueue.load(); log.info("load consume queue " + this.topic + "-" + this.queueId + " " + (result ? "OK" : "Failed")); return result; } - public void recover() { final List mappedFiles = this.mappedFileQueue.getMappedFiles(); if (!mappedFiles.isEmpty()) { @@ -98,18 +93,17 @@ public class ConsumeQueue { this.maxPhysicOffset = offset; } else { log.info("recover current consume queue file over, " + mappedFile.getFileName() + " " - + offset + " " + size + " " + tagsCode); + + offset + " " + size + " " + tagsCode); break; } } - if (mapedFileOffset == mapedFileSizeLogics) { index++; if (index >= mappedFiles.size()) { log.info("recover last consume queue file over, last maped file " - + mappedFile.getFileName()); + + mappedFile.getFileName()); break; } else { mappedFile = mappedFiles.get(index); @@ -120,7 +114,7 @@ public class ConsumeQueue { } } else { log.info("recover current consume queue queue over " + mappedFile.getFileName() + " " - + (processOffset + mapedFileOffset)); + + (processOffset + mapedFileOffset)); break; } } @@ -137,8 +131,8 @@ public class ConsumeQueue { if (mappedFile != null) { long offset = 0; int low = - minLogicOffset > mappedFile.getFileFromOffset() ? (int) (minLogicOffset - mappedFile - .getFileFromOffset()) : 0; + minLogicOffset > mappedFile.getFileFromOffset() ? (int)(minLogicOffset - mappedFile + .getFileFromOffset()) : 0; int high = 0; int midOffset = -1, targetOffset = -1, leftOffset = -1, rightOffset = -1; long leftIndexValue = -1L, rightIndexValue = -1L; @@ -160,7 +154,7 @@ public class ConsumeQueue { } long storeTime = - this.defaultMessageStore.getCommitLog().pickupStoreTimestamp(phyOffset, size); + this.defaultMessageStore.getCommitLog().pickupStoreTimestamp(phyOffset, size); if (storeTime < 0) { return 0; } else if (storeTime == timestamp) { @@ -189,8 +183,8 @@ public class ConsumeQueue { offset = leftOffset; } else { offset = - Math.abs(timestamp - leftIndexValue) > Math.abs(timestamp - - rightIndexValue) ? rightOffset : leftOffset; + Math.abs(timestamp - leftIndexValue) > Math.abs(timestamp + - rightIndexValue) ? rightOffset : leftOffset; } } @@ -223,7 +217,6 @@ public class ConsumeQueue { int size = byteBuffer.getInt(); byteBuffer.getLong(); - if (0 == i) { if (offset >= phyOffet) { this.mappedFileQueue.deleteLastMappedFile(); @@ -249,7 +242,6 @@ public class ConsumeQueue { mappedFile.setFlushedPosition(pos); this.maxPhysicOffset = offset; - if (pos == logicFileSize) { return; } @@ -283,7 +275,6 @@ public class ConsumeQueue { int size = byteBuffer.getInt(); byteBuffer.getLong(); - if (offset >= 0 && size > 0) { lastOffset = offset + size; } else { @@ -295,12 +286,10 @@ public class ConsumeQueue { return lastOffset; } - public boolean flush(final int flushLeastPages) { return this.mappedFileQueue.flush(flushLeastPages); } - public int deleteExpiredFile(long offset) { int cnt = this.mappedFileQueue.deleteExpiredFileByOffset(offset, CQ_STORE_UNIT_SIZE); this.correctMinOffset(offset); @@ -322,7 +311,7 @@ public class ConsumeQueue { if (offsetPy >= phyMinOffset) { this.minLogicOffset = result.getMappedFile().getFileFromOffset() + i; log.info("compute logics min offset: " + this.getMinOffsetInQuque() + ", topic: " - + this.topic + ", queueId: " + this.queueId); + + this.topic + ", queueId: " + this.queueId); break; } } @@ -335,14 +324,12 @@ public class ConsumeQueue { } } - public long getMinOffsetInQuque() { return this.minLogicOffset / CQ_STORE_UNIT_SIZE; } - public void putMessagePositionInfoWrapper(long offset, int size, long tagsCode, long storeTimestamp, - long logicOffset) { + long logicOffset) { final int maxRetries = 30; boolean canWrite = this.defaultMessageStore.getRunningFlags().isWriteable(); for (int i = 0; i < maxRetries && canWrite; i++) { @@ -353,7 +340,7 @@ public class ConsumeQueue { } else { // XXX: warn and notify me log.warn("[BUG]put commit log position info to " + topic + ":" + queueId + " " + offset - + " failed, retry " + i + " times"); + + " failed, retry " + i + " times"); try { Thread.sleep(1000); @@ -369,7 +356,7 @@ public class ConsumeQueue { } private boolean putMessagePositionInfo(final long offset, final int size, final long tagsCode, - final long cqOffset) { + final long cqOffset) { if (offset <= this.maxPhysicOffset) { return true; @@ -392,19 +379,19 @@ public class ConsumeQueue { this.mappedFileQueue.setCommittedWhere(expectLogicOffset); this.fillPreBlank(mappedFile, expectLogicOffset); log.info("fill pre blank space " + mappedFile.getFileName() + " " + expectLogicOffset + " " - + mappedFile.getWrotePosition()); + + mappedFile.getWrotePosition()); } if (cqOffset != 0) { long currentLogicOffset = mappedFile.getWrotePosition() + mappedFile.getFileFromOffset(); if (expectLogicOffset != currentLogicOffset) { LOG_ERROR.warn( - "[BUG]logic queue order maybe wrong, expectLogicOffset: {} currentLogicOffset: {} Topic: {} QID: {} Diff: {}", - expectLogicOffset, - currentLogicOffset, - this.topic, - this.queueId, - expectLogicOffset - currentLogicOffset + "[BUG]logic queue order maybe wrong, expectLogicOffset: {} currentLogicOffset: {} Topic: {} QID: {} Diff: {}", + expectLogicOffset, + currentLogicOffset, + this.topic, + this.queueId, + expectLogicOffset - currentLogicOffset ); } } @@ -414,14 +401,13 @@ public class ConsumeQueue { return false; } - private void fillPreBlank(final MappedFile mappedFile, final long untilWhere) { ByteBuffer byteBuffer = ByteBuffer.allocate(CQ_STORE_UNIT_SIZE); byteBuffer.putLong(0L); byteBuffer.putInt(Integer.MAX_VALUE); byteBuffer.putLong(0L); - int until = (int) (untilWhere % this.mappedFileQueue.getMappedFileSize()); + int until = (int)(untilWhere % this.mappedFileQueue.getMappedFileSize()); for (int i = 0; i < until; i += CQ_STORE_UNIT_SIZE) { mappedFile.appendMessage(byteBuffer.array()); } @@ -433,7 +419,7 @@ public class ConsumeQueue { if (offset >= this.getMinLogicOffset()) { MappedFile mappedFile = this.mappedFileQueue.findMappedFileByOffset(offset); if (mappedFile != null) { - SelectMappedBufferResult result = mappedFile.selectMappedBuffer((int) (offset % mappedFileSize)); + SelectMappedBufferResult result = mappedFile.selectMappedBuffer((int)(offset % mappedFileSize)); return result; } } @@ -480,12 +466,10 @@ public class ConsumeQueue { return this.getMaxOffsetInQuque() - this.getMinOffsetInQuque(); } - public long getMaxOffsetInQuque() { return this.mappedFileQueue.getMaxOffset() / CQ_STORE_UNIT_SIZE; } - public void checkSelf() { mappedFileQueue.checkSelf(); } diff --git a/store/src/main/java/org/apache/rocketmq/store/DefaultMessageFilter.java b/store/src/main/java/org/apache/rocketmq/store/DefaultMessageFilter.java index ac149f4b..4ebcb3e6 100644 --- a/store/src/main/java/org/apache/rocketmq/store/DefaultMessageFilter.java +++ b/store/src/main/java/org/apache/rocketmq/store/DefaultMessageFilter.java @@ -6,19 +6,18 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.store; import org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData; - public class DefaultMessageFilter implements MessageFilter { @Override diff --git a/store/src/main/java/org/apache/rocketmq/store/DefaultMessageStore.java b/store/src/main/java/org/apache/rocketmq/store/DefaultMessageStore.java index 8714055b..7e3af19e 100644 --- a/store/src/main/java/org/apache/rocketmq/store/DefaultMessageStore.java +++ b/store/src/main/java/org/apache/rocketmq/store/DefaultMessageStore.java @@ -16,7 +16,27 @@ */ package org.apache.rocketmq.store; -import org.apache.rocketmq.common.*; +import java.io.File; +import java.io.IOException; +import java.net.SocketAddress; +import java.nio.ByteBuffer; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; +import org.apache.rocketmq.common.BrokerConfig; +import org.apache.rocketmq.common.MixAll; +import org.apache.rocketmq.common.ServiceThread; +import org.apache.rocketmq.common.SystemClock; +import org.apache.rocketmq.common.ThreadFactoryImpl; +import org.apache.rocketmq.common.UtilAll; import org.apache.rocketmq.common.constant.LoggerName; import org.apache.rocketmq.common.message.MessageDecoder; import org.apache.rocketmq.common.message.MessageExt; @@ -34,21 +54,8 @@ import org.apache.rocketmq.store.stats.BrokerStatsManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.io.IOException; -import java.net.SocketAddress; -import java.nio.ByteBuffer; -import java.util.*; -import java.util.Map.Entry; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicLong; - import static org.apache.rocketmq.store.config.BrokerRole.SLAVE; - public class DefaultMessageStore implements MessageStore { private static final Logger log = LoggerFactory.getLogger(LoggerName.STORE_LOGGER_NAME); @@ -84,7 +91,7 @@ public class DefaultMessageStore implements MessageStore { private final SystemClock systemClock = new SystemClock(); private final ScheduledExecutorService scheduledExecutorService = - Executors.newSingleThreadScheduledExecutor(new ThreadFactoryImpl("StoreScheduledThread")); + Executors.newSingleThreadScheduledExecutor(new ThreadFactoryImpl("StoreScheduledThread")); private final BrokerStatsManager brokerStatsManager; private final MessageArrivingListener messageArrivingListener; private final BrokerConfig brokerConfig; @@ -96,7 +103,7 @@ public class DefaultMessageStore implements MessageStore { private AtomicLong printTimes = new AtomicLong(0); public DefaultMessageStore(final MessageStoreConfig messageStoreConfig, final BrokerStatsManager brokerStatsManager, - final MessageArrivingListener messageArrivingListener, final BrokerConfig brokerConfig) throws IOException { + final MessageArrivingListener messageArrivingListener, final BrokerConfig brokerConfig) throws IOException { this.messageArrivingListener = messageArrivingListener; this.brokerConfig = brokerConfig; this.messageStoreConfig = messageStoreConfig; @@ -122,13 +129,11 @@ public class DefaultMessageStore implements MessageStore { this.transientStorePool.init(); } - this.allocateMappedFileService.start(); this.indexService.start(); } - public void truncateDirtyLogicFiles(long phyOffset) { ConcurrentHashMap> tables = DefaultMessageStore.this.consumeQueueTable; @@ -139,7 +144,6 @@ public class DefaultMessageStore implements MessageStore { } } - /** * @throws IOException */ @@ -162,11 +166,10 @@ public class DefaultMessageStore implements MessageStore { if (result) { this.storeCheckpoint = - new StoreCheckpoint(StorePathConfigHelper.getStoreCheckpoint(this.messageStoreConfig.getStorePathRootDir())); + new StoreCheckpoint(StorePathConfigHelper.getStoreCheckpoint(this.messageStoreConfig.getStorePathRootDir())); this.indexService.load(lastExitOK); - this.recover(lastExitOK); log.info("load over, and the max phy offset = {}", this.getMaxPhyOffset()); @@ -191,7 +194,6 @@ public class DefaultMessageStore implements MessageStore { this.commitLog.start(); this.storeStatsService.start(); - if (this.scheduleMessageService != null && SLAVE != messageStoreConfig.getBrokerRole()) { this.scheduleMessageService.start(); } @@ -293,19 +295,16 @@ public class DefaultMessageStore implements MessageStore { this.printTimes.set(0); } - if (msg.getTopic().length() > Byte.MAX_VALUE) { log.warn("putMessage message topic length too long " + msg.getTopic().length()); return new PutMessageResult(PutMessageStatus.MESSAGE_ILLEGAL, null); } - if (msg.getPropertiesString() != null && msg.getPropertiesString().length() > Short.MAX_VALUE) { log.warn("putMessage message properties length too long " + msg.getPropertiesString().length()); return new PutMessageResult(PutMessageStatus.PROPERTIES_SIZE_EXCEEDED, null); } - if (this.isOSPageCacheBusy()) { return new PutMessageResult(PutMessageStatus.OS_PAGECACHE_BUSY, null); } @@ -332,7 +331,7 @@ public class DefaultMessageStore implements MessageStore { long diff = this.systemClock.now() - begin; if (diff < 10000000 // - && diff > this.messageStoreConfig.getOsPageCacheBusyTimeOutMills()) { + && diff > this.messageStoreConfig.getOsPageCacheBusyTimeOutMills()) { return true; } @@ -353,7 +352,7 @@ public class DefaultMessageStore implements MessageStore { } public GetMessageResult getMessage(final String group, final String topic, final int queueId, final long offset, final int maxMsgNums, - final SubscriptionData subscriptionData) { + final SubscriptionData subscriptionData) { if (this.shutdown) { log.warn("message store has shutdown, so getMessage is forbidden"); return null; @@ -366,7 +365,6 @@ public class DefaultMessageStore implements MessageStore { long beginTime = this.getSystemClock().now(); - GetMessageStatus status = GetMessageStatus.NO_MESSAGE_IN_QUEUE; long nextBeginOffset = offset; long minOffset = 0; @@ -374,7 +372,6 @@ public class DefaultMessageStore implements MessageStore { GetMessageResult getResult = new GetMessageResult(); - final long maxOffsetPy = this.commitLog.getMaxOffset(); ConsumeQueue consumeQueue = findConsumeQueue(topic, queueId); @@ -417,21 +414,18 @@ public class DefaultMessageStore implements MessageStore { maxPhyOffsetPulling = offsetPy; - if (nextPhyFileStartOffset != Long.MIN_VALUE) { if (offsetPy < nextPhyFileStartOffset) continue; } - boolean isInDisk = checkInDiskByCommitOffset(offsetPy, maxOffsetPy); if (this.isTheBatchFull(sizePy, maxMsgNums, getResult.getBufferTotalSize(), getResult.getMessageCount(), - isInDisk)) { + isInDisk)) { break; } - if (this.messageFilter.isMessageMatched(subscriptionData, tagsCode)) { SelectMappedBufferResult selectResult = this.commitLog.getMessage(offsetPy, sizePy); if (selectResult != null) { @@ -444,7 +438,6 @@ public class DefaultMessageStore implements MessageStore { status = GetMessageStatus.MESSAGE_WAS_REMOVING; } - nextPhyFileStartOffset = this.commitLog.rollNextFile(offsetPy); } } else { @@ -458,7 +451,6 @@ public class DefaultMessageStore implements MessageStore { } } - if (diskFallRecorded) { long fallBehind = maxOffsetPy - maxPhyOffsetPulling; brokerStatsManager.recordDiskFallBehindSize(group, topic, queueId, fallBehind); @@ -466,10 +458,9 @@ public class DefaultMessageStore implements MessageStore { nextBeginOffset = offset + (i / ConsumeQueue.CQ_STORE_UNIT_SIZE); - long diff = maxOffsetPy - maxPhyOffsetPulling; - long memory = (long) (StoreUtil.TOTAL_PHYSICAL_MEMORY_SIZE - * (this.messageStoreConfig.getAccessMessageInMemoryMaxRatio() / 100.0)); + long memory = (long)(StoreUtil.TOTAL_PHYSICAL_MEMORY_SIZE + * (this.messageStoreConfig.getAccessMessageInMemoryMaxRatio() / 100.0)); getResult.setSuggestPullingFromSlave(diff > memory); } finally { @@ -479,7 +470,7 @@ public class DefaultMessageStore implements MessageStore { status = GetMessageStatus.OFFSET_FOUND_NULL; nextBeginOffset = nextOffsetCorrection(offset, consumeQueue.rollNextFile(offset)); log.warn("consumer request topic: " + topic + "offset: " + offset + " minOffset: " + minOffset + " maxOffset: " - + maxOffset + ", but access logic queue failed."); + + maxOffset + ", but access logic queue failed."); } } } else { @@ -605,7 +596,6 @@ public class DefaultMessageStore implements MessageStore { } - { String storePathLogics = StorePathConfigHelper.getStorePathConsumeQueue(this.messageStoreConfig.getStorePathRootDir()); @@ -613,7 +603,6 @@ public class DefaultMessageStore implements MessageStore { result.put(RunningStats.consumeQueueDiskRatio.name(), String.valueOf(logicsRatio)); } - { if (this.scheduleMessageService != null) { this.scheduleMessageService.buildRunningStats(result); @@ -741,7 +730,6 @@ public class DefaultMessageStore implements MessageStore { break; } - Collections.sort(queryOffsetResult.getPhyOffsets()); queryMessageResult.setIndexLastUpdatePhyoffset(queryOffsetResult.getIndexLastUpdatePhyoffset()); @@ -784,12 +772,10 @@ public class DefaultMessageStore implements MessageStore { } } - if (queryMessageResult.getBufferTotalSize() > 0) { break; } - if (lastQueryMsgTime < begin) { break; } @@ -825,8 +811,8 @@ public class DefaultMessageStore implements MessageStore { for (ConsumeQueue cq : queueTable.values()) { cq.destroy(); log.info("cleanUnusedTopic: {} {} ConsumeQueue cleaned", // - cq.getTopic(), // - cq.getQueueId() // + cq.getTopic(), // + cq.getQueueId() // ); this.commitLog.removeQueueFromTopicQueueTable(cq.getTopic(), cq.getQueueId()); @@ -854,23 +840,22 @@ public class DefaultMessageStore implements MessageStore { Entry nextQT = itQT.next(); long maxCLOffsetInConsumeQueue = nextQT.getValue().getLastOffset(); - if (maxCLOffsetInConsumeQueue == -1) { log.warn("maybe ConsumeQueue was created just now. topic={} queueId={} maxPhysicOffset={} minLogicOffset={}.", // - nextQT.getValue().getTopic(), // - nextQT.getValue().getQueueId(), // - nextQT.getValue().getMaxPhysicOffset(), // - nextQT.getValue().getMinLogicOffset()); + nextQT.getValue().getTopic(), // + nextQT.getValue().getQueueId(), // + nextQT.getValue().getMaxPhysicOffset(), // + nextQT.getValue().getMinLogicOffset()); } else if (maxCLOffsetInConsumeQueue < minCommitLogOffset) { log.info( - "cleanExpiredConsumerQueue: {} {} consumer queue destroyed, minCommitLogOffset: {} maxCLOffsetInConsumeQueue: {}", // - topic, // - nextQT.getKey(), // - minCommitLogOffset, // - maxCLOffsetInConsumeQueue); + "cleanExpiredConsumerQueue: {} {} consumer queue destroyed, minCommitLogOffset: {} maxCLOffsetInConsumeQueue: {}", // + topic, // + nextQT.getKey(), // + minCommitLogOffset, // + maxCLOffsetInConsumeQueue); DefaultMessageStore.this.commitLog.removeQueueFromTopicQueueTable(nextQT.getValue().getTopic(), - nextQT.getValue().getQueueId()); + nextQT.getValue().getQueueId()); nextQT.getValue().destroy(); itQT.remove(); @@ -910,7 +895,7 @@ public class DefaultMessageStore implements MessageStore { long offsetPy = bufferConsumeQueue.getByteBuffer().getLong(); final ByteBuffer msgIdMemory = ByteBuffer.allocate(MessageDecoder.MSG_ID_LENGTH); String msgId = - MessageDecoder.createMessageId(msgIdMemory, MessageExt.socketAddress2ByteBuffer(storeHost), offsetPy); + MessageDecoder.createMessageId(msgIdMemory, MessageExt.socketAddress2ByteBuffer(storeHost), offsetPy); messageIds.put(msgId, nextOffset++); if (nextOffset > maxOffset) { return messageIds; @@ -1006,11 +991,11 @@ public class DefaultMessageStore implements MessageStore { ConsumeQueue logic = map.get(queueId); if (null == logic) { ConsumeQueue newLogic = new ConsumeQueue(// - topic, // - queueId, // - StorePathConfigHelper.getStorePathConsumeQueue(this.messageStoreConfig.getStorePathRootDir()), // - this.getMessageStoreConfig().getMapedFileSizeConsumeQueue(), // - this); + topic, // + queueId, // + StorePathConfigHelper.getStorePathConsumeQueue(this.messageStoreConfig.getStorePathRootDir()), // + this.getMessageStoreConfig().getMapedFileSizeConsumeQueue(), // + this); ConsumeQueue oldLogic = map.putIfAbsent(queueId, newLogic); if (oldLogic != null) { logic = oldLogic; @@ -1031,7 +1016,7 @@ public class DefaultMessageStore implements MessageStore { } private boolean checkInDiskByCommitOffset(long offsetPy, long maxOffsetPy) { - long memory = (long) (StoreUtil.TOTAL_PHYSICAL_MEMORY_SIZE * (this.messageStoreConfig.getAccessMessageInMemoryMaxRatio() / 100.0)); + long memory = (long)(StoreUtil.TOTAL_PHYSICAL_MEMORY_SIZE * (this.messageStoreConfig.getAccessMessageInMemoryMaxRatio() / 100.0)); return (maxOffsetPy - offsetPy) > memory; } @@ -1045,7 +1030,6 @@ public class DefaultMessageStore implements MessageStore { return true; } - if (isInDisk) { if ((bufferTotal + sizePy) > this.messageStoreConfig.getMaxTransferBytesOnMessageInDisk()) { return true; @@ -1093,7 +1077,6 @@ public class DefaultMessageStore implements MessageStore { } }, 1000 * 60, this.messageStoreConfig.getCleanResourceInterval(), TimeUnit.MILLISECONDS); - this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() { @Override public void run() { @@ -1101,7 +1084,6 @@ public class DefaultMessageStore implements MessageStore { } }, 1, 10, TimeUnit.MINUTES); - this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() { @Override public void run() { @@ -1113,7 +1095,7 @@ public class DefaultMessageStore implements MessageStore { String stack = UtilAll.jstack(); final String fileName = System.getProperty("user.home") + File.separator + "debug/lock/stack-" - + DefaultMessageStore.this.commitLog.getBeginTimeInLock() + "-" + lockTime; + + DefaultMessageStore.this.commitLog.getBeginTimeInLock() + "-" + lockTime; MixAll.string2FileNotSafe(stack, fileName); } } @@ -1174,11 +1156,11 @@ public class DefaultMessageStore implements MessageStore { continue; } ConsumeQueue logic = new ConsumeQueue( - topic, - queueId, - StorePathConfigHelper.getStorePathConsumeQueue(this.messageStoreConfig.getStorePathRootDir()), - this.getMessageStoreConfig().getMapedFileSizeConsumeQueue(), - this); + topic, + queueId, + StorePathConfigHelper.getStorePathConsumeQueue(this.messageStoreConfig.getStorePathRootDir()), + this.getMessageStoreConfig().getMapedFileSizeConsumeQueue(), + this); this.putConsumeQueue(topic, queueId, logic); if (!logic.load()) { return false; @@ -1196,7 +1178,6 @@ public class DefaultMessageStore implements MessageStore { private void recover(final boolean lastExitOK) { this.recoverConsumeQueue(); - if (lastExitOK) { this.commitLog.recoverNormally(); } else { @@ -1285,7 +1266,7 @@ public class DefaultMessageStore implements MessageStore { case MessageSysFlag.TRANSACTION_NOT_TYPE: case MessageSysFlag.TRANSACTION_COMMIT_TYPE: DefaultMessageStore.this.putMessagePositionInfo(req.getTopic(), req.getQueueId(), req.getCommitLogOffset(), req.getMsgSize(), - req.getTagsCode(), req.getStoreTimestamp(), req.getConsumeQueueOffset()); + req.getTagsCode(), req.getStoreTimestamp(), req.getConsumeQueueOffset()); break; case MessageSysFlag.TRANSACTION_PREPARED_TYPE: case MessageSysFlag.TRANSACTION_ROLLBACK_TYPE: @@ -1298,7 +1279,7 @@ public class DefaultMessageStore implements MessageStore { } public void putMessagePositionInfo(String topic, int queueId, long offset, int size, long tagsCode, long storeTimestamp, - long logicOffset) { + long logicOffset) { ConsumeQueue cq = this.findConsumeQueue(topic, queueId); cq.putMessagePositionInfoWrapper(offset, size, tagsCode, storeTimestamp, logicOffset); } @@ -1311,23 +1292,21 @@ public class DefaultMessageStore implements MessageStore { private final static int MAX_MANUAL_DELETE_FILE_TIMES = 20; private final double diskSpaceWarningLevelRatio = - Double.parseDouble(System.getProperty("rocketmq.broker.diskSpaceWarningLevelRatio", "0.90")); + Double.parseDouble(System.getProperty("rocketmq.broker.diskSpaceWarningLevelRatio", "0.90")); private final double diskSpaceCleanForciblyRatio = - Double.parseDouble(System.getProperty("rocketmq.broker.diskSpaceCleanForciblyRatio", "0.85")); + Double.parseDouble(System.getProperty("rocketmq.broker.diskSpaceCleanForciblyRatio", "0.85")); private long lastRedeleteTimestamp = 0; private volatile int manualDeleteFileSeveralTimes = 0; private volatile boolean cleanImmediately = false; - public void excuteDeleteFilesManualy() { this.manualDeleteFileSeveralTimes = MAX_MANUAL_DELETE_FILE_TIMES; DefaultMessageStore.log.info("excuteDeleteFilesManualy was invoked"); } - public void run() { try { this.deleteExpiredFiles(); @@ -1348,27 +1327,24 @@ public class DefaultMessageStore implements MessageStore { boolean spacefull = this.isSpaceToDelete(); boolean manualDelete = this.manualDeleteFileSeveralTimes > 0; - if (timeup || spacefull || manualDelete) { if (manualDelete) this.manualDeleteFileSeveralTimes--; - boolean cleanAtOnce = DefaultMessageStore.this.getMessageStoreConfig().isCleanFileForciblyEnable() && this.cleanImmediately; log.info("begin to delete before {} hours file. timeup: {} spacefull: {} manualDeleteFileSeveralTimes: {} cleanAtOnce: {}", // - fileReservedTime, // - timeup, // - spacefull, // - manualDeleteFileSeveralTimes, // - cleanAtOnce); - + fileReservedTime, // + timeup, // + spacefull, // + manualDeleteFileSeveralTimes, // + cleanAtOnce); fileReservedTime *= 60 * 60 * 1000; deleteCount = DefaultMessageStore.this.commitLog.deleteExpiredFile(fileReservedTime, deletePhysicFilesInterval, - destroyMapedFileIntervalForcibly, cleanAtOnce); + destroyMapedFileIntervalForcibly, cleanAtOnce); if (deleteCount > 0) { } else if (spacefull) { log.warn("disk space will be full soon, but delete file failed."); @@ -1382,7 +1358,7 @@ public class DefaultMessageStore implements MessageStore { if ((currentTimestamp - this.lastRedeleteTimestamp) > interval) { this.lastRedeleteTimestamp = currentTimestamp; int destroyMapedFileIntervalForcibly = - DefaultMessageStore.this.getMessageStoreConfig().getDestroyMapedFileIntervalForcibly(); + DefaultMessageStore.this.getMessageStoreConfig().getDestroyMapedFileIntervalForcibly(); if (DefaultMessageStore.this.commitLog.retryDeleteFirstFile(destroyMapedFileIntervalForcibly)) { } } @@ -1407,7 +1383,6 @@ public class DefaultMessageStore implements MessageStore { cleanImmediately = false; - { String storePathPhysic = DefaultMessageStore.this.getMessageStoreConfig().getStorePathCommitLog(); double physicRatio = UtilAll.getDiskPartitionSpaceUsedPercent(storePathPhysic); @@ -1433,10 +1408,9 @@ public class DefaultMessageStore implements MessageStore { } } - { String storePathLogics = StorePathConfigHelper - .getStorePathConsumeQueue(DefaultMessageStore.this.getMessageStoreConfig().getStorePathRootDir()); + .getStorePathConsumeQueue(DefaultMessageStore.this.getMessageStoreConfig().getStorePathRootDir()); double logicsRatio = UtilAll.getDiskPartitionSpaceUsedPercent(storePathLogics); if (logicsRatio > diskSpaceWarningLevelRatio) { boolean diskok = DefaultMessageStore.this.runningFlags.getAndMakeDiskFull(); @@ -1490,7 +1464,6 @@ public class DefaultMessageStore implements MessageStore { if (minOffset > this.lastPhysicalMinOffset) { this.lastPhysicalMinOffset = minOffset; - ConcurrentHashMap> tables = DefaultMessageStore.this.consumeQueueTable; for (ConcurrentHashMap maps : tables.values()) { @@ -1506,7 +1479,6 @@ public class DefaultMessageStore implements MessageStore { } } - DefaultMessageStore.this.indexService.deleteExpiredFile(minOffset); } } @@ -1520,7 +1492,6 @@ public class DefaultMessageStore implements MessageStore { private static final int RETRY_TIMES_OVER = 3; private long lastFlushTimestamp = 0; - private void doFlush(int retryTimes) { int flushConsumeQueueLeastPages = DefaultMessageStore.this.getMessageStoreConfig().getFlushConsumeQueueLeastPages(); @@ -1530,7 +1501,6 @@ public class DefaultMessageStore implements MessageStore { long logicsMsgTimestamp = 0; - int flushConsumeQueueThoroughInterval = DefaultMessageStore.this.getMessageStoreConfig().getFlushConsumeQueueThoroughInterval(); long currentTimeMillis = System.currentTimeMillis(); if (currentTimeMillis >= (this.lastFlushTimestamp + flushConsumeQueueThoroughInterval)) { @@ -1558,7 +1528,6 @@ public class DefaultMessageStore implements MessageStore { } } - public void run() { DefaultMessageStore.log.info(this.getServiceName() + " service started"); @@ -1572,19 +1541,16 @@ public class DefaultMessageStore implements MessageStore { } } - this.doFlush(RETRY_TIMES_OVER); DefaultMessageStore.log.info(this.getServiceName() + " service end"); } - @Override public String getServiceName() { return FlushConsumeQueueService.class.getSimpleName(); } - @Override public long getJointime() { return 1000 * 60; @@ -1610,7 +1576,7 @@ public class DefaultMessageStore implements MessageStore { if (this.isCommitLogAvailable()) { log.warn("shutdown ReputMessageService, but commitlog have not finish to be dispatched, CL: {} reputFromOffset: {}", - DefaultMessageStore.this.commitLog.getMaxOffset(), this.reputFromOffset); + DefaultMessageStore.this.commitLog.getMaxOffset(), this.reputFromOffset); } super.shutdown(); @@ -1624,17 +1590,15 @@ public class DefaultMessageStore implements MessageStore { return DefaultMessageStore.this.commitLog.getMaxOffset() - this.reputFromOffset; } - private boolean isCommitLogAvailable() { return this.reputFromOffset < DefaultMessageStore.this.commitLog.getMaxOffset(); } - private void doReput() { for (boolean doNext = true; this.isCommitLogAvailable() && doNext; ) { if (DefaultMessageStore.this.getMessageStoreConfig().isDuplicationEnable() // - && this.reputFromOffset >= DefaultMessageStore.this.getConfirmOffset()) { + && this.reputFromOffset >= DefaultMessageStore.this.getConfirmOffset()) { break; } @@ -1645,7 +1609,7 @@ public class DefaultMessageStore implements MessageStore { for (int readSize = 0; readSize < result.getSize() && doNext; ) { DispatchRequest dispatchRequest = - DefaultMessageStore.this.commitLog.checkMessageAndReturnSize(result.getByteBuffer(), false, false); + DefaultMessageStore.this.commitLog.checkMessageAndReturnSize(result.getByteBuffer(), false, false); int size = dispatchRequest.getMsgSize(); if (dispatchRequest.isSuccess()) { @@ -1653,20 +1617,20 @@ public class DefaultMessageStore implements MessageStore { DefaultMessageStore.this.doDispatch(dispatchRequest); if (BrokerRole.SLAVE != DefaultMessageStore.this.getMessageStoreConfig().getBrokerRole() - && DefaultMessageStore.this.brokerConfig.isLongPollingEnable()) { + && DefaultMessageStore.this.brokerConfig.isLongPollingEnable()) { DefaultMessageStore.this.messageArrivingListener.arriving(dispatchRequest.getTopic(), - dispatchRequest.getQueueId(), dispatchRequest.getConsumeQueueOffset() + 1, - dispatchRequest.getTagsCode()); + dispatchRequest.getQueueId(), dispatchRequest.getConsumeQueueOffset() + 1, + dispatchRequest.getTagsCode()); } // FIXED BUG By shijia this.reputFromOffset += size; readSize += size; if (DefaultMessageStore.this.getMessageStoreConfig().getBrokerRole() == BrokerRole.SLAVE) { DefaultMessageStore.this.storeStatsService - .getSinglePutMessageTopicTimesTotal(dispatchRequest.getTopic()).incrementAndGet(); + .getSinglePutMessageTopicTimesTotal(dispatchRequest.getTopic()).incrementAndGet(); DefaultMessageStore.this.storeStatsService - .getSinglePutMessageTopicSizeTotal(dispatchRequest.getTopic()) - .addAndGet(dispatchRequest.getMsgSize()); + .getSinglePutMessageTopicSizeTotal(dispatchRequest.getTopic()) + .addAndGet(dispatchRequest.getMsgSize()); } } else if (size == 0) { this.reputFromOffset = DefaultMessageStore.this.commitLog.rollNextFile(this.reputFromOffset); @@ -1674,7 +1638,6 @@ public class DefaultMessageStore implements MessageStore { } } else if (!dispatchRequest.isSuccess()) { - if (size > 0) { log.error("[BUG]read total count not equals msg total size. reputFromOffset={}", reputFromOffset); this.reputFromOffset += size; @@ -1682,7 +1645,7 @@ public class DefaultMessageStore implements MessageStore { doNext = false; if (DefaultMessageStore.this.brokerConfig.getBrokerId() == MixAll.MASTER_ID) { log.error("[BUG]the master dispatch message to consume queue error, COMMITLOG OFFSET: {}", - this.reputFromOffset); + this.reputFromOffset); this.reputFromOffset += result.getSize() - readSize; } @@ -1698,7 +1661,6 @@ public class DefaultMessageStore implements MessageStore { } } - @Override public void run() { DefaultMessageStore.log.info(this.getServiceName() + " service started"); @@ -1715,13 +1677,11 @@ public class DefaultMessageStore implements MessageStore { DefaultMessageStore.log.info(this.getServiceName() + " service end"); } - @Override public String getServiceName() { return ReputMessageService.class.getSimpleName(); } - } public int remainTransientStoreBufferNumbs() { @@ -1733,7 +1693,6 @@ public class DefaultMessageStore implements MessageStore { return remainTransientStoreBufferNumbs() == 0; } - public void unlockMappedFile(final MappedFile mappedFile) { this.scheduledExecutorService.schedule(new Runnable() { @Override diff --git a/store/src/main/java/org/apache/rocketmq/store/DispatchRequest.java b/store/src/main/java/org/apache/rocketmq/store/DispatchRequest.java index d0855abd..b086aee5 100644 --- a/store/src/main/java/org/apache/rocketmq/store/DispatchRequest.java +++ b/store/src/main/java/org/apache/rocketmq/store/DispatchRequest.java @@ -31,19 +31,18 @@ public class DispatchRequest { private final int sysFlag; private final long preparedTransactionOffset; - public DispatchRequest( - final String topic, - final int queueId, - final long commitLogOffset, - final int msgSize, - final long tagsCode, - final long storeTimestamp, - final long consumeQueueOffset, - final String keys, - final String uniqKey, - final int sysFlag, - final long preparedTransactionOffset + final String topic, + final int queueId, + final long commitLogOffset, + final int msgSize, + final long tagsCode, + final long storeTimestamp, + final long consumeQueueOffset, + final String keys, + final String uniqKey, + final int sysFlag, + final long preparedTransactionOffset ) { this.topic = topic; this.queueId = queueId; @@ -108,57 +107,46 @@ public class DispatchRequest { this.success = success; } - public String getTopic() { return topic; } - public int getQueueId() { return queueId; } - public long getCommitLogOffset() { return commitLogOffset; } - public int getMsgSize() { return msgSize; } - public long getStoreTimestamp() { return storeTimestamp; } - public long getConsumeQueueOffset() { return consumeQueueOffset; } - public String getKeys() { return keys; } - public long getTagsCode() { return tagsCode; } - public int getSysFlag() { return sysFlag; } - public long getPreparedTransactionOffset() { return preparedTransactionOffset; } - public boolean isSuccess() { return success; } @@ -167,5 +155,4 @@ public class DispatchRequest { return uniqKey; } - } diff --git a/store/src/main/java/org/apache/rocketmq/store/GetMessageResult.java b/store/src/main/java/org/apache/rocketmq/store/GetMessageResult.java index 0f1ba8cd..b7d33f3a 100644 --- a/store/src/main/java/org/apache/rocketmq/store/GetMessageResult.java +++ b/store/src/main/java/org/apache/rocketmq/store/GetMessageResult.java @@ -6,27 +6,25 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.store; -import org.apache.rocketmq.store.stats.BrokerStatsManager; - import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; - +import org.apache.rocketmq.store.stats.BrokerStatsManager; public class GetMessageResult { private final List messageMapedList = - new ArrayList(100); + new ArrayList(100); private final List messageBufferList = new ArrayList(100); @@ -41,97 +39,79 @@ public class GetMessageResult { private int msgCount4Commercial = 0; - public GetMessageResult() { } - public GetMessageStatus getStatus() { return status; } - public void setStatus(GetMessageStatus status) { this.status = status; } - public long getNextBeginOffset() { return nextBeginOffset; } - public void setNextBeginOffset(long nextBeginOffset) { this.nextBeginOffset = nextBeginOffset; } - public long getMinOffset() { return minOffset; } - public void setMinOffset(long minOffset) { this.minOffset = minOffset; } - public long getMaxOffset() { return maxOffset; } - public void setMaxOffset(long maxOffset) { this.maxOffset = maxOffset; } - public List getMessageMapedList() { return messageMapedList; } - public List getMessageBufferList() { return messageBufferList; } - public void addMessage(final SelectMappedBufferResult mapedBuffer) { this.messageMapedList.add(mapedBuffer); this.messageBufferList.add(mapedBuffer.getByteBuffer()); this.bufferTotalSize += mapedBuffer.getSize(); - this.msgCount4Commercial += (int) Math.ceil( - mapedBuffer.getSize() / BrokerStatsManager.SIZE_PER_COUNT); + this.msgCount4Commercial += (int)Math.ceil( + mapedBuffer.getSize() / BrokerStatsManager.SIZE_PER_COUNT); } - public void release() { for (SelectMappedBufferResult select : this.messageMapedList) { select.release(); } } - public int getBufferTotalSize() { return bufferTotalSize; } - public void setBufferTotalSize(int bufferTotalSize) { this.bufferTotalSize = bufferTotalSize; } - public int getMessageCount() { return this.messageMapedList.size(); } - public boolean isSuggestPullingFromSlave() { return suggestPullingFromSlave; } - public void setSuggestPullingFromSlave(boolean suggestPullingFromSlave) { this.suggestPullingFromSlave = suggestPullingFromSlave; } @@ -144,12 +124,11 @@ public class GetMessageResult { this.msgCount4Commercial = msgCount4Commercial; } - @Override public String toString() { return "GetMessageResult [status=" + status + ", nextBeginOffset=" + nextBeginOffset + ", minOffset=" - + minOffset + ", maxOffset=" + maxOffset + ", bufferTotalSize=" + bufferTotalSize - + ", suggestPullingFromSlave=" + suggestPullingFromSlave + "]"; + + minOffset + ", maxOffset=" + maxOffset + ", bufferTotalSize=" + bufferTotalSize + + ", suggestPullingFromSlave=" + suggestPullingFromSlave + "]"; } } diff --git a/store/src/main/java/org/apache/rocketmq/store/GetMessageStatus.java b/store/src/main/java/org/apache/rocketmq/store/GetMessageStatus.java index 003d1d45..f512e126 100644 --- a/store/src/main/java/org/apache/rocketmq/store/GetMessageStatus.java +++ b/store/src/main/java/org/apache/rocketmq/store/GetMessageStatus.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.store; diff --git a/store/src/main/java/org/apache/rocketmq/store/MappedFile.java b/store/src/main/java/org/apache/rocketmq/store/MappedFile.java index ce5f5707..6803ec9f 100644 --- a/store/src/main/java/org/apache/rocketmq/store/MappedFile.java +++ b/store/src/main/java/org/apache/rocketmq/store/MappedFile.java @@ -16,16 +16,8 @@ */ package org.apache.rocketmq.store; -import org.apache.rocketmq.common.UtilAll; -import org.apache.rocketmq.common.constant.LoggerName; -import org.apache.rocketmq.store.config.FlushDiskType; -import org.apache.rocketmq.store.util.LibC; import com.sun.jna.NativeLong; import com.sun.jna.Pointer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import sun.nio.ch.DirectBuffer; - import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; @@ -39,7 +31,13 @@ import java.security.AccessController; import java.security.PrivilegedAction; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; - +import org.apache.rocketmq.common.UtilAll; +import org.apache.rocketmq.common.constant.LoggerName; +import org.apache.rocketmq.store.config.FlushDiskType; +import org.apache.rocketmq.store.util.LibC; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import sun.nio.ch.DirectBuffer; public class MappedFile extends ReferenceResource { public static final int OS_PAGE_SIZE = 1024 * 4; @@ -48,34 +46,23 @@ public class MappedFile extends ReferenceResource { private static final AtomicLong TOTAL_MAPED_VITUAL_MEMORY = new AtomicLong(0); private static final AtomicInteger TOTAL_MAPED_FILES = new AtomicInteger(0); - - private String fileName; - - private long fileFromOffset; - - protected int fileSize; - - private File file; - - private MappedByteBuffer mappedByteBuffer; - protected final AtomicInteger wrotePosition = new AtomicInteger(0); - - private final AtomicInteger flushedPosition = new AtomicInteger(0); //ADD BY ChenYang protected final AtomicInteger committedPosition = new AtomicInteger(0); - - + private final AtomicInteger flushedPosition = new AtomicInteger(0); + protected int fileSize; protected FileChannel fileChannel; - - private volatile long storeTimestamp = 0; - private boolean firstCreateInQueue = false; - /** * Message will put to here first, and then reput to FileChannel if writeBuffer is not null. */ protected ByteBuffer writeBuffer = null; protected TransientStorePool transientStorePool = null; + private String fileName; + private long fileFromOffset; + private File file; + private MappedByteBuffer mappedByteBuffer; + private volatile long storeTimestamp = 0; + private boolean firstCreateInQueue = false; public MappedFile() { } @@ -88,41 +75,6 @@ public class MappedFile extends ReferenceResource { init(fileName, fileSize, transientStorePool); } - public void init(final String fileName, final int fileSize, final TransientStorePool transientStorePool) throws IOException { - init(fileName, fileSize); - this.writeBuffer = transientStorePool.borrowBuffer(); - this.transientStorePool = transientStorePool; - } - - private void init(final String fileName, final int fileSize) throws IOException { - this.fileName = fileName; - this.fileSize = fileSize; - this.file = new File(fileName); - this.fileFromOffset = Long.parseLong(this.file.getName()); - boolean ok = false; - - ensureDirOK(this.file.getParent()); - - try { - this.fileChannel = new RandomAccessFile(this.file, "rw").getChannel(); - this.mappedByteBuffer = this.fileChannel.map(MapMode.READ_WRITE, 0, fileSize); - TOTAL_MAPED_VITUAL_MEMORY.addAndGet(fileSize); - TOTAL_MAPED_FILES.incrementAndGet(); - ok = true; - } catch (FileNotFoundException e) { - log.error("create file channel " + this.fileName + " Failed. ", e); - throw e; - } catch (IOException e) { - log.error("map file " + this.fileName + " Failed. ", e); - throw e; - } finally { - if (!ok && this.fileChannel != null) { - this.fileChannel.close(); - } - } - } - - public static void ensureDirOK(final String dirName) { if (dirName != null) { File f = new File(dirName); @@ -133,14 +85,12 @@ public class MappedFile extends ReferenceResource { } } - public static void clean(final ByteBuffer buffer) { if (buffer == null || !buffer.isDirect() || buffer.capacity() == 0) return; invoke(invoke(viewed(buffer), "cleaner"), "clean"); } - private static Object invoke(final Object target, final String methodName, final Class... args) { return AccessController.doPrivileged(new PrivilegedAction() { public Object run() { @@ -155,9 +105,8 @@ public class MappedFile extends ReferenceResource { }); } - private static Method method(Object target, String methodName, Class[] args) - throws NoSuchMethodException { + throws NoSuchMethodException { try { return target.getClass().getMethod(methodName, args); } catch (NoSuchMethodException e) { @@ -165,11 +114,9 @@ public class MappedFile extends ReferenceResource { } } - private static ByteBuffer viewed(ByteBuffer buffer) { String methodName = "viewedBuffer"; - Method[] methods = buffer.getClass().getMethods(); for (int i = 0; i < methods.length; i++) { if (methods[i].getName().equals("attachment")) { @@ -178,23 +125,54 @@ public class MappedFile extends ReferenceResource { } } - ByteBuffer viewedBuffer = (ByteBuffer) invoke(buffer, methodName); + ByteBuffer viewedBuffer = (ByteBuffer)invoke(buffer, methodName); if (viewedBuffer == null) return buffer; else return viewed(viewedBuffer); } - public static int getTotalmapedfiles() { return TOTAL_MAPED_FILES.get(); } - public static long getTotalMapedVitualMemory() { return TOTAL_MAPED_VITUAL_MEMORY.get(); } + public void init(final String fileName, final int fileSize, final TransientStorePool transientStorePool) throws IOException { + init(fileName, fileSize); + this.writeBuffer = transientStorePool.borrowBuffer(); + this.transientStorePool = transientStorePool; + } + + private void init(final String fileName, final int fileSize) throws IOException { + this.fileName = fileName; + this.fileSize = fileSize; + this.file = new File(fileName); + this.fileFromOffset = Long.parseLong(this.file.getName()); + boolean ok = false; + + ensureDirOK(this.file.getParent()); + + try { + this.fileChannel = new RandomAccessFile(this.file, "rw").getChannel(); + this.mappedByteBuffer = this.fileChannel.map(MapMode.READ_WRITE, 0, fileSize); + TOTAL_MAPED_VITUAL_MEMORY.addAndGet(fileSize); + TOTAL_MAPED_FILES.incrementAndGet(); + ok = true; + } catch (FileNotFoundException e) { + log.error("create file channel " + this.fileName + " Failed. ", e); + throw e; + } catch (IOException e) { + log.error("map file " + this.fileName + " Failed. ", e); + throw e; + } finally { + if (!ok && this.fileChannel != null) { + this.fileChannel.close(); + } + } + } public long getLastModifiedTimestamp() { return this.file.lastModified(); @@ -214,20 +192,18 @@ public class MappedFile extends ReferenceResource { int currentPos = this.wrotePosition.get(); - if (currentPos < this.fileSize) { ByteBuffer byteBuffer = writeBuffer != null ? writeBuffer.slice() : this.mappedByteBuffer.slice(); byteBuffer.position(currentPos); AppendMessageResult result = - cb.doAppend(this.getFileFromOffset(), byteBuffer, this.fileSize - currentPos, msg); + cb.doAppend(this.getFileFromOffset(), byteBuffer, this.fileSize - currentPos, msg); this.wrotePosition.addAndGet(result.getWroteBytes()); this.storeTimestamp = result.getStoreTimestamp(); return result; } - log.error("MappedFile.appendMessage return null, wrotePosition: " + currentPos + " fileSize: " - + this.fileSize); + + this.fileSize); return new AppendMessageResult(AppendMessageStatus.UNKNOWN_ERROR); } @@ -246,7 +222,6 @@ public class MappedFile extends ReferenceResource { public boolean appendMessage(final byte[] data) { int currentPos = this.wrotePosition.get(); - if ((currentPos + data.length) <= this.fileSize) { try { this.fileChannel.position(currentPos); @@ -262,11 +237,7 @@ public class MappedFile extends ReferenceResource { } /** - - * * @param flushLeastPages - - * * @return The current flushed position */ public int flush(final int flushLeastPages) { @@ -370,12 +341,10 @@ public class MappedFile extends ReferenceResource { return flushedPosition.get(); } - public void setFlushedPosition(int pos) { this.flushedPosition.set(pos); } - public boolean isFull() { return this.fileSize == this.wrotePosition.get(); } @@ -392,14 +361,13 @@ public class MappedFile extends ReferenceResource { return new SelectMappedBufferResult(this.fileFromOffset + pos, byteBufferNew, size, this); } else { log.warn("matched, but hold failed, request pos: " + pos + ", fileFromOffset: " - + this.fileFromOffset); + + this.fileFromOffset); } } else { log.warn("selectMappedBuffer request pos invalid, request pos: " + pos + ", size: " + size - + ", fileFromOffset: " + this.fileFromOffset); + + ", fileFromOffset: " + this.fileFromOffset); } - return null; } @@ -419,7 +387,6 @@ public class MappedFile extends ReferenceResource { } } - return null; } @@ -427,13 +394,13 @@ public class MappedFile extends ReferenceResource { public boolean cleanup(final long currentRef) { if (this.isAvailable()) { log.error("this file[REF:" + currentRef + "] " + this.fileName - + " have not shutdown, stop unmaping."); + + " have not shutdown, stop unmaping."); return false; } if (this.isCleanupOver()) { log.error("this file[REF:" + currentRef + "] " + this.fileName - + " have cleanup, do not do it again."); + + " have cleanup, do not do it again."); return true; } @@ -455,9 +422,9 @@ public class MappedFile extends ReferenceResource { long beginTime = System.currentTimeMillis(); boolean result = this.file.delete(); log.info("delete file[REF:" + this.getRefCount() + "] " + this.fileName - + (result ? " OK, " : " Failed, ") + "W:" + this.getWrotePosition() + " M:" - + this.getFlushedPosition() + ", " - + UtilAll.computeEclipseTimeMilliseconds(beginTime)); + + (result ? " OK, " : " Failed, ") + "W:" + this.getWrotePosition() + " M:" + + this.getFlushedPosition() + ", " + + UtilAll.computeEclipseTimeMilliseconds(beginTime)); } catch (Exception e) { log.warn("close file channel " + this.fileName + " Failed. ", e); } @@ -465,7 +432,7 @@ public class MappedFile extends ReferenceResource { return true; } else { log.warn("destroy maped file[REF:" + this.getRefCount() + "] " + this.fileName - + " Failed. cleanupOver: " + this.cleanupOver); + + " Failed. cleanupOver: " + this.cleanupOver); } return false; @@ -475,18 +442,17 @@ public class MappedFile extends ReferenceResource { return wrotePosition.get(); } + public void setWrotePosition(int pos) { + this.wrotePosition.set(pos); + } + /** - * * @return The max position which have valid data */ public int getReadPosition() { return this.writeBuffer == null ? this.wrotePosition.get() : this.committedPosition.get(); } - public void setWrotePosition(int pos) { - this.wrotePosition.set(pos); - } - public void setCommittedPosition(int pos) { this.committedPosition.set(pos); } @@ -497,7 +463,7 @@ public class MappedFile extends ReferenceResource { int flush = 0; long time = System.currentTimeMillis(); for (int i = 0, j = 0; i < this.fileSize; i += MappedFile.OS_PAGE_SIZE, j++) { - byteBuffer.put(i, (byte) 0); + byteBuffer.put(i, (byte)0); // force flush when flush disk type is sync if (type == FlushDiskType.SYNC_FLUSH) { if ((i / OS_PAGE_SIZE) - (flush / OS_PAGE_SIZE) >= pages) { @@ -521,11 +487,11 @@ public class MappedFile extends ReferenceResource { // force flush when prepare load finished if (type == FlushDiskType.SYNC_FLUSH) { log.info("mapped file worm up done, force to disk, mappedFile={}, costTime={}", - this.getFileName(), System.currentTimeMillis() - beginTime); + this.getFileName(), System.currentTimeMillis() - beginTime); mappedByteBuffer.force(); } log.info("mapped file worm up done. mappedFile={}, costTime={}", this.getFileName(), - System.currentTimeMillis() - beginTime); + System.currentTimeMillis() - beginTime); this.mlock(); } @@ -542,25 +508,21 @@ public class MappedFile extends ReferenceResource { return this.mappedByteBuffer.slice(); } - public long getStoreTimestamp() { return storeTimestamp; } - public boolean isFirstCreateInQueue() { return firstCreateInQueue; } - public void setFirstCreateInQueue(boolean firstCreateInQueue) { this.firstCreateInQueue = firstCreateInQueue; } - public void mlock() { final long beginTime = System.currentTimeMillis(); - final long address = ((DirectBuffer) (this.mappedByteBuffer)).address(); + final long address = ((DirectBuffer)(this.mappedByteBuffer)).address(); Pointer pointer = new Pointer(address); { int ret = LibC.INSTANCE.mlock(pointer, new NativeLong(this.fileSize)); @@ -575,7 +537,7 @@ public class MappedFile extends ReferenceResource { public void munlock() { final long beginTime = System.currentTimeMillis(); - final long address = ((DirectBuffer) (this.mappedByteBuffer)).address(); + final long address = ((DirectBuffer)(this.mappedByteBuffer)).address(); Pointer pointer = new Pointer(address); int ret = LibC.INSTANCE.munlock(pointer, new NativeLong(this.fileSize)); log.info("munlock {} {} {} ret = {} time consuming = {}", address, this.fileName, this.fileSize, ret, System.currentTimeMillis() - beginTime); diff --git a/store/src/main/java/org/apache/rocketmq/store/MappedFileQueue.java b/store/src/main/java/org/apache/rocketmq/store/MappedFileQueue.java index a208a074..49455c6b 100644 --- a/store/src/main/java/org/apache/rocketmq/store/MappedFileQueue.java +++ b/store/src/main/java/org/apache/rocketmq/store/MappedFileQueue.java @@ -16,17 +16,19 @@ */ package org.apache.rocketmq.store; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import java.util.concurrent.CopyOnWriteArrayList; import org.apache.rocketmq.common.UtilAll; import org.apache.rocketmq.common.constant.LoggerName; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.io.IOException; -import java.util.*; -import java.util.concurrent.CopyOnWriteArrayList; - - public class MappedFileQueue { private static final Logger log = LoggerFactory.getLogger(LoggerName.STORE_LOGGER_NAME); private static final Logger LOG_ERROR = LoggerFactory.getLogger(LoggerName.STORE_ERROR_LOGGER_NAME); @@ -46,15 +48,13 @@ public class MappedFileQueue { private volatile long storeTimestamp = 0; - public MappedFileQueue(final String storePath, int mappedFileSize, - AllocateMappedFileService allocateMappedFileService) { + AllocateMappedFileService allocateMappedFileService) { this.storePath = storePath; this.mappedFileSize = mappedFileSize; this.allocateMappedFileService = allocateMappedFileService; } - public void checkSelf() { if (!this.mappedFiles.isEmpty()) { @@ -66,7 +66,7 @@ public class MappedFileQueue { if (pre != null) { if (cur.getFileFromOffset() - pre.getFileFromOffset() != this.mappedFileSize) { LOG_ERROR.error("[BUG]The mappedFile queue's data is damaged, the adjacent mappedFile's offset don't match. pre file {}, cur file {}", - pre.getFileName(), cur.getFileName()); + pre.getFileName(), cur.getFileName()); } } pre = cur; @@ -74,7 +74,6 @@ public class MappedFileQueue { } } - public MappedFile getMappedFileByTime(final long timestamp) { Object[] mfs = this.copyMappedFiles(0); @@ -82,16 +81,15 @@ public class MappedFileQueue { return null; for (int i = 0; i < mfs.length; i++) { - MappedFile mappedFile = (MappedFile) mfs[i]; + MappedFile mappedFile = (MappedFile)mfs[i]; if (mappedFile.getLastModifiedTimestamp() >= timestamp) { return mappedFile; } } - return (MappedFile) mfs[mfs.length - 1]; + return (MappedFile)mfs[mfs.length - 1]; } - private Object[] copyMappedFiles(final int reservedMappedFiles) { Object[] mfs; @@ -103,7 +101,6 @@ public class MappedFileQueue { return mfs; } - public void truncateDirtyFiles(long offset) { List willRemoveFiles = new ArrayList(); @@ -111,9 +108,9 @@ public class MappedFileQueue { long fileTailOffset = file.getFileFromOffset() + this.mappedFileSize; if (fileTailOffset > offset) { if (offset >= file.getFileFromOffset()) { - file.setWrotePosition((int) (offset % this.mappedFileSize)); - file.setCommittedPosition((int) (offset % this.mappedFileSize)); - file.setFlushedPosition((int) (offset % this.mappedFileSize)); + file.setWrotePosition((int)(offset % this.mappedFileSize)); + file.setCommittedPosition((int)(offset % this.mappedFileSize)); + file.setFlushedPosition((int)(offset % this.mappedFileSize)); } else { file.destroy(1000); willRemoveFiles.add(file); @@ -124,7 +121,6 @@ public class MappedFileQueue { this.deleteExpiredFile(willRemoveFiles); } - private void deleteExpiredFile(List files) { if (!files.isEmpty()) { @@ -148,7 +144,6 @@ public class MappedFileQueue { } } - public boolean load() { File dir = new File(this.storePath); File[] files = dir.listFiles(); @@ -159,11 +154,10 @@ public class MappedFileQueue { if (file.length() != this.mappedFileSize) { log.warn(file + "\t" + file.length() - + " length not matched message store config value, ignore it"); + + " length not matched message store config value, ignore it"); return true; } - try { MappedFile mappedFile = new MappedFile(file.getPath(), mappedFileSize); @@ -182,7 +176,6 @@ public class MappedFileQueue { return true; } - public long howMuchFallBehind() { if (this.mappedFiles.isEmpty()) return 0; @@ -198,7 +191,6 @@ public class MappedFileQueue { return 0; } - public MappedFile getLastMappedFile(final long startOffset, boolean needCreate) { long createOffset = -1; MappedFile mappedFileLast = getLastMappedFile(); @@ -214,12 +206,12 @@ public class MappedFileQueue { if (createOffset != -1 && needCreate) { String nextFilePath = this.storePath + File.separator + UtilAll.offset2FileName(createOffset); String nextNextFilePath = this.storePath + File.separator - + UtilAll.offset2FileName(createOffset + this.mappedFileSize); + + UtilAll.offset2FileName(createOffset + this.mappedFileSize); MappedFile mappedFile = null; if (this.allocateMappedFileService != null) { mappedFile = this.allocateMappedFileService.putRequestAndReturnMappedFile(nextFilePath, - nextNextFilePath, this.mappedFileSize); + nextNextFilePath, this.mappedFileSize); } else { try { mappedFile = new MappedFile(nextFilePath, this.mappedFileSize); @@ -268,11 +260,12 @@ public class MappedFileQueue { if (mappedFileLast != null) { long lastOffset = mappedFileLast.getFileFromOffset() + - mappedFileLast.getWrotePosition(); + mappedFileLast.getWrotePosition(); long diff = lastOffset - offset; final int maxDiff = this.mappedFileSize * 2; - if (diff > maxDiff) return false; + if (diff > maxDiff) + return false; } ListIterator iterator = this.mappedFiles.listIterator(); @@ -280,7 +273,7 @@ public class MappedFileQueue { while (iterator.hasPrevious()) { mappedFileLast = iterator.previous(); if (offset >= mappedFileLast.getFileFromOffset()) { - int where = (int) (offset % mappedFileLast.getFileSize()); + int where = (int)(offset % mappedFileLast.getFileSize()); mappedFileLast.setFlushedPosition(where); mappedFileLast.setWrotePosition(where); mappedFileLast.setCommittedPosition(where); @@ -306,7 +299,6 @@ public class MappedFileQueue { return -1; } - public long getMaxOffset() { MappedFile mappedFile = getLastMappedFile(); if (mappedFile != null) { @@ -342,9 +334,9 @@ public class MappedFileQueue { } public int deleteExpiredFileByTime(final long expiredTime, - final int deleteFilesInterval, - final long intervalForcibly, - final boolean cleanImmediately) { + final int deleteFilesInterval, + final long intervalForcibly, + final boolean cleanImmediately) { Object[] mfs = this.copyMappedFiles(0); if (null == mfs) @@ -355,7 +347,7 @@ public class MappedFileQueue { List files = new ArrayList(); if (null != mfs) { for (int i = 0; i < mfsLength; i++) { - MappedFile mappedFile = (MappedFile) mfs[i]; + MappedFile mappedFile = (MappedFile)mfs[i]; long liveMaxTimestamp = mappedFile.getLastModifiedTimestamp() + expiredTime; if (System.currentTimeMillis() >= liveMaxTimestamp || cleanImmediately) { if (mappedFile.destroy(intervalForcibly)) { @@ -384,7 +376,6 @@ public class MappedFileQueue { return deleteCount; } - public int deleteExpiredFileByOffset(long offset, int unitSize) { Object[] mfs = this.copyMappedFiles(0); @@ -396,7 +387,7 @@ public class MappedFileQueue { for (int i = 0; i < mfsLength; i++) { boolean destroy; - MappedFile mappedFile = (MappedFile) mfs[i]; + MappedFile mappedFile = (MappedFile)mfs[i]; SelectMappedBufferResult result = mappedFile.selectMappedBuffer(this.mappedFileSize - unitSize); if (result != null) { long maxOffsetInLogicQueue = result.getByteBuffer().getLong(); @@ -404,7 +395,7 @@ public class MappedFileQueue { destroy = maxOffsetInLogicQueue < offset; if (destroy) { log.info("physic min offset " + offset + ", logics in current mappedFile max offset " - + maxOffsetInLogicQueue + ", delete it"); + + maxOffsetInLogicQueue + ", delete it"); } } else { log.warn("this being not executed forever."); @@ -425,7 +416,6 @@ public class MappedFileQueue { return deleteCount; } - public boolean flush(final int flushLeastPages) { boolean result = true; MappedFile mappedFile = this.findMappedFileByOffset(this.flushedWhere, false); @@ -467,10 +457,10 @@ public class MappedFileQueue { try { MappedFile mappedFile = this.getFirstMappedFile(); if (mappedFile != null) { - int index = (int) ((offset / this.mappedFileSize) - (mappedFile.getFileFromOffset() / this.mappedFileSize)); + int index = (int)((offset / this.mappedFileSize) - (mappedFile.getFileFromOffset() / this.mappedFileSize)); if (index < 0 || index >= this.mappedFiles.size()) { LOG_ERROR.warn("Offset for {} not matched. Request offset: {}, index: {}, " + - "mappedFileSize: {}, mappedFiles count: {}", + "mappedFileSize: {}, mappedFiles count: {}", mappedFile, offset, index, @@ -494,7 +484,6 @@ public class MappedFileQueue { return null; } - public MappedFile getFirstMappedFile() { MappedFile mappedFileFirst = null; @@ -515,14 +504,13 @@ public class MappedFileQueue { return findMappedFileByOffset(offset, false); } - public long getMappedMemorySize() { long size = 0; Object[] mfs = this.copyMappedFiles(0); if (mfs != null) { for (Object mf : mfs) { - if (((ReferenceResource) mf).isAvailable()) { + if (((ReferenceResource)mf).isAvailable()) { size += this.mappedFileSize; } } @@ -531,7 +519,6 @@ public class MappedFileQueue { return size; } - public boolean retryDeleteFirstFile(final long intervalForcibly) { MappedFile mappedFile = this.getFirstMappedFile(); if (mappedFile != null) { @@ -554,14 +541,12 @@ public class MappedFileQueue { return false; } - public void shutdown(final long intervalForcibly) { for (MappedFile mf : this.mappedFiles) { mf.shutdown(intervalForcibly); } } - public void destroy() { for (MappedFile mf : this.mappedFiles) { mf.destroy(1000 * 3); @@ -576,27 +561,22 @@ public class MappedFileQueue { } } - public long getFlushedWhere() { return flushedWhere; } - public void setFlushedWhere(long flushedWhere) { this.flushedWhere = flushedWhere; } - public long getStoreTimestamp() { return storeTimestamp; } - public List getMappedFiles() { return mappedFiles; } - public int getMappedFileSize() { return mappedFileSize; } diff --git a/store/src/main/java/org/apache/rocketmq/store/MessageArrivingListener.java b/store/src/main/java/org/apache/rocketmq/store/MessageArrivingListener.java index 25304b90..ebc57a74 100644 --- a/store/src/main/java/org/apache/rocketmq/store/MessageArrivingListener.java +++ b/store/src/main/java/org/apache/rocketmq/store/MessageArrivingListener.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.store; diff --git a/store/src/main/java/org/apache/rocketmq/store/MessageExtBrokerInner.java b/store/src/main/java/org/apache/rocketmq/store/MessageExtBrokerInner.java index dabb418d..4cbdacf2 100644 --- a/store/src/main/java/org/apache/rocketmq/store/MessageExtBrokerInner.java +++ b/store/src/main/java/org/apache/rocketmq/store/MessageExtBrokerInner.java @@ -6,20 +6,19 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.store; import org.apache.rocketmq.common.TopicFilterType; import org.apache.rocketmq.common.message.MessageExt; - public class MessageExtBrokerInner extends MessageExt { private static final long serialVersionUID = 7256001576878700634L; private String propertiesString; @@ -32,22 +31,18 @@ public class MessageExtBrokerInner extends MessageExt { return tags.hashCode(); } - public String getPropertiesString() { return propertiesString; } - public void setPropertiesString(String propertiesString) { this.propertiesString = propertiesString; } - public long getTagsCode() { return tagsCode; } - public void setTagsCode(long tagsCode) { this.tagsCode = tagsCode; } diff --git a/store/src/main/java/org/apache/rocketmq/store/MessageFilter.java b/store/src/main/java/org/apache/rocketmq/store/MessageFilter.java index cb7304e3..41228576 100644 --- a/store/src/main/java/org/apache/rocketmq/store/MessageFilter.java +++ b/store/src/main/java/org/apache/rocketmq/store/MessageFilter.java @@ -6,19 +6,18 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.store; import org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData; - public interface MessageFilter { boolean isMessageMatched(final SubscriptionData subscriptionData, final Long tagsCode); } diff --git a/store/src/main/java/org/apache/rocketmq/store/MessageStore.java b/store/src/main/java/org/apache/rocketmq/store/MessageStore.java index 328a700c..9ed74e61 100644 --- a/store/src/main/java/org/apache/rocketmq/store/MessageStore.java +++ b/store/src/main/java/org/apache/rocketmq/store/MessageStore.java @@ -6,114 +6,87 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.store; -import org.apache.rocketmq.common.message.MessageExt; -import org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData; - import java.util.HashMap; import java.util.Set; - +import org.apache.rocketmq.common.message.MessageExt; +import org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData; public interface MessageStore { boolean load(); - void start() throws Exception; - void shutdown(); - void destroy(); PutMessageResult putMessage(final MessageExtBrokerInner msg); - GetMessageResult getMessage(final String group, final String topic, final int queueId, - final long offset, final int maxMsgNums, final SubscriptionData subscriptionData); - + final long offset, final int maxMsgNums, final SubscriptionData subscriptionData); long getMaxOffsetInQuque(final String topic, final int queueId); - long getMinOffsetInQuque(final String topic, final int queueId); - long getCommitLogOffsetInQueue(final String topic, final int queueId, final long cqOffset); - long getOffsetInQueueByTime(final String topic, final int queueId, final long timestamp); - MessageExt lookMessageByOffset(final long commitLogOffset); - SelectMappedBufferResult selectOneMessageByOffset(final long commitLogOffset); - SelectMappedBufferResult selectOneMessageByOffset(final long commitLogOffset, final int msgSize); String getRunningDataInfo(); - HashMap getRuntimeInfo(); - long getMaxPhyOffset(); - long getMinPhyOffset(); - long getEarliestMessageTime(final String topic, final int queueId); - long getEarliestMessageTime(); + long getEarliestMessageTime(); long getMessageStoreTimeStamp(final String topic, final int queueId, final long offset); - long getMessageTotalInQueue(final String topic, final int queueId); SelectMappedBufferResult getCommitLogData(final long offset); - boolean appendToCommitLog(final long startOffset, final byte[] data); void excuteDeleteFilesManualy(); - QueryMessageResult queryMessage(final String topic, final String key, final int maxNum, - final long begin, final long end); - + final long begin, final long end); void updateHaMasterAddress(final String newAddr); - long slaveFallBehindMuch(); - long now(); - int cleanUnusedTopic(final Set topics); - void cleanExpiredConsumerQueue(); - boolean checkInDiskByConsumeOffset(final String topic, final int queueId, long consumeOffset); - long dispatchBehindBytes(); long flush(); diff --git a/store/src/main/java/org/apache/rocketmq/store/PutMessageResult.java b/store/src/main/java/org/apache/rocketmq/store/PutMessageResult.java index d36e7ee9..b6ede7e5 100644 --- a/store/src/main/java/org/apache/rocketmq/store/PutMessageResult.java +++ b/store/src/main/java/org/apache/rocketmq/store/PutMessageResult.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.store; @@ -20,42 +20,35 @@ public class PutMessageResult { private PutMessageStatus putMessageStatus; private AppendMessageResult appendMessageResult; - public PutMessageResult(PutMessageStatus putMessageStatus, AppendMessageResult appendMessageResult) { this.putMessageStatus = putMessageStatus; this.appendMessageResult = appendMessageResult; } - public boolean isOk() { return this.appendMessageResult != null && this.appendMessageResult.isOk(); } - public AppendMessageResult getAppendMessageResult() { return appendMessageResult; } - public void setAppendMessageResult(AppendMessageResult appendMessageResult) { this.appendMessageResult = appendMessageResult; } - public PutMessageStatus getPutMessageStatus() { return putMessageStatus; } - public void setPutMessageStatus(PutMessageStatus putMessageStatus) { this.putMessageStatus = putMessageStatus; } - @Override public String toString() { return "PutMessageResult [putMessageStatus=" + putMessageStatus + ", appendMessageResult=" - + appendMessageResult + "]"; + + appendMessageResult + "]"; } } diff --git a/store/src/main/java/org/apache/rocketmq/store/PutMessageStatus.java b/store/src/main/java/org/apache/rocketmq/store/PutMessageStatus.java index 1b6ec9ae..abab63f2 100644 --- a/store/src/main/java/org/apache/rocketmq/store/PutMessageStatus.java +++ b/store/src/main/java/org/apache/rocketmq/store/PutMessageStatus.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.store; diff --git a/store/src/main/java/org/apache/rocketmq/store/QueryMessageResult.java b/store/src/main/java/org/apache/rocketmq/store/QueryMessageResult.java index 1f300a20..8b45b7c4 100644 --- a/store/src/main/java/org/apache/rocketmq/store/QueryMessageResult.java +++ b/store/src/main/java/org/apache/rocketmq/store/QueryMessageResult.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.store; @@ -20,11 +20,10 @@ import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; - public class QueryMessageResult { private final List messageMapedList = - new ArrayList(100); + new ArrayList(100); private final List messageBufferList = new ArrayList(100); private long indexLastUpdateTimestamp; @@ -32,46 +31,38 @@ public class QueryMessageResult { private int bufferTotalSize = 0; - public void addMessage(final SelectMappedBufferResult mapedBuffer) { this.messageMapedList.add(mapedBuffer); this.messageBufferList.add(mapedBuffer.getByteBuffer()); this.bufferTotalSize += mapedBuffer.getSize(); } - public void release() { for (SelectMappedBufferResult select : this.messageMapedList) { select.release(); } } - public long getIndexLastUpdateTimestamp() { return indexLastUpdateTimestamp; } - public void setIndexLastUpdateTimestamp(long indexLastUpdateTimestamp) { this.indexLastUpdateTimestamp = indexLastUpdateTimestamp; } - public long getIndexLastUpdatePhyoffset() { return indexLastUpdatePhyoffset; } - public void setIndexLastUpdatePhyoffset(long indexLastUpdatePhyoffset) { this.indexLastUpdatePhyoffset = indexLastUpdatePhyoffset; } - public List getMessageBufferList() { return messageBufferList; } - public int getBufferTotalSize() { return bufferTotalSize; } diff --git a/store/src/main/java/org/apache/rocketmq/store/ReferenceResource.java b/store/src/main/java/org/apache/rocketmq/store/ReferenceResource.java index 65632324..b8b75dae 100644 --- a/store/src/main/java/org/apache/rocketmq/store/ReferenceResource.java +++ b/store/src/main/java/org/apache/rocketmq/store/ReferenceResource.java @@ -6,26 +6,24 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.store; import java.util.concurrent.atomic.AtomicLong; - public abstract class ReferenceResource { protected final AtomicLong refCount = new AtomicLong(1); protected volatile boolean available = true; protected volatile boolean cleanupOver = false; private volatile long firstShutdownTimestamp = 0; - public synchronized boolean hold() { if (this.isAvailable()) { if (this.refCount.getAndIncrement() > 0) { @@ -38,21 +36,16 @@ public abstract class ReferenceResource { return false; } - public boolean isAvailable() { return this.available; } - - public void shutdown(final long intervalForcibly) { if (this.available) { this.available = false; this.firstShutdownTimestamp = System.currentTimeMillis(); this.release(); - } - - else if (this.getRefCount() > 0) { + } else if (this.getRefCount() > 0) { if ((System.currentTimeMillis() - this.firstShutdownTimestamp) >= intervalForcibly) { this.refCount.set(-1000 - this.getRefCount()); this.release(); @@ -77,7 +70,6 @@ public abstract class ReferenceResource { public abstract boolean cleanup(final long currentRef); - public boolean isCleanupOver() { return this.refCount.get() <= 0 && this.cleanupOver; } diff --git a/store/src/main/java/org/apache/rocketmq/store/RunningFlags.java b/store/src/main/java/org/apache/rocketmq/store/RunningFlags.java index 8e7f29ff..52c269c6 100644 --- a/store/src/main/java/org/apache/rocketmq/store/RunningFlags.java +++ b/store/src/main/java/org/apache/rocketmq/store/RunningFlags.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.store; @@ -29,16 +29,13 @@ public class RunningFlags { private static final int DISK_FULL_BIT = 1 << 4; private volatile int flagBits = 0; - public RunningFlags() { } - public int getFlagBits() { return flagBits; } - public boolean getAndMakeReadable() { boolean result = this.isReadable(); if (!result) { @@ -47,7 +44,6 @@ public class RunningFlags { return result; } - public boolean isReadable() { if ((this.flagBits & NOT_READABLE_BIT) == 0) { return true; @@ -56,7 +52,6 @@ public class RunningFlags { return false; } - public boolean getAndMakeNotReadable() { boolean result = this.isReadable(); if (result) { @@ -65,7 +60,6 @@ public class RunningFlags { return result; } - public boolean getAndMakeWriteable() { boolean result = this.isWriteable(); if (!result) { @@ -74,7 +68,6 @@ public class RunningFlags { return result; } - public boolean isWriteable() { if ((this.flagBits & (NOT_WRITEABLE_BIT | WRITE_LOGICS_QUEUE_ERROR_BIT | DISK_FULL_BIT | WRITE_INDEX_FILE_ERROR_BIT)) == 0) { return true; @@ -83,7 +76,6 @@ public class RunningFlags { return false; } - public boolean getAndMakeNotWriteable() { boolean result = this.isWriteable(); if (result) { @@ -92,12 +84,10 @@ public class RunningFlags { return result; } - public void makeLogicsQueueError() { this.flagBits |= WRITE_LOGICS_QUEUE_ERROR_BIT; } - public boolean isLogicsQueueError() { if ((this.flagBits & WRITE_LOGICS_QUEUE_ERROR_BIT) == WRITE_LOGICS_QUEUE_ERROR_BIT) { return true; @@ -106,12 +96,10 @@ public class RunningFlags { return false; } - public void makeIndexFileError() { this.flagBits |= WRITE_INDEX_FILE_ERROR_BIT; } - public boolean isIndexFileError() { if ((this.flagBits & WRITE_INDEX_FILE_ERROR_BIT) == WRITE_INDEX_FILE_ERROR_BIT) { return true; @@ -120,14 +108,12 @@ public class RunningFlags { return false; } - public boolean getAndMakeDiskFull() { boolean result = !((this.flagBits & DISK_FULL_BIT) == DISK_FULL_BIT); this.flagBits |= DISK_FULL_BIT; return result; } - public boolean getAndMakeDiskOK() { boolean result = !((this.flagBits & DISK_FULL_BIT) == DISK_FULL_BIT); this.flagBits &= ~DISK_FULL_BIT; diff --git a/store/src/main/java/org/apache/rocketmq/store/SelectMappedBufferResult.java b/store/src/main/java/org/apache/rocketmq/store/SelectMappedBufferResult.java index 218f809b..ddd93835 100644 --- a/store/src/main/java/org/apache/rocketmq/store/SelectMappedBufferResult.java +++ b/store/src/main/java/org/apache/rocketmq/store/SelectMappedBufferResult.java @@ -6,19 +6,18 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.store; import java.nio.ByteBuffer; - public class SelectMappedBufferResult { private final long startOffset; @@ -29,7 +28,6 @@ public class SelectMappedBufferResult { private MappedFile mappedFile; - public SelectMappedBufferResult(long startOffset, ByteBuffer byteBuffer, int size, MappedFile mappedFile) { this.startOffset = startOffset; this.byteBuffer = byteBuffer; @@ -37,28 +35,23 @@ public class SelectMappedBufferResult { this.mappedFile = mappedFile; } - public ByteBuffer getByteBuffer() { return byteBuffer; } - public int getSize() { return size; } - public void setSize(final int s) { this.size = s; this.byteBuffer.limit(this.size); } - public MappedFile getMappedFile() { return mappedFile; } - // @Override // protected void finalize() { // if (this.mappedFile != null) { @@ -66,7 +59,6 @@ public class SelectMappedBufferResult { // } // } - public synchronized void release() { if (this.mappedFile != null) { this.mappedFile.release(); @@ -74,7 +66,6 @@ public class SelectMappedBufferResult { } } - public long getStartOffset() { return startOffset; } diff --git a/store/src/main/java/org/apache/rocketmq/store/StoreCheckpoint.java b/store/src/main/java/org/apache/rocketmq/store/StoreCheckpoint.java index 7fb51584..49a342ec 100644 --- a/store/src/main/java/org/apache/rocketmq/store/StoreCheckpoint.java +++ b/store/src/main/java/org/apache/rocketmq/store/StoreCheckpoint.java @@ -6,28 +6,26 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.store; -import org.apache.rocketmq.common.UtilAll; -import org.apache.rocketmq.common.constant.LoggerName; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; import java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; import java.nio.channels.FileChannel.MapMode; - +import org.apache.rocketmq.common.UtilAll; +import org.apache.rocketmq.common.constant.LoggerName; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class StoreCheckpoint { private static final Logger log = LoggerFactory.getLogger(LoggerName.STORE_LOGGER_NAME); @@ -38,7 +36,6 @@ public class StoreCheckpoint { private volatile long logicsMsgTimestamp = 0; private volatile long indexMsgTimestamp = 0; - public StoreCheckpoint(final String scpPath) throws IOException { File file = new File(scpPath); MappedFile.ensureDirOK(file.getParent()); @@ -55,17 +52,16 @@ public class StoreCheckpoint { this.indexMsgTimestamp = this.mappedByteBuffer.getLong(16); log.info("store checkpoint file physicMsgTimestamp " + this.physicMsgTimestamp + ", " - + UtilAll.timeMillisToHumanString(this.physicMsgTimestamp)); + + UtilAll.timeMillisToHumanString(this.physicMsgTimestamp)); log.info("store checkpoint file logicsMsgTimestamp " + this.logicsMsgTimestamp + ", " - + UtilAll.timeMillisToHumanString(this.logicsMsgTimestamp)); + + UtilAll.timeMillisToHumanString(this.logicsMsgTimestamp)); log.info("store checkpoint file indexMsgTimestamp " + this.indexMsgTimestamp + ", " - + UtilAll.timeMillisToHumanString(this.indexMsgTimestamp)); + + UtilAll.timeMillisToHumanString(this.indexMsgTimestamp)); } else { log.info("store checkpoint file not exists, " + scpPath); } } - public void shutdown() { this.flush(); @@ -79,7 +75,6 @@ public class StoreCheckpoint { } } - public void flush() { this.mappedByteBuffer.putLong(0, this.physicMsgTimestamp); this.mappedByteBuffer.putLong(8, this.logicsMsgTimestamp); @@ -87,36 +82,29 @@ public class StoreCheckpoint { this.mappedByteBuffer.force(); } - public long getPhysicMsgTimestamp() { return physicMsgTimestamp; } - public void setPhysicMsgTimestamp(long physicMsgTimestamp) { this.physicMsgTimestamp = physicMsgTimestamp; } - public long getLogicsMsgTimestamp() { return logicsMsgTimestamp; } - public void setLogicsMsgTimestamp(long logicsMsgTimestamp) { this.logicsMsgTimestamp = logicsMsgTimestamp; } - public long getMinTimestampIndex() { return Math.min(this.getMinTimestamp(), this.indexMsgTimestamp); } - public long getMinTimestamp() { long min = Math.min(this.physicMsgTimestamp, this.logicsMsgTimestamp); - // fixed https://github.org/apache/rocketmqissues/467 min -= 1000 * 3; if (min < 0) @@ -125,12 +113,10 @@ public class StoreCheckpoint { return min; } - public long getIndexMsgTimestamp() { return indexMsgTimestamp; } - public void setIndexMsgTimestamp(long indexMsgTimestamp) { this.indexMsgTimestamp = indexMsgTimestamp; } diff --git a/store/src/main/java/org/apache/rocketmq/store/StoreStatsService.java b/store/src/main/java/org/apache/rocketmq/store/StoreStatsService.java index 91b70fb9..d4ba1479 100644 --- a/store/src/main/java/org/apache/rocketmq/store/StoreStatsService.java +++ b/store/src/main/java/org/apache/rocketmq/store/StoreStatsService.java @@ -16,11 +16,6 @@ */ package org.apache.rocketmq.store; -import org.apache.rocketmq.common.ServiceThread; -import org.apache.rocketmq.common.constant.LoggerName; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.text.MessageFormat; import java.util.HashMap; import java.util.LinkedList; @@ -28,7 +23,10 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.locks.ReentrantLock; - +import org.apache.rocketmq.common.ServiceThread; +import org.apache.rocketmq.common.constant.LoggerName; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class StoreStatsService extends ServiceThread { private static final Logger log = LoggerFactory.getLogger(LoggerName.STORE_LOGGER_NAME); @@ -36,7 +34,7 @@ public class StoreStatsService extends ServiceThread { private static final int FREQUENCY_OF_SAMPLING = 1000; private static final int MAX_RECORDS_OF_SAMPLING = 60 * 10; - private static final String[] PUT_MESSAGE_ENTIRE_TIME_MAX_DESC = new String[]{ + private static final String[] PUT_MESSAGE_ENTIRE_TIME_MAX_DESC = new String[] { "[<=0ms]", "[0~10ms]", "[10~50ms]", "[50~100ms]", "[100~200ms]", "[200~500ms]", "[500ms~1s]", "[1~2s]", "[2~3s]", "[3~4s]", "[4~5s]", "[5~10s]", "[10s~]", }; @@ -45,9 +43,9 @@ public class StoreStatsService extends ServiceThread { private final AtomicLong putMessageFailedTimes = new AtomicLong(0); private final Map putMessageTopicTimesTotal = - new ConcurrentHashMap(128); + new ConcurrentHashMap(128); private final Map putMessageTopicSizeTotal = - new ConcurrentHashMap(128); + new ConcurrentHashMap(128); private final AtomicLong getMessageTimesTotalFound = new AtomicLong(0); private final AtomicLong getMessageTransferedMsgCount = new AtomicLong(0); @@ -71,7 +69,6 @@ public class StoreStatsService extends ServiceThread { private ReentrantLock lockSampling = new ReentrantLock(); private long lastPrintTimestamp = System.currentTimeMillis(); - public StoreStatsService() { this.initPutMessageDistributeTime(); } @@ -96,7 +93,8 @@ public class StoreStatsService extends ServiceThread { public void setPutMessageEntireTimeMax(long value) { final AtomicLong[] times = this.putMessageDistributeTime; - if (null == times) return; + if (null == times) + return; // us if (value <= 0) { @@ -140,37 +138,32 @@ public class StoreStatsService extends ServiceThread { if (value > this.putMessageEntireTimeMax) { this.lockPut.lock(); this.putMessageEntireTimeMax = - value > this.putMessageEntireTimeMax ? value : this.putMessageEntireTimeMax; + value > this.putMessageEntireTimeMax ? value : this.putMessageEntireTimeMax; this.lockPut.unlock(); } } - public long getGetMessageEntireTimeMax() { return getMessageEntireTimeMax; } - public void setGetMessageEntireTimeMax(long value) { if (value > this.getMessageEntireTimeMax) { this.lockGet.lock(); this.getMessageEntireTimeMax = - value > this.getMessageEntireTimeMax ? value : this.getMessageEntireTimeMax; + value > this.getMessageEntireTimeMax ? value : this.getMessageEntireTimeMax; this.lockGet.unlock(); } } - public long getDispatchMaxBuffer() { return dispatchMaxBuffer; } - public void setDispatchMaxBuffer(long value) { this.dispatchMaxBuffer = value > this.dispatchMaxBuffer ? value : this.dispatchMaxBuffer; } - @Override public String toString() { final StringBuilder sb = new StringBuilder(1024); @@ -184,9 +177,9 @@ public class StoreStatsService extends ServiceThread { sb.append("\tputMessageTimesTotal: " + totalTimes + "\r\n"); sb.append("\tputMessageSizeTotal: " + this.getPutMessageSizeTotal() + "\r\n"); sb.append("\tputMessageDistributeTime: " + this.getPutMessageDistributeTimeStringInfo(totalTimes) - + "\r\n"); + + "\r\n"); sb.append("\tputMessageAverageSize: " + (this.getPutMessageSizeTotal() / totalTimes.doubleValue()) - + "\r\n"); + + "\r\n"); sb.append("\tdispatchMaxBuffer: " + this.dispatchMaxBuffer + "\r\n"); sb.append("\tgetMessageEntireTimeMax: " + this.getMessageEntireTimeMax + "\r\n"); sb.append("\tputTps: " + this.getPutTps() + "\r\n"); @@ -218,7 +211,7 @@ public class StoreStatsService extends ServiceThread { long hours = (time % day) / hour; long minutes = (time % hour) / minute; long seconds = (time % minute) / second; - return messageFormat.format(new Long[]{days, hours, minutes, seconds}); + return messageFormat.format(new Long[] {days, hours, minutes, seconds}); } public long getPutMessageSizeTotal() { @@ -239,11 +232,9 @@ public class StoreStatsService extends ServiceThread { sb.append(this.getPutTps(10)); sb.append(" "); - sb.append(this.getPutTps(60)); sb.append(" "); - sb.append(this.getPutTps(600)); return sb.toString(); @@ -255,11 +246,9 @@ public class StoreStatsService extends ServiceThread { sb.append(this.getGetFoundTps(10)); sb.append(" "); - sb.append(this.getGetFoundTps(60)); sb.append(" "); - sb.append(this.getGetFoundTps(600)); return sb.toString(); @@ -271,11 +260,9 @@ public class StoreStatsService extends ServiceThread { sb.append(this.getGetMissTps(10)); sb.append(" "); - sb.append(this.getGetMissTps(60)); sb.append(" "); - sb.append(this.getGetMissTps(600)); return sb.toString(); @@ -287,11 +274,9 @@ public class StoreStatsService extends ServiceThread { sb.append(this.getGetTotalTps(10)); sb.append(" "); - sb.append(this.getGetTotalTps(60)); sb.append(" "); - sb.append(this.getGetTotalTps(600)); return sb.toString(); @@ -303,11 +288,9 @@ public class StoreStatsService extends ServiceThread { sb.append(this.getGetTransferedTps(10)); sb.append(" "); - sb.append(this.getGetTransferedTps(60)); sb.append(" "); - sb.append(this.getGetTransferedTps(600)); return sb.toString(); @@ -315,7 +298,8 @@ public class StoreStatsService extends ServiceThread { private String putMessageDistributeTimeToString() { final AtomicLong[] times = this.putMessageDistributeTime; - if (null == times) return null; + if (null == times) + return null; final StringBuilder sb = new StringBuilder(); for (int i = 0; i < times.length; i++) { @@ -352,7 +336,7 @@ public class StoreStatsService extends ServiceThread { if (this.getTimesFoundList.size() > time) { CallSnapshot lastBefore = - this.getTimesFoundList.get(this.getTimesFoundList.size() - (time + 1)); + this.getTimesFoundList.get(this.getTimesFoundList.size() - (time + 1)); result += CallSnapshot.getTPS(lastBefore, last); } } finally { @@ -370,7 +354,7 @@ public class StoreStatsService extends ServiceThread { if (this.getTimesMissList.size() > time) { CallSnapshot lastBefore = - this.getTimesMissList.get(this.getTimesMissList.size() - (time + 1)); + this.getTimesMissList.get(this.getTimesMissList.size() - (time + 1)); result += CallSnapshot.getTPS(lastBefore, last); } @@ -391,7 +375,7 @@ public class StoreStatsService extends ServiceThread { if (this.getTimesFoundList.size() > time) { CallSnapshot lastBefore = - this.getTimesFoundList.get(this.getTimesFoundList.size() - (time + 1)); + this.getTimesFoundList.get(this.getTimesFoundList.size() - (time + 1)); found = CallSnapshot.getTPS(lastBefore, last); } } @@ -400,7 +384,7 @@ public class StoreStatsService extends ServiceThread { if (this.getTimesMissList.size() > time) { CallSnapshot lastBefore = - this.getTimesMissList.get(this.getTimesMissList.size() - (time + 1)); + this.getTimesMissList.get(this.getTimesMissList.size() - (time + 1)); miss = CallSnapshot.getTPS(lastBefore, last); } } @@ -420,7 +404,7 @@ public class StoreStatsService extends ServiceThread { if (this.transferedMsgCountList.size() > time) { CallSnapshot lastBefore = - this.transferedMsgCountList.get(this.transferedMsgCountList.size() - (time + 1)); + this.transferedMsgCountList.get(this.transferedMsgCountList.size() - (time + 1)); result += CallSnapshot.getTPS(lastBefore, last); } @@ -445,9 +429,9 @@ public class StoreStatsService extends ServiceThread { result.put("putMessageTimesTotal", String.valueOf(totalTimes)); result.put("putMessageSizeTotal", String.valueOf(this.getPutMessageSizeTotal())); result.put("putMessageDistributeTime", - String.valueOf(this.getPutMessageDistributeTimeStringInfo(totalTimes))); + String.valueOf(this.getPutMessageDistributeTimeStringInfo(totalTimes))); result.put("putMessageAverageSize", - String.valueOf(this.getPutMessageSizeTotal() / totalTimes.doubleValue())); + String.valueOf(this.getPutMessageSizeTotal() / totalTimes.doubleValue())); result.put("dispatchMaxBuffer", String.valueOf(this.dispatchMaxBuffer)); result.put("getMessageEntireTimeMax", String.valueOf(this.getMessageEntireTimeMax)); result.put("putTps", String.valueOf(this.getPutTps())); @@ -491,19 +475,19 @@ public class StoreStatsService extends ServiceThread { } this.getTimesFoundList.add(new CallSnapshot(System.currentTimeMillis(), - this.getMessageTimesTotalFound.get())); + this.getMessageTimesTotalFound.get())); if (this.getTimesFoundList.size() > (MAX_RECORDS_OF_SAMPLING + 1)) { this.getTimesFoundList.removeFirst(); } this.getTimesMissList.add(new CallSnapshot(System.currentTimeMillis(), - this.getMessageTimesTotalMiss.get())); + this.getMessageTimesTotalMiss.get())); if (this.getTimesMissList.size() > (MAX_RECORDS_OF_SAMPLING + 1)) { this.getTimesMissList.removeFirst(); } this.transferedMsgCountList.add(new CallSnapshot(System.currentTimeMillis(), - this.getMessageTransferedMsgCount.get())); + this.getMessageTransferedMsgCount.get())); if (this.transferedMsgCountList.size() > (MAX_RECORDS_OF_SAMPLING + 1)) { this.transferedMsgCountList.removeFirst(); } @@ -518,14 +502,15 @@ public class StoreStatsService extends ServiceThread { this.lastPrintTimestamp = System.currentTimeMillis(); log.info("[STORETPS] put_tps {} get_found_tps {} get_miss_tps {} get_transfered_tps {}", - this.getPutTps(printTPSInterval), - this.getGetFoundTps(printTPSInterval), - this.getGetMissTps(printTPSInterval), - this.getGetTransferedTps(printTPSInterval) + this.getPutTps(printTPSInterval), + this.getGetFoundTps(printTPSInterval), + this.getGetMissTps(printTPSInterval), + this.getGetTransferedTps(printTPSInterval) ); final AtomicLong[] times = this.initPutMessageDistributeTime(); - if (null == times) return; + if (null == times) + return; final StringBuilder sb = new StringBuilder(); long totalPut = 0; @@ -544,22 +529,18 @@ public class StoreStatsService extends ServiceThread { return getMessageTimesTotalFound; } - public AtomicLong getGetMessageTimesTotalMiss() { return getMessageTimesTotalMiss; } - public AtomicLong getGetMessageTransferedMsgCount() { return getMessageTransferedMsgCount; } - public AtomicLong getPutMessageFailedTimes() { return putMessageFailedTimes; } - public AtomicLong getSinglePutMessageTopicSizeTotal(String topic) { AtomicLong rs = putMessageTopicSizeTotal.get(topic); if (null == rs) { @@ -569,7 +550,6 @@ public class StoreStatsService extends ServiceThread { return rs; } - public AtomicLong getSinglePutMessageTopicTimesTotal(String topic) { AtomicLong rs = putMessageTopicTimesTotal.get(topic); if (null == rs) { @@ -579,12 +559,10 @@ public class StoreStatsService extends ServiceThread { return rs; } - public Map getPutMessageTopicTimesTotal() { return putMessageTopicTimesTotal; } - public Map getPutMessageTopicSizeTotal() { return putMessageTopicSizeTotal; } @@ -593,13 +571,11 @@ public class StoreStatsService extends ServiceThread { public final long timestamp; public final long callTimesTotal; - public CallSnapshot(long timestamp, long callTimesTotal) { this.timestamp = timestamp; this.callTimesTotal = callTimesTotal; } - public static double getTPS(final CallSnapshot begin, final CallSnapshot end) { long total = end.callTimesTotal - begin.callTimesTotal; Long time = end.timestamp - begin.timestamp; diff --git a/store/src/main/java/org/apache/rocketmq/store/StoreUtil.java b/store/src/main/java/org/apache/rocketmq/store/StoreUtil.java index d44720c4..9cd71454 100644 --- a/store/src/main/java/org/apache/rocketmq/store/StoreUtil.java +++ b/store/src/main/java/org/apache/rocketmq/store/StoreUtil.java @@ -6,33 +6,31 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.store; import java.lang.management.ManagementFactory; import java.lang.management.OperatingSystemMXBean; - /** * */ public class StoreUtil { public static final long TOTAL_PHYSICAL_MEMORY_SIZE = getTotalPhysicalMemorySize(); - @SuppressWarnings("restriction") public static long getTotalPhysicalMemorySize() { long physicalTotal = 1024 * 1024 * 1024 * 24; OperatingSystemMXBean osmxb = ManagementFactory.getOperatingSystemMXBean(); if (osmxb instanceof com.sun.management.OperatingSystemMXBean) { - physicalTotal = ((com.sun.management.OperatingSystemMXBean) osmxb).getTotalPhysicalMemorySize(); + physicalTotal = ((com.sun.management.OperatingSystemMXBean)osmxb).getTotalPhysicalMemorySize(); } return physicalTotal; diff --git a/store/src/main/java/org/apache/rocketmq/store/TransientStorePool.java b/store/src/main/java/org/apache/rocketmq/store/TransientStorePool.java index bd5b629d..3e332baf 100644 --- a/store/src/main/java/org/apache/rocketmq/store/TransientStorePool.java +++ b/store/src/main/java/org/apache/rocketmq/store/TransientStorePool.java @@ -16,19 +16,18 @@ */ package org.apache.rocketmq.store; +import com.sun.jna.NativeLong; +import com.sun.jna.Pointer; +import java.nio.ByteBuffer; +import java.util.Deque; +import java.util.concurrent.ConcurrentLinkedDeque; import org.apache.rocketmq.common.constant.LoggerName; import org.apache.rocketmq.store.config.MessageStoreConfig; import org.apache.rocketmq.store.util.LibC; -import com.sun.jna.NativeLong; -import com.sun.jna.Pointer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import sun.nio.ch.DirectBuffer; -import java.nio.ByteBuffer; -import java.util.Deque; -import java.util.concurrent.ConcurrentLinkedDeque; - public class TransientStorePool { private static final Logger log = LoggerFactory.getLogger(LoggerName.STORE_LOGGER_NAME); @@ -51,7 +50,7 @@ public class TransientStorePool { for (int i = 0; i < poolSize; i++) { ByteBuffer byteBuffer = ByteBuffer.allocateDirect(fileSize); - final long address = ((DirectBuffer) byteBuffer).address(); + final long address = ((DirectBuffer)byteBuffer).address(); Pointer pointer = new Pointer(address); LibC.INSTANCE.mlock(pointer, new NativeLong(fileSize)); @@ -61,7 +60,7 @@ public class TransientStorePool { public void destroy() { for (ByteBuffer byteBuffer : availableBuffers) { - final long address = ((DirectBuffer) byteBuffer).address(); + final long address = ((DirectBuffer)byteBuffer).address(); Pointer pointer = new Pointer(address); LibC.INSTANCE.munlock(pointer, new NativeLong(fileSize)); } diff --git a/store/src/main/java/org/apache/rocketmq/store/config/BrokerRole.java b/store/src/main/java/org/apache/rocketmq/store/config/BrokerRole.java index 6ebb723e..bebacc90 100644 --- a/store/src/main/java/org/apache/rocketmq/store/config/BrokerRole.java +++ b/store/src/main/java/org/apache/rocketmq/store/config/BrokerRole.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.store.config; diff --git a/store/src/main/java/org/apache/rocketmq/store/config/FlushDiskType.java b/store/src/main/java/org/apache/rocketmq/store/config/FlushDiskType.java index 02b0cedb..6a52a674 100644 --- a/store/src/main/java/org/apache/rocketmq/store/config/FlushDiskType.java +++ b/store/src/main/java/org/apache/rocketmq/store/config/FlushDiskType.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.store.config; diff --git a/store/src/main/java/org/apache/rocketmq/store/config/MessageStoreConfig.java b/store/src/main/java/org/apache/rocketmq/store/config/MessageStoreConfig.java index 205adec4..d1e2bfec 100644 --- a/store/src/main/java/org/apache/rocketmq/store/config/MessageStoreConfig.java +++ b/store/src/main/java/org/apache/rocketmq/store/config/MessageStoreConfig.java @@ -6,22 +6,20 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.store.config; +import java.io.File; import org.apache.rocketmq.common.annotation.ImportantField; import org.apache.rocketmq.store.ConsumeQueue; -import java.io.File; - - public class MessageStoreConfig { //The root directory in which the log data is kept @ImportantField @@ -30,7 +28,7 @@ public class MessageStoreConfig { //The directory in which the commitlog is kept @ImportantField private String storePathCommitLog = System.getProperty("user.home") + File.separator + "store" - + File.separator + "commitlog"; + + File.separator + "commitlog"; // CommitLog file size,default is 1G private int mapedFileSizeCommitLog = 1024 * 1024 * 1024; @@ -133,7 +131,7 @@ public class MessageStoreConfig { private boolean transientStorePoolEnable = false; private int transientStorePoolSize = 5; private boolean fastFailIfNoBufferInStorePool = false; - + public boolean isDebugLockEnable() { return debugLockEnable; } @@ -170,119 +168,96 @@ public class MessageStoreConfig { return warmMapedFileEnable; } - public void setWarmMapedFileEnable(boolean warmMapedFileEnable) { this.warmMapedFileEnable = warmMapedFileEnable; } - public int getMapedFileSizeCommitLog() { return mapedFileSizeCommitLog; } - public void setMapedFileSizeCommitLog(int mapedFileSizeCommitLog) { this.mapedFileSizeCommitLog = mapedFileSizeCommitLog; } - public int getMapedFileSizeConsumeQueue() { - int factor = (int) Math.ceil(this.mapedFileSizeConsumeQueue / (ConsumeQueue.CQ_STORE_UNIT_SIZE * 1.0)); - return (int) (factor * ConsumeQueue.CQ_STORE_UNIT_SIZE); + int factor = (int)Math.ceil(this.mapedFileSizeConsumeQueue / (ConsumeQueue.CQ_STORE_UNIT_SIZE * 1.0)); + return (int)(factor * ConsumeQueue.CQ_STORE_UNIT_SIZE); } - public void setMapedFileSizeConsumeQueue(int mapedFileSizeConsumeQueue) { this.mapedFileSizeConsumeQueue = mapedFileSizeConsumeQueue; } - public int getFlushIntervalCommitLog() { return flushIntervalCommitLog; } - public void setFlushIntervalCommitLog(int flushIntervalCommitLog) { this.flushIntervalCommitLog = flushIntervalCommitLog; } - public int getFlushIntervalConsumeQueue() { return flushIntervalConsumeQueue; } - public void setFlushIntervalConsumeQueue(int flushIntervalConsumeQueue) { this.flushIntervalConsumeQueue = flushIntervalConsumeQueue; } - public int getPutMsgIndexHightWater() { return putMsgIndexHightWater; } - public void setPutMsgIndexHightWater(int putMsgIndexHightWater) { this.putMsgIndexHightWater = putMsgIndexHightWater; } - public int getCleanResourceInterval() { return cleanResourceInterval; } - public void setCleanResourceInterval(int cleanResourceInterval) { this.cleanResourceInterval = cleanResourceInterval; } - public int getMaxMessageSize() { return maxMessageSize; } - public void setMaxMessageSize(int maxMessageSize) { this.maxMessageSize = maxMessageSize; } - public boolean isCheckCRCOnRecover() { return checkCRCOnRecover; } - public boolean getCheckCRCOnRecover() { return checkCRCOnRecover; } - public void setCheckCRCOnRecover(boolean checkCRCOnRecover) { this.checkCRCOnRecover = checkCRCOnRecover; } - public String getStorePathCommitLog() { return storePathCommitLog; } - public void setStorePathCommitLog(String storePathCommitLog) { this.storePathCommitLog = storePathCommitLog; } - public String getDeleteWhen() { return deleteWhen; } - public void setDeleteWhen(String deleteWhen) { this.deleteWhen = deleteWhen; } - public int getDiskMaxUsedSpaceRatio() { if (this.diskMaxUsedSpaceRatio < 10) return 10; @@ -293,361 +268,294 @@ public class MessageStoreConfig { return diskMaxUsedSpaceRatio; } - public void setDiskMaxUsedSpaceRatio(int diskMaxUsedSpaceRatio) { this.diskMaxUsedSpaceRatio = diskMaxUsedSpaceRatio; } - public int getDeleteCommitLogFilesInterval() { return deleteCommitLogFilesInterval; } - public void setDeleteCommitLogFilesInterval(int deleteCommitLogFilesInterval) { this.deleteCommitLogFilesInterval = deleteCommitLogFilesInterval; } - public int getDeleteConsumeQueueFilesInterval() { return deleteConsumeQueueFilesInterval; } - public void setDeleteConsumeQueueFilesInterval(int deleteConsumeQueueFilesInterval) { this.deleteConsumeQueueFilesInterval = deleteConsumeQueueFilesInterval; } - public int getMaxTransferBytesOnMessageInMemory() { return maxTransferBytesOnMessageInMemory; } - public void setMaxTransferBytesOnMessageInMemory(int maxTransferBytesOnMessageInMemory) { this.maxTransferBytesOnMessageInMemory = maxTransferBytesOnMessageInMemory; } - public int getMaxTransferCountOnMessageInMemory() { return maxTransferCountOnMessageInMemory; } - public void setMaxTransferCountOnMessageInMemory(int maxTransferCountOnMessageInMemory) { this.maxTransferCountOnMessageInMemory = maxTransferCountOnMessageInMemory; } - public int getMaxTransferBytesOnMessageInDisk() { return maxTransferBytesOnMessageInDisk; } - public void setMaxTransferBytesOnMessageInDisk(int maxTransferBytesOnMessageInDisk) { this.maxTransferBytesOnMessageInDisk = maxTransferBytesOnMessageInDisk; } - public int getMaxTransferCountOnMessageInDisk() { return maxTransferCountOnMessageInDisk; } - public void setMaxTransferCountOnMessageInDisk(int maxTransferCountOnMessageInDisk) { this.maxTransferCountOnMessageInDisk = maxTransferCountOnMessageInDisk; } - public int getFlushCommitLogLeastPages() { return flushCommitLogLeastPages; } - public void setFlushCommitLogLeastPages(int flushCommitLogLeastPages) { this.flushCommitLogLeastPages = flushCommitLogLeastPages; } - public int getFlushConsumeQueueLeastPages() { return flushConsumeQueueLeastPages; } - public void setFlushConsumeQueueLeastPages(int flushConsumeQueueLeastPages) { this.flushConsumeQueueLeastPages = flushConsumeQueueLeastPages; } - public int getFlushCommitLogThoroughInterval() { return flushCommitLogThoroughInterval; } - public void setFlushCommitLogThoroughInterval(int flushCommitLogThoroughInterval) { this.flushCommitLogThoroughInterval = flushCommitLogThoroughInterval; } - public int getFlushConsumeQueueThoroughInterval() { return flushConsumeQueueThoroughInterval; } - public void setFlushConsumeQueueThoroughInterval(int flushConsumeQueueThoroughInterval) { this.flushConsumeQueueThoroughInterval = flushConsumeQueueThoroughInterval; } - public int getDestroyMapedFileIntervalForcibly() { return destroyMapedFileIntervalForcibly; } - public void setDestroyMapedFileIntervalForcibly(int destroyMapedFileIntervalForcibly) { this.destroyMapedFileIntervalForcibly = destroyMapedFileIntervalForcibly; } - public int getFileReservedTime() { return fileReservedTime; } - public void setFileReservedTime(int fileReservedTime) { this.fileReservedTime = fileReservedTime; } - public int getRedeleteHangedFileInterval() { return redeleteHangedFileInterval; } - public void setRedeleteHangedFileInterval(int redeleteHangedFileInterval) { this.redeleteHangedFileInterval = redeleteHangedFileInterval; } - public int getAccessMessageInMemoryMaxRatio() { return accessMessageInMemoryMaxRatio; } - public void setAccessMessageInMemoryMaxRatio(int accessMessageInMemoryMaxRatio) { this.accessMessageInMemoryMaxRatio = accessMessageInMemoryMaxRatio; } - public boolean isMessageIndexEnable() { return messageIndexEnable; } - public void setMessageIndexEnable(boolean messageIndexEnable) { this.messageIndexEnable = messageIndexEnable; } - public int getMaxHashSlotNum() { return maxHashSlotNum; } - public void setMaxHashSlotNum(int maxHashSlotNum) { this.maxHashSlotNum = maxHashSlotNum; } - public int getMaxIndexNum() { return maxIndexNum; } - public void setMaxIndexNum(int maxIndexNum) { this.maxIndexNum = maxIndexNum; } - public int getMaxMsgsNumBatch() { return maxMsgsNumBatch; } - public void setMaxMsgsNumBatch(int maxMsgsNumBatch) { this.maxMsgsNumBatch = maxMsgsNumBatch; } - public int getHaListenPort() { return haListenPort; } - public void setHaListenPort(int haListenPort) { this.haListenPort = haListenPort; } - public int getHaSendHeartbeatInterval() { return haSendHeartbeatInterval; } - public void setHaSendHeartbeatInterval(int haSendHeartbeatInterval) { this.haSendHeartbeatInterval = haSendHeartbeatInterval; } - public int getHaHousekeepingInterval() { return haHousekeepingInterval; } - public void setHaHousekeepingInterval(int haHousekeepingInterval) { this.haHousekeepingInterval = haHousekeepingInterval; } - public BrokerRole getBrokerRole() { return brokerRole; } - public void setBrokerRole(BrokerRole brokerRole) { - this.brokerRole = brokerRole; - } - public void setBrokerRole(String brokerRole) { this.brokerRole = BrokerRole.valueOf(brokerRole); } + public void setBrokerRole(BrokerRole brokerRole) { + this.brokerRole = brokerRole; + } + public int getHaTransferBatchSize() { return haTransferBatchSize; } - public void setHaTransferBatchSize(int haTransferBatchSize) { this.haTransferBatchSize = haTransferBatchSize; } - public int getHaSlaveFallbehindMax() { return haSlaveFallbehindMax; } - public void setHaSlaveFallbehindMax(int haSlaveFallbehindMax) { this.haSlaveFallbehindMax = haSlaveFallbehindMax; } - public FlushDiskType getFlushDiskType() { return flushDiskType; } - public void setFlushDiskType(FlushDiskType flushDiskType) { - this.flushDiskType = flushDiskType; - } - public void setFlushDiskType(String type) { this.flushDiskType = FlushDiskType.valueOf(type); } + public void setFlushDiskType(FlushDiskType flushDiskType) { + this.flushDiskType = flushDiskType; + } + public int getSyncFlushTimeout() { return syncFlushTimeout; } - public void setSyncFlushTimeout(int syncFlushTimeout) { this.syncFlushTimeout = syncFlushTimeout; } - public String getHaMasterAddress() { return haMasterAddress; } - public void setHaMasterAddress(String haMasterAddress) { this.haMasterAddress = haMasterAddress; } - public String getMessageDelayLevel() { return messageDelayLevel; } - public void setMessageDelayLevel(String messageDelayLevel) { this.messageDelayLevel = messageDelayLevel; } - public long getFlushDelayOffsetInterval() { return flushDelayOffsetInterval; } - public void setFlushDelayOffsetInterval(long flushDelayOffsetInterval) { this.flushDelayOffsetInterval = flushDelayOffsetInterval; } - public boolean isCleanFileForciblyEnable() { return cleanFileForciblyEnable; } - public void setCleanFileForciblyEnable(boolean cleanFileForciblyEnable) { this.cleanFileForciblyEnable = cleanFileForciblyEnable; } - public boolean isMessageIndexSafe() { return messageIndexSafe; } - public void setMessageIndexSafe(boolean messageIndexSafe) { this.messageIndexSafe = messageIndexSafe; } - public boolean isFlushCommitLogTimed() { return flushCommitLogTimed; } - public void setFlushCommitLogTimed(boolean flushCommitLogTimed) { this.flushCommitLogTimed = flushCommitLogTimed; } - public String getStorePathRootDir() { return storePathRootDir; } - public void setStorePathRootDir(String storePathRootDir) { this.storePathRootDir = storePathRootDir; } - public int getFlushLeastPagesWhenWarmMapedFile() { return flushLeastPagesWhenWarmMapedFile; } - public void setFlushLeastPagesWhenWarmMapedFile(int flushLeastPagesWhenWarmMapedFile) { this.flushLeastPagesWhenWarmMapedFile = flushLeastPagesWhenWarmMapedFile; } - public boolean isOffsetCheckInSlave() { return offsetCheckInSlave; } - public void setOffsetCheckInSlave(boolean offsetCheckInSlave) { this.offsetCheckInSlave = offsetCheckInSlave; } @@ -666,7 +574,7 @@ public class MessageStoreConfig { */ public boolean isTransientStorePoolEnable() { return transientStorePoolEnable && FlushDiskType.ASYNC_FLUSH == getFlushDiskType() - && BrokerRole.SLAVE != getBrokerRole(); + && BrokerRole.SLAVE != getBrokerRole(); } public void setTransientStorePoolEnable(final boolean transientStorePoolEnable) { diff --git a/store/src/main/java/org/apache/rocketmq/store/config/StorePathConfigHelper.java b/store/src/main/java/org/apache/rocketmq/store/config/StorePathConfigHelper.java index 87964364..d1cd7ded 100644 --- a/store/src/main/java/org/apache/rocketmq/store/config/StorePathConfigHelper.java +++ b/store/src/main/java/org/apache/rocketmq/store/config/StorePathConfigHelper.java @@ -6,51 +6,44 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.store.config; import java.io.File; - public class StorePathConfigHelper { public static String getStorePathConsumeQueue(final String rootDir) { return rootDir + File.separator + "consumequeue"; } - public static String getStorePathIndex(final String rootDir) { return rootDir + File.separator + "index"; } - public static String getStoreCheckpoint(final String rootDir) { return rootDir + File.separator + "checkpoint"; } - public static String getAbortFile(final String rootDir) { return rootDir + File.separator + "abort"; } - public static String getDelayOffsetStorePath(final String rootDir) { return rootDir + File.separator + "config" + File.separator + "delayOffset.json"; } - public static String getTranStateTableStorePath(final String rootDir) { return rootDir + File.separator + "transaction" + File.separator + "statetable"; } - public static String getTranRedoLogStorePath(final String rootDir) { return rootDir + File.separator + "transaction" + File.separator + "redolog"; } diff --git a/store/src/main/java/org/apache/rocketmq/store/ha/HAConnection.java b/store/src/main/java/org/apache/rocketmq/store/ha/HAConnection.java index e8965d3b..a601e810 100644 --- a/store/src/main/java/org/apache/rocketmq/store/ha/HAConnection.java +++ b/store/src/main/java/org/apache/rocketmq/store/ha/HAConnection.java @@ -6,16 +6,21 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.store.ha; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.SelectionKey; +import java.nio.channels.Selector; +import java.nio.channels.SocketChannel; import org.apache.rocketmq.common.ServiceThread; import org.apache.rocketmq.common.constant.LoggerName; import org.apache.rocketmq.remoting.common.RemotingUtil; @@ -23,13 +28,6 @@ import org.apache.rocketmq.store.SelectMappedBufferResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.channels.SelectionKey; -import java.nio.channels.Selector; -import java.nio.channels.SocketChannel; - - public class HAConnection { private static final Logger log = LoggerFactory.getLogger(LoggerName.STORE_LOGGER_NAME); private final HAService haService; @@ -41,7 +39,6 @@ public class HAConnection { private volatile long slaveRequestOffset = -1; private volatile long slaveAckOffset = -1; - public HAConnection(final HAService haService, final SocketChannel socketChannel) throws IOException { this.haService = haService; this.socketChannel = socketChannel; @@ -56,20 +53,17 @@ public class HAConnection { this.haService.getConnectionCount().incrementAndGet(); } - public void start() { this.readSocketService.start(); this.writeSocketService.start(); } - public void shutdown() { this.writeSocketService.shutdown(true); this.readSocketService.shutdown(true); this.close(); } - public void close() { if (this.socketChannel != null) { try { @@ -80,7 +74,6 @@ public class HAConnection { } } - public SocketChannel getSocketChannel() { return socketChannel; } @@ -97,7 +90,6 @@ public class HAConnection { private int processPostion = 0; private volatile long lastReadTimestamp = System.currentTimeMillis(); - public ReadSocketService(final SocketChannel socketChannel) throws IOException { this.selector = RemotingUtil.openSelector(); this.socketChannel = socketChannel; @@ -105,7 +97,6 @@ public class HAConnection { this.thread.setDaemon(true); } - @Override public void run() { HAConnection.log.info(this.getServiceName() + " service started"); @@ -119,7 +110,6 @@ public class HAConnection { break; } - long interval = HAConnection.this.haService.getDefaultMessageStore().getSystemClock().now() - this.lastReadTimestamp; if (interval > HAConnection.this.haService.getDefaultMessageStore().getMessageStoreConfig().getHaHousekeepingInterval()) { log.warn("ha housekeeping, found this connection[" + HAConnection.this.clientAddr + "] expired, " + interval); @@ -135,10 +125,8 @@ public class HAConnection { writeSocketService.makeStop(); - haService.removeConnection(HAConnection.this); - HAConnection.this.haService.getConnectionCount().decrementAndGet(); SelectionKey sk = this.socketChannel.keyFor(this.selector); @@ -180,14 +168,12 @@ public class HAConnection { long readOffset = this.byteBufferRead.getLong(pos - 8); this.processPostion = pos; - HAConnection.this.slaveAckOffset = readOffset; if (HAConnection.this.slaveRequestOffset < 0) { HAConnection.this.slaveRequestOffset = readOffset; log.info("slave[" + HAConnection.this.clientAddr + "] request offset " + readOffset); } - HAConnection.this.haService.notifyTransferSome(HAConnection.this.slaveAckOffset); } } else if (readSize == 0) { @@ -223,7 +209,6 @@ public class HAConnection { private boolean lastWriteOver = true; private long lastWriteTimestamp = System.currentTimeMillis(); - public WriteSocketService(final SocketChannel socketChannel) throws IOException { this.selector = RemotingUtil.openSelector(); this.socketChannel = socketChannel; @@ -231,7 +216,6 @@ public class HAConnection { this.thread.setDaemon(true); } - @Override public void run() { HAConnection.log.info(this.getServiceName() + " service started"); @@ -245,15 +229,13 @@ public class HAConnection { continue; } - - if (-1 == this.nextTransferFromWhere) { if (0 == HAConnection.this.slaveRequestOffset) { long masterOffset = HAConnection.this.haService.getDefaultMessageStore().getCommitLog().getMaxOffset(); masterOffset = - masterOffset - - (masterOffset % HAConnection.this.haService.getDefaultMessageStore().getMessageStoreConfig() - .getMapedFileSizeCommitLog()); + masterOffset + - (masterOffset % HAConnection.this.haService.getDefaultMessageStore().getMessageStoreConfig() + .getMapedFileSizeCommitLog()); if (masterOffset < 0) { masterOffset = 0; @@ -265,16 +247,16 @@ public class HAConnection { } log.info("master transfer data from " + this.nextTransferFromWhere + " to slave[" + HAConnection.this.clientAddr - + "], and slave request " + HAConnection.this.slaveRequestOffset); + + "], and slave request " + HAConnection.this.slaveRequestOffset); } if (this.lastWriteOver) { long interval = - HAConnection.this.haService.getDefaultMessageStore().getSystemClock().now() - this.lastWriteTimestamp; + HAConnection.this.haService.getDefaultMessageStore().getSystemClock().now() - this.lastWriteTimestamp; if (interval > HAConnection.this.haService.getDefaultMessageStore().getMessageStoreConfig() - .getHaSendHeartbeatInterval()) { + .getHaSendHeartbeatInterval()) { // Build Header this.byteBufferHeader.position(0); @@ -287,16 +269,14 @@ public class HAConnection { if (!this.lastWriteOver) continue; } - } - - else { + } else { this.lastWriteOver = this.transferData(); if (!this.lastWriteOver) continue; } SelectMappedBufferResult selectResult = - HAConnection.this.haService.getDefaultMessageStore().getCommitLogData(this.nextTransferFromWhere); + HAConnection.this.haService.getDefaultMessageStore().getCommitLogData(this.nextTransferFromWhere); if (selectResult != null) { int size = selectResult.getSize(); if (size > HAConnection.this.haService.getDefaultMessageStore().getMessageStoreConfig().getHaTransferBatchSize()) { @@ -328,7 +308,6 @@ public class HAConnection { } } - if (this.selectMappedBufferResult != null) { this.selectMappedBufferResult.release(); } @@ -337,7 +316,6 @@ public class HAConnection { readSocketService.makeStop(); - haService.removeConnection(HAConnection.this); SelectionKey sk = this.socketChannel.keyFor(this.selector); @@ -355,7 +333,6 @@ public class HAConnection { HAConnection.log.info(this.getServiceName() + " service end"); } - /** */ @@ -409,13 +386,11 @@ public class HAConnection { return result; } - @Override public String getServiceName() { return WriteSocketService.class.getSimpleName(); } - @Override public void shutdown() { super.shutdown(); diff --git a/store/src/main/java/org/apache/rocketmq/store/ha/HAService.java b/store/src/main/java/org/apache/rocketmq/store/ha/HAService.java index 84a3af66..82fe8f4f 100644 --- a/store/src/main/java/org/apache/rocketmq/store/ha/HAService.java +++ b/store/src/main/java/org/apache/rocketmq/store/ha/HAService.java @@ -16,19 +16,15 @@ */ package org.apache.rocketmq.store.ha; -import org.apache.rocketmq.common.ServiceThread; -import org.apache.rocketmq.common.constant.LoggerName; -import org.apache.rocketmq.remoting.common.RemotingUtil; -import org.apache.rocketmq.store.DefaultMessageStore; -import org.apache.rocketmq.store.CommitLog; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.io.IOException; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.nio.ByteBuffer; -import java.nio.channels.*; +import java.nio.channels.ClosedChannelException; +import java.nio.channels.SelectionKey; +import java.nio.channels.Selector; +import java.nio.channels.ServerSocketChannel; +import java.nio.channels.SocketChannel; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; @@ -36,7 +32,13 @@ import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; - +import org.apache.rocketmq.common.ServiceThread; +import org.apache.rocketmq.common.constant.LoggerName; +import org.apache.rocketmq.remoting.common.RemotingUtil; +import org.apache.rocketmq.store.CommitLog; +import org.apache.rocketmq.store.DefaultMessageStore; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class HAService { private static final Logger log = LoggerFactory.getLogger(LoggerName.STORE_LOGGER_NAME); @@ -56,38 +58,33 @@ public class HAService { private final HAClient haClient; - public HAService(final DefaultMessageStore defaultMessageStore) throws IOException { this.defaultMessageStore = defaultMessageStore; this.acceptSocketService = - new AcceptSocketService(defaultMessageStore.getMessageStoreConfig().getHaListenPort()); + new AcceptSocketService(defaultMessageStore.getMessageStoreConfig().getHaListenPort()); this.groupTransferService = new GroupTransferService(); this.haClient = new HAClient(); } - public void updateMasterAddress(final String newAddr) { if (this.haClient != null) { this.haClient.updateMasterAddress(newAddr); } } - public void putRequest(final CommitLog.GroupCommitRequest request) { this.groupTransferService.putRequest(request); } - public boolean isSlaveOK(final long masterPutWhere) { boolean result = this.connectionCount.get() > 0; result = - result - && ((masterPutWhere - this.push2SlaveMaxOffset.get()) < this.defaultMessageStore - .getMessageStoreConfig().getHaSlaveFallbehindMax()); + result + && ((masterPutWhere - this.push2SlaveMaxOffset.get()) < this.defaultMessageStore + .getMessageStoreConfig().getHaSlaveFallbehindMax()); return result; } - /** */ @@ -103,12 +100,10 @@ public class HAService { } } - public AtomicInteger getConnectionCount() { return connectionCount; } - // public void notifyTransferSome() { // this.groupTransferService.notifyTransferSome(); // } @@ -120,21 +115,18 @@ public class HAService { this.haClient.start(); } - public void addConnection(final HAConnection conn) { synchronized (this.connectionList) { this.connectionList.add(conn); } } - public void removeConnection(final HAConnection conn) { synchronized (this.connectionList) { this.connectionList.remove(conn); } } - public void shutdown() { this.haClient.shutdown(); this.acceptSocketService.shutdown(true); @@ -142,7 +134,6 @@ public class HAService { this.groupTransferService.shutdown(); } - public void destroyConnections() { synchronized (this.connectionList) { for (HAConnection c : this.connectionList) { @@ -153,12 +144,10 @@ public class HAService { } } - public DefaultMessageStore getDefaultMessageStore() { return defaultMessageStore; } - public WaitNotifyObject getWaitNotifyObject() { return waitNotifyObject; } @@ -171,9 +160,9 @@ public class HAService { * Listens to slave connections to create {@link HAConnection}. */ class AcceptSocketService extends ServiceThread { + private final SocketAddress socketAddressListen; private ServerSocketChannel serverSocketChannel; private Selector selector; - private final SocketAddress socketAddressListen; public AcceptSocketService(final int port) { this.socketAddressListen = new InetSocketAddress(port); @@ -181,6 +170,7 @@ public class HAService { /** * Starts listening to slave connections. + * * @throws Exception If fails. */ public void beginAccept() throws Exception { @@ -199,8 +189,7 @@ public class HAService { try { this.serverSocketChannel.close(); this.selector.close(); - } - catch (IOException e) { + } catch (IOException e) { log.error("AcceptSocketService shutdown exception", e); } } @@ -218,11 +207,11 @@ public class HAService { if (selected != null) { for (SelectionKey k : selected) { if ((k.readyOps() & SelectionKey.OP_ACCEPT) != 0) { - SocketChannel sc = ((ServerSocketChannel) k.channel()).accept(); + SocketChannel sc = ((ServerSocketChannel)k.channel()).accept(); if (sc != null) { HAService.log.info("HAService receive new connection, " - + sc.socket().getRemoteSocketAddress()); + + sc.socket().getRemoteSocketAddress()); try { HAConnection conn = new HAConnection(HAService.this, sc); @@ -264,7 +253,6 @@ public class HAService { private volatile List requestsWrite = new ArrayList<>(); private volatile List requestsRead = new ArrayList<>(); - public void putRequest(final CommitLog.GroupCommitRequest request) { synchronized (this) { this.requestsWrite.add(request); @@ -274,19 +262,16 @@ public class HAService { } } - public void notifyTransferSome() { this.notifyTransferObject.wakeup(); } - private void swapRequests() { List tmp = this.requestsWrite; this.requestsWrite = this.requestsRead; this.requestsRead = tmp; } - private void doWaitTransfer() { if (!this.requestsRead.isEmpty()) { for (CommitLog.GroupCommitRequest req : this.requestsRead) { @@ -307,7 +292,6 @@ public class HAService { } } - public void run() { log.info(this.getServiceName() + " service started"); @@ -323,13 +307,11 @@ public class HAService { log.info(this.getServiceName() + " service end"); } - @Override protected void onWaitEnd() { this.swapRequests(); } - @Override public String getServiceName() { return GroupTransferService.class.getSimpleName(); @@ -349,12 +331,10 @@ public class HAService { private ByteBuffer byteBufferRead = ByteBuffer.allocate(READ_MAX_BUFFER_SIZE); private ByteBuffer byteBufferBackup = ByteBuffer.allocate(READ_MAX_BUFFER_SIZE); - public HAClient() throws IOException { this.selector = RemotingUtil.openSelector(); } - public void updateMasterAddress(final String newAddr) { String currentAddr = this.masterAddress.get(); if (currentAddr == null || !currentAddr.equals(newAddr)) { @@ -363,17 +343,15 @@ public class HAService { } } - private boolean isTimeToReportOffset() { long interval = - HAService.this.defaultMessageStore.getSystemClock().now() - this.lastWriteTimestamp; + HAService.this.defaultMessageStore.getSystemClock().now() - this.lastWriteTimestamp; boolean needHeart = interval > HAService.this.defaultMessageStore.getMessageStoreConfig() - .getHaSendHeartbeatInterval(); + .getHaSendHeartbeatInterval(); return needHeart; } - private boolean reportSlaveMaxOffset(final long maxOffset) { this.reportOffset.position(0); this.reportOffset.limit(8); @@ -386,7 +364,7 @@ public class HAService { this.socketChannel.write(this.reportOffset); } catch (IOException e) { log.error(this.getServiceName() - + "reportSlaveMaxOffset this.socketChannel.write exception", e); + + "reportSlaveMaxOffset this.socketChannel.write exception", e); return false; } } @@ -394,7 +372,6 @@ public class HAService { return !this.reportOffset.hasRemaining(); } - // private void reallocateByteBuffer() { // ByteBuffer bb = ByteBuffer.allocate(READ_MAX_BUFFER_SIZE); // int remain = this.byteBufferRead.limit() - this.dispatchPostion; @@ -423,14 +400,12 @@ public class HAService { this.dispatchPostion = 0; } - private void swapByteBuffer() { ByteBuffer tmp = this.byteBufferRead; this.byteBufferRead = this.byteBufferBackup; this.byteBufferBackup = tmp; } - private boolean processReadEvent() { int readSizeZeroTimes = 0; while (this.byteBufferRead.hasRemaining()) { @@ -462,7 +437,6 @@ public class HAService { return true; } - private boolean dispatchReadRequest() { final int msgHeaderSize = 8 + 4; // phyoffset + size int readSocketPos = this.byteBufferRead.position(); @@ -475,22 +449,19 @@ public class HAService { long slavePhyOffset = HAService.this.defaultMessageStore.getMaxPhyOffset(); - if (slavePhyOffset != 0) { if (slavePhyOffset != masterPhyOffset) { log.error("master pushed offset not equal the max phy offset in slave, SLAVE: " - + slavePhyOffset + " MASTER: " + masterPhyOffset); + + slavePhyOffset + " MASTER: " + masterPhyOffset); return false; } } - if (diff >= (msgHeaderSize + bodySize)) { byte[] bodyData = new byte[bodySize]; this.byteBufferRead.position(this.dispatchPostion + msgHeaderSize); this.byteBufferRead.get(bodyData); - HAService.this.defaultMessageStore.appendToCommitLog(masterPhyOffset, bodyData); this.byteBufferRead.position(readSocketPos); @@ -514,7 +485,6 @@ public class HAService { return true; } - private boolean reportSlaveMaxOffsetPlus() { boolean result = true; long currentPhyOffset = HAService.this.defaultMessageStore.getMaxPhyOffset(); @@ -530,7 +500,6 @@ public class HAService { return result; } - private boolean connectMaster() throws ClosedChannelException { if (null == socketChannel) { String addr = this.masterAddress.get(); @@ -553,7 +522,6 @@ public class HAService { return this.socketChannel != null; } - private void closeMaster() { if (null != this.socketChannel) { try { @@ -581,7 +549,6 @@ public class HAService { } } - @Override public void run() { log.info(this.getServiceName() + " service started"); @@ -597,10 +564,8 @@ public class HAService { } } - this.selector.select(1000); - boolean ok = this.processReadEvent(); if (!ok) { this.closeMaster(); @@ -610,14 +575,13 @@ public class HAService { continue; } - long interval = - HAService.this.getDefaultMessageStore().getSystemClock().now() - - this.lastWriteTimestamp; + HAService.this.getDefaultMessageStore().getSystemClock().now() + - this.lastWriteTimestamp; if (interval > HAService.this.getDefaultMessageStore().getMessageStoreConfig() - .getHaHousekeepingInterval()) { + .getHaHousekeepingInterval()) { log.warn("HAClient, housekeeping, found this connection[" + this.masterAddress - + "] expired, " + interval); + + "] expired, " + interval); this.closeMaster(); log.warn("HAClient, master not response some time, so close connection"); } @@ -633,7 +597,6 @@ public class HAService { log.info(this.getServiceName() + " service end"); } - // // private void disableWriteFlag() { // if (this.socketChannel != null) { diff --git a/store/src/main/java/org/apache/rocketmq/store/ha/WaitNotifyObject.java b/store/src/main/java/org/apache/rocketmq/store/ha/WaitNotifyObject.java index c059e102..a96af5eb 100644 --- a/store/src/main/java/org/apache/rocketmq/store/ha/WaitNotifyObject.java +++ b/store/src/main/java/org/apache/rocketmq/store/ha/WaitNotifyObject.java @@ -6,27 +6,25 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.store.ha; import java.util.HashMap; - public class WaitNotifyObject { protected final HashMap waitingThreadTable = - new HashMap(16); + new HashMap(16); protected volatile boolean hasNotified = false; - public void wakeup() { synchronized (this) { if (!this.hasNotified) { @@ -36,7 +34,6 @@ public class WaitNotifyObject { } } - protected void waitForRunning(long interval) { synchronized (this) { if (this.hasNotified) { @@ -56,7 +53,6 @@ public class WaitNotifyObject { } } - protected void onWaitEnd() { } diff --git a/store/src/main/java/org/apache/rocketmq/store/index/IndexFile.java b/store/src/main/java/org/apache/rocketmq/store/index/IndexFile.java index d6a223db..de1a31de 100644 --- a/store/src/main/java/org/apache/rocketmq/store/index/IndexFile.java +++ b/store/src/main/java/org/apache/rocketmq/store/index/IndexFile.java @@ -6,28 +6,26 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.store.index; -import org.apache.rocketmq.common.constant.LoggerName; -import org.apache.rocketmq.store.MappedFile; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.io.IOException; import java.nio.ByteBuffer; import java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; import java.nio.channels.FileLock; import java.util.List; - +import org.apache.rocketmq.common.constant.LoggerName; +import org.apache.rocketmq.store.MappedFile; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class IndexFile { private static final Logger log = LoggerFactory.getLogger(LoggerName.STORE_LOGGER_NAME); @@ -41,11 +39,10 @@ public class IndexFile { private final MappedByteBuffer mappedByteBuffer; private final IndexHeader indexHeader; - public IndexFile(final String fileName, final int hashSlotNum, final int indexNum, - final long endPhyOffset, final long endTimestamp) throws IOException { + final long endPhyOffset, final long endTimestamp) throws IOException { int fileTotalSize = - IndexHeader.INDEX_HEADER_SIZE + (hashSlotNum * hashSlotSize) + (indexNum * indexSize); + IndexHeader.INDEX_HEADER_SIZE + (hashSlotNum * hashSlotSize) + (indexNum * indexSize); this.mappedFile = new MappedFile(fileName, fileTotalSize); this.fileChannel = this.mappedFile.getFileChannel(); this.mappedByteBuffer = this.mappedFile.getMappedByteBuffer(); @@ -66,17 +63,14 @@ public class IndexFile { } } - public String getFileName() { return this.mappedFile.getFileName(); } - public void load() { this.indexHeader.load(); } - public void flush() { long beginTime = System.currentTimeMillis(); if (this.mappedFile.hold()) { @@ -114,10 +108,8 @@ public class IndexFile { long timeDiff = storeTimestamp - this.indexHeader.getBeginTimestamp(); - timeDiff = timeDiff / 1000; - if (this.indexHeader.getBeginTimestamp() <= 0) { timeDiff = 0; } else if (timeDiff > Integer.MAX_VALUE) { @@ -127,19 +119,16 @@ public class IndexFile { } int absIndexPos = - IndexHeader.INDEX_HEADER_SIZE + this.hashSlotNum * hashSlotSize - + this.indexHeader.getIndexCount() * indexSize; - + IndexHeader.INDEX_HEADER_SIZE + this.hashSlotNum * hashSlotSize + + this.indexHeader.getIndexCount() * indexSize; this.mappedByteBuffer.putInt(absIndexPos, keyHash); this.mappedByteBuffer.putLong(absIndexPos + 4, phyOffset); - this.mappedByteBuffer.putInt(absIndexPos + 4 + 8, (int) timeDiff); + this.mappedByteBuffer.putInt(absIndexPos + 4 + 8, (int)timeDiff); this.mappedByteBuffer.putInt(absIndexPos + 4 + 8 + 4, slotValue); - this.mappedByteBuffer.putInt(absSlotPos, this.indexHeader.getIndexCount()); - if (this.indexHeader.getIndexCount() <= 1) { this.indexHeader.setBeginPhyOffset(phyOffset); this.indexHeader.setBeginTimestamp(storeTimestamp); @@ -192,22 +181,22 @@ public class IndexFile { public boolean isTimeMatched(final long begin, final long end) { boolean result = - begin < this.indexHeader.getBeginTimestamp() && end > this.indexHeader.getEndTimestamp(); + begin < this.indexHeader.getBeginTimestamp() && end > this.indexHeader.getEndTimestamp(); result = - result - || (begin >= this.indexHeader.getBeginTimestamp() && begin <= this.indexHeader - .getEndTimestamp()); + result + || (begin >= this.indexHeader.getBeginTimestamp() && begin <= this.indexHeader + .getEndTimestamp()); result = - result - || (end >= this.indexHeader.getBeginTimestamp() && end <= this.indexHeader - .getEndTimestamp()); + result + || (end >= this.indexHeader.getBeginTimestamp() && end <= this.indexHeader + .getEndTimestamp()); return result; } public void selectPhyOffset(final List phyOffsets, final String key, final int maxNum, - final long begin, final long end, boolean lock) { + final long begin, final long end, boolean lock) { if (this.mappedFile.hold()) { int keyHash = indexKeyHashMethod(key); int slotPos = keyHash % this.hashSlotNum; @@ -227,25 +216,24 @@ public class IndexFile { // } if (slotValue <= invalidIndex || slotValue > this.indexHeader.getIndexCount() - || this.indexHeader.getIndexCount() <= 1) { + || this.indexHeader.getIndexCount() <= 1) { // TODO NOTFOUND } else { - for (int nextIndexToRead = slotValue;;) { + for (int nextIndexToRead = slotValue; ; ) { if (phyOffsets.size() >= maxNum) { break; } int absIndexPos = - IndexHeader.INDEX_HEADER_SIZE + this.hashSlotNum * hashSlotSize - + nextIndexToRead * indexSize; + IndexHeader.INDEX_HEADER_SIZE + this.hashSlotNum * hashSlotSize + + nextIndexToRead * indexSize; int keyHashRead = this.mappedByteBuffer.getInt(absIndexPos); long phyOffsetRead = this.mappedByteBuffer.getLong(absIndexPos + 4); - long timeDiff = (long) this.mappedByteBuffer.getInt(absIndexPos + 4 + 8); + long timeDiff = (long)this.mappedByteBuffer.getInt(absIndexPos + 4 + 8); int prevIndexRead = this.mappedByteBuffer.getInt(absIndexPos + 4 + 8 + 4); - if (timeDiff < 0) { break; } @@ -260,8 +248,8 @@ public class IndexFile { } if (prevIndexRead <= invalidIndex - || prevIndexRead > this.indexHeader.getIndexCount() - || prevIndexRead == nextIndexToRead || timeRead < begin) { + || prevIndexRead > this.indexHeader.getIndexCount() + || prevIndexRead == nextIndexToRead || timeRead < begin) { break; } diff --git a/store/src/main/java/org/apache/rocketmq/store/index/IndexHeader.java b/store/src/main/java/org/apache/rocketmq/store/index/IndexHeader.java index 130f08e4..0c00abd3 100644 --- a/store/src/main/java/org/apache/rocketmq/store/index/IndexHeader.java +++ b/store/src/main/java/org/apache/rocketmq/store/index/IndexHeader.java @@ -20,7 +20,6 @@ import java.nio.ByteBuffer; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; - /** * @@ -43,12 +42,10 @@ public class IndexHeader { private AtomicInteger indexCount = new AtomicInteger(1); - public IndexHeader(final ByteBuffer byteBuffer) { this.byteBuffer = byteBuffer; } - public void load() { this.beginTimestamp.set(byteBuffer.getLong(beginTimestampIndex)); this.endTimestamp.set(byteBuffer.getLong(endTimestampIndex)); @@ -72,67 +69,55 @@ public class IndexHeader { this.byteBuffer.putInt(indexCountIndex, this.indexCount.get()); } - public long getBeginTimestamp() { return beginTimestamp.get(); } - public void setBeginTimestamp(long beginTimestamp) { this.beginTimestamp.set(beginTimestamp); this.byteBuffer.putLong(beginTimestampIndex, beginTimestamp); } - public long getEndTimestamp() { return endTimestamp.get(); } - public void setEndTimestamp(long endTimestamp) { this.endTimestamp.set(endTimestamp); this.byteBuffer.putLong(endTimestampIndex, endTimestamp); } - public long getBeginPhyOffset() { return beginPhyOffset.get(); } - public void setBeginPhyOffset(long beginPhyOffset) { this.beginPhyOffset.set(beginPhyOffset); this.byteBuffer.putLong(beginPhyoffsetIndex, beginPhyOffset); } - public long getEndPhyOffset() { return endPhyOffset.get(); } - public void setEndPhyOffset(long endPhyOffset) { this.endPhyOffset.set(endPhyOffset); this.byteBuffer.putLong(endPhyoffsetIndex, endPhyOffset); } - public AtomicInteger getHashSlotCount() { return hashSlotCount; } - public void incHashSlotCount() { int value = this.hashSlotCount.incrementAndGet(); this.byteBuffer.putInt(hashSlotcountIndex, value); } - public int getIndexCount() { return indexCount.get(); } - public void incIndexCount() { int value = this.indexCount.incrementAndGet(); this.byteBuffer.putInt(indexCountIndex, value); diff --git a/store/src/main/java/org/apache/rocketmq/store/index/IndexService.java b/store/src/main/java/org/apache/rocketmq/store/index/IndexService.java index 939ba2db..b72ffe90 100644 --- a/store/src/main/java/org/apache/rocketmq/store/index/IndexService.java +++ b/store/src/main/java/org/apache/rocketmq/store/index/IndexService.java @@ -16,6 +16,13 @@ */ package org.apache.rocketmq.store.index; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; import org.apache.rocketmq.common.UtilAll; import org.apache.rocketmq.common.constant.LoggerName; import org.apache.rocketmq.common.message.MessageConst; @@ -26,39 +33,25 @@ import org.apache.rocketmq.store.config.StorePathConfigHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.locks.ReadWriteLock; -import java.util.concurrent.locks.ReentrantReadWriteLock; - - public class IndexService { private static final Logger log = LoggerFactory.getLogger(LoggerName.STORE_LOGGER_NAME); + /** Maximum times to attempt index file creation. */ + private static final int MAX_TRY_IDX_CREATE = 3; private final DefaultMessageStore defaultMessageStore; - private final int hashSlotNum; private final int indexNum; private final String storePath; - private final ArrayList indexFileList = new ArrayList(); private final ReadWriteLock readWriteLock = new ReentrantReadWriteLock(); - /** Maximum times to attempt index file creation. */ - private static final int MAX_TRY_IDX_CREATE = 3; - - public IndexService(final DefaultMessageStore store) { this.defaultMessageStore = store; this.hashSlotNum = store.getMessageStoreConfig().getMaxHashSlotNum(); this.indexNum = store.getMessageStoreConfig().getMaxIndexNum(); this.storePath = - StorePathConfigHelper.getStorePathIndex(store.getMessageStoreConfig().getStorePathRootDir()); + StorePathConfigHelper.getStorePathIndex(store.getMessageStoreConfig().getStorePathRootDir()); } - public boolean load(final boolean lastExitOK) { File dir = new File(this.storePath); File[] files = dir.listFiles(); @@ -72,7 +65,7 @@ public class IndexService { if (!lastExitOK) { if (f.getEndTimestamp() > this.defaultMessageStore.getStoreCheckpoint() - .getIndexMsgTimestamp()) { + .getIndexMsgTimestamp()) { f.destroy(0); continue; } @@ -113,7 +106,7 @@ public class IndexService { if (files != null) { List fileList = new ArrayList(); for (int i = 0; i < (files.length - 1); i++) { - IndexFile f = (IndexFile) files[i]; + IndexFile f = (IndexFile)files[i]; if (f.getEndPhyOffset() < offset) { fileList.add(f); } else { @@ -145,7 +138,6 @@ public class IndexService { } } - public void destroy() { try { this.readWriteLock.readLock().lock(); @@ -160,7 +152,6 @@ public class IndexService { } } - public QueryOffsetResult queryOffset(String topic, String key, int maxNum, long begin, long end) { List phyOffsets = new ArrayList(maxNum); @@ -183,7 +174,6 @@ public class IndexService { f.selectPhyOffset(phyOffsets, buildKey(topic, key), maxNum, begin, end, lastFile); } - if (f.getBeginTimestamp() < begin) { break; } @@ -202,12 +192,10 @@ public class IndexService { return new QueryOffsetResult(phyOffsets, indexLastUpdateTimestamp, indexLastUpdatePhyoffset); } - private String buildKey(final String topic, final String key) { return topic + "#" + key; } - public void buildIndex(DispatchRequest req) { IndexFile indexFile = retryGetAndCreateIndexFile(); if (indexFile != null) { @@ -255,7 +243,6 @@ public class IndexService { } } - private IndexFile putKey(IndexFile indexFile, DispatchRequest msg, String idxKey) { for (boolean ok = indexFile.putKey(idxKey, msg.getCommitLogOffset(), msg.getStoreTimestamp()); !ok; ) { log.warn("Index file [" + indexFile.getFileName() + "] is full, trying to create another one"); @@ -300,7 +287,6 @@ public class IndexService { return indexFile; } - public IndexFile getAndCreateLastIndexFile() { IndexFile indexFile = null; IndexFile prevIndexFile = null; @@ -323,15 +309,14 @@ public class IndexService { this.readWriteLock.readLock().unlock(); } - if (indexFile == null) { try { String fileName = - this.storePath + File.separator - + UtilAll.timeMillisToHumanString(System.currentTimeMillis()); + this.storePath + File.separator + + UtilAll.timeMillisToHumanString(System.currentTimeMillis()); indexFile = - new IndexFile(fileName, this.hashSlotNum, this.indexNum, lastUpdateEndPhyOffset, - lastUpdateIndexTimestamp); + new IndexFile(fileName, this.hashSlotNum, this.indexNum, lastUpdateEndPhyOffset, + lastUpdateIndexTimestamp); this.readWriteLock.writeLock().lock(); this.indexFileList.add(indexFile); } catch (Exception e) { @@ -340,7 +325,6 @@ public class IndexService { this.readWriteLock.writeLock().unlock(); } - if (indexFile != null) { final IndexFile flushThisFile = prevIndexFile; Thread flushThread = new Thread(new Runnable() { @@ -358,7 +342,6 @@ public class IndexService { return indexFile; } - public void flush(final IndexFile f) { if (null == f) return; @@ -377,12 +360,10 @@ public class IndexService { } } - public void start() { } - public void shutdown() { } diff --git a/store/src/main/java/org/apache/rocketmq/store/index/QueryOffsetResult.java b/store/src/main/java/org/apache/rocketmq/store/index/QueryOffsetResult.java index e126aee0..a864c895 100644 --- a/store/src/main/java/org/apache/rocketmq/store/index/QueryOffsetResult.java +++ b/store/src/main/java/org/apache/rocketmq/store/index/QueryOffsetResult.java @@ -6,43 +6,38 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.store.index; import java.util.List; - public class QueryOffsetResult { private final List phyOffsets; private final long indexLastUpdateTimestamp; private final long indexLastUpdatePhyoffset; - public QueryOffsetResult(List phyOffsets, long indexLastUpdateTimestamp, - long indexLastUpdatePhyoffset) { + long indexLastUpdatePhyoffset) { this.phyOffsets = phyOffsets; this.indexLastUpdateTimestamp = indexLastUpdateTimestamp; this.indexLastUpdatePhyoffset = indexLastUpdatePhyoffset; } - public List getPhyOffsets() { return phyOffsets; } - public long getIndexLastUpdateTimestamp() { return indexLastUpdateTimestamp; } - public long getIndexLastUpdatePhyoffset() { return indexLastUpdatePhyoffset; } diff --git a/store/src/main/java/org/apache/rocketmq/store/schedule/DelayOffsetSerializeWrapper.java b/store/src/main/java/org/apache/rocketmq/store/schedule/DelayOffsetSerializeWrapper.java index b1520e14..ebe3ffeb 100644 --- a/store/src/main/java/org/apache/rocketmq/store/schedule/DelayOffsetSerializeWrapper.java +++ b/store/src/main/java/org/apache/rocketmq/store/schedule/DelayOffsetSerializeWrapper.java @@ -6,34 +6,30 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.store.schedule; -import org.apache.rocketmq.remoting.protocol.RemotingSerializable; - import java.util.concurrent.ConcurrentHashMap; - +import org.apache.rocketmq.remoting.protocol.RemotingSerializable; /** * */ public class DelayOffsetSerializeWrapper extends RemotingSerializable { private ConcurrentHashMap offsetTable = - new ConcurrentHashMap(32); - + new ConcurrentHashMap(32); public ConcurrentHashMap getOffsetTable() { return offsetTable; } - public void setOffsetTable(ConcurrentHashMap offsetTable) { this.offsetTable = offsetTable; } diff --git a/store/src/main/java/org/apache/rocketmq/store/schedule/ScheduleMessageService.java b/store/src/main/java/org/apache/rocketmq/store/schedule/ScheduleMessageService.java index c03c181d..3df48064 100644 --- a/store/src/main/java/org/apache/rocketmq/store/schedule/ScheduleMessageService.java +++ b/store/src/main/java/org/apache/rocketmq/store/schedule/ScheduleMessageService.java @@ -6,16 +6,23 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.store.schedule; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Timer; +import java.util.TimerTask; +import java.util.concurrent.ConcurrentHashMap; import org.apache.rocketmq.common.ConfigManager; import org.apache.rocketmq.common.TopicFilterType; import org.apache.rocketmq.common.constant.LoggerName; @@ -24,16 +31,16 @@ import org.apache.rocketmq.common.message.MessageConst; import org.apache.rocketmq.common.message.MessageDecoder; import org.apache.rocketmq.common.message.MessageExt; import org.apache.rocketmq.common.running.RunningStats; -import org.apache.rocketmq.store.*; +import org.apache.rocketmq.store.ConsumeQueue; +import org.apache.rocketmq.store.DefaultMessageStore; +import org.apache.rocketmq.store.MessageExtBrokerInner; +import org.apache.rocketmq.store.PutMessageResult; +import org.apache.rocketmq.store.PutMessageStatus; +import org.apache.rocketmq.store.SelectMappedBufferResult; import org.apache.rocketmq.store.config.StorePathConfigHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.*; -import java.util.Map.Entry; -import java.util.concurrent.ConcurrentHashMap; - - /** * */ @@ -45,10 +52,10 @@ public class ScheduleMessageService extends ConfigManager { private static final long DELAY_FOR_A_PERIOD = 10000L; private final ConcurrentHashMap delayLevelTable = - new ConcurrentHashMap(32); + new ConcurrentHashMap(32); private final ConcurrentHashMap offsetTable = - new ConcurrentHashMap(32); + new ConcurrentHashMap(32); private final Timer timer = new Timer("ScheduleMessageTimerThread", true); @@ -56,7 +63,6 @@ public class ScheduleMessageService extends ConfigManager { private int maxDelayLevel; - public ScheduleMessageService(final DefaultMessageStore defaultMessageStore) { this.defaultMessageStore = defaultMessageStore; } @@ -65,6 +71,10 @@ public class ScheduleMessageService extends ConfigManager { return queueId + 1; } + public static int delayLevel2QueueId(final int delayLevel) { + return delayLevel - 1; + } + public void buildRunningStats(HashMap stats) { Iterator> it = this.offsetTable.entrySet().iterator(); while (it.hasNext()) { @@ -78,16 +88,10 @@ public class ScheduleMessageService extends ConfigManager { } } - public static int delayLevel2QueueId(final int delayLevel) { - return delayLevel - 1; - } - - private void updateOffset(int delayLevel, long offset) { this.offsetTable.put(delayLevel, offset); } - public long computeDeliverTimestamp(final int delayLevel, final long storeTimestamp) { Long time = this.delayLevelTable.get(delayLevel); if (time != null) { @@ -97,7 +101,6 @@ public class ScheduleMessageService extends ConfigManager { return storeTimestamp + 1000; } - public void start() { for (Map.Entry entry : this.delayLevelTable.entrySet()) { @@ -126,17 +129,14 @@ public class ScheduleMessageService extends ConfigManager { }, 10000, this.defaultMessageStore.getMessageStoreConfig().getFlushDelayOffsetInterval()); } - public void shutdown() { this.timer.cancel(); } - public int getMaxDelayLevel() { return maxDelayLevel; } - public String encode() { return this.encode(false); } @@ -150,14 +150,14 @@ public class ScheduleMessageService extends ConfigManager { @Override public String configFilePath() { return StorePathConfigHelper.getDelayOffsetStorePath(this.defaultMessageStore.getMessageStoreConfig() - .getStorePathRootDir()); + .getStorePathRootDir()); } @Override public void decode(String jsonString) { if (jsonString != null) { DelayOffsetSerializeWrapper delayOffsetSerializeWrapper = - DelayOffsetSerializeWrapper.fromJson(jsonString, DelayOffsetSerializeWrapper.class); + DelayOffsetSerializeWrapper.fromJson(jsonString, DelayOffsetSerializeWrapper.class); if (delayOffsetSerializeWrapper != null) { this.offsetTable.putAll(delayOffsetSerializeWrapper.getOffsetTable()); } @@ -206,13 +206,11 @@ public class ScheduleMessageService extends ConfigManager { private final int delayLevel; private final long offset; - public DeliverDelayedMessageTimerTask(int delayLevel, long offset) { this.delayLevel = delayLevel; this.offset = offset; } - @Override public void run() { try { @@ -221,11 +219,10 @@ public class ScheduleMessageService extends ConfigManager { // XXX: warn and notify me log.error("ScheduleMessageService, executeOnTimeup exception", e); ScheduleMessageService.this.timer.schedule(new DeliverDelayedMessageTimerTask( - this.delayLevel, this.offset), DELAY_FOR_A_PERIOD); + this.delayLevel, this.offset), DELAY_FOR_A_PERIOD); } } - /** * @@ -243,11 +240,10 @@ public class ScheduleMessageService extends ConfigManager { return result; } - public void executeOnTimeup() { ConsumeQueue cq = - ScheduleMessageService.this.defaultMessageStore.findConsumeQueue(SCHEDULE_TOPIC, - delayLevel2QueueId(delayLevel)); + ScheduleMessageService.this.defaultMessageStore.findConsumeQueue(SCHEDULE_TOPIC, + delayLevel2QueueId(delayLevel)); long failScheduleOffset = offset; @@ -262,7 +258,6 @@ public class ScheduleMessageService extends ConfigManager { int sizePy = bufferCQ.getByteBuffer().getInt(); long tagsCode = bufferCQ.getByteBuffer().getLong(); - long now = System.currentTimeMillis(); long deliverTimestamp = this.correctDeliverTimestamp(now, tagsCode); @@ -272,31 +267,29 @@ public class ScheduleMessageService extends ConfigManager { if (countdown <= 0) { MessageExt msgExt = - ScheduleMessageService.this.defaultMessageStore.lookMessageByOffset( - offsetPy, sizePy); + ScheduleMessageService.this.defaultMessageStore.lookMessageByOffset( + offsetPy, sizePy); if (msgExt != null) { try { MessageExtBrokerInner msgInner = this.messageTimeup(msgExt); PutMessageResult putMessageResult = - ScheduleMessageService.this.defaultMessageStore - .putMessage(msgInner); + ScheduleMessageService.this.defaultMessageStore + .putMessage(msgInner); if (putMessageResult != null - && putMessageResult.getPutMessageStatus() == PutMessageStatus.PUT_OK) { + && putMessageResult.getPutMessageStatus() == PutMessageStatus.PUT_OK) { continue; - } - - else { + } else { // XXX: warn and notify me log.error( - "ScheduleMessageService, a message time up, but reput it failed, topic: {} msgId {}", - msgExt.getTopic(), msgExt.getMsgId()); + "ScheduleMessageService, a message time up, but reput it failed, topic: {} msgId {}", + msgExt.getTopic(), msgExt.getMsgId()); ScheduleMessageService.this.timer.schedule( - new DeliverDelayedMessageTimerTask(this.delayLevel, - nextOffset), DELAY_FOR_A_PERIOD); + new DeliverDelayedMessageTimerTask(this.delayLevel, + nextOffset), DELAY_FOR_A_PERIOD); ScheduleMessageService.this.updateOffset(this.delayLevel, - nextOffset); + nextOffset); return; } } catch (Exception e) { @@ -307,17 +300,15 @@ public class ScheduleMessageService extends ConfigManager { */ log.error( - "ScheduleMessageService, messageTimeup execute error, drop it. msgExt=" - + msgExt + ", nextOffset=" + nextOffset + ",offsetPy=" - + offsetPy + ",sizePy=" + sizePy, e); + "ScheduleMessageService, messageTimeup execute error, drop it. msgExt=" + + msgExt + ", nextOffset=" + nextOffset + ",offsetPy=" + + offsetPy + ",sizePy=" + sizePy, e); } } - } - - else { + } else { ScheduleMessageService.this.timer.schedule( - new DeliverDelayedMessageTimerTask(this.delayLevel, nextOffset), - countdown); + new DeliverDelayedMessageTimerTask(this.delayLevel, nextOffset), + countdown); ScheduleMessageService.this.updateOffset(this.delayLevel, nextOffset); return; } @@ -325,7 +316,7 @@ public class ScheduleMessageService extends ConfigManager { nextOffset = offset + (i / ConsumeQueue.CQ_STORE_UNIT_SIZE); ScheduleMessageService.this.timer.schedule(new DeliverDelayedMessageTimerTask( - this.delayLevel, nextOffset), DELAY_FOR_A_WHILE); + this.delayLevel, nextOffset), DELAY_FOR_A_WHILE); ScheduleMessageService.this.updateOffset(this.delayLevel, nextOffset); return; } finally { @@ -342,16 +333,15 @@ public class ScheduleMessageService extends ConfigManager { if (offset < cqMinOffset) { failScheduleOffset = cqMinOffset; log.error("schedule CQ offset invalid. offset=" + offset + ", cqMinOffset=" - + cqMinOffset + ", queueId=" + cq.getQueueId()); + + cqMinOffset + ", queueId=" + cq.getQueueId()); } } } // end of if (cq != null) ScheduleMessageService.this.timer.schedule(new DeliverDelayedMessageTimerTask(this.delayLevel, - failScheduleOffset), DELAY_FOR_A_WHILE); + failScheduleOffset), DELAY_FOR_A_WHILE); } - private MessageExtBrokerInner messageTimeup(MessageExt msgExt) { MessageExtBrokerInner msgInner = new MessageExtBrokerInner(); msgInner.setBody(msgExt.getBody()); @@ -360,7 +350,7 @@ public class ScheduleMessageService extends ConfigManager { TopicFilterType topicFilterType = MessageExt.parseTopicFilterType(msgInner.getSysFlag()); long tagsCodeValue = - MessageExtBrokerInner.tagsString2tagsCode(topicFilterType, msgInner.getTags()); + MessageExtBrokerInner.tagsString2tagsCode(topicFilterType, msgInner.getTags()); msgInner.setTagsCode(tagsCodeValue); msgInner.setPropertiesString(MessageDecoder.messageProperties2String(msgExt.getProperties())); diff --git a/store/src/main/java/org/apache/rocketmq/store/stats/BrokerStats.java b/store/src/main/java/org/apache/rocketmq/store/stats/BrokerStats.java index dd4f6dff..cd87b0dc 100644 --- a/store/src/main/java/org/apache/rocketmq/store/stats/BrokerStats.java +++ b/store/src/main/java/org/apache/rocketmq/store/stats/BrokerStats.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.store.stats; @@ -21,7 +21,6 @@ import org.apache.rocketmq.store.DefaultMessageStore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - public class BrokerStats { private static final Logger log = LoggerFactory.getLogger(LoggerName.BROKER_LOGGER_NAME); private final DefaultMessageStore defaultMessageStore; @@ -34,12 +33,10 @@ public class BrokerStats { private volatile long msgGetTotalTodayMorning; - public BrokerStats(DefaultMessageStore defaultMessageStore) { this.defaultMessageStore = defaultMessageStore; } - /** */ @@ -48,60 +45,50 @@ public class BrokerStats { this.msgGetTotalYesterdayMorning = this.msgGetTotalTodayMorning; this.msgPutTotalTodayMorning = - this.defaultMessageStore.getStoreStatsService().getPutMessageTimesTotal(); + this.defaultMessageStore.getStoreStatsService().getPutMessageTimesTotal(); this.msgGetTotalTodayMorning = - this.defaultMessageStore.getStoreStatsService().getGetMessageTransferedMsgCount().get(); + this.defaultMessageStore.getStoreStatsService().getGetMessageTransferedMsgCount().get(); log.info("yesterday put message total: {}", msgPutTotalTodayMorning - msgPutTotalYesterdayMorning); log.info("yesterday get message total: {}", msgGetTotalTodayMorning - msgGetTotalYesterdayMorning); } - public long getMsgPutTotalYesterdayMorning() { return msgPutTotalYesterdayMorning; } - public void setMsgPutTotalYesterdayMorning(long msgPutTotalYesterdayMorning) { this.msgPutTotalYesterdayMorning = msgPutTotalYesterdayMorning; } - public long getMsgPutTotalTodayMorning() { return msgPutTotalTodayMorning; } - public void setMsgPutTotalTodayMorning(long msgPutTotalTodayMorning) { this.msgPutTotalTodayMorning = msgPutTotalTodayMorning; } - public long getMsgGetTotalYesterdayMorning() { return msgGetTotalYesterdayMorning; } - public void setMsgGetTotalYesterdayMorning(long msgGetTotalYesterdayMorning) { this.msgGetTotalYesterdayMorning = msgGetTotalYesterdayMorning; } - public long getMsgGetTotalTodayMorning() { return msgGetTotalTodayMorning; } - public void setMsgGetTotalTodayMorning(long msgGetTotalTodayMorning) { this.msgGetTotalTodayMorning = msgGetTotalTodayMorning; } - public long getMsgPutTotalTodayNow() { return this.defaultMessageStore.getStoreStatsService().getPutMessageTimesTotal(); } - public long getMsgGetTotalTodayNow() { return this.defaultMessageStore.getStoreStatsService().getGetMessageTransferedMsgCount().get(); } diff --git a/store/src/main/java/org/apache/rocketmq/store/stats/BrokerStatsManager.java b/store/src/main/java/org/apache/rocketmq/store/stats/BrokerStatsManager.java index b14780b1..f128b097 100644 --- a/store/src/main/java/org/apache/rocketmq/store/stats/BrokerStatsManager.java +++ b/store/src/main/java/org/apache/rocketmq/store/stats/BrokerStatsManager.java @@ -6,16 +6,19 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.store.stats; +import java.util.HashMap; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; import org.apache.rocketmq.common.ThreadFactoryImpl; import org.apache.rocketmq.common.constant.LoggerName; import org.apache.rocketmq.common.stats.MomentStatsItemSet; @@ -24,11 +27,6 @@ import org.apache.rocketmq.common.stats.StatsItemSet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.HashMap; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; - - public class BrokerStatsManager { public static final String TOPIC_PUT_NUMS = "TOPIC_PUT_NUMS"; @@ -65,9 +63,9 @@ public class BrokerStatsManager { private static final Logger log = LoggerFactory.getLogger(LoggerName.ROCKETMQ_STATS_LOGGER_NAME); private static final Logger COMMERCIAL_LOG = LoggerFactory.getLogger(LoggerName.COMMERCIAL_LOGGER_NAME); private final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryImpl( - "BrokerStatsThread")); + "BrokerStatsThread")); private final ScheduledExecutorService commercialExecutor = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryImpl( - "CommercialStatsThread")); + "CommercialStatsThread")); private final HashMap statsTable = new HashMap(); private final String clusterName; private final MomentStatsItemSet momentStatsItemSetFallSize = new MomentStatsItemSet(GROUP_GET_FALL_SIZE, scheduledExecutorService, log); @@ -89,7 +87,6 @@ public class BrokerStatsManager { this.statsTable.put(BROKER_GET_FROM_DISK_NUMS, new StatsItemSet(BROKER_GET_FROM_DISK_NUMS, this.scheduledExecutorService, log)); this.statsTable.put(BROKER_GET_FROM_DISK_SIZE, new StatsItemSet(BROKER_GET_FROM_DISK_SIZE, this.scheduledExecutorService, log)); - this.statsTable.put(COMMERCIAL_SEND_TIMES, new StatsItemSet(COMMERCIAL_SEND_TIMES, this.commercialExecutor, COMMERCIAL_LOG)); this.statsTable.put(COMMERCIAL_RCV_TIMES, new StatsItemSet(COMMERCIAL_RCV_TIMES, this.commercialExecutor, COMMERCIAL_LOG)); this.statsTable.put(COMMERCIAL_SEND_SIZE, new StatsItemSet(COMMERCIAL_SEND_SIZE, this.commercialExecutor, COMMERCIAL_LOG)); @@ -154,42 +151,36 @@ public class BrokerStatsManager { this.statsTable.get(GROUP_GET_LATENCY).addValue(statsKey, incValue, 1); } - public void incBrokerPutNums() { this.statsTable.get(BROKER_PUT_NUMS).getAndCreateStatsItem(this.clusterName).getValue().incrementAndGet(); } - public void incBrokerGetNums(final int incValue) { this.statsTable.get(BROKER_GET_NUMS).getAndCreateStatsItem(this.clusterName).getValue().addAndGet(incValue); } - public void incSendBackNums(final String group, final String topic) { final String statsKey = buildStatsKey(topic, group); this.statsTable.get(SNDBCK_PUT_NUMS).addValue(statsKey, 1, 1); } - public double tpsGroupGetNums(final String group, final String topic) { final String statsKey = buildStatsKey(topic, group); return this.statsTable.get(GROUP_GET_NUMS).getStatsDataInMinute(statsKey).getTps(); } - public void recordDiskFallBehindTime(final String group, final String topic, final int queueId, final long fallBehind) { final String statsKey = String.format("%d@%s@%s", queueId, topic, group); this.momentStatsItemSetFallTime.getAndCreateStatsItem(statsKey).getValue().set(fallBehind); } - public void recordDiskFallBehindSize(final String group, final String topic, final int queueId, final long fallBehind) { final String statsKey = String.format("%d@%s@%s", queueId, topic, group); this.momentStatsItemSetFallSize.getAndCreateStatsItem(statsKey).getValue().set(fallBehind); } public void incCommercialValue(final String key, final String owner, final String group, - final String topic, final String type, final int incValue) { + final String topic, final String type, final int incValue) { final String statsKey = buildCommercialStatsKey(owner, topic, group, type); this.statsTable.get(key).addValue(statsKey, incValue, 1); } @@ -206,7 +197,6 @@ public class BrokerStatsManager { return strBuilder.toString(); } - public enum StatsType { SEND_SUCCESS, SEND_FAILURE, diff --git a/store/src/main/java/org/apache/rocketmq/store/util/LibC.java b/store/src/main/java/org/apache/rocketmq/store/util/LibC.java index ee9e68bb..dc5d6a94 100644 --- a/store/src/main/java/org/apache/rocketmq/store/util/LibC.java +++ b/store/src/main/java/org/apache/rocketmq/store/util/LibC.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.store.util; @@ -22,9 +22,8 @@ import com.sun.jna.NativeLong; import com.sun.jna.Platform; import com.sun.jna.Pointer; - public interface LibC extends Library { - LibC INSTANCE = (LibC) Native.loadLibrary(Platform.isWindows() ? "msvcrt" : "c", LibC.class); + LibC INSTANCE = (LibC)Native.loadLibrary(Platform.isWindows() ? "msvcrt" : "c", LibC.class); int MADV_WILLNEED = 3; int MADV_DONTNEED = 4; diff --git a/store/src/test/java/org/apache/rocketmq/store/DefaultMessageStoreTest.java b/store/src/test/java/org/apache/rocketmq/store/DefaultMessageStoreTest.java index bfcb33e7..5c6bde24 100644 --- a/store/src/test/java/org/apache/rocketmq/store/DefaultMessageStoreTest.java +++ b/store/src/test/java/org/apache/rocketmq/store/DefaultMessageStoreTest.java @@ -6,17 +6,21 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.store; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.SocketAddress; +import java.util.concurrent.atomic.AtomicInteger; import org.apache.rocketmq.common.BrokerConfig; import org.apache.rocketmq.store.config.FlushDiskType; import org.apache.rocketmq.store.config.MessageStoreConfig; @@ -26,17 +30,11 @@ import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.util.concurrent.atomic.AtomicInteger; - import static org.junit.Assert.assertTrue; - public class DefaultMessageStoreTest { private static final Logger logger = LoggerFactory.getLogger(DefaultMessageStoreTest.class); - + private static final String StoreMessage = "Once, there was a chance for me!"; private static int QUEUE_TOTAL = 100; @@ -82,7 +80,7 @@ public class DefaultMessageStoreTest { PutMessageResult result = master.putMessage(buildMessage()); logger.debug(i + "\t" + result.getAppendMessageResult().getMsgId()); } - + for (long i = 0; i < totalMsgs; i++) { GetMessageResult result = master.getMessage("GROUP_A", "TOPIC_A", 0, i, 1024 * 1024, null); if (result == null) { @@ -133,7 +131,7 @@ public class DefaultMessageStoreTest { PutMessageResult result = master.putMessage(buildMessage()); logger.debug(i + "\t" + result.getAppendMessageResult().getMsgId()); } - + for (long i = 0; i < totalMsgs; i++) { GetMessageResult result = master.getMessage("GROUP_A", "TOPIC_A", 0, i, 1024 * 1024, null); if (result == null) { @@ -142,7 +140,7 @@ public class DefaultMessageStoreTest { assertTrue(result != null); result.release(); logger.debug("read " + i + " OK"); - + } } finally { master.shutdown(); @@ -150,9 +148,9 @@ public class DefaultMessageStoreTest { } logger.debug("================================================================"); } - + private class MyMessageArrivingListener implements MessageArrivingListener { - + @Override public void arriving(String topic, int queueId, long logicOffset, long tagsCode) { // Do nothing here diff --git a/store/src/test/java/org/apache/rocketmq/store/MappedFileQueueTest.java b/store/src/test/java/org/apache/rocketmq/store/MappedFileQueueTest.java index ac1e0164..018cf990 100644 --- a/store/src/test/java/org/apache/rocketmq/store/MappedFileQueueTest.java +++ b/store/src/test/java/org/apache/rocketmq/store/MappedFileQueueTest.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: MappedFileQueueTest.java 1831 2013-05-16 01:39:51Z vintagewang@apache.org $ */ /** @@ -20,12 +22,17 @@ */ package org.apache.rocketmq.store; -import org.junit.*; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.junit.Assert.*; - +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; public class MappedFileQueueTest { private static final Logger logger = LoggerFactory.getLogger(MappedFileQueueTest.class); @@ -55,7 +62,7 @@ public class MappedFileQueueTest { logger.debug("================================================================"); MappedFileQueue mappedFileQueue = - new MappedFileQueue("target/unit_test_store/a/", 1024, null); + new MappedFileQueue("target/unit_test_store/a/", 1024, null); for (int i = 0; i < 1024; i++) { MappedFile mappedFile = mappedFileQueue.getLastMappedFile(0); @@ -73,7 +80,6 @@ public class MappedFileQueueTest { logger.debug("MappedFileQueue.getLastMappedFile() OK"); } - @Test public void test_findMapedFileByOffset() { // four-byte string. @@ -81,7 +87,7 @@ public class MappedFileQueueTest { logger.debug("================================================================"); MappedFileQueue mappedFileQueue = - new MappedFileQueue("target/unit_test_store/b/", 1024, null); + new MappedFileQueue("target/unit_test_store/b/", 1024, null); for (int i = 0; i < 1024; i++) { MappedFile mappedFile = mappedFileQueue.getLastMappedFile(0); @@ -96,23 +102,23 @@ public class MappedFileQueueTest { MappedFile mappedFile = mappedFileQueue.findMappedFileByOffset(0); assertTrue(mappedFile != null); assertEquals(mappedFile.getFileFromOffset(), 0); - + mappedFile = mappedFileQueue.findMappedFileByOffset(100); assertTrue(mappedFile != null); assertEquals(mappedFile.getFileFromOffset(), 0); - + mappedFile = mappedFileQueue.findMappedFileByOffset(1024); assertTrue(mappedFile != null); assertEquals(mappedFile.getFileFromOffset(), 1024); - + mappedFile = mappedFileQueue.findMappedFileByOffset(1024 + 100); assertTrue(mappedFile != null); assertEquals(mappedFile.getFileFromOffset(), 1024); - + mappedFile = mappedFileQueue.findMappedFileByOffset(1024 * 2); assertTrue(mappedFile != null); assertEquals(mappedFile.getFileFromOffset(), 1024 * 2); - + mappedFile = mappedFileQueue.findMappedFileByOffset(1024 * 2 + 100); assertTrue(mappedFile != null); assertEquals(mappedFile.getFileFromOffset(), 1024 * 2); @@ -135,7 +141,7 @@ public class MappedFileQueueTest { logger.debug("================================================================"); MappedFileQueue mappedFileQueue = - new MappedFileQueue("target/unit_test_store/c/", 1024, null); + new MappedFileQueue("target/unit_test_store/c/", 1024, null); for (int i = 0; i < 1024; i++) { MappedFile mappedFile = mappedFileQueue.getLastMappedFile(0); @@ -148,27 +154,27 @@ public class MappedFileQueueTest { boolean result = mappedFileQueue.flush(0); assertFalse(result); assertEquals(1024 * 1, mappedFileQueue.getFlushedWhere()); - + result = mappedFileQueue.flush(0); assertFalse(result); assertEquals(1024 * 2, mappedFileQueue.getFlushedWhere()); - + result = mappedFileQueue.flush(0); assertFalse(result); assertEquals(1024 * 3, mappedFileQueue.getFlushedWhere()); - + result = mappedFileQueue.flush(0); assertFalse(result); assertEquals(1024 * 4, mappedFileQueue.getFlushedWhere()); - + result = mappedFileQueue.flush(0); assertFalse(result); assertEquals(1024 * 5, mappedFileQueue.getFlushedWhere()); - + result = mappedFileQueue.flush(0); assertFalse(result); assertEquals(1024 * 6, mappedFileQueue.getFlushedWhere()); - + mappedFileQueue.shutdown(1000); mappedFileQueue.destroy(); logger.debug("MappedFileQueue.flush() OK"); @@ -180,7 +186,7 @@ public class MappedFileQueueTest { logger.debug("================================================================"); MappedFileQueue mappedFileQueue = - new MappedFileQueue("target/unit_test_store/d/", 1024, null); + new MappedFileQueue("target/unit_test_store/d/", 1024, null); for (int i = 0; i < 1024; i++) { MappedFile mappedFile = mappedFileQueue.getLastMappedFile(0); diff --git a/store/src/test/java/org/apache/rocketmq/store/MappedFileTest.java b/store/src/test/java/org/apache/rocketmq/store/MappedFileTest.java index bfa09e94..a10f4eb5 100644 --- a/store/src/test/java/org/apache/rocketmq/store/MappedFileTest.java +++ b/store/src/test/java/org/apache/rocketmq/store/MappedFileTest.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: MappedFileTest.java 1831 2013-05-16 01:39:51Z vintagewang@apache.org $ */ /** @@ -20,6 +22,7 @@ */ package org.apache.rocketmq.store; +import java.io.IOException; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Ignore; @@ -27,16 +30,12 @@ import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; - import static org.junit.Assert.assertTrue; - public class MappedFileTest { - + private static final Logger logger = LoggerFactory.getLogger(MappedFileTest.class); - - + private static final String StoreMessage = "Once, there was a chance for me!"; @BeforeClass @@ -54,15 +53,15 @@ public class MappedFileTest { boolean result = mappedFile.appendMessage(StoreMessage.getBytes()); assertTrue(result); logger.debug("write OK"); - + SelectMappedBufferResult selectMappedBufferResult = mappedFile.selectMappedBuffer(0); byte[] data = new byte[StoreMessage.length()]; selectMappedBufferResult.getByteBuffer().get(data); String readString = new String(data); - + logger.debug("Read: " + readString); assertTrue(readString.equals(StoreMessage)); - + mappedFile.shutdown(1000); assertTrue(!mappedFile.isAvailable()); selectMappedBufferResult.release(); @@ -76,11 +75,11 @@ public class MappedFileTest { boolean result = mappedFile.appendMessage(StoreMessage.getBytes()); assertTrue(result); logger.debug("write OK"); - + SelectMappedBufferResult selectMappedBufferResult = mappedFile.selectMappedBuffer(0); selectMappedBufferResult.release(); mappedFile.shutdown(1000); - + byte[] data = new byte[StoreMessage.length()]; selectMappedBufferResult.getByteBuffer().get(data); String readString = new String(data); diff --git a/store/src/test/java/org/apache/rocketmq/store/StoreCheckpointTest.java b/store/src/test/java/org/apache/rocketmq/store/StoreCheckpointTest.java index f0245a9e..2fe4d469 100644 --- a/store/src/test/java/org/apache/rocketmq/store/StoreCheckpointTest.java +++ b/store/src/test/java/org/apache/rocketmq/store/StoreCheckpointTest.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: StoreCheckpointTest.java 1831 2013-05-16 01:39:51Z vintagewang@apache.org $ */ /** @@ -20,15 +22,13 @@ */ package org.apache.rocketmq.store; +import java.io.IOException; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; -import java.io.IOException; - import static org.junit.Assert.assertTrue; - public class StoreCheckpointTest { @BeforeClass public static void setUpBeforeClass() throws Exception { @@ -47,7 +47,7 @@ public class StoreCheckpointTest { storeCheckpoint.setPhysicMsgTimestamp(physicMsgTimestamp); storeCheckpoint.setLogicsMsgTimestamp(logicsMsgTimestamp); storeCheckpoint.flush(); - + long diff = physicMsgTimestamp - storeCheckpoint.getMinTimestamp(); assertTrue(diff == 3000); storeCheckpoint.shutdown(); diff --git a/store/src/test/java/org/apache/rocketmq/store/index/IndexFileTest.java b/store/src/test/java/org/apache/rocketmq/store/index/IndexFileTest.java index 95cf0c89..cdecb20e 100644 --- a/store/src/test/java/org/apache/rocketmq/store/index/IndexFileTest.java +++ b/store/src/test/java/org/apache/rocketmq/store/index/IndexFileTest.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: IndexFileTest.java 1831 2013-05-16 01:39:51Z vintagewang@apache.org $ */ /** @@ -20,16 +22,14 @@ */ package org.apache.rocketmq.store.index; -import org.junit.Test; - import java.util.ArrayList; import java.util.List; +import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; - public class IndexFileTest { private static final int HASH_SLOT_NUM = 100; private static final int INDEX_NUM = 400; @@ -45,15 +45,14 @@ public class IndexFileTest { // put over index file capacity. boolean putResult = indexFile.putKey(Long.toString(400), 400, System.currentTimeMillis()); assertFalse(putResult); - + indexFile.destroy(0); } - @Test public void test_put_get_index() throws Exception { IndexFile indexFile = new IndexFile("200", HASH_SLOT_NUM, INDEX_NUM, 0, 0); - + for (long i = 0; i < (INDEX_NUM - 1); i++) { boolean putResult = indexFile.putKey(Long.toString(i), i, System.currentTimeMillis()); assertTrue(putResult); @@ -62,7 +61,7 @@ public class IndexFileTest { // put over index file capacity. boolean putResult = indexFile.putKey(Long.toString(400), 400, System.currentTimeMillis()); assertFalse(putResult); - + final List phyOffsets = new ArrayList(); indexFile.selectPhyOffset(phyOffsets, "60", 10, 0, Long.MAX_VALUE, true); assertFalse(phyOffsets.isEmpty()); diff --git a/store/src/test/java/org/apache/rocketmq/store/schedule/ScheduleMessageTest.java b/store/src/test/java/org/apache/rocketmq/store/schedule/ScheduleMessageTest.java index 7ac8233b..c5d97566 100644 --- a/store/src/test/java/org/apache/rocketmq/store/schedule/ScheduleMessageTest.java +++ b/store/src/test/java/org/apache/rocketmq/store/schedule/ScheduleMessageTest.java @@ -6,13 +6,15 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: ScheduleMessageTest.java 1831 2013-05-16 01:39:51Z vintagewang@apache.org $ */ /** @@ -20,19 +22,21 @@ */ package org.apache.rocketmq.store.schedule; -import org.apache.rocketmq.store.*; -import org.apache.rocketmq.store.*; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.SocketAddress; +import java.util.concurrent.atomic.AtomicInteger; +import org.apache.rocketmq.store.DefaultMessageStore; +import org.apache.rocketmq.store.GetMessageResult; +import org.apache.rocketmq.store.MessageExtBrokerInner; +import org.apache.rocketmq.store.MessageStore; +import org.apache.rocketmq.store.PutMessageResult; import org.apache.rocketmq.store.config.MessageStoreConfig; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.util.concurrent.atomic.AtomicInteger; - import static org.junit.Assert.assertTrue; @Ignore @@ -65,7 +69,6 @@ public class ScheduleMessageTest { long totalMsgs = 10000; QUEUE_TOTAL = 32; - MessageBody = StoreMessage.getBytes(); MessageStoreConfig messageStoreConfig = new MessageStoreConfig(); @@ -79,7 +82,6 @@ public class ScheduleMessageTest { boolean load = master.load(); assertTrue(load); - master.start(); for (int i = 0; i < totalMsgs; i++) { MessageExtBrokerInner msg = buildMessage(); @@ -92,7 +94,6 @@ public class ScheduleMessageTest { System.out.println("write message over, wait time up"); Thread.sleep(1000 * 20); - for (long i = 0; i < totalMsgs; i++) { try { GetMessageResult result = master.getMessage("GROUP_A", "TOPIC_A", 0, i, 1024 * 1024, null); @@ -110,10 +111,8 @@ public class ScheduleMessageTest { Thread.sleep(1000 * 15); - master.shutdown(); - master.destroy(); System.out.println("================================================================"); } diff --git a/store/src/test/resources/logback-test.xml b/store/src/test/resources/logback-test.xml index 25fc615d..752ad59a 100644 --- a/store/src/test/resources/logback-test.xml +++ b/store/src/test/resources/logback-test.xml @@ -17,19 +17,19 @@ --> - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n - UTF-8 - - + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n + UTF-8 + + - - - + + + - - - + + + diff --git a/style/copyright/Apache.xml b/style/copyright/Apache.xml index f728d8a6..d54449b5 100644 --- a/style/copyright/Apache.xml +++ b/style/copyright/Apache.xml @@ -1,6 +1,7 @@ - - + + \ No newline at end of file diff --git a/style/copyright/profiles_settings.xml b/style/copyright/profiles_settings.xml index 0cba7235..d75ac237 100644 --- a/style/copyright/profiles_settings.xml +++ b/style/copyright/profiles_settings.xml @@ -1,44 +1,44 @@ - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/style/rmq_codeStyle.xml b/style/rmq_codeStyle.xml index e6a9b7de..a2872f0e 100644 --- a/style/rmq_codeStyle.xml +++ b/style/rmq_codeStyle.xml @@ -1,140 +1,140 @@ - - - \ No newline at end of file diff --git a/tools/pom.xml b/tools/pom.xml index aa05fea1..d80beaec 100644 --- a/tools/pom.xml +++ b/tools/pom.xml @@ -15,7 +15,7 @@ limitations under the License. --> - org.apache.rocketmq diff --git a/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExt.java b/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExt.java index c6a80b03..e8751bd3 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExt.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExt.java @@ -16,6 +16,11 @@ */ package org.apache.rocketmq.tools.admin; +import java.io.UnsupportedEncodingException; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; import org.apache.rocketmq.client.ClientConfig; import org.apache.rocketmq.client.QueryResult; import org.apache.rocketmq.client.exception.MQBrokerException; @@ -27,19 +32,28 @@ import org.apache.rocketmq.common.admin.RollbackStats; import org.apache.rocketmq.common.admin.TopicStatsTable; import org.apache.rocketmq.common.message.MessageExt; import org.apache.rocketmq.common.message.MessageQueue; -import org.apache.rocketmq.common.protocol.body.*; +import org.apache.rocketmq.common.protocol.body.BrokerStatsData; +import org.apache.rocketmq.common.protocol.body.ClusterInfo; +import org.apache.rocketmq.common.protocol.body.ConsumeMessageDirectlyResult; +import org.apache.rocketmq.common.protocol.body.ConsumeStatsList; +import org.apache.rocketmq.common.protocol.body.ConsumerConnection; +import org.apache.rocketmq.common.protocol.body.ConsumerRunningInfo; +import org.apache.rocketmq.common.protocol.body.GroupList; +import org.apache.rocketmq.common.protocol.body.KVTable; +import org.apache.rocketmq.common.protocol.body.ProducerConnection; +import org.apache.rocketmq.common.protocol.body.QueueTimeSpan; +import org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper; +import org.apache.rocketmq.common.protocol.body.TopicConfigSerializeWrapper; +import org.apache.rocketmq.common.protocol.body.TopicList; import org.apache.rocketmq.common.protocol.route.TopicRouteData; import org.apache.rocketmq.common.subscription.SubscriptionGroupConfig; import org.apache.rocketmq.remoting.RPCHook; +import org.apache.rocketmq.remoting.exception.RemotingCommandException; +import org.apache.rocketmq.remoting.exception.RemotingConnectException; +import org.apache.rocketmq.remoting.exception.RemotingException; +import org.apache.rocketmq.remoting.exception.RemotingSendRequestException; +import org.apache.rocketmq.remoting.exception.RemotingTimeoutException; import org.apache.rocketmq.tools.admin.api.MessageTrack; -import org.apache.rocketmq.remoting.exception.*; - -import java.io.UnsupportedEncodingException; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Set; - public class DefaultMQAdminExt extends ClientConfig implements MQAdminExt { private final DefaultMQAdminExtImpl defaultMQAdminExtImpl; @@ -93,7 +107,6 @@ public class DefaultMQAdminExt extends ClientConfig implements MQAdminExt { return defaultMQAdminExtImpl.maxOffset(mq); } - @Override public long minOffset(MessageQueue mq) throws MQClientException { return defaultMQAdminExtImpl.minOffset(mq); @@ -111,7 +124,7 @@ public class DefaultMQAdminExt extends ClientConfig implements MQAdminExt { @Override public QueryResult queryMessage(String topic, String key, int maxNum, long begin, long end) throws MQClientException, - InterruptedException { + InterruptedException { return defaultMQAdminExtImpl.queryMessage(topic, key, maxNum, begin, end); } @@ -127,25 +140,25 @@ public class DefaultMQAdminExt extends ClientConfig implements MQAdminExt { @Override public void updateBrokerConfig(String brokerAddr, Properties properties) throws RemotingConnectException, RemotingSendRequestException, - RemotingTimeoutException, UnsupportedEncodingException, InterruptedException, MQBrokerException { + RemotingTimeoutException, UnsupportedEncodingException, InterruptedException, MQBrokerException { defaultMQAdminExtImpl.updateBrokerConfig(brokerAddr, properties); } @Override public Properties getBrokerConfig(final String brokerAddr) throws RemotingConnectException, - RemotingSendRequestException, RemotingTimeoutException, UnsupportedEncodingException, InterruptedException, MQBrokerException { + RemotingSendRequestException, RemotingTimeoutException, UnsupportedEncodingException, InterruptedException, MQBrokerException { return defaultMQAdminExtImpl.getBrokerConfig(brokerAddr); } @Override public void createAndUpdateTopicConfig(String addr, TopicConfig config) throws RemotingException, MQBrokerException, - InterruptedException, MQClientException { + InterruptedException, MQClientException { defaultMQAdminExtImpl.createAndUpdateTopicConfig(addr, config); } @Override public void createAndUpdateSubscriptionGroupConfig(String addr, SubscriptionGroupConfig config) throws RemotingException, - MQBrokerException, InterruptedException, MQClientException { + MQBrokerException, InterruptedException, MQClientException { defaultMQAdminExtImpl.createAndUpdateSubscriptionGroupConfig(addr, config); } @@ -161,7 +174,7 @@ public class DefaultMQAdminExt extends ClientConfig implements MQAdminExt { @Override public TopicStatsTable examineTopicStats(String topic) throws RemotingException, MQClientException, InterruptedException, - MQBrokerException { + MQBrokerException { return defaultMQAdminExtImpl.examineTopicStats(topic); } @@ -177,25 +190,25 @@ public class DefaultMQAdminExt extends ClientConfig implements MQAdminExt { @Override public KVTable fetchBrokerRuntimeStats(final String brokerAddr) throws RemotingConnectException, RemotingSendRequestException, - RemotingTimeoutException, InterruptedException, MQBrokerException { + RemotingTimeoutException, InterruptedException, MQBrokerException { return this.defaultMQAdminExtImpl.fetchBrokerRuntimeStats(brokerAddr); } @Override public ConsumeStats examineConsumeStats(String consumerGroup) throws RemotingException, MQClientException, InterruptedException, - MQBrokerException { + MQBrokerException { return examineConsumeStats(consumerGroup, null); } @Override public ConsumeStats examineConsumeStats(String consumerGroup, String topic) throws RemotingException, MQClientException, - InterruptedException, MQBrokerException { + InterruptedException, MQBrokerException { return defaultMQAdminExtImpl.examineConsumeStats(consumerGroup, topic); } @Override public ClusterInfo examineBrokerClusterInfo() throws InterruptedException, RemotingConnectException, RemotingTimeoutException, - RemotingSendRequestException, MQBrokerException { + RemotingSendRequestException, MQBrokerException { return defaultMQAdminExtImpl.examineBrokerClusterInfo(); } @@ -206,13 +219,13 @@ public class DefaultMQAdminExt extends ClientConfig implements MQAdminExt { @Override public ConsumerConnection examineConsumerConnectionInfo(String consumerGroup) throws InterruptedException, MQBrokerException, - RemotingException, MQClientException { + RemotingException, MQClientException { return defaultMQAdminExtImpl.examineConsumerConnectionInfo(consumerGroup); } @Override public ProducerConnection examineProducerConnectionInfo(String producerGroup, final String topic) throws RemotingException, - MQClientException, InterruptedException, MQBrokerException { + MQClientException, InterruptedException, MQBrokerException { return defaultMQAdminExtImpl.examineProducerConnectionInfo(producerGroup, topic); } @@ -223,7 +236,7 @@ public class DefaultMQAdminExt extends ClientConfig implements MQAdminExt { @Override public int wipeWritePermOfBroker(final String namesrvAddr, String brokerName) throws RemotingCommandException, - RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQClientException { + RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQClientException { return defaultMQAdminExtImpl.wipeWritePermOfBroker(namesrvAddr, brokerName); } @@ -244,148 +257,150 @@ public class DefaultMQAdminExt extends ClientConfig implements MQAdminExt { @Override public void deleteTopicInBroker(Set addrs, String topic) throws RemotingException, MQBrokerException, InterruptedException, - MQClientException { + MQClientException { defaultMQAdminExtImpl.deleteTopicInBroker(addrs, topic); } @Override public void deleteTopicInNameServer(Set addrs, String topic) throws RemotingException, MQBrokerException, InterruptedException, - MQClientException { + MQClientException { defaultMQAdminExtImpl.deleteTopicInNameServer(addrs, topic); } @Override public void deleteSubscriptionGroup(String addr, String groupName) throws RemotingException, MQBrokerException, InterruptedException, - MQClientException { + MQClientException { defaultMQAdminExtImpl.deleteSubscriptionGroup(addr, groupName); } @Override public void createAndUpdateKvConfig(String namespace, String key, String value) throws RemotingException, MQBrokerException, - InterruptedException, MQClientException { + InterruptedException, MQClientException { defaultMQAdminExtImpl.createAndUpdateKvConfig(namespace, key, value); } @Override public void deleteKvConfig(String namespace, String key) throws RemotingException, MQBrokerException, InterruptedException, - MQClientException { + MQClientException { defaultMQAdminExtImpl.deleteKvConfig(namespace, key); } public List resetOffsetByTimestampOld(String consumerGroup, String topic, long timestamp, boolean force) - throws RemotingException, MQBrokerException, InterruptedException, MQClientException { + throws RemotingException, MQBrokerException, InterruptedException, MQClientException { return defaultMQAdminExtImpl.resetOffsetByTimestampOld(consumerGroup, topic, timestamp, force); } @Override public Map resetOffsetByTimestamp(String topic, String group, long timestamp, boolean isForce) - throws RemotingException, MQBrokerException, InterruptedException, MQClientException { + throws RemotingException, MQBrokerException, InterruptedException, MQClientException { return resetOffsetByTimestamp(topic, group, timestamp, isForce, false); } public Map resetOffsetByTimestamp(String topic, String group, long timestamp, boolean isForce, boolean isC) - throws RemotingException, MQBrokerException, InterruptedException, MQClientException { + throws RemotingException, MQBrokerException, InterruptedException, MQClientException { return defaultMQAdminExtImpl.resetOffsetByTimestamp(topic, group, timestamp, isForce, isC); } @Override public void resetOffsetNew(String consumerGroup, String topic, long timestamp) throws RemotingException, MQBrokerException, - InterruptedException, MQClientException { + InterruptedException, MQClientException { this.defaultMQAdminExtImpl.resetOffsetNew(consumerGroup, topic, timestamp); } @Override public Map> getConsumeStatus(String topic, String group, String clientAddr) throws RemotingException, - MQBrokerException, InterruptedException, MQClientException { + MQBrokerException, InterruptedException, MQClientException { return defaultMQAdminExtImpl.getConsumeStatus(topic, group, clientAddr); } @Override public void createOrUpdateOrderConf(String key, String value, boolean isCluster) throws RemotingException, MQBrokerException, - InterruptedException, MQClientException { + InterruptedException, MQClientException { defaultMQAdminExtImpl.createOrUpdateOrderConf(key, value, isCluster); } @Override public GroupList queryTopicConsumeByWho(String topic) throws InterruptedException, MQBrokerException, RemotingException, - MQClientException { + MQClientException { return this.defaultMQAdminExtImpl.queryTopicConsumeByWho(topic); } @Override public List queryConsumeTimeSpan(final String topic, final String group) throws InterruptedException, MQBrokerException, - RemotingException, MQClientException { + RemotingException, MQClientException { return this.defaultMQAdminExtImpl.queryConsumeTimeSpan(topic, group); } @Override public boolean cleanExpiredConsumerQueue(String cluster) throws RemotingConnectException, RemotingSendRequestException, - RemotingTimeoutException, MQClientException, InterruptedException { + RemotingTimeoutException, MQClientException, InterruptedException { return defaultMQAdminExtImpl.cleanExpiredConsumerQueue(cluster); } @Override public boolean cleanExpiredConsumerQueueByAddr(String addr) throws RemotingConnectException, RemotingSendRequestException, - RemotingTimeoutException, MQClientException, InterruptedException { + RemotingTimeoutException, MQClientException, InterruptedException { return defaultMQAdminExtImpl.cleanExpiredConsumerQueueByAddr(addr); } @Override public boolean cleanUnusedTopic(String cluster) throws RemotingConnectException, RemotingSendRequestException, - RemotingTimeoutException, MQClientException, InterruptedException { + RemotingTimeoutException, MQClientException, InterruptedException { return defaultMQAdminExtImpl.cleanUnusedTopicByAddr(cluster); } @Override public boolean cleanUnusedTopicByAddr(String addr) throws RemotingConnectException, RemotingSendRequestException, - RemotingTimeoutException, MQClientException, InterruptedException { + RemotingTimeoutException, MQClientException, InterruptedException { return defaultMQAdminExtImpl.cleanUnusedTopicByAddr(addr); } @Override public ConsumerRunningInfo getConsumerRunningInfo(String consumerGroup, String clientId, boolean jstack) throws RemotingException, - MQClientException, InterruptedException { + MQClientException, InterruptedException { return defaultMQAdminExtImpl.getConsumerRunningInfo(consumerGroup, clientId, jstack); } @Override public ConsumeMessageDirectlyResult consumeMessageDirectly(String consumerGroup, String clientId, String msgId) - throws RemotingException, MQClientException, InterruptedException, MQBrokerException { + throws RemotingException, MQClientException, InterruptedException, MQBrokerException { return defaultMQAdminExtImpl.consumeMessageDirectly(consumerGroup, clientId, msgId); } @Override - public ConsumeMessageDirectlyResult consumeMessageDirectly(final String consumerGroup, final String clientId, final String topic, final String msgId) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { + public ConsumeMessageDirectlyResult consumeMessageDirectly(final String consumerGroup, final String clientId, final String topic, + final String msgId) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { return defaultMQAdminExtImpl.consumeMessageDirectly(consumerGroup, clientId, topic, msgId); } @Override public List messageTrackDetail(MessageExt msg) throws RemotingException, MQClientException, InterruptedException, - MQBrokerException { + MQBrokerException { return this.defaultMQAdminExtImpl.messageTrackDetail(msg); } @Override public void cloneGroupOffset(String srcGroup, String destGroup, String topic, boolean isOffline) throws RemotingException, - MQClientException, InterruptedException, MQBrokerException { + MQClientException, InterruptedException, MQBrokerException { this.defaultMQAdminExtImpl.cloneGroupOffset(srcGroup, destGroup, topic, isOffline); } @Override public BrokerStatsData viewBrokerStatsData(String brokerAddr, String statsName, String statsKey) throws RemotingConnectException, - RemotingSendRequestException, RemotingTimeoutException, MQClientException, InterruptedException { + RemotingSendRequestException, RemotingTimeoutException, MQClientException, InterruptedException { return this.defaultMQAdminExtImpl.viewBrokerStatsData(brokerAddr, statsName, statsKey); } @Override public Set getClusterList(String topic) throws RemotingConnectException, RemotingSendRequestException, - RemotingTimeoutException, MQClientException, InterruptedException { + RemotingTimeoutException, MQClientException, InterruptedException { return this.defaultMQAdminExtImpl.getClusterList(topic); } @Override - public ConsumeStatsList fetchConsumeStatsInBroker(final String brokerAddr, boolean isOrder, long timeoutMillis) throws RemotingConnectException, RemotingSendRequestException, - RemotingTimeoutException, MQClientException, InterruptedException { + public ConsumeStatsList fetchConsumeStatsInBroker(final String brokerAddr, boolean isOrder, + long timeoutMillis) throws RemotingConnectException, RemotingSendRequestException, + RemotingTimeoutException, MQClientException, InterruptedException { return this.defaultMQAdminExtImpl.fetchConsumeStatsInBroker(brokerAddr, isOrder, timeoutMillis); } @@ -395,24 +410,25 @@ public class DefaultMQAdminExt extends ClientConfig implements MQAdminExt { } @Override - public SubscriptionGroupWrapper getAllSubscriptionGroup(final String brokerAddr, long timeoutMillis) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, - RemotingConnectException, MQBrokerException { + public SubscriptionGroupWrapper getAllSubscriptionGroup(final String brokerAddr, + long timeoutMillis) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, + RemotingConnectException, MQBrokerException { return this.defaultMQAdminExtImpl.getAllSubscriptionGroup(brokerAddr, timeoutMillis); } @Override - public TopicConfigSerializeWrapper getAllTopicGroup(final String brokerAddr, long timeoutMillis) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, - RemotingConnectException, MQBrokerException { + public TopicConfigSerializeWrapper getAllTopicGroup(final String brokerAddr, + long timeoutMillis) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, + RemotingConnectException, MQBrokerException { return this.defaultMQAdminExtImpl.getAllTopicGroup(brokerAddr, timeoutMillis); } - /* (non-Javadoc) * @see org.apache.rocketmq.client.MQAdmin#queryMessageByUniqKey(java.lang.String, java.lang.String) */ @Override public MessageExt viewMessage(String topic, String msgId) - throws RemotingException, MQBrokerException, InterruptedException, MQClientException { + throws RemotingException, MQBrokerException, InterruptedException, MQClientException { return this.defaultMQAdminExtImpl.viewMessage(topic, msgId); } @@ -433,23 +449,24 @@ public class DefaultMQAdminExt extends ClientConfig implements MQAdminExt { } @Override - public void updateConsumeOffset(String brokerAddr, String consumeGroup, MessageQueue mq, long offset) throws RemotingException, InterruptedException, MQBrokerException { + public void updateConsumeOffset(String brokerAddr, String consumeGroup, MessageQueue mq, + long offset) throws RemotingException, InterruptedException, MQBrokerException { this.defaultMQAdminExtImpl.updateConsumeOffset(brokerAddr, consumeGroup, mq, offset); } @Override public void updateNameServerConfig(final Properties properties, final List nameServers) - throws InterruptedException, RemotingConnectException, - UnsupportedEncodingException, MQBrokerException, RemotingTimeoutException, - MQClientException, RemotingSendRequestException { + throws InterruptedException, RemotingConnectException, + UnsupportedEncodingException, MQBrokerException, RemotingTimeoutException, + MQClientException, RemotingSendRequestException { this.defaultMQAdminExtImpl.updateNameServerConfig(properties, nameServers); } @Override public Map getNameServerConfig(final List nameServers) - throws InterruptedException, RemotingTimeoutException, - RemotingSendRequestException, RemotingConnectException, MQClientException, - UnsupportedEncodingException { + throws InterruptedException, RemotingTimeoutException, + RemotingSendRequestException, RemotingConnectException, MQClientException, + UnsupportedEncodingException { return this.defaultMQAdminExtImpl.getNameServerConfig(nameServers); } } diff --git a/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExtImpl.java b/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExtImpl.java index a0117a87..847a2c0b 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExtImpl.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExtImpl.java @@ -16,6 +16,20 @@ */ package org.apache.rocketmq.tools.admin; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Properties; +import java.util.Random; +import java.util.Set; +import org.apache.commons.lang3.StringUtils; import org.apache.rocketmq.client.QueryResult; import org.apache.rocketmq.client.admin.MQAdminExtInner; import org.apache.rocketmq.client.exception.MQBrokerException; @@ -27,12 +41,32 @@ import org.apache.rocketmq.common.MixAll; import org.apache.rocketmq.common.ServiceState; import org.apache.rocketmq.common.TopicConfig; import org.apache.rocketmq.common.UtilAll; -import org.apache.rocketmq.common.admin.*; +import org.apache.rocketmq.common.admin.ConsumeStats; +import org.apache.rocketmq.common.admin.OffsetWrapper; +import org.apache.rocketmq.common.admin.RollbackStats; +import org.apache.rocketmq.common.admin.TopicOffset; +import org.apache.rocketmq.common.admin.TopicStatsTable; import org.apache.rocketmq.common.help.FAQUrl; -import org.apache.rocketmq.common.message.*; +import org.apache.rocketmq.common.message.MessageClientExt; +import org.apache.rocketmq.common.message.MessageConst; +import org.apache.rocketmq.common.message.MessageDecoder; +import org.apache.rocketmq.common.message.MessageExt; +import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.common.namesrv.NamesrvUtil; import org.apache.rocketmq.common.protocol.ResponseCode; -import org.apache.rocketmq.common.protocol.body.*; +import org.apache.rocketmq.common.protocol.body.BrokerStatsData; +import org.apache.rocketmq.common.protocol.body.ClusterInfo; +import org.apache.rocketmq.common.protocol.body.ConsumeMessageDirectlyResult; +import org.apache.rocketmq.common.protocol.body.ConsumeStatsList; +import org.apache.rocketmq.common.protocol.body.ConsumerConnection; +import org.apache.rocketmq.common.protocol.body.ConsumerRunningInfo; +import org.apache.rocketmq.common.protocol.body.GroupList; +import org.apache.rocketmq.common.protocol.body.KVTable; +import org.apache.rocketmq.common.protocol.body.ProducerConnection; +import org.apache.rocketmq.common.protocol.body.QueueTimeSpan; +import org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper; +import org.apache.rocketmq.common.protocol.body.TopicConfigSerializeWrapper; +import org.apache.rocketmq.common.protocol.body.TopicList; import org.apache.rocketmq.common.protocol.header.UpdateConsumerOffsetRequestHeader; import org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData; import org.apache.rocketmq.common.protocol.route.BrokerData; @@ -42,17 +76,15 @@ import org.apache.rocketmq.common.subscription.SubscriptionGroupConfig; import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.remoting.common.RemotingHelper; import org.apache.rocketmq.remoting.common.RemotingUtil; +import org.apache.rocketmq.remoting.exception.RemotingCommandException; +import org.apache.rocketmq.remoting.exception.RemotingConnectException; +import org.apache.rocketmq.remoting.exception.RemotingException; +import org.apache.rocketmq.remoting.exception.RemotingSendRequestException; +import org.apache.rocketmq.remoting.exception.RemotingTimeoutException; import org.apache.rocketmq.tools.admin.api.MessageTrack; import org.apache.rocketmq.tools.admin.api.TrackType; -import org.apache.commons.lang3.StringUtils; -import org.apache.rocketmq.remoting.exception.*; import org.slf4j.Logger; -import java.io.UnsupportedEncodingException; -import java.util.*; -import java.util.Map.Entry; - - public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { private final Logger log = ClientLogger.getLog(); private final DefaultMQAdminExt defaultMQAdminExt; @@ -62,19 +94,16 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { private long timeoutMillis = 20000; private Random random = new Random(); - public DefaultMQAdminExtImpl(DefaultMQAdminExt defaultMQAdminExt, long timeoutMillis) { this(defaultMQAdminExt, null, timeoutMillis); } - public DefaultMQAdminExtImpl(DefaultMQAdminExt defaultMQAdminExt, RPCHook rpcHook, long timeoutMillis) { this.defaultMQAdminExt = defaultMQAdminExt; this.rpcHook = rpcHook; this.timeoutMillis = timeoutMillis; } - @Override public void start() throws MQClientException { switch (this.serviceState) { @@ -89,8 +118,8 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { if (!registerOK) { this.serviceState = ServiceState.CREATE_JUST; throw new MQClientException("The adminExt group[" + this.defaultMQAdminExt.getAdminExtGroup() - + "] has created already, specifed another name please."// - + FAQUrl.suggestTodo(FAQUrl.GROUP_NAME_DUPLICATE_URL), null); + + "] has created already, specifed another name please."// + + FAQUrl.suggestTodo(FAQUrl.GROUP_NAME_DUPLICATE_URL), null); } mqClientInstance.start(); @@ -103,14 +132,13 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { case START_FAILED: case SHUTDOWN_ALREADY: throw new MQClientException("The AdminExt service state not OK, maybe started once, "// - + this.serviceState// - + FAQUrl.suggestTodo(FAQUrl.CLIENT_SERVICE_NOT_OK), null); + + this.serviceState// + + FAQUrl.suggestTodo(FAQUrl.CLIENT_SERVICE_NOT_OK), null); default: break; } } - @Override public void shutdown() { switch (this.serviceState) { @@ -132,25 +160,25 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { @Override public void updateBrokerConfig(String brokerAddr, Properties properties) throws RemotingConnectException, RemotingSendRequestException, - RemotingTimeoutException, UnsupportedEncodingException, InterruptedException, MQBrokerException { + RemotingTimeoutException, UnsupportedEncodingException, InterruptedException, MQBrokerException { this.mqClientInstance.getMQClientAPIImpl().updateBrokerConfig(brokerAddr, properties, timeoutMillis); } @Override public Properties getBrokerConfig(final String brokerAddr) throws RemotingConnectException, - RemotingSendRequestException, RemotingTimeoutException, UnsupportedEncodingException, InterruptedException, MQBrokerException { + RemotingSendRequestException, RemotingTimeoutException, UnsupportedEncodingException, InterruptedException, MQBrokerException { return this.mqClientInstance.getMQClientAPIImpl().getBrokerConfig(brokerAddr, timeoutMillis); } @Override public void createAndUpdateTopicConfig(String addr, TopicConfig config) throws RemotingException, MQBrokerException, - InterruptedException, MQClientException { + InterruptedException, MQClientException { this.mqClientInstance.getMQClientAPIImpl().createTopic(addr, this.defaultMQAdminExt.getCreateTopicKey(), config, timeoutMillis); } @Override public void createAndUpdateSubscriptionGroupConfig(String addr, SubscriptionGroupConfig config) throws RemotingException, - MQBrokerException, InterruptedException, MQClientException { + MQBrokerException, InterruptedException, MQClientException { this.mqClientInstance.getMQClientAPIImpl().createSubscriptionGroup(addr, config, timeoutMillis); } @@ -168,7 +196,7 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { @Override public TopicStatsTable examineTopicStats(String topic) throws RemotingException, MQClientException, InterruptedException, - MQBrokerException { + MQBrokerException { TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic); TopicStatsTable topicStatsTable = new TopicStatsTable(); @@ -199,19 +227,19 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { @Override public KVTable fetchBrokerRuntimeStats(final String brokerAddr) throws RemotingConnectException, RemotingSendRequestException, - RemotingTimeoutException, InterruptedException, MQBrokerException { + RemotingTimeoutException, InterruptedException, MQBrokerException { return this.mqClientInstance.getMQClientAPIImpl().getBrokerRuntimeInfo(brokerAddr, timeoutMillis); } @Override public ConsumeStats examineConsumeStats(String consumerGroup) throws RemotingException, MQClientException, InterruptedException, - MQBrokerException { + MQBrokerException { return examineConsumeStats(consumerGroup, null); } @Override public ConsumeStats examineConsumeStats(String consumerGroup, String topic) throws RemotingException, MQClientException, - InterruptedException, MQBrokerException { + InterruptedException, MQBrokerException { String retryTopic = MixAll.getRetryTopic(consumerGroup); TopicRouteData topicRouteData = this.examineTopicRouteInfo(retryTopic); ConsumeStats result = new ConsumeStats(); @@ -220,7 +248,7 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { String addr = bd.selectBrokerAddr(); if (addr != null) { ConsumeStats consumeStats = - this.mqClientInstance.getMQClientAPIImpl().getConsumeStats(addr, consumerGroup, topic, timeoutMillis * 3); + this.mqClientInstance.getMQClientAPIImpl().getConsumeStats(addr, consumerGroup, topic, timeoutMillis * 3); result.getOffsetTable().putAll(consumeStats.getOffsetTable()); double value = result.getConsumeTps() + consumeStats.getConsumeTps(); result.setConsumeTps(value); @@ -229,7 +257,7 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { if (result.getOffsetTable().isEmpty()) { throw new MQClientException(ResponseCode.CONSUMER_NOT_ONLINE, - "Not found the consumer group consume stats, because return offset table is empty, maybe the consumer not consume any message"); + "Not found the consumer group consume stats, because return offset table is empty, maybe the consumer not consume any message"); } return result; @@ -237,7 +265,7 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { @Override public ClusterInfo examineBrokerClusterInfo() throws InterruptedException, MQBrokerException, RemotingTimeoutException, - RemotingSendRequestException, RemotingConnectException { + RemotingSendRequestException, RemotingConnectException { return this.mqClientInstance.getMQClientAPIImpl().getBrokerClusterInfo(timeoutMillis); } @@ -246,7 +274,6 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { return this.mqClientInstance.getMQClientAPIImpl().getTopicRouteInfoFromNameServer(topic, timeoutMillis); } - @Override public MessageExt viewMessage(String topic, String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { try { @@ -260,7 +287,7 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { @Override public ConsumerConnection examineConsumerConnectionInfo(String consumerGroup) throws InterruptedException, MQBrokerException, - RemotingException, MQClientException { + RemotingException, MQClientException { ConsumerConnection result = new ConsumerConnection(); String topic = MixAll.getRetryTopic(consumerGroup); List brokers = this.examineTopicRouteInfo(topic).getBrokerDatas(); @@ -283,7 +310,7 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { @Override public ProducerConnection examineProducerConnectionInfo(String producerGroup, final String topic) throws RemotingException, - MQClientException, InterruptedException, MQBrokerException { + MQClientException, InterruptedException, MQBrokerException { ProducerConnection result = new ProducerConnection(); List brokers = this.examineTopicRouteInfo(topic).getBrokerDatas(); BrokerData brokerData = brokers.get(random.nextInt(brokers.size())); @@ -310,7 +337,7 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { @Override public int wipeWritePermOfBroker(final String namesrvAddr, String brokerName) throws RemotingCommandException, - RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQClientException { + RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQClientException { return this.mqClientInstance.getMQClientAPIImpl().wipeWritePermOfBroker(namesrvAddr, brokerName, timeoutMillis); } @@ -332,7 +359,7 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { @Override public void deleteTopicInBroker(Set addrs, String topic) throws RemotingException, MQBrokerException, InterruptedException, - MQClientException { + MQClientException { for (String addr : addrs) { this.mqClientInstance.getMQClientAPIImpl().deleteTopicInBroker(addr, topic, timeoutMillis); } @@ -340,7 +367,7 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { @Override public void deleteTopicInNameServer(Set addrs, String topic) throws RemotingException, MQBrokerException, InterruptedException, - MQClientException { + MQClientException { if (addrs == null) { String ns = this.mqClientInstance.getMQClientAPIImpl().fetchNameServerAddr(); addrs = new HashSet(Arrays.asList(ns.split(";"))); @@ -352,25 +379,25 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { @Override public void deleteSubscriptionGroup(String addr, String groupName) throws RemotingException, MQBrokerException, InterruptedException, - MQClientException { + MQClientException { this.mqClientInstance.getMQClientAPIImpl().deleteSubscriptionGroup(addr, groupName, timeoutMillis); } @Override public void createAndUpdateKvConfig(String namespace, String key, String value) throws RemotingException, MQBrokerException, - InterruptedException, MQClientException { + InterruptedException, MQClientException { this.mqClientInstance.getMQClientAPIImpl().putKVConfigValue(namespace, key, value, timeoutMillis); } @Override public void deleteKvConfig(String namespace, String key) throws RemotingException, MQBrokerException, InterruptedException, - MQClientException { + MQClientException { this.mqClientInstance.getMQClientAPIImpl().deleteKVConfigValue(namespace, key, timeoutMillis); } @Override public List resetOffsetByTimestampOld(String consumerGroup, String topic, long timestamp, boolean force) - throws RemotingException, MQBrokerException, InterruptedException, MQClientException { + throws RemotingException, MQBrokerException, InterruptedException, MQClientException { TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic); List rollbackStatsList = new ArrayList(); Map topicRouteMap = new HashMap(); @@ -397,7 +424,7 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { if (!hasConsumed) { HashMap topicStatus = - this.mqClientInstance.getMQClientAPIImpl().getTopicStatsInfo(addr, topic, timeoutMillis).getOffsetTable(); + this.mqClientInstance.getMQClientAPIImpl().getTopicStatsInfo(addr, topic, timeoutMillis).getOffsetTable(); for (int i = 0; i < topicRouteMap.get(addr); i++) { MessageQueue queue = new MessageQueue(topic, bd.getBrokerName(), i); OffsetWrapper offsetWrapper = new OffsetWrapper(); @@ -415,13 +442,13 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { @Override public Map resetOffsetByTimestamp(String topic, String group, long timestamp, boolean isForce) - throws RemotingException, MQBrokerException, InterruptedException, MQClientException { + throws RemotingException, MQBrokerException, InterruptedException, MQClientException { return resetOffsetByTimestamp(topic, group, timestamp, isForce, false); } @Override public void resetOffsetNew(String consumerGroup, String topic, long timestamp) throws RemotingException, MQBrokerException, - InterruptedException, MQClientException { + InterruptedException, MQClientException { try { this.resetOffsetByTimestamp(topic, consumerGroup, timestamp, true); } catch (MQClientException e) { @@ -434,7 +461,7 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { } public Map resetOffsetByTimestamp(String topic, String group, long timestamp, boolean isForce, boolean isC) - throws RemotingException, MQBrokerException, InterruptedException, MQClientException { + throws RemotingException, MQBrokerException, InterruptedException, MQClientException { TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic); List brokerDatas = topicRouteData.getBrokerDatas(); Map allOffsetTable = new HashMap(); @@ -443,8 +470,8 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { String addr = brokerData.selectBrokerAddr(); if (addr != null) { Map offsetTable = - this.mqClientInstance.getMQClientAPIImpl().invokeBrokerToResetOffset(addr, topic, group, timestamp, isForce, - timeoutMillis, isC); + this.mqClientInstance.getMQClientAPIImpl().invokeBrokerToResetOffset(addr, topic, group, timestamp, isForce, + timeoutMillis, isC); if (offsetTable != null) { allOffsetTable.putAll(offsetTable); } @@ -455,18 +482,17 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { } private RollbackStats resetOffsetConsumeOffset(String brokerAddr, String consumeGroup, MessageQueue queue, OffsetWrapper offsetWrapper, - long timestamp, boolean force) throws RemotingException, InterruptedException, MQBrokerException { + long timestamp, boolean force) throws RemotingException, InterruptedException, MQBrokerException { long resetOffset; if (timestamp == -1) { resetOffset = this.mqClientInstance.getMQClientAPIImpl().getMaxOffset(brokerAddr, queue.getTopic(), queue.getQueueId(), timeoutMillis); } else { resetOffset = - this.mqClientInstance.getMQClientAPIImpl().searchOffset(brokerAddr, queue.getTopic(), queue.getQueueId(), timestamp, - timeoutMillis); + this.mqClientInstance.getMQClientAPIImpl().searchOffset(brokerAddr, queue.getTopic(), queue.getQueueId(), timestamp, + timeoutMillis); } - RollbackStats rollbackStats = new RollbackStats(); rollbackStats.setBrokerName(queue.getBrokerName()); rollbackStats.setQueueId(queue.getQueueId()); @@ -489,31 +515,31 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { @Override public Map> getConsumeStatus(String topic, String group, String clientAddr) throws RemotingException, - MQBrokerException, InterruptedException, MQClientException { + MQBrokerException, InterruptedException, MQClientException { TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic); List brokerDatas = topicRouteData.getBrokerDatas(); if (brokerDatas != null && brokerDatas.size() > 0) { String addr = brokerDatas.get(0).selectBrokerAddr(); if (addr != null) { return this.mqClientInstance.getMQClientAPIImpl().invokeBrokerToGetConsumerStatus(addr, topic, group, clientAddr, - timeoutMillis); + timeoutMillis); } } return Collections.EMPTY_MAP; } public void createOrUpdateOrderConf(String key, String value, boolean isCluster) throws RemotingException, MQBrokerException, - InterruptedException, MQClientException { + InterruptedException, MQClientException { if (isCluster) { this.mqClientInstance.getMQClientAPIImpl() - .putKVConfigValue(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG, key, value, timeoutMillis); + .putKVConfigValue(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG, key, value, timeoutMillis); } else { String oldOrderConfs = null; try { oldOrderConfs = - this.mqClientInstance.getMQClientAPIImpl().getKVConfigValue(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG, key, - timeoutMillis); + this.mqClientInstance.getMQClientAPIImpl().getKVConfigValue(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG, key, + timeoutMillis); } catch (Exception e) { e.printStackTrace(); } @@ -536,13 +562,13 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { splitor = ";"; } this.mqClientInstance.getMQClientAPIImpl().putKVConfigValue(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG, key, - newOrderConf.toString(), timeoutMillis); + newOrderConf.toString(), timeoutMillis); } } @Override public GroupList queryTopicConsumeByWho(String topic) throws InterruptedException, MQBrokerException, RemotingException, - MQClientException { + MQClientException { TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic); for (BrokerData bd : topicRouteData.getBrokerDatas()) { @@ -559,7 +585,7 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { @Override public List queryConsumeTimeSpan(final String topic, final String group) throws InterruptedException, MQBrokerException, - RemotingException, MQClientException { + RemotingException, MQClientException { List spanSet = new ArrayList(); TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic); for (BrokerData bd : topicRouteData.getBrokerDatas()) { @@ -573,7 +599,7 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { @Override public boolean cleanExpiredConsumerQueue(String cluster) throws RemotingConnectException, RemotingSendRequestException, - RemotingTimeoutException, MQClientException, InterruptedException { + RemotingTimeoutException, MQClientException, InterruptedException { boolean result = false; try { ClusterInfo clusterInfo = examineBrokerClusterInfo(); @@ -592,7 +618,7 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { } public boolean cleanExpiredConsumerQueueByCluster(ClusterInfo clusterInfo, String cluster) throws RemotingConnectException, - RemotingSendRequestException, RemotingTimeoutException, MQClientException, InterruptedException { + RemotingSendRequestException, RemotingTimeoutException, MQClientException, InterruptedException { boolean result = false; String[] addrs = clusterInfo.retrieveAllAddrByCluster(cluster); for (String addr : addrs) { @@ -603,7 +629,7 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { @Override public boolean cleanExpiredConsumerQueueByAddr(String addr) throws RemotingConnectException, RemotingSendRequestException, - RemotingTimeoutException, MQClientException, InterruptedException { + RemotingTimeoutException, MQClientException, InterruptedException { boolean result = mqClientInstance.getMQClientAPIImpl().cleanExpiredConsumeQueue(addr, timeoutMillis); log.warn("clean expired ConsumeQueue on target " + addr + " broker " + result); return result; @@ -611,7 +637,7 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { @Override public boolean cleanUnusedTopic(String cluster) throws RemotingConnectException, RemotingSendRequestException, - RemotingTimeoutException, MQClientException, InterruptedException { + RemotingTimeoutException, MQClientException, InterruptedException { boolean result = false; try { ClusterInfo clusterInfo = examineBrokerClusterInfo(); @@ -630,7 +656,7 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { } public boolean cleanUnusedTopicByCluster(ClusterInfo clusterInfo, String cluster) throws RemotingConnectException, - RemotingSendRequestException, RemotingTimeoutException, MQClientException, InterruptedException { + RemotingSendRequestException, RemotingTimeoutException, MQClientException, InterruptedException { boolean result = false; String[] addrs = clusterInfo.retrieveAllAddrByCluster(cluster); for (String addr : addrs) { @@ -641,7 +667,7 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { @Override public boolean cleanUnusedTopicByAddr(String addr) throws RemotingConnectException, RemotingSendRequestException, - RemotingTimeoutException, MQClientException, InterruptedException { + RemotingTimeoutException, MQClientException, InterruptedException { boolean result = mqClientInstance.getMQClientAPIImpl().cleanUnusedTopicByAddr(addr, timeoutMillis); log.warn("clean expired ConsumeQueue on target " + addr + " broker " + result); return result; @@ -649,7 +675,7 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { @Override public ConsumerRunningInfo getConsumerRunningInfo(String consumerGroup, String clientId, boolean jstack) throws RemotingException, - MQClientException, InterruptedException { + MQClientException, InterruptedException { String topic = MixAll.RETRY_GROUP_TOPIC_PREFIX + consumerGroup; TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic); List brokerDatas = topicRouteData.getBrokerDatas(); @@ -658,7 +684,7 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { String addr = brokerData.selectBrokerAddr(); if (addr != null) { return this.mqClientInstance.getMQClientAPIImpl().getConsumerRunningInfo(addr, consumerGroup, clientId, jstack, - timeoutMillis * 3); + timeoutMillis * 3); } } } @@ -667,29 +693,30 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { @Override public ConsumeMessageDirectlyResult consumeMessageDirectly(String consumerGroup, String clientId, String msgId) - throws RemotingException, MQClientException, InterruptedException, MQBrokerException { + throws RemotingException, MQClientException, InterruptedException, MQBrokerException { MessageExt msg = this.viewMessage(msgId); return this.mqClientInstance.getMQClientAPIImpl().consumeMessageDirectly(RemotingUtil.socketAddress2String(msg.getStoreHost()), - consumerGroup, clientId, msgId, timeoutMillis * 3); + consumerGroup, clientId, msgId, timeoutMillis * 3); } @Override - public ConsumeMessageDirectlyResult consumeMessageDirectly(final String consumerGroup, final String clientId, final String topic, final String msgId) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { + public ConsumeMessageDirectlyResult consumeMessageDirectly(final String consumerGroup, final String clientId, final String topic, + final String msgId) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { MessageExt msg = this.viewMessage(topic, msgId); if (msg.getProperty(MessageConst.PROPERTY_UNIQ_CLIENT_MESSAGE_ID_KEYIDX) == null) { return this.mqClientInstance.getMQClientAPIImpl().consumeMessageDirectly(RemotingUtil.socketAddress2String(msg.getStoreHost()), - consumerGroup, clientId, msgId, timeoutMillis * 3); + consumerGroup, clientId, msgId, timeoutMillis * 3); } else { - MessageClientExt msgClient = (MessageClientExt) msg; + MessageClientExt msgClient = (MessageClientExt)msg; return this.mqClientInstance.getMQClientAPIImpl().consumeMessageDirectly(RemotingUtil.socketAddress2String(msg.getStoreHost()), - consumerGroup, clientId, msgClient.getOffsetMsgId(), timeoutMillis * 3); + consumerGroup, clientId, msgClient.getOffsetMsgId(), timeoutMillis * 3); } } @Override public List messageTrackDetail(MessageExt msg) throws RemotingException, MQClientException, InterruptedException, - MQBrokerException { + MQBrokerException { List result = new ArrayList(); GroupList groupList = this.queryTopicConsumeByWho(msg.getTopic()); @@ -750,8 +777,8 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { Entry next = it.next(); if (next.getKey().equals(msg.getTopic())) { if (next.getValue().getTagsSet().contains(msg.getTags()) - || next.getValue().getTagsSet().contains("*") - || next.getValue().getTagsSet().isEmpty()) { + || next.getValue().getTagsSet().contains("*") + || next.getValue().getTagsSet().isEmpty()) { } else { mt.setTrackType(TrackType.CONSUMED_BUT_FILTERED); } @@ -771,7 +798,7 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { } public boolean consumed(final MessageExt msg, final String group) throws RemotingException, MQClientException, InterruptedException, - MQBrokerException { + MQBrokerException { ConsumeStats cstats = this.examineConsumeStats(group); @@ -799,7 +826,7 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { @Override public void cloneGroupOffset(String srcGroup, String destGroup, String topic, boolean isOffline) throws RemotingException, - MQClientException, InterruptedException, MQBrokerException { + MQClientException, InterruptedException, MQBrokerException { String retryTopic = MixAll.getRetryTopic(srcGroup); TopicRouteData topicRouteData = this.examineTopicRouteInfo(retryTopic); @@ -813,26 +840,26 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { @Override public BrokerStatsData viewBrokerStatsData(String brokerAddr, String statsName, String statsKey) throws RemotingConnectException, - RemotingSendRequestException, RemotingTimeoutException, MQClientException, InterruptedException { + RemotingSendRequestException, RemotingTimeoutException, MQClientException, InterruptedException { return this.mqClientInstance.getMQClientAPIImpl().viewBrokerStatsData(brokerAddr, statsName, statsKey, timeoutMillis); } @Override public Set getClusterList(String topic) throws RemotingConnectException, RemotingSendRequestException, - RemotingTimeoutException, MQClientException, InterruptedException { + RemotingTimeoutException, MQClientException, InterruptedException { return this.mqClientInstance.getMQClientAPIImpl().getClusterList(topic, timeoutMillis); } @Override public ConsumeStatsList fetchConsumeStatsInBroker(final String brokerAddr, boolean isOrder, long timeoutMillis) - throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, MQClientException, - InterruptedException { + throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, MQClientException, + InterruptedException { return this.mqClientInstance.getMQClientAPIImpl().fetchConsumeStatsInBroker(brokerAddr, isOrder, timeoutMillis); } @Override public Set getTopicClusterList(final String topic) throws InterruptedException, MQBrokerException, MQClientException, - RemotingException { + RemotingException { Set clusterSet = new HashSet(); ClusterInfo clusterInfo = examineBrokerClusterInfo(); TopicRouteData topicRouteData = examineTopicRouteInfo(topic); @@ -850,13 +877,13 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { @Override public SubscriptionGroupWrapper getAllSubscriptionGroup(final String brokerAddr, long timeoutMillis) throws InterruptedException, - RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException { + RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException { return this.mqClientInstance.getMQClientAPIImpl().getAllSubscriptionGroup(brokerAddr, timeoutMillis); } @Override public TopicConfigSerializeWrapper getAllTopicGroup(final String brokerAddr, long timeoutMillis) throws InterruptedException, - RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException { + RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException { return this.mqClientInstance.getMQClientAPIImpl().getAllTopicConfig(brokerAddr, timeoutMillis); } @@ -897,12 +924,13 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { @Override public QueryResult queryMessage(String topic, String key, int maxNum, long begin, long end) throws MQClientException, - InterruptedException { + InterruptedException { return this.mqClientInstance.getMQAdminImpl().queryMessage(topic, key, maxNum, begin, end); } @Override - public void updateConsumeOffset(String brokerAddr, String consumeGroup, MessageQueue mq, long offset) throws RemotingException, InterruptedException, MQBrokerException { + public void updateConsumeOffset(String brokerAddr, String consumeGroup, MessageQueue mq, + long offset) throws RemotingException, InterruptedException, MQBrokerException { UpdateConsumerOffsetRequestHeader requestHeader = new UpdateConsumerOffsetRequestHeader(); requestHeader.setConsumerGroup(consumeGroup); requestHeader.setTopic(mq.getTopic()); @@ -913,17 +941,17 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { @Override public void updateNameServerConfig(final Properties properties, final List nameServers) - throws InterruptedException, RemotingConnectException, - UnsupportedEncodingException, RemotingSendRequestException, RemotingTimeoutException, - MQClientException, MQBrokerException { + throws InterruptedException, RemotingConnectException, + UnsupportedEncodingException, RemotingSendRequestException, RemotingTimeoutException, + MQClientException, MQBrokerException { this.mqClientInstance.getMQClientAPIImpl().updateNameServerConfig(properties, nameServers, timeoutMillis); } @Override public Map getNameServerConfig(final List nameServers) - throws InterruptedException, RemotingTimeoutException, - RemotingSendRequestException, RemotingConnectException, MQClientException, - UnsupportedEncodingException { + throws InterruptedException, RemotingTimeoutException, + RemotingSendRequestException, RemotingConnectException, MQClientException, + UnsupportedEncodingException { return this.mqClientInstance.getMQClientAPIImpl().getNameServerConfig(nameServers, timeoutMillis); } diff --git a/tools/src/main/java/org/apache/rocketmq/tools/admin/MQAdminExt.java b/tools/src/main/java/org/apache/rocketmq/tools/admin/MQAdminExt.java index df4fe892..50560109 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/admin/MQAdminExt.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/admin/MQAdminExt.java @@ -16,6 +16,11 @@ */ package org.apache.rocketmq.tools.admin; +import java.io.UnsupportedEncodingException; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; import org.apache.rocketmq.client.MQAdmin; import org.apache.rocketmq.client.exception.MQBrokerException; import org.apache.rocketmq.client.exception.MQClientException; @@ -25,17 +30,27 @@ import org.apache.rocketmq.common.admin.RollbackStats; import org.apache.rocketmq.common.admin.TopicStatsTable; import org.apache.rocketmq.common.message.MessageExt; import org.apache.rocketmq.common.message.MessageQueue; -import org.apache.rocketmq.common.protocol.body.*; +import org.apache.rocketmq.common.protocol.body.BrokerStatsData; +import org.apache.rocketmq.common.protocol.body.ClusterInfo; +import org.apache.rocketmq.common.protocol.body.ConsumeMessageDirectlyResult; +import org.apache.rocketmq.common.protocol.body.ConsumeStatsList; +import org.apache.rocketmq.common.protocol.body.ConsumerConnection; +import org.apache.rocketmq.common.protocol.body.ConsumerRunningInfo; +import org.apache.rocketmq.common.protocol.body.GroupList; +import org.apache.rocketmq.common.protocol.body.KVTable; +import org.apache.rocketmq.common.protocol.body.ProducerConnection; +import org.apache.rocketmq.common.protocol.body.QueueTimeSpan; +import org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper; +import org.apache.rocketmq.common.protocol.body.TopicConfigSerializeWrapper; +import org.apache.rocketmq.common.protocol.body.TopicList; import org.apache.rocketmq.common.protocol.route.TopicRouteData; import org.apache.rocketmq.common.subscription.SubscriptionGroupConfig; +import org.apache.rocketmq.remoting.exception.RemotingCommandException; +import org.apache.rocketmq.remoting.exception.RemotingConnectException; +import org.apache.rocketmq.remoting.exception.RemotingException; +import org.apache.rocketmq.remoting.exception.RemotingSendRequestException; +import org.apache.rocketmq.remoting.exception.RemotingTimeoutException; import org.apache.rocketmq.tools.admin.api.MessageTrack; -import org.apache.rocketmq.remoting.exception.*; - -import java.io.UnsupportedEncodingException; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Set; public interface MQAdminExt extends MQAdmin { void start() throws MQClientException; @@ -43,53 +58,53 @@ public interface MQAdminExt extends MQAdmin { void shutdown(); void updateBrokerConfig(final String brokerAddr, final Properties properties) throws RemotingConnectException, - RemotingSendRequestException, RemotingTimeoutException, UnsupportedEncodingException, InterruptedException, MQBrokerException; + RemotingSendRequestException, RemotingTimeoutException, UnsupportedEncodingException, InterruptedException, MQBrokerException; Properties getBrokerConfig(final String brokerAddr) throws RemotingConnectException, - RemotingSendRequestException, RemotingTimeoutException, UnsupportedEncodingException, InterruptedException, MQBrokerException; + RemotingSendRequestException, RemotingTimeoutException, UnsupportedEncodingException, InterruptedException, MQBrokerException; void createAndUpdateTopicConfig(final String addr, final TopicConfig config) throws RemotingException, MQBrokerException, - InterruptedException, MQClientException; + InterruptedException, MQClientException; void createAndUpdateSubscriptionGroupConfig(final String addr, final SubscriptionGroupConfig config) throws RemotingException, - MQBrokerException, InterruptedException, MQClientException; + MQBrokerException, InterruptedException, MQClientException; SubscriptionGroupConfig examineSubscriptionGroupConfig(final String addr, final String group); TopicConfig examineTopicConfig(final String addr, final String topic); TopicStatsTable examineTopicStats(final String topic) throws RemotingException, MQClientException, InterruptedException, - MQBrokerException; + MQBrokerException; TopicList fetchAllTopicList() throws RemotingException, MQClientException, InterruptedException; TopicList fetchTopicsByCLuster(String clusterName) throws RemotingException, MQClientException, InterruptedException; KVTable fetchBrokerRuntimeStats(final String brokerAddr) throws RemotingConnectException, RemotingSendRequestException, - RemotingTimeoutException, InterruptedException, MQBrokerException; + RemotingTimeoutException, InterruptedException, MQBrokerException; ConsumeStats examineConsumeStats(final String consumerGroup) throws RemotingException, MQClientException, InterruptedException, - MQBrokerException; + MQBrokerException; ConsumeStats examineConsumeStats(final String consumerGroup, final String topic) throws RemotingException, MQClientException, - InterruptedException, MQBrokerException; + InterruptedException, MQBrokerException; ClusterInfo examineBrokerClusterInfo() throws InterruptedException, MQBrokerException, RemotingTimeoutException, - RemotingSendRequestException, RemotingConnectException; + RemotingSendRequestException, RemotingConnectException; TopicRouteData examineTopicRouteInfo(final String topic) throws RemotingException, MQClientException, InterruptedException; ConsumerConnection examineConsumerConnectionInfo(final String consumerGroup) throws RemotingConnectException, - RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQBrokerException, RemotingException, - MQClientException; + RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQBrokerException, RemotingException, + MQClientException; ProducerConnection examineProducerConnectionInfo(final String producerGroup, final String topic) throws RemotingException, - MQClientException, InterruptedException, MQBrokerException; + MQClientException, InterruptedException, MQBrokerException; List getNameServerAddressList(); int wipeWritePermOfBroker(final String namesrvAddr, String brokerName) throws RemotingCommandException, - RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQClientException; + RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQClientException; void putKVConfig(final String namespace, final String key, final String value); @@ -98,91 +113,94 @@ public interface MQAdminExt extends MQAdmin { KVTable getKVListByNamespace(final String namespace) throws RemotingException, MQClientException, InterruptedException; void deleteTopicInBroker(final Set addrs, final String topic) throws RemotingException, MQBrokerException, - InterruptedException, MQClientException; + InterruptedException, MQClientException; void deleteTopicInNameServer(final Set addrs, final String topic) throws RemotingException, MQBrokerException, - InterruptedException, MQClientException; + InterruptedException, MQClientException; void deleteSubscriptionGroup(final String addr, String groupName) throws RemotingException, MQBrokerException, - InterruptedException, MQClientException; + InterruptedException, MQClientException; void createAndUpdateKvConfig(String namespace, String key, String value) throws RemotingException, MQBrokerException, - InterruptedException, MQClientException; + InterruptedException, MQClientException; void deleteKvConfig(String namespace, String key) throws RemotingException, MQBrokerException, InterruptedException, - MQClientException; + MQClientException; List resetOffsetByTimestampOld(String consumerGroup, String topic, long timestamp, boolean force) - throws RemotingException, MQBrokerException, InterruptedException, MQClientException; + throws RemotingException, MQBrokerException, InterruptedException, MQClientException; Map resetOffsetByTimestamp(String topic, String group, long timestamp, boolean isForce) - throws RemotingException, MQBrokerException, InterruptedException, MQClientException; + throws RemotingException, MQBrokerException, InterruptedException, MQClientException; void resetOffsetNew(String consumerGroup, String topic, long timestamp) throws RemotingException, MQBrokerException, - InterruptedException, MQClientException; + InterruptedException, MQClientException; Map> getConsumeStatus(String topic, String group, String clientAddr) throws RemotingException, - MQBrokerException, InterruptedException, MQClientException; + MQBrokerException, InterruptedException, MQClientException; void createOrUpdateOrderConf(String key, String value, boolean isCluster) throws RemotingException, MQBrokerException, - InterruptedException, MQClientException; + InterruptedException, MQClientException; GroupList queryTopicConsumeByWho(final String topic) throws RemotingConnectException, RemotingSendRequestException, - RemotingTimeoutException, InterruptedException, MQBrokerException, RemotingException, MQClientException; + RemotingTimeoutException, InterruptedException, MQBrokerException, RemotingException, MQClientException; List queryConsumeTimeSpan(final String topic, final String group) throws InterruptedException, MQBrokerException, - RemotingException, MQClientException; + RemotingException, MQClientException; boolean cleanExpiredConsumerQueue(String cluster) throws RemotingConnectException, RemotingSendRequestException, - RemotingTimeoutException, MQClientException, InterruptedException; + RemotingTimeoutException, MQClientException, InterruptedException; boolean cleanExpiredConsumerQueueByAddr(String addr) throws RemotingConnectException, RemotingSendRequestException, - RemotingTimeoutException, MQClientException, InterruptedException; + RemotingTimeoutException, MQClientException, InterruptedException; boolean cleanUnusedTopic(String cluster) throws RemotingConnectException, RemotingSendRequestException, - RemotingTimeoutException, MQClientException, InterruptedException; - + RemotingTimeoutException, MQClientException, InterruptedException; boolean cleanUnusedTopicByAddr(String addr) throws RemotingConnectException, RemotingSendRequestException, - RemotingTimeoutException, MQClientException, InterruptedException; + RemotingTimeoutException, MQClientException, InterruptedException; ConsumerRunningInfo getConsumerRunningInfo(final String consumerGroup, final String clientId, final boolean jstack) - throws RemotingException, MQClientException, InterruptedException; + throws RemotingException, MQClientException, InterruptedException; ConsumeMessageDirectlyResult consumeMessageDirectly(String consumerGroup, - String clientId, - String msgId) throws RemotingException, MQClientException, InterruptedException, MQBrokerException; + String clientId, + String msgId) throws RemotingException, MQClientException, InterruptedException, MQBrokerException; ConsumeMessageDirectlyResult consumeMessageDirectly(String consumerGroup, - String clientId, - String topic, - String msgId) throws RemotingException, MQClientException, InterruptedException, MQBrokerException; + String clientId, + String topic, + String msgId) throws RemotingException, MQClientException, InterruptedException, MQBrokerException; List messageTrackDetail(MessageExt msg) throws RemotingException, MQClientException, InterruptedException, - MQBrokerException; + MQBrokerException; void cloneGroupOffset(String srcGroup, String destGroup, String topic, boolean isOffline) throws RemotingException, - MQClientException, InterruptedException, MQBrokerException; + MQClientException, InterruptedException, MQBrokerException; BrokerStatsData viewBrokerStatsData(final String brokerAddr, final String statsName, final String statsKey) - throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, MQClientException, - InterruptedException; + throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, MQClientException, + InterruptedException; Set getClusterList(final String topic) throws RemotingConnectException, RemotingSendRequestException, - RemotingTimeoutException, MQClientException, InterruptedException; + RemotingTimeoutException, MQClientException, InterruptedException; - ConsumeStatsList fetchConsumeStatsInBroker(final String brokerAddr, boolean isOrder, long timeoutMillis) throws RemotingConnectException, RemotingSendRequestException, - RemotingTimeoutException, MQClientException, InterruptedException; + ConsumeStatsList fetchConsumeStatsInBroker(final String brokerAddr, boolean isOrder, + long timeoutMillis) throws RemotingConnectException, RemotingSendRequestException, + RemotingTimeoutException, MQClientException, InterruptedException; Set getTopicClusterList(final String topic) throws InterruptedException, MQBrokerException, MQClientException, RemotingException; - SubscriptionGroupWrapper getAllSubscriptionGroup(final String brokerAddr, long timeoutMillis) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, - RemotingConnectException, MQBrokerException; + SubscriptionGroupWrapper getAllSubscriptionGroup(final String brokerAddr, + long timeoutMillis) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, + RemotingConnectException, MQBrokerException; - TopicConfigSerializeWrapper getAllTopicGroup(final String brokerAddr, long timeoutMillis) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, - RemotingConnectException, MQBrokerException; + TopicConfigSerializeWrapper getAllTopicGroup(final String brokerAddr, + long timeoutMillis) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, + RemotingConnectException, MQBrokerException; - void updateConsumeOffset(String brokerAddr, String consumeGroup, MessageQueue mq, long offset) throws RemotingException, InterruptedException, MQBrokerException; + void updateConsumeOffset(String brokerAddr, String consumeGroup, MessageQueue mq, + long offset) throws RemotingException, InterruptedException, MQBrokerException; /** * Update name server config. @@ -193,7 +211,6 @@ public interface MQAdminExt extends MQAdmin { * * @param properties * @param nameServers - * * @throws InterruptedException * @throws RemotingConnectException * @throws UnsupportedEncodingException @@ -203,8 +220,8 @@ public interface MQAdminExt extends MQAdmin { * @throws MQBrokerException */ void updateNameServerConfig(final Properties properties, final List nameServers) throws InterruptedException, RemotingConnectException, - UnsupportedEncodingException, RemotingSendRequestException, RemotingTimeoutException, - MQClientException, MQBrokerException; + UnsupportedEncodingException, RemotingSendRequestException, RemotingTimeoutException, + MQClientException, MQBrokerException; /** * Get name server config. @@ -213,9 +230,7 @@ public interface MQAdminExt extends MQAdmin { *
If param(nameServers) is null or empty, will use name servers from ns! * * @param nameServers - * * @return The fetched name server config - * * @throws InterruptedException * @throws RemotingTimeoutException * @throws RemotingSendRequestException @@ -224,6 +239,6 @@ public interface MQAdminExt extends MQAdmin { * @throws UnsupportedEncodingException */ Map getNameServerConfig(final List nameServers) throws InterruptedException, - RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, - MQClientException, UnsupportedEncodingException; + RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, + MQClientException, UnsupportedEncodingException; } diff --git a/tools/src/main/java/org/apache/rocketmq/tools/admin/api/MessageTrack.java b/tools/src/main/java/org/apache/rocketmq/tools/admin/api/MessageTrack.java index 324b6618..4445482c 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/admin/api/MessageTrack.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/admin/api/MessageTrack.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.tools.admin.api; @@ -22,40 +22,33 @@ public class MessageTrack { private TrackType trackType; private String exceptionDesc; - public String getConsumerGroup() { return consumerGroup; } - public void setConsumerGroup(String consumerGroup) { this.consumerGroup = consumerGroup; } - public TrackType getTrackType() { return trackType; } - public void setTrackType(TrackType trackType) { this.trackType = trackType; } - public String getExceptionDesc() { return exceptionDesc; } - public void setExceptionDesc(String exceptionDesc) { this.exceptionDesc = exceptionDesc; } - @Override public String toString() { return "MessageTrack [consumerGroup=" + consumerGroup + ", trackType=" + trackType - + ", exceptionDesc=" + exceptionDesc + "]"; + + ", exceptionDesc=" + exceptionDesc + "]"; } } diff --git a/tools/src/main/java/org/apache/rocketmq/tools/admin/api/TrackType.java b/tools/src/main/java/org/apache/rocketmq/tools/admin/api/TrackType.java index 36345f90..df70523c 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/admin/api/TrackType.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/admin/api/TrackType.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.tools.admin.api; diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/CommandUtil.java b/tools/src/main/java/org/apache/rocketmq/tools/command/CommandUtil.java index c675d9a0..8b86ab8f 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/CommandUtil.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/CommandUtil.java @@ -16,6 +16,14 @@ */ package org.apache.rocketmq.tools.command; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; import org.apache.rocketmq.client.exception.MQBrokerException; import org.apache.rocketmq.common.MixAll; import org.apache.rocketmq.common.protocol.body.ClusterInfo; @@ -25,16 +33,13 @@ import org.apache.rocketmq.remoting.exception.RemotingSendRequestException; import org.apache.rocketmq.remoting.exception.RemotingTimeoutException; import org.apache.rocketmq.tools.admin.MQAdminExt; -import java.util.*; - - public class CommandUtil { public static Map/*slave addr*/> fetchMasterAndSlaveDistinguish( - final MQAdminExt adminExt, final String clusterName) - throws InterruptedException, RemotingConnectException, - RemotingTimeoutException, RemotingSendRequestException, - MQBrokerException { + final MQAdminExt adminExt, final String clusterName) + throws InterruptedException, RemotingConnectException, + RemotingTimeoutException, RemotingSendRequestException, + MQBrokerException { Map> masterAndSlaveMap = new HashMap>(4); ClusterInfo clusterInfoSerializeWrapper = adminExt.examineBrokerClusterInfo(); @@ -42,7 +47,7 @@ public class CommandUtil { if (brokerNameSet == null) { System.out - .printf("[error] Make sure the specified clusterName exists or the nameserver which connected is correct."); + .printf("[error] Make sure the specified clusterName exists or the nameserver which connected is correct."); return masterAndSlaveMap; } @@ -58,7 +63,7 @@ public class CommandUtil { for (Long id : brokerData.getBrokerAddrs().keySet()) { if (brokerData.getBrokerAddrs().get(id) == null - || id.longValue() == MixAll.MASTER_ID) { + || id.longValue() == MixAll.MASTER_ID) { continue; } @@ -70,8 +75,8 @@ public class CommandUtil { } public static Set fetchMasterAddrByClusterName(final MQAdminExt adminExt, final String clusterName) - throws InterruptedException, RemotingConnectException, RemotingTimeoutException, - RemotingSendRequestException, MQBrokerException { + throws InterruptedException, RemotingConnectException, RemotingTimeoutException, + RemotingSendRequestException, MQBrokerException { Set masterSet = new HashSet(); ClusterInfo clusterInfoSerializeWrapper = adminExt.examineBrokerClusterInfo(); @@ -91,15 +96,15 @@ public class CommandUtil { } } else { System.out - .printf("[error] Make sure the specified clusterName exists or the nameserver which connected is correct."); + .printf("[error] Make sure the specified clusterName exists or the nameserver which connected is correct."); } return masterSet; } public static Set fetchMasterAndSlaveAddrByClusterName(final MQAdminExt adminExt, final String clusterName) - throws InterruptedException, RemotingConnectException, RemotingTimeoutException, - RemotingSendRequestException, MQBrokerException { + throws InterruptedException, RemotingConnectException, RemotingTimeoutException, + RemotingSendRequestException, MQBrokerException { Set masterSet = new HashSet(); ClusterInfo clusterInfoSerializeWrapper = adminExt.examineBrokerClusterInfo(); @@ -116,29 +121,27 @@ public class CommandUtil { } } else { System.out - .printf("[error] Make sure the specified clusterName exists or the nameserver which connected is correct."); + .printf("[error] Make sure the specified clusterName exists or the nameserver which connected is correct."); } return masterSet; } - public static Set fetchBrokerNameByClusterName(final MQAdminExt adminExt, final String clusterName) - throws Exception { + throws Exception { ClusterInfo clusterInfoSerializeWrapper = adminExt.examineBrokerClusterInfo(); Set brokerNameSet = clusterInfoSerializeWrapper.getClusterAddrTable().get(clusterName); if (brokerNameSet.isEmpty()) { throw new Exception( - "Make sure the specified clusterName exists or the nameserver which connected is correct."); + "Make sure the specified clusterName exists or the nameserver which connected is correct."); } return brokerNameSet; } - public static String fetchBrokerNameByAddr(final MQAdminExt adminExt, final String addr) throws Exception { ClusterInfo clusterInfoSerializeWrapper = adminExt.examineBrokerClusterInfo(); HashMap brokerAddrTable = - clusterInfoSerializeWrapper.getBrokerAddrTable(); + clusterInfoSerializeWrapper.getBrokerAddrTable(); Iterator> it = brokerAddrTable.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = it.next(); @@ -147,8 +150,7 @@ public class CommandUtil { return entry.getKey(); } throw new Exception( - "Make sure the specified broker addr exists or the nameserver which connected is correct."); + "Make sure the specified broker addr exists or the nameserver which connected is correct."); } - } diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/MQAdminStartup.java b/tools/src/main/java/org/apache/rocketmq/tools/command/MQAdminStartup.java index d11dd230..a1753c11 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/MQAdminStartup.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/MQAdminStartup.java @@ -6,45 +6,71 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.tools.command; import ch.qos.logback.classic.LoggerContext; import ch.qos.logback.classic.joran.JoranConfigurator; import ch.qos.logback.core.joran.spi.JoranException; +import java.util.ArrayList; +import java.util.List; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.PosixParser; import org.apache.rocketmq.common.MQVersion; import org.apache.rocketmq.common.MixAll; import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.remoting.protocol.RemotingCommand; import org.apache.rocketmq.srvutil.ServerUtil; +import org.apache.rocketmq.tools.command.broker.BrokerConsumeStatsSubCommad; +import org.apache.rocketmq.tools.command.broker.BrokerStatusSubCommand; +import org.apache.rocketmq.tools.command.broker.CleanExpiredCQSubCommand; +import org.apache.rocketmq.tools.command.broker.CleanUnusedTopicCommand; +import org.apache.rocketmq.tools.command.broker.GetBrokerConfigCommand; +import org.apache.rocketmq.tools.command.broker.SendMsgStatusCommand; +import org.apache.rocketmq.tools.command.broker.UpdateBrokerConfigSubCommand; import org.apache.rocketmq.tools.command.cluster.CLusterSendMsgRTCommand; import org.apache.rocketmq.tools.command.cluster.ClusterListSubCommand; import org.apache.rocketmq.tools.command.connection.ConsumerConnectionSubCommand; import org.apache.rocketmq.tools.command.connection.ProducerConnectionSubCommand; -import org.apache.rocketmq.tools.command.consumer.*; -import org.apache.rocketmq.tools.command.namesrv.*; +import org.apache.rocketmq.tools.command.consumer.ConsumerProgressSubCommand; +import org.apache.rocketmq.tools.command.consumer.ConsumerStatusSubCommand; +import org.apache.rocketmq.tools.command.consumer.DeleteSubscriptionGroupCommand; +import org.apache.rocketmq.tools.command.consumer.StartMonitoringSubCommand; +import org.apache.rocketmq.tools.command.consumer.UpdateSubGroupSubCommand; +import org.apache.rocketmq.tools.command.message.CheckMsgSendRTCommand; +import org.apache.rocketmq.tools.command.message.PrintMessageByQueueCommand; +import org.apache.rocketmq.tools.command.message.PrintMessageSubCommand; +import org.apache.rocketmq.tools.command.message.QueryMsgByIdSubCommand; +import org.apache.rocketmq.tools.command.message.QueryMsgByKeySubCommand; +import org.apache.rocketmq.tools.command.message.QueryMsgByOffsetSubCommand; +import org.apache.rocketmq.tools.command.message.QueryMsgByUniqueKeySubCommand; +import org.apache.rocketmq.tools.command.namesrv.DeleteKvConfigCommand; +import org.apache.rocketmq.tools.command.namesrv.GetNamesrvConfigCommand; +import org.apache.rocketmq.tools.command.namesrv.UpdateKvConfigCommand; +import org.apache.rocketmq.tools.command.namesrv.UpdateNamesrvConfigCommand; +import org.apache.rocketmq.tools.command.namesrv.WipeWritePermSubCommand; import org.apache.rocketmq.tools.command.offset.CloneGroupOffsetCommand; import org.apache.rocketmq.tools.command.offset.ResetOffsetByTimeCommand; import org.apache.rocketmq.tools.command.stats.StatsAllSubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.PosixParser; -import org.apache.rocketmq.tools.command.broker.*; -import org.apache.rocketmq.tools.command.message.*; -import org.apache.rocketmq.tools.command.topic.*; +import org.apache.rocketmq.tools.command.topic.AllocateMQSubCommand; +import org.apache.rocketmq.tools.command.topic.DeleteTopicSubCommand; +import org.apache.rocketmq.tools.command.topic.TopicClusterSubCommand; +import org.apache.rocketmq.tools.command.topic.TopicListSubCommand; +import org.apache.rocketmq.tools.command.topic.TopicRouteSubCommand; +import org.apache.rocketmq.tools.command.topic.TopicStatusSubCommand; +import org.apache.rocketmq.tools.command.topic.UpdateOrderConfCommand; +import org.apache.rocketmq.tools.command.topic.UpdateTopicPermSubCommand; +import org.apache.rocketmq.tools.command.topic.UpdateTopicSubCommand; import org.slf4j.LoggerFactory; -import java.util.ArrayList; -import java.util.List; - - public class MQAdminStartup { protected static List subCommandList = new ArrayList(); @@ -55,7 +81,6 @@ public class MQAdminStartup { public static void main0(String[] args, RPCHook rpcHook) { System.setProperty(RemotingCommand.REMOTING_VERSION_KEY, Integer.toString(MQVersion.CURRENT_VERSION)); - //PackageConflictDetect.detectFastjson(); initCommand(); @@ -86,11 +111,10 @@ public class MQAdminStartup { if (cmd != null) { String[] subargs = parseSubArgs(args); - Options options = ServerUtil.buildCommandlineOptions(new Options()); final CommandLine commandLine = - ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), - new PosixParser()); + ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), + new PosixParser()); if (null == commandLine) { System.exit(-1); return; @@ -124,7 +148,6 @@ public class MQAdminStartup { initCommand(new TopicStatusSubCommand()); initCommand(new TopicClusterSubCommand()); - initCommand(new BrokerStatusSubCommand()); initCommand(new QueryMsgByIdSubCommand()); initCommand(new QueryMsgByKeySubCommand()); @@ -136,7 +159,6 @@ public class MQAdminStartup { initCommand(new SendMsgStatusCommand()); initCommand(new BrokerConsumeStatsSubCommad()); - initCommand(new ProducerConnectionSubCommand()); initCommand(new ConsumerConnectionSubCommand()); initCommand(new ConsumerProgressSubCommand()); @@ -172,7 +194,7 @@ public class MQAdminStartup { private static void initLogback() throws JoranException { String rocketmqHome = System.getProperty(MixAll.ROCKETMQ_HOME_PROPERTY, System.getenv(MixAll.ROCKETMQ_HOME_ENV)); - LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); + LoggerContext lc = (LoggerContext)LoggerFactory.getILoggerFactory(); JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(lc); lc.reset(); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/SubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/SubCommand.java index 744685e3..20352760 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/SubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/SubCommand.java @@ -6,30 +6,26 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.tools.command; -import org.apache.rocketmq.remoting.RPCHook; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Options; - +import org.apache.rocketmq.remoting.RPCHook; public interface SubCommand { public String commandName(); - public String commandDesc(); - public Options buildCommandlineOptions(final Options options); - public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook); } diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/broker/BrokerConsumeStatsSubCommad.java b/tools/src/main/java/org/apache/rocketmq/tools/command/broker/BrokerConsumeStatsSubCommad.java index 57ca9070..485b58cf 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/broker/BrokerConsumeStatsSubCommad.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/broker/BrokerConsumeStatsSubCommad.java @@ -16,6 +16,14 @@ */ package org.apache.rocketmq.tools.command.broker; +import java.util.Collections; +import java.util.Date; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; import org.apache.rocketmq.common.UtilAll; import org.apache.rocketmq.common.admin.ConsumeStats; import org.apache.rocketmq.common.admin.OffsetWrapper; @@ -24,12 +32,6 @@ import org.apache.rocketmq.common.protocol.body.ConsumeStatsList; import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -import java.util.*; - public class BrokerConsumeStatsSubCommad implements SubCommand { @@ -86,14 +88,14 @@ public class BrokerConsumeStatsSubCommad implements SubCommand { ConsumeStatsList consumeStatsList = defaultMQAdminExt.fetchConsumeStatsInBroker(brokerAddr, isOrder, timeoutMillis); System.out.printf("%-32s %-32s %-32s %-4s %-20s %-20s %-20s %s%n", - "#Topic", - "#Group", - "#Broker Name", - "#QID", - "#Broker Offset", - "#Consumer Offset", - "#Diff", - "#LastTime"); + "#Topic", + "#Group", + "#Broker Name", + "#QID", + "#Broker Offset", + "#Consumer Offset", + "#Diff", + "#LastTime"); for (Map> map : consumeStatsList.getConsumeStatsList()) { for (Map.Entry> entry : map.entrySet()) { String group = entry.getKey(); @@ -117,14 +119,14 @@ public class BrokerConsumeStatsSubCommad implements SubCommand { } if (offsetWrapper.getLastTimestamp() > 0) System.out.printf("%-32s %-32s %-32s %-4d %-20d %-20d %-20d %s%n", - UtilAll.frontStringAtLeast(mq.getTopic(), 32), - group, - UtilAll.frontStringAtLeast(mq.getBrokerName(), 32), - mq.getQueueId(), - offsetWrapper.getBrokerOffset(), - offsetWrapper.getConsumerOffset(), - diff, - lastTime + UtilAll.frontStringAtLeast(mq.getTopic(), 32), + group, + UtilAll.frontStringAtLeast(mq.getBrokerName(), 32), + mq.getQueueId(), + offsetWrapper.getBrokerOffset(), + offsetWrapper.getConsumerOffset(), + diff, + lastTime ); } } diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/broker/BrokerStatusSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/broker/BrokerStatusSubCommand.java index 3f5ff79a..2fad2d1f 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/broker/BrokerStatusSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/broker/BrokerStatusSubCommand.java @@ -16,6 +16,13 @@ */ package org.apache.rocketmq.tools.command.broker; +import java.util.Iterator; +import java.util.Map.Entry; +import java.util.Set; +import java.util.TreeMap; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; import org.apache.rocketmq.client.exception.MQBrokerException; import org.apache.rocketmq.common.protocol.body.KVTable; import org.apache.rocketmq.remoting.RPCHook; @@ -25,15 +32,6 @@ import org.apache.rocketmq.remoting.exception.RemotingTimeoutException; import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; import org.apache.rocketmq.tools.command.CommandUtil; import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -import java.util.Iterator; -import java.util.Map.Entry; -import java.util.Set; -import java.util.TreeMap; - public class BrokerStatusSubCommand implements SubCommand { @@ -42,13 +40,11 @@ public class BrokerStatusSubCommand implements SubCommand { return "brokerStatus"; } - @Override public String commandDesc() { return "Fetch broker runtime status data"; } - @Override public Options buildCommandlineOptions(Options options) { Option opt = new Option("b", "brokerAddr", true, "Broker address"); @@ -77,7 +73,7 @@ public class BrokerStatusSubCommand implements SubCommand { printBrokerRuntimeStats(defaultMQAdminExt, brokerAddr, false); } else if (clusterName != null) { Set masterSet = - CommandUtil.fetchMasterAndSlaveAddrByClusterName(defaultMQAdminExt, clusterName); + CommandUtil.fetchMasterAndSlaveAddrByClusterName(defaultMQAdminExt, clusterName); for (String ba : masterSet) { try { printBrokerRuntimeStats(defaultMQAdminExt, ba, true); @@ -87,7 +83,6 @@ public class BrokerStatusSubCommand implements SubCommand { } } - } catch (Exception e) { e.printStackTrace(); } finally { @@ -95,7 +90,8 @@ public class BrokerStatusSubCommand implements SubCommand { } } - public void printBrokerRuntimeStats(final DefaultMQAdminExt defaultMQAdminExt, final String brokerAddr, final boolean printBroker) throws InterruptedException, MQBrokerException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException { + public void printBrokerRuntimeStats(final DefaultMQAdminExt defaultMQAdminExt, final String brokerAddr, + final boolean printBroker) throws InterruptedException, MQBrokerException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException { KVTable kvTable = defaultMQAdminExt.fetchBrokerRuntimeStats(brokerAddr); TreeMap tmp = new TreeMap(); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/broker/CleanExpiredCQSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/broker/CleanExpiredCQSubCommand.java index 71aa78b7..d15ad648 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/broker/CleanExpiredCQSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/broker/CleanExpiredCQSubCommand.java @@ -6,24 +6,23 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.tools.command.broker; -import org.apache.rocketmq.remoting.RPCHook; -import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; -import org.apache.rocketmq.tools.command.SubCommand; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; - +import org.apache.rocketmq.remoting.RPCHook; +import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; +import org.apache.rocketmq.tools.command.SubCommand; public class CleanExpiredCQSubCommand implements SubCommand { @@ -32,13 +31,11 @@ public class CleanExpiredCQSubCommand implements SubCommand { return "cleanExpiredCQ"; } - @Override public String commandDesc() { return "Clean expired ConsumeQueue on broker."; } - @Override public Options buildCommandlineOptions(Options options) { Option opt = new Option("b", "brokerAddr", true, "Broker address"); @@ -52,7 +49,6 @@ public class CleanExpiredCQSubCommand implements SubCommand { return options; } - @Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/broker/CleanUnusedTopicCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/broker/CleanUnusedTopicCommand.java index 0e4c4b4e..ca5778b2 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/broker/CleanUnusedTopicCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/broker/CleanUnusedTopicCommand.java @@ -6,24 +6,23 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.tools.command.broker; -import org.apache.rocketmq.remoting.RPCHook; -import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; -import org.apache.rocketmq.tools.command.SubCommand; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; - +import org.apache.rocketmq.remoting.RPCHook; +import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; +import org.apache.rocketmq.tools.command.SubCommand; public class CleanUnusedTopicCommand implements SubCommand { @@ -32,13 +31,11 @@ public class CleanUnusedTopicCommand implements SubCommand { return "cleanUnusedTopic"; } - @Override public String commandDesc() { return "Clean unused topic on broker."; } - @Override public Options buildCommandlineOptions(Options options) { Option opt = new Option("b", "brokerAddr", true, "Broker address"); @@ -52,7 +49,6 @@ public class CleanUnusedTopicCommand implements SubCommand { return options; } - @Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/broker/GetBrokerConfigCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/broker/GetBrokerConfigCommand.java index 2956264b..d0a271e9 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/broker/GetBrokerConfigCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/broker/GetBrokerConfigCommand.java @@ -17,6 +17,13 @@ package org.apache.rocketmq.tools.command.broker; +import java.io.UnsupportedEncodingException; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; import org.apache.rocketmq.client.exception.MQBrokerException; import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.remoting.exception.RemotingConnectException; @@ -26,14 +33,6 @@ import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; import org.apache.rocketmq.tools.admin.MQAdminExt; import org.apache.rocketmq.tools.command.CommandUtil; import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -import java.io.UnsupportedEncodingException; -import java.util.List; -import java.util.Map; -import java.util.Properties; public class GetBrokerConfigCommand implements SubCommand { @Override @@ -72,29 +71,29 @@ public class GetBrokerConfigCommand implements SubCommand { defaultMQAdminExt.start(); getAndPrint(defaultMQAdminExt, - String.format("============%s============\n", brokerAddr), - brokerAddr); + String.format("============%s============\n", brokerAddr), + brokerAddr); } else if (commandLine.hasOption('c')) { String clusterName = commandLine.getOptionValue('c').trim(); defaultMQAdminExt.start(); Map> masterAndSlaveMap - = CommandUtil.fetchMasterAndSlaveDistinguish(defaultMQAdminExt, clusterName); + = CommandUtil.fetchMasterAndSlaveDistinguish(defaultMQAdminExt, clusterName); for (String masterAddr : masterAndSlaveMap.keySet()) { getAndPrint( - defaultMQAdminExt, - String.format("============Master: %s============\n", masterAddr), - masterAddr + defaultMQAdminExt, + String.format("============Master: %s============\n", masterAddr), + masterAddr ); for (String slaveAddr : masterAndSlaveMap.get(masterAddr)) { getAndPrint( - defaultMQAdminExt, - String.format("============My Master: %s=====Slave: %s============\n", masterAddr, slaveAddr), - slaveAddr + defaultMQAdminExt, + String.format("============My Master: %s=====Slave: %s============\n", masterAddr, slaveAddr), + slaveAddr ); } } @@ -108,9 +107,9 @@ public class GetBrokerConfigCommand implements SubCommand { } protected void getAndPrint(final MQAdminExt defaultMQAdminExt, final String printPrefix, final String addr) - throws InterruptedException, RemotingConnectException, - UnsupportedEncodingException, RemotingTimeoutException, - MQBrokerException, RemotingSendRequestException { + throws InterruptedException, RemotingConnectException, + UnsupportedEncodingException, RemotingTimeoutException, + MQBrokerException, RemotingSendRequestException { System.out.print(printPrefix); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/broker/SendMsgStatusCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/broker/SendMsgStatusCommand.java index d40ba21d..d770d12d 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/broker/SendMsgStatusCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/broker/SendMsgStatusCommand.java @@ -16,33 +16,41 @@ */ package org.apache.rocketmq.tools.command.broker; +import java.io.UnsupportedEncodingException; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; import org.apache.rocketmq.client.producer.DefaultMQProducer; import org.apache.rocketmq.client.producer.SendResult; import org.apache.rocketmq.common.MixAll; import org.apache.rocketmq.common.message.Message; import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; -import java.io.UnsupportedEncodingException; +public class SendMsgStatusCommand implements SubCommand { + private static Message buildMessage(final String topic, final int messageSize) throws UnsupportedEncodingException { + Message msg = new Message(); + msg.setTopic(topic); -public class SendMsgStatusCommand implements SubCommand { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < messageSize; i += 11) { + sb.append("hello jodie"); + } + msg.setBody(sb.toString().getBytes(MixAll.DEFAULT_CHARSET)); + return msg; + } @Override public String commandName() { return "sendMsgStatus"; } - @Override public String commandDesc() { return "send msg to broker."; } - @Override public Options buildCommandlineOptions(Options options) { Option opt = new Option("b", "brokerName", true, "Broker Name"); @@ -60,7 +68,6 @@ public class SendMsgStatusCommand implements SubCommand { return options; } - @Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { final DefaultMQProducer producer = new DefaultMQProducer("PID_SMSC", rpcHook); @@ -85,17 +92,4 @@ public class SendMsgStatusCommand implements SubCommand { producer.shutdown(); } } - - - private static Message buildMessage(final String topic, final int messageSize) throws UnsupportedEncodingException { - Message msg = new Message(); - msg.setTopic(topic); - - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < messageSize; i += 11) { - sb.append("hello jodie"); - } - msg.setBody(sb.toString().getBytes(MixAll.DEFAULT_CHARSET)); - return msg; - } } diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/broker/UpdateBrokerConfigSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/broker/UpdateBrokerConfigSubCommand.java index 1de94572..8718c9e8 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/broker/UpdateBrokerConfigSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/broker/UpdateBrokerConfigSubCommand.java @@ -6,28 +6,26 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.tools.command.broker; +import java.util.Properties; +import java.util.Set; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.srvutil.ServerUtil; import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; import org.apache.rocketmq.tools.command.CommandUtil; import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -import java.util.Properties; -import java.util.Set; - public class UpdateBrokerConfigSubCommand implements SubCommand { @@ -36,13 +34,11 @@ public class UpdateBrokerConfigSubCommand implements SubCommand { return "updateBrokerConfig"; } - @Override public String commandDesc() { return "Update broker's config"; } - @Override public Options buildCommandlineOptions(Options options) { Option opt = new Option("b", "brokerAddr", true, "update which broker"); @@ -64,7 +60,6 @@ public class UpdateBrokerConfigSubCommand implements SubCommand { return options; } - @Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); @@ -92,7 +87,7 @@ public class UpdateBrokerConfigSubCommand implements SubCommand { defaultMQAdminExt.start(); Set masterSet = - CommandUtil.fetchMasterAddrByClusterName(defaultMQAdminExt, clusterName); + CommandUtil.fetchMasterAddrByClusterName(defaultMQAdminExt, clusterName); for (String brokerAddr : masterSet) { try { defaultMQAdminExt.updateBrokerConfig(brokerAddr, properties); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/cluster/CLusterSendMsgRTCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/cluster/CLusterSendMsgRTCommand.java index a8bd3a8d..1ae6d526 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/cluster/CLusterSendMsgRTCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/cluster/CLusterSendMsgRTCommand.java @@ -17,6 +17,16 @@ package org.apache.rocketmq.tools.command.cluster; +import java.math.BigDecimal; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Set; +import java.util.TimeZone; +import java.util.TreeSet; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; import org.apache.rocketmq.client.producer.DefaultMQProducer; import org.apache.rocketmq.common.MixAll; import org.apache.rocketmq.common.message.Message; @@ -24,13 +34,6 @@ import org.apache.rocketmq.common.protocol.body.ClusterInfo; import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -import java.math.BigDecimal; -import java.text.SimpleDateFormat; -import java.util.*; public class CLusterSendMsgRTCommand implements SubCommand { @@ -90,24 +93,24 @@ public class CLusterSendMsgRTCommand implements SubCommand { ClusterInfo clusterInfoSerializeWrapper = defaultMQAdminExt.examineBrokerClusterInfo(); HashMap> clusterAddr = clusterInfoSerializeWrapper - .getClusterAddrTable(); + .getClusterAddrTable(); Set clusterNames = null; long amount = !commandLine.hasOption('a') ? 50 : Long.parseLong(commandLine - .getOptionValue('a').trim()); + .getOptionValue('a').trim()); long size = !commandLine.hasOption('s') ? 128 : Long.parseLong(commandLine - .getOptionValue('s').trim()); + .getOptionValue('s').trim()); long interval = !commandLine.hasOption('i') ? 10 : Long.parseLong(commandLine - .getOptionValue('i').trim()); + .getOptionValue('i').trim()); boolean printAsTlog = !commandLine.hasOption('p') ? false : Boolean - .parseBoolean(commandLine.getOptionValue('p').trim()); + .parseBoolean(commandLine.getOptionValue('p').trim()); String machineRoom = !commandLine.hasOption('m') ? "noname" : commandLine - .getOptionValue('m').trim(); + .getOptionValue('m').trim(); if (commandLine.hasOption('c')) { clusterNames = new TreeSet(); @@ -118,11 +121,11 @@ public class CLusterSendMsgRTCommand implements SubCommand { if (!printAsTlog) { System.out.printf("%-24s %-24s %-4s %-8s %-8s%n", - "#Cluster Name", - "#Broker Name", - "#RT", - "#successCount", - "#failCount" + "#Cluster Name", + "#Broker Name", + "#RT", + "#successCount", + "#failCount" ); } @@ -158,19 +161,19 @@ public class CLusterSendMsgRTCommand implements SubCommand { } } - double rt = (double) elapsed / (amount - 1); + double rt = (double)elapsed / (amount - 1); if (!printAsTlog) { System.out.printf("%-24s %-24s %-8s %-16s %-16s%n", - clusterName, - brokerName, - String.format("%.2f", rt), - successCount, - failCount + clusterName, + brokerName, + String.format("%.2f", rt), + successCount, + failCount ); } else { System.out.printf(String.format("%s|%s|%s|%s|%s%n", getCurTime(), - machineRoom, clusterName, brokerName, - new BigDecimal(rt).setScale(0, BigDecimal.ROUND_HALF_UP))); + machineRoom, clusterName, brokerName, + new BigDecimal(rt).setScale(0, BigDecimal.ROUND_HALF_UP))); } } diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/cluster/ClusterListSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/cluster/ClusterListSubCommand.java index b649af18..eb250cf0 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/cluster/ClusterListSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/cluster/ClusterListSubCommand.java @@ -16,6 +16,13 @@ */ package org.apache.rocketmq.tools.command.cluster; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; import org.apache.rocketmq.client.exception.MQBrokerException; import org.apache.rocketmq.common.protocol.body.ClusterInfo; import org.apache.rocketmq.common.protocol.body.KVTable; @@ -26,15 +33,6 @@ import org.apache.rocketmq.remoting.exception.RemotingSendRequestException; import org.apache.rocketmq.remoting.exception.RemotingTimeoutException; import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -import java.util.Iterator; -import java.util.Map; -import java.util.Set; -import java.util.TreeSet; - public class ClusterListSubCommand implements SubCommand { @@ -43,13 +41,11 @@ public class ClusterListSubCommand implements SubCommand { return "clusterList"; } - @Override public String commandDesc() { return "List all of clusters"; } - @Override public Options buildCommandlineOptions(Options options) { Option opt = new Option("m", "moreStats", false, "Print more stats"); @@ -89,7 +85,8 @@ public class ClusterListSubCommand implements SubCommand { } else { this.printClusterBaseInfo(defaultMQAdminExt); } - } while (enableInterval); + } + while (enableInterval); } catch (Exception e) { e.printStackTrace(); } finally { @@ -98,17 +95,17 @@ public class ClusterListSubCommand implements SubCommand { } private void printClusterMoreStats(final DefaultMQAdminExt defaultMQAdminExt) throws RemotingConnectException, - RemotingTimeoutException, RemotingSendRequestException, InterruptedException, MQBrokerException { + RemotingTimeoutException, RemotingSendRequestException, InterruptedException, MQBrokerException { ClusterInfo clusterInfoSerializeWrapper = defaultMQAdminExt.examineBrokerClusterInfo(); System.out.printf("%-16s %-32s %14s %14s %14s %14s%n", - "#Cluster Name", - "#Broker Name", - "#InTotalYest", - "#OutTotalYest", - "#InTotalToday", - "#OutTotalToday" + "#Cluster Name", + "#Broker Name", + "#InTotalYest", + "#OutTotalYest", + "#InTotalToday", + "#OutTotalToday" ); Iterator>> itCluster = clusterInfoSerializeWrapper.getClusterAddrTable().entrySet().iterator(); @@ -149,12 +146,12 @@ public class ClusterListSubCommand implements SubCommand { } System.out.printf("%-16s %-32s %14d %14d %14d %14d%n", - clusterName, - brokerName, - inTotalYest, - outTotalYest, - inTotalToday, - outTotalToday + clusterName, + brokerName, + inTotalYest, + outTotalYest, + inTotalToday, + outTotalToday ); } } @@ -167,21 +164,21 @@ public class ClusterListSubCommand implements SubCommand { } private void printClusterBaseInfo(final DefaultMQAdminExt defaultMQAdminExt) throws RemotingConnectException, RemotingTimeoutException, - RemotingSendRequestException, InterruptedException, MQBrokerException { + RemotingSendRequestException, InterruptedException, MQBrokerException { ClusterInfo clusterInfoSerializeWrapper = defaultMQAdminExt.examineBrokerClusterInfo(); System.out.printf("%-16s %-22s %-4s %-22s %-16s %19s %19s %10s %5s %6s%n", - "#Cluster Name", - "#Broker Name", - "#BID", - "#Addr", - "#Version", - "#InTPS(LOAD)", - "#OutTPS(LOAD)", - "#PCWait(ms)", - "#Hour", - "#SPACE" + "#Cluster Name", + "#Broker Name", + "#BID", + "#Addr", + "#Version", + "#InTPS(LOAD)", + "#OutTPS(LOAD)", + "#PCWait(ms)", + "#Hour", + "#SPACE" ); Iterator>> itCluster = clusterInfoSerializeWrapper.getClusterAddrTable().entrySet().iterator(); @@ -254,16 +251,16 @@ public class ClusterListSubCommand implements SubCommand { } System.out.printf("%-16s %-22s %-4s %-22s %-16s %19s %19s %10s %5s %6s%n", - clusterName, - brokerName, - next1.getKey().longValue(), - next1.getValue(), - version, - String.format("%9.2f(%s,%sms)", in, sendThreadPoolQueueSize, sendThreadPoolQueueHeadWaitTimeMills), - String.format("%9.2f(%s,%sms)", out, pullThreadPoolQueueSize, pullThreadPoolQueueHeadWaitTimeMills), - pageCacheLockTimeMills, - String.format("%2.2f", hour), - String.format("%.4f", space) + clusterName, + brokerName, + next1.getKey().longValue(), + next1.getValue(), + version, + String.format("%9.2f(%s,%sms)", in, sendThreadPoolQueueSize, sendThreadPoolQueueHeadWaitTimeMills), + String.format("%9.2f(%s,%sms)", out, pullThreadPoolQueueSize, pullThreadPoolQueueHeadWaitTimeMills), + pageCacheLockTimeMills, + String.format("%2.2f", hour), + String.format("%.4f", space) ); } } diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/connection/ConsumerConnectionSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/connection/ConsumerConnectionSubCommand.java index 355e8948..7f7f88d9 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/connection/ConsumerConnectionSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/connection/ConsumerConnectionSubCommand.java @@ -16,6 +16,11 @@ */ package org.apache.rocketmq.tools.command.connection; +import java.util.Iterator; +import java.util.Map.Entry; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; import org.apache.rocketmq.common.MQVersion; import org.apache.rocketmq.common.protocol.body.Connection; import org.apache.rocketmq.common.protocol.body.ConsumerConnection; @@ -23,13 +28,6 @@ import org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData; import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -import java.util.Iterator; -import java.util.Map.Entry; - public class ConsumerConnectionSubCommand implements SubCommand { @@ -65,15 +63,14 @@ public class ConsumerConnectionSubCommand implements SubCommand { ConsumerConnection cc = defaultMQAdminExt.examineConsumerConnectionInfo(group); - int i = 1; for (Connection conn : cc.getConnectionSet()) { System.out.printf("%03d %-32s %-22s %-8s %s%n", - i++, - conn.getClientId(), - conn.getClientAddr(), - conn.getLanguage(), - MQVersion.getVersionDesc(conn.getVersion()) + i++, + conn.getClientId(), + conn.getClientAddr(), + conn.getLanguage(), + MQVersion.getVersionDesc(conn.getVersion()) ); } @@ -84,9 +81,9 @@ public class ConsumerConnectionSubCommand implements SubCommand { Entry entry = it.next(); SubscriptionData sd = entry.getValue(); System.out.printf("%03d Topic: %-40s SubExpression: %s%n", - i++, - sd.getTopic(), - sd.getSubString() + i++, + sd.getTopic(), + sd.getSubString() ); } diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/connection/ProducerConnectionSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/connection/ProducerConnectionSubCommand.java index 0b5b0abd..387c9c8f 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/connection/ProducerConnectionSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/connection/ProducerConnectionSubCommand.java @@ -16,16 +16,15 @@ */ package org.apache.rocketmq.tools.command.connection; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; import org.apache.rocketmq.common.MQVersion; import org.apache.rocketmq.common.protocol.body.Connection; import org.apache.rocketmq.common.protocol.body.ProducerConnection; import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - public class ProducerConnectionSubCommand implements SubCommand { @@ -69,11 +68,11 @@ public class ProducerConnectionSubCommand implements SubCommand { int i = 1; for (Connection conn : pc.getConnectionSet()) { System.out.printf("%04d %-32s %-22s %-8s %s%n", - i++, - conn.getClientId(), - conn.getClientAddr(), - conn.getLanguage(), - MQVersion.getVersionDesc(conn.getVersion()) + i++, + conn.getClientId(), + conn.getClientAddr(), + conn.getLanguage(), + MQVersion.getVersionDesc(conn.getVersion()) ); } } catch (Exception e) { diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/consumer/ConsumerProgressSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/consumer/ConsumerProgressSubCommand.java index 56e0853c..3e706143 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/consumer/ConsumerProgressSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/consumer/ConsumerProgressSubCommand.java @@ -16,6 +16,13 @@ */ package org.apache.rocketmq.tools.command.consumer; +import java.util.Collections; +import java.util.Date; +import java.util.LinkedList; +import java.util.List; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; import org.apache.rocketmq.client.log.ClientLogger; import org.apache.rocketmq.common.MQVersion; import org.apache.rocketmq.common.MixAll; @@ -30,17 +37,8 @@ import org.apache.rocketmq.common.protocol.heartbeat.MessageModel; import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; import org.slf4j.Logger; -import java.util.Collections; -import java.util.Date; -import java.util.LinkedList; -import java.util.List; - - public class ConsumerProgressSubCommand implements SubCommand { private final Logger log = ClientLogger.getLog(); @@ -78,13 +76,13 @@ public class ConsumerProgressSubCommand implements SubCommand { Collections.sort(mqList); System.out.printf("%-32s %-32s %-4s %-20s %-20s %-20s %s%n", - "#Topic", - "#Broker Name", - "#QID", - "#Broker Offset", - "#Consumer Offset", - "#Diff", - "#LastTime"); + "#Topic", + "#Broker Name", + "#QID", + "#Broker Offset", + "#Consumer Offset", + "#Diff", + "#LastTime"); long diffTotal = 0L; for (MessageQueue mq : mqList) { @@ -97,13 +95,13 @@ public class ConsumerProgressSubCommand implements SubCommand { } catch (Exception e) { } System.out.printf("%-32s %-32s %-4d %-20d %-20d %-20d %s%n", - UtilAll.frontStringAtLeast(mq.getTopic(), 32), - UtilAll.frontStringAtLeast(mq.getBrokerName(), 32), - mq.getQueueId(), - offsetWrapper.getBrokerOffset(), - offsetWrapper.getConsumerOffset(), - diff, - lastTime + UtilAll.frontStringAtLeast(mq.getTopic(), 32), + UtilAll.frontStringAtLeast(mq.getBrokerName(), 32), + mq.getQueueId(), + offsetWrapper.getBrokerOffset(), + offsetWrapper.getConsumerOffset(), + diff, + lastTime ); } @@ -112,13 +110,13 @@ public class ConsumerProgressSubCommand implements SubCommand { System.out.printf("Diff Total: %d%n", diffTotal); } else { System.out.printf("%-32s %-6s %-24s %-5s %-14s %-7s %s%n", - "#Group", - "#Count", - "#Version", - "#Type", - "#Model", - "#TPS", - "#Diff Total" + "#Group", + "#Count", + "#Version", + "#Type", + "#Model", + "#TPS", + "#Diff Total" ); TopicList topicList = defaultMQAdminExt.fetchAllTopicList(); for (String topic : topicList.getTopicList()) { @@ -143,7 +141,7 @@ public class ConsumerProgressSubCommand implements SubCommand { groupConsumeInfo.setGroup(consumerGroup); if (consumeStats != null) { - groupConsumeInfo.setConsumeTps((int) consumeStats.getConsumeTps()); + groupConsumeInfo.setConsumeTps((int)consumeStats.getConsumeTps()); groupConsumeInfo.setDiffTotal(consumeStats.computeTotalDiff()); } @@ -155,13 +153,13 @@ public class ConsumerProgressSubCommand implements SubCommand { } System.out.printf("%-32s %-6d %-24s %-5s %-14s %-7d %d%n", - UtilAll.frontStringAtLeast(groupConsumeInfo.getGroup(), 32), - groupConsumeInfo.getCount(), - groupConsumeInfo.getCount() > 0 ? groupConsumeInfo.versionDesc() : "OFFLINE", - groupConsumeInfo.consumeTypeDesc(), - groupConsumeInfo.messageModelDesc(), - groupConsumeInfo.getConsumeTps(), - groupConsumeInfo.getDiffTotal() + UtilAll.frontStringAtLeast(groupConsumeInfo.getGroup(), 32), + groupConsumeInfo.getCount(), + groupConsumeInfo.getCount() > 0 ? groupConsumeInfo.versionDesc() : "OFFLINE", + groupConsumeInfo.consumeTypeDesc(), + groupConsumeInfo.messageModelDesc(), + groupConsumeInfo.getConsumeTps(), + groupConsumeInfo.getDiffTotal() ); } catch (Exception e) { log.warn("examineConsumeStats or examineConsumerConnectionInfo exception, " + consumerGroup, e); @@ -177,7 +175,6 @@ public class ConsumerProgressSubCommand implements SubCommand { } } - class GroupConsumeInfo implements Comparable { private String group; private int version; @@ -187,7 +184,6 @@ class GroupConsumeInfo implements Comparable { private int consumeTps; private long diffTotal; - public String getGroup() { return group; } @@ -245,37 +241,31 @@ class GroupConsumeInfo implements Comparable { return diffTotal; } - public void setDiffTotal(long diffTotal) { this.diffTotal = diffTotal; } - @Override public int compareTo(GroupConsumeInfo o) { if (this.count != o.count) { return o.count - this.count; } - return (int) (o.diffTotal - diffTotal); + return (int)(o.diffTotal - diffTotal); } - public int getConsumeTps() { return consumeTps; } - public void setConsumeTps(int consumeTps) { this.consumeTps = consumeTps; } - public int getVersion() { return version; } - public void setVersion(int version) { this.version = version; } diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/consumer/ConsumerStatusSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/consumer/ConsumerStatusSubCommand.java index e15ce1fa..b3f43779 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/consumer/ConsumerStatusSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/consumer/ConsumerStatusSubCommand.java @@ -16,6 +16,12 @@ */ package org.apache.rocketmq.tools.command.consumer; +import java.util.Iterator; +import java.util.Map.Entry; +import java.util.TreeMap; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; import org.apache.rocketmq.common.MQVersion; import org.apache.rocketmq.common.MixAll; import org.apache.rocketmq.common.protocol.body.Connection; @@ -25,20 +31,12 @@ import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; import org.apache.rocketmq.tools.command.MQAdminStartup; import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -import java.util.Iterator; -import java.util.Map.Entry; -import java.util.TreeMap; - public class ConsumerStatusSubCommand implements SubCommand { public static void main(String[] args) { System.setProperty(MixAll.NAMESRV_ADDR_PROPERTY, "127.0.0.1:9876"); - MQAdminStartup.main(new String[]{new ConsumerStatusSubCommand().commandName(), "-g", "benchmark_consumer"}); + MQAdminStartup.main(new String[] {new ConsumerStatusSubCommand().commandName(), "-g", "benchmark_consumer"}); } @Override @@ -86,16 +84,16 @@ public class ConsumerStatusSubCommand implements SubCommand { for (Connection conn : cc.getConnectionSet()) { try { ConsumerRunningInfo consumerRunningInfo = - defaultMQAdminExt.getConsumerRunningInfo(group, conn.getClientId(), jstack); + defaultMQAdminExt.getConsumerRunningInfo(group, conn.getClientId(), jstack); if (consumerRunningInfo != null) { criTable.put(conn.getClientId(), consumerRunningInfo); String filePath = now + "/" + conn.getClientId(); MixAll.string2FileNotSafe(consumerRunningInfo.formatString(), filePath); System.out.printf("%03d %-40s %-20s %s%n", - i++, - conn.getClientId(), - MQVersion.getVersionDesc(conn.getVersion()), - filePath); + i++, + conn.getClientId(), + MQVersion.getVersionDesc(conn.getVersion()), + filePath); } } catch (Exception e) { e.printStackTrace(); @@ -114,7 +112,7 @@ public class ConsumerStatusSubCommand implements SubCommand { while (it.hasNext()) { Entry next = it.next(); String result = - ConsumerRunningInfo.analyzeProcessQueue(next.getKey(), next.getValue()); + ConsumerRunningInfo.analyzeProcessQueue(next.getKey(), next.getValue()); if (result.length() > 0) { System.out.printf(result); } @@ -126,7 +124,7 @@ public class ConsumerStatusSubCommand implements SubCommand { } else { String clientId = commandLine.getOptionValue('i').trim(); ConsumerRunningInfo consumerRunningInfo = - defaultMQAdminExt.getConsumerRunningInfo(group, clientId, jstack); + defaultMQAdminExt.getConsumerRunningInfo(group, clientId, jstack); if (consumerRunningInfo != null) { System.out.printf("%s", consumerRunningInfo.formatString()); } diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/consumer/ConsumerSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/consumer/ConsumerSubCommand.java index 6e7cc275..699625d1 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/consumer/ConsumerSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/consumer/ConsumerSubCommand.java @@ -16,6 +16,12 @@ */ package org.apache.rocketmq.tools.command.consumer; +import java.util.Iterator; +import java.util.Map.Entry; +import java.util.TreeMap; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; import org.apache.rocketmq.common.MQVersion; import org.apache.rocketmq.common.MixAll; import org.apache.rocketmq.common.protocol.body.Connection; @@ -25,20 +31,12 @@ import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; import org.apache.rocketmq.tools.command.MQAdminStartup; import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -import java.util.Iterator; -import java.util.Map.Entry; -import java.util.TreeMap; - public class ConsumerSubCommand implements SubCommand { public static void main(String[] args) { System.setProperty(MixAll.NAMESRV_ADDR_PROPERTY, "127.0.0.1:9876"); - MQAdminStartup.main(new String[]{new ConsumerSubCommand().commandName(), "-g", "benchmark_consumer"}); + MQAdminStartup.main(new String[] {new ConsumerSubCommand().commandName(), "-g", "benchmark_consumer"}); } @Override @@ -81,20 +79,20 @@ public class ConsumerSubCommand implements SubCommand { int i = 1; long now = System.currentTimeMillis(); final TreeMap criTable = - new TreeMap(); + new TreeMap(); for (Connection conn : cc.getConnectionSet()) { try { ConsumerRunningInfo consumerRunningInfo = - defaultMQAdminExt.getConsumerRunningInfo(group, conn.getClientId(), jstack); + defaultMQAdminExt.getConsumerRunningInfo(group, conn.getClientId(), jstack); if (consumerRunningInfo != null) { criTable.put(conn.getClientId(), consumerRunningInfo); String filePath = now + "/" + conn.getClientId(); MixAll.string2FileNotSafe(consumerRunningInfo.formatString(), filePath); System.out.printf("%03d %-40s %-20s %s%n", - i++, - conn.getClientId(), - MQVersion.getVersionDesc(conn.getVersion()), - filePath); + i++, + conn.getClientId(), + MQVersion.getVersionDesc(conn.getVersion()), + filePath); } } catch (Exception e) { e.printStackTrace(); @@ -113,7 +111,7 @@ public class ConsumerSubCommand implements SubCommand { while (it.hasNext()) { Entry next = it.next(); String result = - ConsumerRunningInfo.analyzeProcessQueue(next.getKey(), next.getValue()); + ConsumerRunningInfo.analyzeProcessQueue(next.getKey(), next.getValue()); if (result.length() > 0) { System.out.printf(result); } @@ -125,7 +123,7 @@ public class ConsumerSubCommand implements SubCommand { } else { String clientId = commandLine.getOptionValue('i').trim(); ConsumerRunningInfo consumerRunningInfo = - defaultMQAdminExt.getConsumerRunningInfo(group, clientId, jstack); + defaultMQAdminExt.getConsumerRunningInfo(group, clientId, jstack); if (consumerRunningInfo != null) { System.out.printf(consumerRunningInfo.formatString()); } diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/consumer/DeleteSubscriptionGroupCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/consumer/DeleteSubscriptionGroupCommand.java index 0cc58795..75e6b65b 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/consumer/DeleteSubscriptionGroupCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/consumer/DeleteSubscriptionGroupCommand.java @@ -6,16 +6,20 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.tools.command.consumer; +import java.util.Set; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; import org.apache.rocketmq.common.MixAll; import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.srvutil.ServerUtil; @@ -23,12 +27,6 @@ import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; import org.apache.rocketmq.tools.command.CommandUtil; import org.apache.rocketmq.tools.command.SubCommand; import org.apache.rocketmq.tools.command.topic.DeleteTopicSubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -import java.util.Set; - public class DeleteSubscriptionGroupCommand implements SubCommand { @Override @@ -36,13 +34,11 @@ public class DeleteSubscriptionGroupCommand implements SubCommand { return "deleteSubGroup"; } - @Override public String commandDesc() { return "Delete subscription group from broker."; } - @Override public Options buildCommandlineOptions(Options options) { Option opt = new Option("b", "brokerAddr", true, "delete subscription group from which broker"); @@ -60,7 +56,6 @@ public class DeleteSubscriptionGroupCommand implements SubCommand { return options; } - @Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { DefaultMQAdminExt adminExt = new DefaultMQAdminExt(rpcHook); @@ -75,7 +70,7 @@ public class DeleteSubscriptionGroupCommand implements SubCommand { adminExt.deleteSubscriptionGroup(addr, groupName); System.out.printf("delete subscription group [%s] from broker [%s] success.%n", groupName, - addr); + addr); return; } else if (commandLine.hasOption('c')) { @@ -86,15 +81,15 @@ public class DeleteSubscriptionGroupCommand implements SubCommand { for (String master : masterSet) { adminExt.deleteSubscriptionGroup(master, groupName); System.out.printf( - "delete subscription group [%s] from broker [%s] in cluster [%s] success.%n", - groupName, master, clusterName); + "delete subscription group [%s] from broker [%s] in cluster [%s] success.%n", + groupName, master, clusterName); } try { DeleteTopicSubCommand.deleteTopic(adminExt, clusterName, MixAll.RETRY_GROUP_TOPIC_PREFIX - + groupName); + + groupName); DeleteTopicSubCommand.deleteTopic(adminExt, clusterName, MixAll.DLQ_GROUP_TOPIC_PREFIX - + groupName); + + groupName); } catch (Exception e) { } return; diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/consumer/StartMonitoringSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/consumer/StartMonitoringSubCommand.java index 4d5315b5..8bb7c0dc 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/consumer/StartMonitoringSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/consumer/StartMonitoringSubCommand.java @@ -6,54 +6,49 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.tools.command.consumer; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Options; import org.apache.rocketmq.client.log.ClientLogger; import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.tools.command.SubCommand; import org.apache.rocketmq.tools.monitor.DefaultMonitorListener; import org.apache.rocketmq.tools.monitor.MonitorConfig; import org.apache.rocketmq.tools.monitor.MonitorService; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Options; import org.slf4j.Logger; - public class StartMonitoringSubCommand implements SubCommand { private final Logger log = ClientLogger.getLog(); - @Override public String commandName() { return "startMonitoring"; } - @Override public String commandDesc() { return "Start Monitoring"; } - @Override public Options buildCommandlineOptions(Options options) { return options; } - @Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { try { MonitorService monitorService = - new MonitorService(new MonitorConfig(), new DefaultMonitorListener(), rpcHook); + new MonitorService(new MonitorConfig(), new DefaultMonitorListener(), rpcHook); monitorService.start(); } catch (Exception e) { diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/consumer/UpdateSubGroupSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/consumer/UpdateSubGroupSubCommand.java index 93eb8ec9..4ff032ee 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/consumer/UpdateSubGroupSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/consumer/UpdateSubGroupSubCommand.java @@ -16,18 +16,16 @@ */ package org.apache.rocketmq.tools.command.consumer; +import java.util.Set; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; import org.apache.rocketmq.common.subscription.SubscriptionGroupConfig; import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.srvutil.ServerUtil; import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; import org.apache.rocketmq.tools.command.CommandUtil; import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -import java.util.Set; - public class UpdateSubGroupSubCommand implements SubCommand { @@ -36,13 +34,11 @@ public class UpdateSubGroupSubCommand implements SubCommand { return "updateSubGroup"; } - @Override public String commandDesc() { return "Update or create subscription group"; } - @Override public Options buildCommandlineOptions(Options options) { Option opt = new Option("b", "brokerAddr", true, "create subscription group to which broker"); @@ -92,7 +88,6 @@ public class UpdateSubGroupSubCommand implements SubCommand { return options; } - @Override public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); @@ -110,31 +105,31 @@ public class UpdateSubGroupSubCommand implements SubCommand { // consumeEnable if (commandLine.hasOption('s')) { subscriptionGroupConfig.setConsumeEnable(Boolean.parseBoolean(commandLine.getOptionValue('s') - .trim())); + .trim())); } // consumeFromMinEnable if (commandLine.hasOption('m')) { subscriptionGroupConfig.setConsumeFromMinEnable(Boolean.parseBoolean(commandLine - .getOptionValue('m').trim())); + .getOptionValue('m').trim())); } // consumeBroadcastEnable if (commandLine.hasOption('d')) { subscriptionGroupConfig.setConsumeBroadcastEnable(Boolean.parseBoolean(commandLine - .getOptionValue('d').trim())); + .getOptionValue('d').trim())); } // retryQueueNums if (commandLine.hasOption('q')) { subscriptionGroupConfig.setRetryQueueNums(Integer.parseInt(commandLine.getOptionValue('q') - .trim())); + .trim())); } // retryMaxTimes if (commandLine.hasOption('r')) { subscriptionGroupConfig.setRetryMaxTimes(Integer.parseInt(commandLine.getOptionValue('r') - .trim())); + .trim())); } // brokerId @@ -145,13 +140,13 @@ public class UpdateSubGroupSubCommand implements SubCommand { // whichBrokerWhenConsumeSlowly if (commandLine.hasOption('w')) { subscriptionGroupConfig.setWhichBrokerWhenConsumeSlowly(Long.parseLong(commandLine - .getOptionValue('w').trim())); + .getOptionValue('w').trim())); } // notifyConsumerIdsChanged if (commandLine.hasOption('a')) { subscriptionGroupConfig.setNotifyConsumerIdsChangedEnable(Boolean.parseBoolean(commandLine - .getOptionValue('a').trim())); + .getOptionValue('a').trim())); } if (commandLine.hasOption('b')) { @@ -169,7 +164,7 @@ public class UpdateSubGroupSubCommand implements SubCommand { defaultMQAdminExt.start(); Set masterSet = - CommandUtil.fetchMasterAddrByClusterName(defaultMQAdminExt, clusterName); + CommandUtil.fetchMasterAddrByClusterName(defaultMQAdminExt, clusterName); for (String addr : masterSet) { try { defaultMQAdminExt.createAndUpdateSubscriptionGroupConfig(addr, subscriptionGroupConfig); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/message/CheckMsgSendRTCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/message/CheckMsgSendRTCommand.java index fb0061e3..cade0e01 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/message/CheckMsgSendRTCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/message/CheckMsgSendRTCommand.java @@ -16,6 +16,10 @@ */ package org.apache.rocketmq.tools.command.message; +import java.util.List; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; import org.apache.rocketmq.client.producer.DefaultMQProducer; import org.apache.rocketmq.client.producer.MessageQueueSelector; import org.apache.rocketmq.common.MixAll; @@ -23,11 +27,6 @@ import org.apache.rocketmq.common.message.Message; import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -import java.util.List; public class CheckMsgSendRTCommand implements SubCommand { private static String brokerName = ""; @@ -72,16 +71,16 @@ public class CheckMsgSendRTCommand implements SubCommand { boolean sendSuccess = false; String topic = commandLine.getOptionValue('t').trim(); long amount = !commandLine.hasOption('a') ? 100 : Long.parseLong(commandLine - .getOptionValue('a').trim()); + .getOptionValue('a').trim()); long msgSize = !commandLine.hasOption('s') ? 128 : Long.parseLong(commandLine - .getOptionValue('s').trim()); + .getOptionValue('s').trim()); Message msg = new Message(topic, getStringBySize(msgSize).getBytes(MixAll.DEFAULT_CHARSET)); System.out.printf("%-32s %-4s %-20s %s%n", - "#Broker Name", - "#QID", - "#Send Result", - "#RT" + "#Broker Name", + "#QID", + "#Send Result", + "#RT" ); for (int i = 0; i < amount; i++) { start = System.currentTimeMillis(); @@ -89,7 +88,7 @@ public class CheckMsgSendRTCommand implements SubCommand { producer.send(msg, new MessageQueueSelector() { @Override public MessageQueue select(List mqs, Message msg, Object arg) { - int queueIndex = (Integer) arg % mqs.size(); + int queueIndex = (Integer)arg % mqs.size(); MessageQueue queue = mqs.get(queueIndex); brokerName = queue.getBrokerName(); queueId = queue.getQueueId(); @@ -103,20 +102,19 @@ public class CheckMsgSendRTCommand implements SubCommand { end = System.currentTimeMillis(); } - if (i != 0) { timeElapsed += end - start; } System.out.printf("%-32s %-4s %-20s %s%n", - brokerName, - queueId, - sendSuccess, - end - start + brokerName, + queueId, + sendSuccess, + end - start ); } - double rt = (double) timeElapsed / (amount - 1); + double rt = (double)timeElapsed / (amount - 1); System.out.printf("Avg RT: %s%n", String.format("%.2f", rt)); } catch (Exception e) { e.printStackTrace(); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/message/DecodeMessageIdCommond.java b/tools/src/main/java/org/apache/rocketmq/tools/command/message/DecodeMessageIdCommond.java index 88264b51..40adec9f 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/message/DecodeMessageIdCommond.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/message/DecodeMessageIdCommond.java @@ -6,23 +6,23 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.tools.command.message; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; import org.apache.rocketmq.common.UtilAll; import org.apache.rocketmq.common.message.MessageClientIDSetter; import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; public class DecodeMessageIdCommond implements SubCommand { @Override diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/message/PrintMessageByQueueCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/message/PrintMessageByQueueCommand.java index 33e6804f..aad16441 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/message/PrintMessageByQueueCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/message/PrintMessageByQueueCommand.java @@ -17,6 +17,17 @@ package org.apache.rocketmq.tools.command.message; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicLong; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; +import org.apache.commons.lang3.StringUtils; import org.apache.rocketmq.client.consumer.DefaultMQPullConsumer; import org.apache.rocketmq.client.consumer.PullResult; import org.apache.rocketmq.common.MixAll; @@ -25,33 +36,77 @@ import org.apache.rocketmq.common.message.MessageExt; import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; -import org.apache.commons.lang3.StringUtils; - -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.atomic.AtomicLong; public class PrintMessageByQueueCommand implements SubCommand { + public static long timestampFormat(final String value) { + long timestamp = 0; + try { + timestamp = Long.parseLong(value); + } catch (NumberFormatException e) { + + timestamp = UtilAll.parseDate(value, UtilAll.YYYY_MM_DD_HH_MM_SS_SSS).getTime(); + } + + return timestamp; + } + + private static void calculateByTag(final List msgs, final Map tagCalmap, final boolean calByTag) { + if (!calByTag) + return; + + for (MessageExt msg : msgs) { + String tag = msg.getTags(); + if (StringUtils.isNotBlank(tag)) { + AtomicLong count = tagCalmap.get(tag); + if (count == null) { + count = new AtomicLong(); + tagCalmap.put(tag, count); + } + count.incrementAndGet(); + } + } + } + + private static void printCalculateByTag(final Map tagCalmap, final boolean calByTag) { + if (!calByTag) + return; + + List list = new ArrayList(); + for (Map.Entry entry : tagCalmap.entrySet()) { + TagCountBean tagBean = new TagCountBean(entry.getKey(), entry.getValue()); + list.add(tagBean); + } + Collections.sort(list); + + for (TagCountBean tagCountBean : list) { + System.out.printf("Tag: %-30s Count: %s%n", tagCountBean.getTag(), tagCountBean.getCount()); + } + } + + public static void printMessage(final List msgs, final String charsetName, boolean printMsg, boolean printBody) { + if (!printMsg) + return; + + for (MessageExt msg : msgs) { + try { + System.out.printf("MSGID: %s %s BODY: %s%n", msg.getMsgId(), msg.toString(), + printBody ? new String(msg.getBody(), charsetName) : "NOT PRINT BODY"); + } catch (UnsupportedEncodingException e) { + } + } + } + @Override public String commandName() { return "printMsgByQueue"; } - @Override public String commandDesc() { return "Print Message Detail"; } - @Override public Options buildCommandlineOptions(Options options) { Option opt = new Option("t", "topic", true, "topic name"); @@ -94,7 +149,6 @@ public class PrintMessageByQueueCommand implements SubCommand { opt.setRequired(false); options.addOption(opt); - return options; } @@ -104,15 +158,15 @@ public class PrintMessageByQueueCommand implements SubCommand { try { String charsetName = - !commandLine.hasOption('c') ? "UTF-8" : commandLine.getOptionValue('c').trim(); + !commandLine.hasOption('c') ? "UTF-8" : commandLine.getOptionValue('c').trim(); boolean printMsg = - !commandLine.hasOption('p') ? false : Boolean.parseBoolean(commandLine.getOptionValue('p').trim()); + !commandLine.hasOption('p') ? false : Boolean.parseBoolean(commandLine.getOptionValue('p').trim()); boolean printBody = - !commandLine.hasOption('d') ? false : Boolean.parseBoolean(commandLine.getOptionValue('d').trim()); + !commandLine.hasOption('d') ? false : Boolean.parseBoolean(commandLine.getOptionValue('d').trim()); boolean calByTag = - !commandLine.hasOption('f') ? false : Boolean.parseBoolean(commandLine.getOptionValue('f').trim()); + !commandLine.hasOption('f') ? false : Boolean.parseBoolean(commandLine.getOptionValue('f').trim()); String subExpression = - !commandLine.hasOption('s') ? "*" : commandLine.getOptionValue('s').trim(); + !commandLine.hasOption('s') ? "*" : commandLine.getOptionValue('s').trim(); String topic = commandLine.getOptionValue('t').trim(); String brokerName = commandLine.getOptionValue('a').trim(); @@ -165,70 +219,10 @@ public class PrintMessageByQueueCommand implements SubCommand { } } - public static long timestampFormat(final String value) { - long timestamp = 0; - try { - timestamp = Long.parseLong(value); - } catch (NumberFormatException e) { - - timestamp = UtilAll.parseDate(value, UtilAll.YYYY_MM_DD_HH_MM_SS_SSS).getTime(); - } - - return timestamp; - } - - - private static void calculateByTag(final List msgs, final Map tagCalmap, final boolean calByTag) { - if (!calByTag) - return; - - for (MessageExt msg : msgs) { - String tag = msg.getTags(); - if (StringUtils.isNotBlank(tag)) { - AtomicLong count = tagCalmap.get(tag); - if (count == null) { - count = new AtomicLong(); - tagCalmap.put(tag, count); - } - count.incrementAndGet(); - } - } - } - - private static void printCalculateByTag(final Map tagCalmap, final boolean calByTag) { - if (!calByTag) - return; - - List list = new ArrayList(); - for (Map.Entry entry : tagCalmap.entrySet()) { - TagCountBean tagBean = new TagCountBean(entry.getKey(), entry.getValue()); - list.add(tagBean); - } - Collections.sort(list); - - for (TagCountBean tagCountBean : list) { - System.out.printf("Tag: %-30s Count: %s%n", tagCountBean.getTag(), tagCountBean.getCount()); - } - } - - public static void printMessage(final List msgs, final String charsetName, boolean printMsg, boolean printBody) { - if (!printMsg) - return; - - for (MessageExt msg : msgs) { - try { - System.out.printf("MSGID: %s %s BODY: %s%n", msg.getMsgId(), msg.toString(), - printBody ? new String(msg.getBody(), charsetName) : "NOT PRINT BODY"); - } catch (UnsupportedEncodingException e) { - } - } - } - static class TagCountBean implements Comparable { private String tag; private AtomicLong count; - public TagCountBean(final String tag, final AtomicLong count) { this.tag = tag; this.count = count; @@ -250,10 +244,9 @@ public class PrintMessageByQueueCommand implements SubCommand { this.count = count; } - @Override public int compareTo(final TagCountBean o) { - return (int) (o.getCount().get() - this.count.get()); + return (int)(o.getCount().get() - this.count.get()); } } } diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/message/PrintMessageSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/message/PrintMessageSubCommand.java index e8c9368c..4f87d779 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/message/PrintMessageSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/message/PrintMessageSubCommand.java @@ -16,6 +16,12 @@ */ package org.apache.rocketmq.tools.command.message; +import java.io.UnsupportedEncodingException; +import java.util.List; +import java.util.Set; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; import org.apache.rocketmq.client.consumer.DefaultMQPullConsumer; import org.apache.rocketmq.client.consumer.PullResult; import org.apache.rocketmq.common.MixAll; @@ -24,29 +30,41 @@ import org.apache.rocketmq.common.message.MessageExt; import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; -import java.io.UnsupportedEncodingException; -import java.util.List; -import java.util.Set; +public class PrintMessageSubCommand implements SubCommand { + + public static long timestampFormat(final String value) { + long timestamp = 0; + try { + timestamp = Long.parseLong(value); + } catch (NumberFormatException e) { + timestamp = UtilAll.parseDate(value, UtilAll.YYYY_MM_DD_HH_MM_SS_SSS).getTime(); + } + return timestamp; + } -public class PrintMessageSubCommand implements SubCommand { + public static void printMessage(final List msgs, final String charsetName, boolean printBody) { + for (MessageExt msg : msgs) { + try { + System.out.printf("MSGID: %s %s BODY: %s%n", msg.getMsgId(), msg.toString(), + printBody ? new String(msg.getBody(), charsetName) : "NOT PRINT BODY"); + } catch (UnsupportedEncodingException e) { + // + } + } + } @Override public String commandName() { return "printMsg"; } - @Override public String commandDesc() { return "Print Message Detail"; } - @Override public Options buildCommandlineOptions(Options options) { Option opt = new Option("t", "topic", true, "topic name"); @@ -62,20 +80,20 @@ public class PrintMessageSubCommand implements SubCommand { options.addOption(opt); opt = - new Option("b", "beginTimestamp ", true, - "Begin timestamp[currentTimeMillis|yyyy-MM-dd#HH:mm:ss:SSS]"); + new Option("b", "beginTimestamp ", true, + "Begin timestamp[currentTimeMillis|yyyy-MM-dd#HH:mm:ss:SSS]"); opt.setRequired(false); options.addOption(opt); opt = - new Option("e", "endTimestamp ", true, - "End timestamp[currentTimeMillis|yyyy-MM-dd#HH:mm:ss:SSS]"); + new Option("e", "endTimestamp ", true, + "End timestamp[currentTimeMillis|yyyy-MM-dd#HH:mm:ss:SSS]"); opt.setRequired(false); options.addOption(opt); opt = - new Option("d", "printBody ", true, - "print body"); + new Option("d", "printBody ", true, + "print body"); opt.setRequired(false); options.addOption(opt); @@ -90,13 +108,13 @@ public class PrintMessageSubCommand implements SubCommand { String topic = commandLine.getOptionValue('t').trim(); String charsetName = // - !commandLine.hasOption('c') ? "UTF-8" : commandLine.getOptionValue('c').trim(); + !commandLine.hasOption('c') ? "UTF-8" : commandLine.getOptionValue('c').trim(); String subExpression = // - !commandLine.hasOption('s') ? "*" : commandLine.getOptionValue('s').trim(); + !commandLine.hasOption('s') ? "*" : commandLine.getOptionValue('s').trim(); boolean printBody = // - !commandLine.hasOption('d') ? true : Boolean.parseBoolean(commandLine.getOptionValue('d').trim()); + !commandLine.hasOption('d') ? true : Boolean.parseBoolean(commandLine.getOptionValue('d').trim()); consumer.start(); @@ -149,26 +167,4 @@ public class PrintMessageSubCommand implements SubCommand { consumer.shutdown(); } } - - public static long timestampFormat(final String value) { - long timestamp = 0; - try { - timestamp = Long.parseLong(value); - } catch (NumberFormatException e) { - timestamp = UtilAll.parseDate(value, UtilAll.YYYY_MM_DD_HH_MM_SS_SSS).getTime(); - } - - return timestamp; - } - - public static void printMessage(final List msgs, final String charsetName, boolean printBody) { - for (MessageExt msg : msgs) { - try { - System.out.printf("MSGID: %s %s BODY: %s%n", msg.getMsgId(), msg.toString(), - printBody ? new String(msg.getBody(), charsetName) : "NOT PRINT BODY"); - } catch (UnsupportedEncodingException e) { - // - } - } - } } diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/message/QueryMsgByIdSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/message/QueryMsgByIdSubCommand.java index fded7b6d..38f9a72f 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/message/QueryMsgByIdSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/message/QueryMsgByIdSubCommand.java @@ -16,6 +16,15 @@ */ package org.apache.rocketmq.tools.command.message; +import java.io.DataOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.List; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; +import org.apache.commons.lang3.StringUtils; import org.apache.rocketmq.client.exception.MQBrokerException; import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.client.producer.DefaultMQProducer; @@ -30,19 +39,140 @@ import org.apache.rocketmq.remoting.exception.RemotingException; import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; import org.apache.rocketmq.tools.admin.api.MessageTrack; import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; -import org.apache.commons.lang3.StringUtils; -import java.io.DataOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.List; +public class QueryMsgByIdSubCommand implements SubCommand { + public static void queryById(final DefaultMQAdminExt admin, final String msgId) throws MQClientException, + RemotingException, MQBrokerException, InterruptedException, IOException { + MessageExt msg = admin.viewMessage(msgId); + printMsg(admin, msg); + } + + public static void printMsg(final DefaultMQAdminExt admin, final MessageExt msg) throws IOException { + if (msg == null) { + System.out.printf("%nMessage not found!"); + return; + } + + String bodyTmpFilePath = createBodyFile(msg); + String msgId = msg.getMsgId(); + if (msg instanceof MessageClientExt) { + msgId = ((MessageClientExt)msg).getOffsetMsgId(); + } + + System.out.printf("%-20s %s%n", + "OffsetID:", + msgId + ); + + System.out.printf("%-20s %s%n", + "OffsetID:", + msgId + ); + + System.out.printf("%-20s %s%n", + "Topic:", + msg.getTopic() + ); + + System.out.printf("%-20s %s%n", + "Tags:", + "[" + msg.getTags() + "]" + ); + + System.out.printf("%-20s %s%n", + "Keys:", + "[" + msg.getKeys() + "]" + ); + + System.out.printf("%-20s %d%n", + "Queue ID:", + msg.getQueueId() + ); + + System.out.printf("%-20s %d%n", + "Queue Offset:", + msg.getQueueOffset() + ); + + System.out.printf("%-20s %d%n", + "CommitLog Offset:", + msg.getCommitLogOffset() + ); + + System.out.printf("%-20s %d%n", + "Reconsume Times:", + msg.getReconsumeTimes() + ); + + System.out.printf("%-20s %s%n", + "Born Timestamp:", + UtilAll.timeMillisToHumanString2(msg.getBornTimestamp()) + ); + + System.out.printf("%-20s %s%n", + "Store Timestamp:", + UtilAll.timeMillisToHumanString2(msg.getStoreTimestamp()) + ); + + System.out.printf("%-20s %s%n", + "Born Host:", + RemotingHelper.parseSocketAddressAddr(msg.getBornHost()) + ); + + System.out.printf("%-20s %s%n", + "Store Host:", + RemotingHelper.parseSocketAddressAddr(msg.getStoreHost()) + ); + + System.out.printf("%-20s %d%n", + "System Flag:", + msg.getSysFlag() + ); + + System.out.printf("%-20s %s%n", + "Properties:", + msg.getProperties() != null ? msg.getProperties().toString() : "" + ); + + System.out.printf("%-20s %s%n", + "Message Body Path:", + bodyTmpFilePath + ); + + try { + List mtdList = admin.messageTrackDetail(msg); + if (mtdList.isEmpty()) { + System.out.printf("%n%nWARN: No Consumer"); + } else { + System.out.printf("%n%n"); + for (MessageTrack mt : mtdList) { + System.out.printf("%s", mt); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + private static String createBodyFile(MessageExt msg) throws IOException { + DataOutputStream dos = null; + try { + String bodyTmpFilePath = "/tmp/rocketmq/msgbodys"; + File file = new File(bodyTmpFilePath); + if (!file.exists()) { + file.mkdirs(); + } + bodyTmpFilePath = bodyTmpFilePath + "/" + msg.getMsgId(); + dos = new DataOutputStream(new FileOutputStream(bodyTmpFilePath)); + dos.write(msg.getBody()); + return bodyTmpFilePath; + } finally { + if (dos != null) + dos.close(); + } + } -public class QueryMsgByIdSubCommand implements SubCommand { @Override public String commandName() { return "queryMsgById"; @@ -134,14 +264,15 @@ public class QueryMsgByIdSubCommand implements SubCommand { private void pushMsg(final DefaultMQAdminExt defaultMQAdminExt, final String consumerGroup, final String clientId, final String msgId) { try { ConsumeMessageDirectlyResult result = - defaultMQAdminExt.consumeMessageDirectly(consumerGroup, clientId, msgId); + defaultMQAdminExt.consumeMessageDirectly(consumerGroup, clientId, msgId); System.out.printf("%s", result); } catch (Exception e) { e.printStackTrace(); } } - private void sendMsg(final DefaultMQAdminExt defaultMQAdminExt, final DefaultMQProducer defaultMQProducer, final String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { + private void sendMsg(final DefaultMQAdminExt defaultMQAdminExt, final DefaultMQProducer defaultMQProducer, + final String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { try { MessageExt msg = defaultMQAdminExt.viewMessage(msgId); if (msg != null) { @@ -156,136 +287,4 @@ public class QueryMsgByIdSubCommand implements SubCommand { e.printStackTrace(); } } - - public static void queryById(final DefaultMQAdminExt admin, final String msgId) throws MQClientException, - RemotingException, MQBrokerException, InterruptedException, IOException { - MessageExt msg = admin.viewMessage(msgId); - - printMsg(admin, msg); - } - - public static void printMsg(final DefaultMQAdminExt admin, final MessageExt msg) throws IOException { - if (msg == null) { - System.out.printf("%nMessage not found!"); - return; - } - - String bodyTmpFilePath = createBodyFile(msg); - String msgId = msg.getMsgId(); - if (msg instanceof MessageClientExt) { - msgId = ((MessageClientExt) msg).getOffsetMsgId(); - } - - System.out.printf("%-20s %s%n", - "OffsetID:", - msgId - ); - - System.out.printf("%-20s %s%n", - "OffsetID:", - msgId - ); - - System.out.printf("%-20s %s%n", - "Topic:", - msg.getTopic() - ); - - System.out.printf("%-20s %s%n", - "Tags:", - "[" + msg.getTags() + "]" - ); - - System.out.printf("%-20s %s%n", - "Keys:", - "[" + msg.getKeys() + "]" - ); - - System.out.printf("%-20s %d%n", - "Queue ID:", - msg.getQueueId() - ); - - System.out.printf("%-20s %d%n", - "Queue Offset:", - msg.getQueueOffset() - ); - - System.out.printf("%-20s %d%n", - "CommitLog Offset:", - msg.getCommitLogOffset() - ); - - System.out.printf("%-20s %d%n", - "Reconsume Times:", - msg.getReconsumeTimes() - ); - - System.out.printf("%-20s %s%n", - "Born Timestamp:", - UtilAll.timeMillisToHumanString2(msg.getBornTimestamp()) - ); - - System.out.printf("%-20s %s%n", - "Store Timestamp:", - UtilAll.timeMillisToHumanString2(msg.getStoreTimestamp()) - ); - - System.out.printf("%-20s %s%n", - "Born Host:", - RemotingHelper.parseSocketAddressAddr(msg.getBornHost()) - ); - - System.out.printf("%-20s %s%n", - "Store Host:", - RemotingHelper.parseSocketAddressAddr(msg.getStoreHost()) - ); - - System.out.printf("%-20s %d%n", - "System Flag:", - msg.getSysFlag() - ); - - System.out.printf("%-20s %s%n", - "Properties:", - msg.getProperties() != null ? msg.getProperties().toString() : "" - ); - - System.out.printf("%-20s %s%n", - "Message Body Path:", - bodyTmpFilePath - ); - - try { - List mtdList = admin.messageTrackDetail(msg); - if (mtdList.isEmpty()) { - System.out.printf("%n%nWARN: No Consumer"); - } else { - System.out.printf("%n%n"); - for (MessageTrack mt : mtdList) { - System.out.printf("%s", mt); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - private static String createBodyFile(MessageExt msg) throws IOException { - DataOutputStream dos = null; - try { - String bodyTmpFilePath = "/tmp/rocketmq/msgbodys"; - File file = new File(bodyTmpFilePath); - if (!file.exists()) { - file.mkdirs(); - } - bodyTmpFilePath = bodyTmpFilePath + "/" + msg.getMsgId(); - dos = new DataOutputStream(new FileOutputStream(bodyTmpFilePath)); - dos.write(msg.getBody()); - return bodyTmpFilePath; - } finally { - if (dos != null) - dos.close(); - } - } } diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/message/QueryMsgByKeySubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/message/QueryMsgByKeySubCommand.java index ebfc80ef..159bd6ea 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/message/QueryMsgByKeySubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/message/QueryMsgByKeySubCommand.java @@ -6,26 +6,25 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.tools.command.message; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; import org.apache.rocketmq.client.QueryResult; import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.common.message.MessageExt; import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - /** * @@ -75,14 +74,14 @@ public class QueryMsgByKeySubCommand implements SubCommand { } void queryByKey(final DefaultMQAdminExt admin, final String topic, final String key) - throws MQClientException, InterruptedException { + throws MQClientException, InterruptedException { admin.start(); QueryResult queryResult = admin.queryMessage(topic, key, 64, 0, Long.MAX_VALUE); System.out.printf("%-50s %4s %40s%n", - "#Message ID", - "#QID", - "#Offset"); + "#Message ID", + "#QID", + "#Offset"); for (MessageExt msg : queryResult.getMessageList()) { System.out.printf("%-50s %4d %40d%n", msg.getMsgId(), msg.getQueueId(), msg.getQueueOffset()); } diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/message/QueryMsgByOffsetSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/message/QueryMsgByOffsetSubCommand.java index fc5fd561..21336369 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/message/QueryMsgByOffsetSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/message/QueryMsgByOffsetSubCommand.java @@ -16,6 +16,9 @@ */ package org.apache.rocketmq.tools.command.message; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; import org.apache.rocketmq.client.consumer.DefaultMQPullConsumer; import org.apache.rocketmq.client.consumer.PullResult; import org.apache.rocketmq.common.MixAll; @@ -23,10 +26,6 @@ import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - public class QueryMsgByOffsetSubCommand implements SubCommand { diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/message/QueryMsgByUniqueKeySubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/message/QueryMsgByUniqueKeySubCommand.java index 4e4bd619..2a6904ed 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/message/QueryMsgByUniqueKeySubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/message/QueryMsgByUniqueKeySubCommand.java @@ -16,6 +16,14 @@ */ package org.apache.rocketmq.tools.command.message; +import java.io.DataOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.List; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; import org.apache.rocketmq.client.exception.MQBrokerException; import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.common.UtilAll; @@ -27,125 +35,83 @@ import org.apache.rocketmq.remoting.exception.RemotingException; import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; import org.apache.rocketmq.tools.admin.api.MessageTrack; import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -import java.io.DataOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.List; public class QueryMsgByUniqueKeySubCommand implements SubCommand { - @Override - public String commandName() { - return "queryMsgByUniqueKey"; - } - - @Override - public String commandDesc() { - return "Query Message by Unique key"; - } - - @Override - public Options buildCommandlineOptions(Options options) { - Option opt = new Option("i", "msgId", true, "Message Id"); - opt.setRequired(true); - options.addOption(opt); - - opt = new Option("g", "consumerGroup", true, "consumer group name"); - opt.setRequired(false); - options.addOption(opt); - - opt = new Option("d", "clientId", true, "The consumer's client id"); - opt.setRequired(false); - options.addOption(opt); - - opt = new Option("t", "topic", true, "The topic of msg"); - opt.setRequired(true); - options.addOption(opt); - - return options; - } - - public static void queryById(final DefaultMQAdminExt admin, final String topic, final String msgId) throws MQClientException, - RemotingException, MQBrokerException, InterruptedException, IOException { + RemotingException, MQBrokerException, InterruptedException, IOException { MessageExt msg = admin.viewMessage(topic, msgId); - String bodyTmpFilePath = createBodyFile(msg); System.out.printf("%-20s %s%n", - "Topic:", - msg.getTopic() + "Topic:", + msg.getTopic() ); System.out.printf("%-20s %s%n", - "Tags:", - "[" + msg.getTags() + "]" + "Tags:", + "[" + msg.getTags() + "]" ); System.out.printf("%-20s %s%n", - "Keys:", - "[" + msg.getKeys() + "]" + "Keys:", + "[" + msg.getKeys() + "]" ); System.out.printf("%-20s %d%n", - "Queue ID:", - msg.getQueueId() + "Queue ID:", + msg.getQueueId() ); System.out.printf("%-20s %d%n", - "Queue Offset:", - msg.getQueueOffset() + "Queue Offset:", + msg.getQueueOffset() ); System.out.printf("%-20s %d%n", - "CommitLog Offset:", - msg.getCommitLogOffset() + "CommitLog Offset:", + msg.getCommitLogOffset() ); System.out.printf("%-20s %d%n", - "Reconsume Times:", - msg.getReconsumeTimes() + "Reconsume Times:", + msg.getReconsumeTimes() ); System.out.printf("%-20s %s%n", - "Born Timestamp:", - UtilAll.timeMillisToHumanString2(msg.getBornTimestamp()) + "Born Timestamp:", + UtilAll.timeMillisToHumanString2(msg.getBornTimestamp()) ); System.out.printf("%-20s %s%n", - "Store Timestamp:", - UtilAll.timeMillisToHumanString2(msg.getStoreTimestamp()) + "Store Timestamp:", + UtilAll.timeMillisToHumanString2(msg.getStoreTimestamp()) ); System.out.printf("%-20s %s%n", - "Born Host:", - RemotingHelper.parseSocketAddressAddr(msg.getBornHost()) + "Born Host:", + RemotingHelper.parseSocketAddressAddr(msg.getBornHost()) ); System.out.printf("%-20s %s%n", - "Store Host:", - RemotingHelper.parseSocketAddressAddr(msg.getStoreHost()) + "Store Host:", + RemotingHelper.parseSocketAddressAddr(msg.getStoreHost()) ); System.out.printf("%-20s %d%n", - "System Flag:", - msg.getSysFlag() + "System Flag:", + msg.getSysFlag() ); System.out.printf("%-20s %s%n", - "Properties:", - msg.getProperties() != null ? msg.getProperties().toString() : "" + "Properties:", + msg.getProperties() != null ? msg.getProperties().toString() : "" ); System.out.printf("%-20s %s%n", - "Message Body Path:", - bodyTmpFilePath + "Message Body Path:", + bodyTmpFilePath ); try { @@ -163,6 +129,54 @@ public class QueryMsgByUniqueKeySubCommand implements SubCommand { } } + private static String createBodyFile(MessageExt msg) throws IOException { + DataOutputStream dos = null; + try { + String bodyTmpFilePath = "/tmp/rocketmq/msgbodys"; + File file = new File(bodyTmpFilePath); + if (!file.exists()) { + file.mkdirs(); + } + bodyTmpFilePath = bodyTmpFilePath + "/" + msg.getMsgId(); + dos = new DataOutputStream(new FileOutputStream(bodyTmpFilePath)); + dos.write(msg.getBody()); + return bodyTmpFilePath; + } finally { + if (dos != null) + dos.close(); + } + } + + @Override + public String commandName() { + return "queryMsgByUniqueKey"; + } + + @Override + public String commandDesc() { + return "Query Message by Unique key"; + } + + @Override + public Options buildCommandlineOptions(Options options) { + Option opt = new Option("i", "msgId", true, "Message Id"); + opt.setRequired(true); + options.addOption(opt); + + opt = new Option("g", "consumerGroup", true, "consumer group name"); + opt.setRequired(false); + options.addOption(opt); + + opt = new Option("d", "clientId", true, "The consumer's client id"); + opt.setRequired(false); + options.addOption(opt); + + opt = new Option("t", "topic", true, "The topic of msg"); + opt.setRequired(true); + options.addOption(opt); + + return options; + } @Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { @@ -178,7 +192,7 @@ public class QueryMsgByUniqueKeySubCommand implements SubCommand { final String consumerGroup = commandLine.getOptionValue('g').trim(); final String clientId = commandLine.getOptionValue('d').trim(); ConsumeMessageDirectlyResult result = - defaultMQAdminExt.consumeMessageDirectly(consumerGroup, clientId, topic, msgId); + defaultMQAdminExt.consumeMessageDirectly(consumerGroup, clientId, topic, msgId); System.out.printf("%s", result); } else { queryById(defaultMQAdminExt, topic, msgId); @@ -189,23 +203,4 @@ public class QueryMsgByUniqueKeySubCommand implements SubCommand { defaultMQAdminExt.shutdown(); } } - - - private static String createBodyFile(MessageExt msg) throws IOException { - DataOutputStream dos = null; - try { - String bodyTmpFilePath = "/tmp/rocketmq/msgbodys"; - File file = new File(bodyTmpFilePath); - if (!file.exists()) { - file.mkdirs(); - } - bodyTmpFilePath = bodyTmpFilePath + "/" + msg.getMsgId(); - dos = new DataOutputStream(new FileOutputStream(bodyTmpFilePath)); - dos.write(msg.getBody()); - return bodyTmpFilePath; - } finally { - if (dos != null) - dos.close(); - } - } } diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/message/Store.java b/tools/src/main/java/org/apache/rocketmq/tools/command/message/Store.java index ee923c66..e25c61f0 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/message/Store.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/message/Store.java @@ -17,19 +17,18 @@ package org.apache.rocketmq.tools.command.message; -import org.apache.rocketmq.common.MixAll; -import org.apache.rocketmq.store.ConsumeQueue; -import org.apache.rocketmq.store.MappedFile; -import org.apache.rocketmq.store.MappedFileQueue; -import org.apache.rocketmq.store.SelectMappedBufferResult; -import org.apache.rocketmq.store.config.StorePathConfigHelper; - import java.io.File; import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import java.util.Date; import java.util.List; import java.util.concurrent.ConcurrentHashMap; +import org.apache.rocketmq.common.MixAll; +import org.apache.rocketmq.store.ConsumeQueue; +import org.apache.rocketmq.store.MappedFile; +import org.apache.rocketmq.store.MappedFileQueue; +import org.apache.rocketmq.store.SelectMappedBufferResult; +import org.apache.rocketmq.store.config.StorePathConfigHelper; public class Store { public final static int MESSAGE_MAGIC_CODE = 0xAABBCCDD ^ 1880681586 + 8; @@ -49,7 +48,7 @@ public class Store { this.lSize = lSize; mapedFileQueue = new MappedFileQueue(cStorePath, cSize, null); consumeQueueTable = - new ConcurrentHashMap>(); + new ConcurrentHashMap>(); } public boolean load() { @@ -75,11 +74,11 @@ public class Store { for (File fileQueueId : fileQueueIdList) { int queueId = Integer.parseInt(fileQueueId.getName()); ConsumeQueue logic = new ConsumeQueue( - topic, - queueId, - StorePathConfigHelper.getStorePathConsumeQueue(lStorePath), - lSize, - null); + topic, + queueId, + StorePathConfigHelper.getStorePathConsumeQueue(lStorePath), + lSize, + null); this.putConsumeQueue(topic, queueId, logic); if (!logic.load()) { return false; @@ -92,7 +91,6 @@ public class Store { return true; } - private void putConsumeQueue(final String topic, final int queueId, final ConsumeQueue consumeQueue) { ConcurrentHashMap map = this.consumeQueueTable.get(topic); if (null == map) { @@ -181,16 +179,14 @@ public class Store { e.printStackTrace(); } - Date storeTime = new Date(storeTimestamp); - long currentPhyOffset = startOffset + position; if (physicOffset != currentPhyOffset) { System.out.printf(storeTime - + " [fetal error] physicOffset != currentPhyOffset. position=" + position - + ", msgCount=" + msgCount + ", physicOffset=" + physicOffset - + ", currentPhyOffset=" + currentPhyOffset); + + " [fetal error] physicOffset != currentPhyOffset. position=" + position + + ", msgCount=" + msgCount + ", physicOffset=" + physicOffset + + ", currentPhyOffset=" + currentPhyOffset); errorCount++; if (!openAll) { success = false; @@ -205,8 +201,8 @@ public class Store { int sizePy = smb.getByteBuffer().getInt(); if (physicOffset != offsetPy) { System.out.printf(storeTime + " [fetal error] physicOffset != offsetPy. position=" - + position + ", msgCount=" + msgCount + ", physicOffset=" + physicOffset - + ", offsetPy=" + offsetPy); + + position + ", msgCount=" + msgCount + ", physicOffset=" + physicOffset + + ", offsetPy=" + offsetPy); errorCount++; if (!openAll) { success = false; @@ -215,8 +211,8 @@ public class Store { } if (totalSize != sizePy) { System.out.printf(storeTime + " [fetal error] totalSize != sizePy. position=" - + position + ", msgCount=" + msgCount + ", totalSize=" + totalSize - + ", sizePy=" + sizePy); + + position + ", msgCount=" + msgCount + ", totalSize=" + totalSize + + ", sizePy=" + sizePy); errorCount++; if (!openAll) { success = false; @@ -233,7 +229,7 @@ public class Store { } System.out.printf("end travel " + mapedFile.getFileName() + ", total msg=" + msgCount - + ", error count=" + errorCount + ", cost:" + (System.currentTimeMillis() - startTime)); + + ", error count=" + errorCount + ", cost:" + (System.currentTimeMillis() - startTime)); } System.out.printf("travel " + (success ? "ok" : "fail")); @@ -243,7 +239,7 @@ public class Store { ConcurrentHashMap map = consumeQueueTable.get(topic); if (null == map) { ConcurrentHashMap newMap = - new ConcurrentHashMap(128); + new ConcurrentHashMap(128); ConcurrentHashMap oldMap = consumeQueueTable.putIfAbsent(topic, newMap); if (oldMap != null) { map = oldMap; @@ -254,11 +250,11 @@ public class Store { ConsumeQueue logic = map.get(queueId); if (null == logic) { ConsumeQueue newLogic = new ConsumeQueue( - topic, - queueId, - StorePathConfigHelper.getStorePathConsumeQueue(lStorePath), - lSize, - null); + topic, + queueId, + StorePathConfigHelper.getStorePathConsumeQueue(lStorePath), + lSize, + null); ConsumeQueue oldLogic = map.putIfAbsent(queueId, newLogic); if (oldLogic != null) { logic = oldLogic; diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/namesrv/DeleteKvConfigCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/namesrv/DeleteKvConfigCommand.java index 0ae8f44f..b4fb7ddc 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/namesrv/DeleteKvConfigCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/namesrv/DeleteKvConfigCommand.java @@ -6,23 +6,22 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.tools.command.namesrv; -import org.apache.rocketmq.remoting.RPCHook; -import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; -import org.apache.rocketmq.tools.command.SubCommand; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; - +import org.apache.rocketmq.remoting.RPCHook; +import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; +import org.apache.rocketmq.tools.command.SubCommand; /** * @@ -34,13 +33,11 @@ public class DeleteKvConfigCommand implements SubCommand { return "deleteKvConfig"; } - @Override public String commandDesc() { return "Delete KV config."; } - @Override public Options buildCommandlineOptions(Options options) { Option opt = new Option("s", "namespace", true, "set the namespace"); @@ -53,7 +50,6 @@ public class DeleteKvConfigCommand implements SubCommand { return options; } - @Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/namesrv/GetNamesrvConfigCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/namesrv/GetNamesrvConfigCommand.java index b2c95d3e..f4c95d38 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/namesrv/GetNamesrvConfigCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/namesrv/GetNamesrvConfigCommand.java @@ -6,27 +6,26 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.tools.command.namesrv; -import org.apache.rocketmq.remoting.RPCHook; -import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; -import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Options; - import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Properties; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Options; +import org.apache.rocketmq.remoting.RPCHook; +import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; +import org.apache.rocketmq.tools.command.SubCommand; public class GetNamesrvConfigCommand implements SubCommand { @@ -67,7 +66,7 @@ public class GetNamesrvConfigCommand implements SubCommand { for (String server : nameServerConfigs.keySet()) { System.out.printf("============%s============\n", - server); + server); for (Object key : nameServerConfigs.get(server).keySet()) { System.out.printf("%-50s= %s\n", key, nameServerConfigs.get(server).get(key)); } diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/namesrv/UpdateKvConfigCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/namesrv/UpdateKvConfigCommand.java index a2d4f431..9d5f7a9c 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/namesrv/UpdateKvConfigCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/namesrv/UpdateKvConfigCommand.java @@ -6,23 +6,22 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.tools.command.namesrv; -import org.apache.rocketmq.remoting.RPCHook; -import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; -import org.apache.rocketmq.tools.command.SubCommand; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; - +import org.apache.rocketmq.remoting.RPCHook; +import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; +import org.apache.rocketmq.tools.command.SubCommand; /** * @@ -34,13 +33,11 @@ public class UpdateKvConfigCommand implements SubCommand { return "updateKvConfig"; } - @Override public String commandDesc() { return "Create or update KV config."; } - @Override public Options buildCommandlineOptions(Options options) { Option opt = new Option("s", "namespace", true, "set the namespace"); @@ -57,7 +54,6 @@ public class UpdateKvConfigCommand implements SubCommand { return options; } - @Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/namesrv/UpdateNamesrvConfigCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/namesrv/UpdateNamesrvConfigCommand.java index c6517d63..807636cf 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/namesrv/UpdateNamesrvConfigCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/namesrv/UpdateNamesrvConfigCommand.java @@ -6,27 +6,26 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.tools.command.namesrv; -import org.apache.rocketmq.remoting.RPCHook; -import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; -import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - import java.util.Arrays; import java.util.List; import java.util.Properties; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; +import org.apache.rocketmq.remoting.RPCHook; +import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; +import org.apache.rocketmq.tools.command.SubCommand; public class UpdateNamesrvConfigCommand implements SubCommand { @Override @@ -80,7 +79,7 @@ public class UpdateNamesrvConfigCommand implements SubCommand { defaultMQAdminExt.updateNameServerConfig(properties, serverList); System.out.printf("update name server config success!%s\n%s : %s\n", - serverList == null ? "" : serverList, key, value); + serverList == null ? "" : serverList, key, value); return; } catch (Exception e) { e.printStackTrace(); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/namesrv/WipeWritePermSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/namesrv/WipeWritePermSubCommand.java index 66f7159c..86e78480 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/namesrv/WipeWritePermSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/namesrv/WipeWritePermSubCommand.java @@ -6,24 +6,23 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.tools.command.namesrv; -import org.apache.rocketmq.remoting.RPCHook; -import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; -import org.apache.rocketmq.tools.command.SubCommand; +import java.util.List; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; - -import java.util.List; +import org.apache.rocketmq.remoting.RPCHook; +import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; +import org.apache.rocketmq.tools.command.SubCommand; public class WipeWritePermSubCommand implements SubCommand { @@ -32,13 +31,11 @@ public class WipeWritePermSubCommand implements SubCommand { return "wipeWritePerm"; } - @Override public String commandDesc() { return "Wipe write perm of broker in all name server"; } - @Override public Options buildCommandlineOptions(Options options) { Option opt = new Option("b", "brokerName", true, "broker name"); @@ -47,7 +44,6 @@ public class WipeWritePermSubCommand implements SubCommand { return options; } - @Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); @@ -63,14 +59,14 @@ public class WipeWritePermSubCommand implements SubCommand { try { int wipeTopicCount = defaultMQAdminExt.wipeWritePermOfBroker(namesrvAddr, brokerName); System.out.printf("wipe write perm of broker[%s] in name server[%s] OK, %d%n", - brokerName, - namesrvAddr, - wipeTopicCount + brokerName, + namesrvAddr, + wipeTopicCount ); } catch (Exception e) { System.out.printf("wipe write perm of broker[%s] in name server[%s] Failed%n", - brokerName, - namesrvAddr + brokerName, + namesrvAddr ); e.printStackTrace(); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/offset/CloneGroupOffsetCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/offset/CloneGroupOffsetCommand.java index 3cb7e3f4..fe239aa1 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/offset/CloneGroupOffsetCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/offset/CloneGroupOffsetCommand.java @@ -6,17 +6,21 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.tools.command.offset; +import java.util.Set; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; import org.apache.rocketmq.common.admin.ConsumeStats; import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.common.protocol.route.BrokerData; @@ -24,11 +28,6 @@ import org.apache.rocketmq.common.protocol.route.TopicRouteData; import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -import java.util.Set; public class CloneGroupOffsetCommand implements SubCommand { @Override @@ -94,7 +93,7 @@ public class CloneGroupOffsetCommand implements SubCommand { } } System.out.printf("clone group offset success. srcGroup[%s], destGroup=[%s], topic[%s]", - srcGroup, destGroup, topic); + srcGroup, destGroup, topic); } catch (Exception e) { e.printStackTrace(); } finally { diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/offset/GetConsumerStatusCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/offset/GetConsumerStatusCommand.java index 1623f525..68b62e1b 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/offset/GetConsumerStatusCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/offset/GetConsumerStatusCommand.java @@ -17,16 +17,15 @@ package org.apache.rocketmq.tools.command.offset; +import java.util.Map; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; import org.apache.rocketmq.common.UtilAll; import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -import java.util.Map; public class GetConsumerStatusCommand implements SubCommand { @Override @@ -70,15 +69,15 @@ public class GetConsumerStatusCommand implements SubCommand { defaultMQAdminExt.start(); Map> consumerStatusTable = - defaultMQAdminExt.getConsumeStatus(topic, group, originClientId); + defaultMQAdminExt.getConsumeStatus(topic, group, originClientId); System.out.printf("get consumer status from client. group=%s, topic=%s, originClientId=%s%n", - group, topic, originClientId); + group, topic, originClientId); System.out.printf("%-50s %-15s %-15s %-20s%n", - "#clientId", - "#brokerName", - "#queueId", - "#offset"); + "#clientId", + "#brokerName", + "#queueId", + "#offset"); for (Map.Entry> entry : consumerStatusTable.entrySet()) { String clientId = entry.getKey(); @@ -86,10 +85,10 @@ public class GetConsumerStatusCommand implements SubCommand { for (Map.Entry entry1 : mqTable.entrySet()) { MessageQueue mq = entry1.getKey(); System.out.printf("%-50s %-15s %-15d %-20d%n", - UtilAll.frontStringAtLeast(clientId, 50), - mq.getBrokerName(), - mq.getQueueId(), - mqTable.get(mq)); + UtilAll.frontStringAtLeast(clientId, 50), + mq.getBrokerName(), + mq.getQueueId(), + mqTable.get(mq)); } } } catch (Exception e) { diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/offset/ResetOffsetByTimeCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/offset/ResetOffsetByTimeCommand.java index 5eb30b54..e07a7c82 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/offset/ResetOffsetByTimeCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/offset/ResetOffsetByTimeCommand.java @@ -17,6 +17,12 @@ package org.apache.rocketmq.tools.command.offset; +import java.util.Iterator; +import java.util.Map; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.PosixParser; import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.common.UtilAll; import org.apache.rocketmq.common.message.MessageQueue; @@ -25,22 +31,14 @@ import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.srvutil.ServerUtil; import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.PosixParser; - -import java.util.Iterator; -import java.util.Map; - public class ResetOffsetByTimeCommand implements SubCommand { public static void main(String[] args) { ResetOffsetByTimeCommand cmd = new ResetOffsetByTimeCommand(); Options options = ServerUtil.buildCommandlineOptions(new Options()); - String[] subargs = new String[]{"-t Jodie_rest_test", "-g CID_Jodie_rest_test", "-s -1", "-f true"}; + String[] subargs = new String[] {"-t Jodie_rest_test", "-g CID_Jodie_rest_test", "-s -1", "-f true"}; final CommandLine commandLine = - ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser()); + ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser()); cmd.execute(commandLine, options, null); } @@ -120,20 +118,20 @@ public class ResetOffsetByTimeCommand implements SubCommand { } System.out.printf("rollback consumer offset by specified group[%s], topic[%s], force[%s], timestamp(string)[%s], timestamp(long)[%s]%n", - group, topic, force, timeStampStr, timestamp); + group, topic, force, timeStampStr, timestamp); System.out.printf("%-40s %-40s %-40s%n", - "#brokerName", - "#queueId", - "#offset"); + "#brokerName", + "#queueId", + "#offset"); Iterator> iterator = offsetTable.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry entry = iterator.next(); System.out.printf("%-40s %-40d %-40d%n", - UtilAll.frontStringAtLeast(entry.getKey().getBrokerName(), 32), - entry.getKey().getQueueId(), - entry.getValue()); + UtilAll.frontStringAtLeast(entry.getKey().getBrokerName(), 32), + entry.getKey().getQueueId(), + entry.getValue()); } } catch (Exception e) { e.printStackTrace(); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/offset/ResetOffsetByTimeOldCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/offset/ResetOffsetByTimeOldCommand.java index 0f15f69c..9b304742 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/offset/ResetOffsetByTimeOldCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/offset/ResetOffsetByTimeOldCommand.java @@ -6,17 +6,22 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.tools.command.offset; +import java.util.Date; +import java.util.List; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; import org.apache.rocketmq.client.exception.MQBrokerException; import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.common.UtilAll; @@ -25,19 +30,40 @@ import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.remoting.exception.RemotingException; import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -import java.util.Date; -import java.util.List; - /** * * */ public class ResetOffsetByTimeOldCommand implements SubCommand { + public static void resetOffset(DefaultMQAdminExt defaultMQAdminExt, String consumerGroup, String topic, long timestamp, boolean force, + String timeStampStr) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { + List rollbackStatsList = defaultMQAdminExt.resetOffsetByTimestampOld(consumerGroup, topic, timestamp, force); + System.out.printf( + "rollback consumer offset by specified consumerGroup[%s], topic[%s], force[%s], timestamp(string)[%s], timestamp(long)[%s]%n", + consumerGroup, topic, force, timeStampStr, timestamp); + + System.out.printf("%-20s %-20s %-20s %-20s %-20s %-20s%n", + "#brokerName", + "#queueId", + "#brokerOffset", + "#consumerOffset", + "#timestampOffset", + "#rollbackOffset" + ); + + for (RollbackStats rollbackStats : rollbackStatsList) { + System.out.printf("%-20s %-20d %-20d %-20d %-20d %-20d%n", + UtilAll.frontStringAtLeast(rollbackStats.getBrokerName(), 32), + rollbackStats.getQueueId(), + rollbackStats.getBrokerOffset(), + rollbackStats.getConsumerOffset(), + rollbackStats.getTimestampOffset(), + rollbackStats.getRollbackOffset() + ); + } + } + @Override public String commandName() { return "resetOffsetByTimeOld"; @@ -104,32 +130,4 @@ public class ResetOffsetByTimeOldCommand implements SubCommand { defaultMQAdminExt.shutdown(); } } - - public static void resetOffset(DefaultMQAdminExt defaultMQAdminExt, String consumerGroup, String topic, long timestamp, boolean force, - String timeStampStr) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { - List rollbackStatsList = defaultMQAdminExt.resetOffsetByTimestampOld(consumerGroup, topic, timestamp, force); - System.out.printf( - "rollback consumer offset by specified consumerGroup[%s], topic[%s], force[%s], timestamp(string)[%s], timestamp(long)[%s]%n", - consumerGroup, topic, force, timeStampStr, timestamp); - - System.out.printf("%-20s %-20s %-20s %-20s %-20s %-20s%n", - "#brokerName", - "#queueId", - "#brokerOffset", - "#consumerOffset", - "#timestampOffset", - "#rollbackOffset" - ); - - for (RollbackStats rollbackStats : rollbackStatsList) { - System.out.printf("%-20s %-20d %-20d %-20d %-20d %-20d%n", - UtilAll.frontStringAtLeast(rollbackStats.getBrokerName(), 32), - rollbackStats.getQueueId(), - rollbackStats.getBrokerOffset(), - rollbackStats.getConsumerOffset(), - rollbackStats.getTimestampOffset(), - rollbackStats.getRollbackOffset() - ); - } - } } diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/stats/StatsAllSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/stats/StatsAllSubCommand.java index 90a361c8..81a7f788 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/stats/StatsAllSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/stats/StatsAllSubCommand.java @@ -17,6 +17,9 @@ package org.apache.rocketmq.tools.command.stats; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; import org.apache.rocketmq.client.exception.MQBrokerException; import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.common.MixAll; @@ -32,82 +35,10 @@ import org.apache.rocketmq.remoting.exception.RemotingException; import org.apache.rocketmq.store.stats.BrokerStatsManager; import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - public class StatsAllSubCommand implements SubCommand { - @Override - public String commandName() { - return "statsAll"; - } - - @Override - public String commandDesc() { - return "Topic and Consumer tps stats"; - } - - @Override - public Options buildCommandlineOptions(Options options) { - Option opt = new Option("a", "activeTopic", false, "print active topic only"); - opt.setRequired(false); - options.addOption(opt); - - opt = new Option("t", "topic", true, "print select topic only"); - opt.setRequired(false); - options.addOption(opt); - - return options; - } - - @Override - public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { - DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); - - defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); - - try { - defaultMQAdminExt.start(); - - TopicList topicList = defaultMQAdminExt.fetchAllTopicList(); - - System.out.printf("%-32s %-32s %12s %11s %11s %14s %14s%n", - "#Topic", - "#Consumer Group", - "#Accumulation", - "#InTPS", - "#OutTPS", - "#InMsg24Hour", - "#OutMsg24Hour" - ); - - boolean activeTopic = commandLine.hasOption('a'); - String selectTopic = commandLine.getOptionValue('t'); - - for (String topic : topicList.getTopicList()) { - if (topic.startsWith(MixAll.RETRY_GROUP_TOPIC_PREFIX) || topic.startsWith(MixAll.DLQ_GROUP_TOPIC_PREFIX)) { - continue; - } - - if (selectTopic != null && selectTopic != "" && !topic.equals(selectTopic)) { - continue; - } - - try { - printTopicDetail(defaultMQAdminExt, topic, activeTopic); - } catch (Exception e) { - } - } - } catch (Exception e) { - e.printStackTrace(); - } finally { - defaultMQAdminExt.shutdown(); - } - } - public static void printTopicDetail(final DefaultMQAdminExt admin, final String topic, final boolean activeTopic) - throws RemotingException, MQClientException, InterruptedException, MQBrokerException { + throws RemotingException, MQClientException, InterruptedException, MQBrokerException { TopicRouteData topicRouteData = admin.examineTopicRouteInfo(topic); GroupList groupList = admin.queryTopicConsumeByWho(topic); @@ -116,7 +47,6 @@ public class StatsAllSubCommand implements SubCommand { long inMsgCntToday = 0; - for (BrokerData bd : topicRouteData.getBrokerDatas()) { String masterAddr = bd.getBrokerAddrs().get(MixAll.MASTER_ID); if (masterAddr != null) { @@ -161,16 +91,16 @@ public class StatsAllSubCommand implements SubCommand { } if (!activeTopic || (inMsgCntToday > 0) || - (outMsgCntToday > 0)) { + (outMsgCntToday > 0)) { System.out.printf("%-32s %-32s %12d %11.2f %11.2f %14d %14d%n", - UtilAll.frontStringAtLeast(topic, 32), - UtilAll.frontStringAtLeast(group, 32), - accumulate, - inTPS, - outTPS, - inMsgCntToday, - outMsgCntToday + UtilAll.frontStringAtLeast(topic, 32), + UtilAll.frontStringAtLeast(group, 32), + accumulate, + inTPS, + outTPS, + inMsgCntToday, + outMsgCntToday ); } } @@ -178,13 +108,13 @@ public class StatsAllSubCommand implements SubCommand { if (!activeTopic || (inMsgCntToday > 0)) { System.out.printf("%-32s %-32s %12d %11.2f %11s %14d %14s%n", - UtilAll.frontStringAtLeast(topic, 32), - "", - 0, - inTPS, - "", - inMsgCntToday, - "NO_CONSUMER" + UtilAll.frontStringAtLeast(topic, 32), + "", + 0, + inTPS, + "", + inMsgCntToday, + "NO_CONSUMER" ); } } @@ -205,4 +135,72 @@ public class StatsAllSubCommand implements SubCommand { return 0; } + + @Override + public String commandName() { + return "statsAll"; + } + + @Override + public String commandDesc() { + return "Topic and Consumer tps stats"; + } + + @Override + public Options buildCommandlineOptions(Options options) { + Option opt = new Option("a", "activeTopic", false, "print active topic only"); + opt.setRequired(false); + options.addOption(opt); + + opt = new Option("t", "topic", true, "print select topic only"); + opt.setRequired(false); + options.addOption(opt); + + return options; + } + + @Override + public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { + DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); + + defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); + + try { + defaultMQAdminExt.start(); + + TopicList topicList = defaultMQAdminExt.fetchAllTopicList(); + + System.out.printf("%-32s %-32s %12s %11s %11s %14s %14s%n", + "#Topic", + "#Consumer Group", + "#Accumulation", + "#InTPS", + "#OutTPS", + "#InMsg24Hour", + "#OutMsg24Hour" + ); + + boolean activeTopic = commandLine.hasOption('a'); + String selectTopic = commandLine.getOptionValue('t'); + + for (String topic : topicList.getTopicList()) { + if (topic.startsWith(MixAll.RETRY_GROUP_TOPIC_PREFIX) || topic.startsWith(MixAll.DLQ_GROUP_TOPIC_PREFIX)) { + continue; + } + + if (selectTopic != null && selectTopic != "" && !topic.equals(selectTopic)) { + continue; + } + + try { + printTopicDetail(defaultMQAdminExt, topic, activeTopic); + } catch (Exception e) { + } + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + defaultMQAdminExt.shutdown(); + } + } } diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/topic/AllocateMQSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/topic/AllocateMQSubCommand.java index 09d80110..709aada7 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/topic/AllocateMQSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/topic/AllocateMQSubCommand.java @@ -16,6 +16,13 @@ */ package org.apache.rocketmq.tools.command.topic; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; import org.apache.rocketmq.client.consumer.rebalance.AllocateMessageQueueAveragely; import org.apache.rocketmq.client.impl.factory.MQClientInstance; import org.apache.rocketmq.common.message.MessageQueue; @@ -24,15 +31,6 @@ import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.remoting.protocol.RemotingSerializable; import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - public class AllocateMQSubCommand implements SubCommand { @Override @@ -40,13 +38,11 @@ public class AllocateMQSubCommand implements SubCommand { return "allocateMQ"; } - @Override public String commandDesc() { return "Allocate MQ"; } - @Override public Options buildCommandlineOptions(Options options) { Option opt = new Option("t", "topic", true, "topic name"); @@ -60,7 +56,6 @@ public class AllocateMQSubCommand implements SubCommand { return options; } - @Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { DefaultMQAdminExt adminExt = new DefaultMQAdminExt(rpcHook); @@ -81,7 +76,6 @@ public class AllocateMQSubCommand implements SubCommand { final AllocateMessageQueueAveragely averagely = new AllocateMessageQueueAveragely(); - RebalanceResult rr = new RebalanceResult(); for (String i : ipList) { diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/topic/DeleteTopicSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/topic/DeleteTopicSubCommand.java index 0749e36e..69cbc99c 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/topic/DeleteTopicSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/topic/DeleteTopicSubCommand.java @@ -6,16 +6,22 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.tools.command.topic; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; import org.apache.rocketmq.client.exception.MQBrokerException; import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.remoting.RPCHook; @@ -24,32 +30,41 @@ import org.apache.rocketmq.srvutil.ServerUtil; import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; import org.apache.rocketmq.tools.command.CommandUtil; import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - /** * * */ public class DeleteTopicSubCommand implements SubCommand { + public static void deleteTopic(final DefaultMQAdminExt adminExt, + final String clusterName, + final String topic + ) throws InterruptedException, MQBrokerException, RemotingException, MQClientException { + + Set masterSet = CommandUtil.fetchMasterAddrByClusterName(adminExt, clusterName); + adminExt.deleteTopicInBroker(masterSet, topic); + System.out.printf("delete topic [%s] from cluster [%s] success.%n", topic, clusterName); + + Set nameServerSet = null; + if (adminExt.getNamesrvAddr() != null) { + String[] ns = adminExt.getNamesrvAddr().trim().split(";"); + nameServerSet = new HashSet(Arrays.asList(ns)); + } + + adminExt.deleteTopicInNameServer(nameServerSet, topic); + System.out.printf("delete topic [%s] from NameServer success.%n", topic); + } + @Override public String commandName() { return "deleteTopic"; } - @Override public String commandDesc() { return "Delete topic from broker and NameServer."; } - @Override public Options buildCommandlineOptions(Options options) { Option opt = new Option("t", "topic", true, "topic name"); @@ -63,29 +78,6 @@ public class DeleteTopicSubCommand implements SubCommand { return options; } - - public static void deleteTopic(final DefaultMQAdminExt adminExt, - final String clusterName, - final String topic - ) throws InterruptedException, MQBrokerException, RemotingException, MQClientException { - - Set masterSet = CommandUtil.fetchMasterAddrByClusterName(adminExt, clusterName); - adminExt.deleteTopicInBroker(masterSet, topic); - System.out.printf("delete topic [%s] from cluster [%s] success.%n", topic, clusterName); - - - Set nameServerSet = null; - if (adminExt.getNamesrvAddr() != null) { - String[] ns = adminExt.getNamesrvAddr().trim().split(";"); - nameServerSet = new HashSet(Arrays.asList(ns)); - } - - - adminExt.deleteTopicInNameServer(nameServerSet, topic); - System.out.printf("delete topic [%s] from NameServer success.%n", topic); - } - - @Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { DefaultMQAdminExt adminExt = new DefaultMQAdminExt(rpcHook); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/topic/RebalanceResult.java b/tools/src/main/java/org/apache/rocketmq/tools/command/topic/RebalanceResult.java index 9f6c0b08..6e6e4ff8 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/topic/RebalanceResult.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/topic/RebalanceResult.java @@ -6,22 +6,21 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.tools.command.topic; -import org.apache.rocketmq.common.message.MessageQueue; - import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.rocketmq.common.message.MessageQueue; public class RebalanceResult { private Map> result = new HashMap>(); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/topic/TopicClusterSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/topic/TopicClusterSubCommand.java index 2bdedd69..6a267a55 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/topic/TopicClusterSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/topic/TopicClusterSubCommand.java @@ -16,15 +16,13 @@ */ package org.apache.rocketmq.tools.command.topic; -import org.apache.rocketmq.remoting.RPCHook; -import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; -import org.apache.rocketmq.tools.command.SubCommand; +import java.util.Set; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; - -import java.util.Set; - +import org.apache.rocketmq.remoting.RPCHook; +import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; +import org.apache.rocketmq.tools.command.SubCommand; /** * @@ -37,13 +35,11 @@ public class TopicClusterSubCommand implements SubCommand { return "topicClusterList"; } - @Override public String commandDesc() { return "get cluster info for topic"; } - @Override public Options buildCommandlineOptions(Options options) { Option opt = new Option("t", "topic", true, "topic name"); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/topic/TopicListSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/topic/TopicListSubCommand.java index 42184fbd..5e23a96d 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/topic/TopicListSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/topic/TopicListSubCommand.java @@ -16,6 +16,12 @@ */ package org.apache.rocketmq.tools.command.topic; +import java.util.Iterator; +import java.util.Map.Entry; +import java.util.Set; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.common.MixAll; import org.apache.rocketmq.common.UtilAll; @@ -28,14 +34,6 @@ import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.remoting.exception.RemotingException; import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -import java.util.Iterator; -import java.util.Map.Entry; -import java.util.Set; - /** * @@ -72,15 +70,15 @@ public class TopicListSubCommand implements SubCommand { ClusterInfo clusterInfo = defaultMQAdminExt.examineBrokerClusterInfo(); System.out.printf("%-20s %-48s %-48s%n", - "#Cluster Name", - "#Topic", - "#Consumer Group" + "#Cluster Name", + "#Topic", + "#Consumer Group" ); TopicList topicList = defaultMQAdminExt.fetchAllTopicList(); for (String topic : topicList.getTopicList()) { if (topic.startsWith(MixAll.RETRY_GROUP_TOPIC_PREFIX) - || topic.startsWith(MixAll.DLQ_GROUP_TOPIC_PREFIX)) { + || topic.startsWith(MixAll.DLQ_GROUP_TOPIC_PREFIX)) { continue; } @@ -89,7 +87,7 @@ public class TopicListSubCommand implements SubCommand { try { clusterName = - this.findTopicBelongToWhichCluster(topic, clusterInfo, defaultMQAdminExt); + this.findTopicBelongToWhichCluster(topic, clusterInfo, defaultMQAdminExt); groupList = defaultMQAdminExt.queryTopicConsumeByWho(topic); } catch (Exception e) { } @@ -101,9 +99,9 @@ public class TopicListSubCommand implements SubCommand { for (String group : groupList.getGroupList()) { System.out.printf("%-20s %-48s %-48s%n", - UtilAll.frontStringAtLeast(clusterName, 20), - UtilAll.frontStringAtLeast(topic, 48), - UtilAll.frontStringAtLeast(group, 48) + UtilAll.frontStringAtLeast(clusterName, 20), + UtilAll.frontStringAtLeast(topic, 48), + UtilAll.frontStringAtLeast(group, 48) ); } } @@ -121,8 +119,8 @@ public class TopicListSubCommand implements SubCommand { } private String findTopicBelongToWhichCluster(final String topic, final ClusterInfo clusterInfo, - final DefaultMQAdminExt defaultMQAdminExt) throws RemotingException, MQClientException, - InterruptedException { + final DefaultMQAdminExt defaultMQAdminExt) throws RemotingException, MQClientException, + InterruptedException { TopicRouteData topicRouteData = defaultMQAdminExt.examineTopicRouteInfo(topic); BrokerData brokerData = topicRouteData.getBrokerDatas().get(0); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/topic/TopicRouteSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/topic/TopicRouteSubCommand.java index 6f89b22c..b7a180fd 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/topic/TopicRouteSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/topic/TopicRouteSubCommand.java @@ -16,14 +16,13 @@ */ package org.apache.rocketmq.tools.command.topic; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; import org.apache.rocketmq.common.protocol.route.TopicRouteData; import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - /** * @@ -36,13 +35,11 @@ public class TopicRouteSubCommand implements SubCommand { return "topicRoute"; } - @Override public String commandDesc() { return "Examine topic route info"; } - @Override public Options buildCommandlineOptions(Options options) { Option opt = new Option("t", "topic", true, "topic name"); @@ -52,7 +49,6 @@ public class TopicRouteSubCommand implements SubCommand { return options; } - @Override public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/topic/TopicStatusSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/topic/TopicStatusSubCommand.java index 73b98c9e..76d9cbca 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/topic/TopicStatusSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/topic/TopicStatusSubCommand.java @@ -6,16 +6,22 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.tools.command.topic; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; import org.apache.rocketmq.common.UtilAll; import org.apache.rocketmq.common.admin.TopicOffset; import org.apache.rocketmq.common.admin.TopicStatsTable; @@ -23,14 +29,6 @@ import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; - /** * @@ -43,13 +41,11 @@ public class TopicStatusSubCommand implements SubCommand { return "topicStatus"; } - @Override public String commandDesc() { return "Examine topic Status info"; } - @Override public Options buildCommandlineOptions(Options options) { Option opt = new Option("t", "topic", true, "topic name"); @@ -58,7 +54,6 @@ public class TopicStatusSubCommand implements SubCommand { return options; } - @Override public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); @@ -75,11 +70,11 @@ public class TopicStatusSubCommand implements SubCommand { Collections.sort(mqList); System.out.printf("%-32s %-4s %-20s %-20s %s%n", - "#Broker Name", - "#QID", - "#Min Offset", - "#Max Offset", - "#Last Updated" + "#Broker Name", + "#QID", + "#Min Offset", + "#Max Offset", + "#Last Updated" ); for (MessageQueue mq : mqList) { @@ -91,11 +86,11 @@ public class TopicStatusSubCommand implements SubCommand { } System.out.printf("%-32s %-4d %-20d %-20d %s%n", - UtilAll.frontStringAtLeast(mq.getBrokerName(), 32), - mq.getQueueId(), - topicOffset.getMinOffset(), - topicOffset.getMaxOffset(), - humanTimestamp + UtilAll.frontStringAtLeast(mq.getBrokerName(), 32), + mq.getQueueId(), + topicOffset.getMinOffset(), + topicOffset.getMaxOffset(), + humanTimestamp ); } } catch (Exception e) { diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/topic/UpdateOrderConfCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/topic/UpdateOrderConfCommand.java index 4cc88eb0..f9f4f1f7 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/topic/UpdateOrderConfCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/topic/UpdateOrderConfCommand.java @@ -6,26 +6,25 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.tools.command.topic; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; import org.apache.rocketmq.common.UtilAll; import org.apache.rocketmq.common.namesrv.NamesrvUtil; import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.srvutil.ServerUtil; import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - /** * @@ -38,13 +37,11 @@ public class UpdateOrderConfCommand implements SubCommand { return "updateOrderConf"; } - @Override public String commandDesc() { return "Create or update or delete order conf"; } - @Override public Options buildCommandlineOptions(Options options) { Option opt = new Option("t", "topic", true, "topic name"); @@ -62,7 +59,6 @@ public class UpdateOrderConfCommand implements SubCommand { return options; } - @Override public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); @@ -76,7 +72,7 @@ public class UpdateOrderConfCommand implements SubCommand { defaultMQAdminExt.start(); String orderConf = - defaultMQAdminExt.getKVConfig(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG, topic); + defaultMQAdminExt.getKVConfig(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG, topic); System.out.printf("get orderConf success. topic=[%s], orderConf=[%s] ", topic, orderConf); return; @@ -93,7 +89,7 @@ public class UpdateOrderConfCommand implements SubCommand { defaultMQAdminExt.createOrUpdateOrderConf(topic, orderConf, true); System.out.printf("update orderConf success. topic=[%s], orderConf=[%s]", topic, - orderConf.toString()); + orderConf.toString()); return; } else if ("delete".equals(type)) { diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/topic/UpdateTopicPermSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/topic/UpdateTopicPermSubCommand.java index cd119a03..fb7ab218 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/topic/UpdateTopicPermSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/topic/UpdateTopicPermSubCommand.java @@ -16,6 +16,11 @@ */ package org.apache.rocketmq.tools.command.topic; +import java.util.List; +import java.util.Set; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; import org.apache.rocketmq.common.TopicConfig; import org.apache.rocketmq.common.protocol.route.QueueData; import org.apache.rocketmq.common.protocol.route.TopicRouteData; @@ -24,13 +29,6 @@ import org.apache.rocketmq.srvutil.ServerUtil; import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; import org.apache.rocketmq.tools.command.CommandUtil; import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -import java.util.List; -import java.util.Set; - public class UpdateTopicPermSubCommand implements SubCommand { @@ -39,13 +37,11 @@ public class UpdateTopicPermSubCommand implements SubCommand { return "updateTopicPerm"; } - @Override public String commandDesc() { return "Update topic perm"; } - @Override public Options buildCommandlineOptions(Options options) { Option opt = new Option("b", "brokerAddr", true, "create topic to which broker"); @@ -67,7 +63,6 @@ public class UpdateTopicPermSubCommand implements SubCommand { return options; } - @Override public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); @@ -106,7 +101,7 @@ public class UpdateTopicPermSubCommand implements SubCommand { } else if (commandLine.hasOption('c')) { String clusterName = commandLine.getOptionValue('c').trim(); Set masterSet = - CommandUtil.fetchMasterAddrByClusterName(defaultMQAdminExt, clusterName); + CommandUtil.fetchMasterAddrByClusterName(defaultMQAdminExt, clusterName); for (String addr : masterSet) { defaultMQAdminExt.createAndUpdateTopicConfig(addr, topicConfig); System.out.printf("update topic perm from %s to %s in %s success.%n", oldPerm, perm, addr); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/topic/UpdateTopicSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/topic/UpdateTopicSubCommand.java index 25dd1f34..d4437b1d 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/topic/UpdateTopicSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/topic/UpdateTopicSubCommand.java @@ -16,6 +16,10 @@ */ package org.apache.rocketmq.tools.command.topic; +import java.util.Set; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; import org.apache.rocketmq.common.TopicConfig; import org.apache.rocketmq.common.sysflag.TopicSysFlag; import org.apache.rocketmq.remoting.RPCHook; @@ -23,12 +27,6 @@ import org.apache.rocketmq.srvutil.ServerUtil; import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; import org.apache.rocketmq.tools.command.CommandUtil; import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -import java.util.Set; - public class UpdateTopicSubCommand implements SubCommand { @@ -37,13 +35,11 @@ public class UpdateTopicSubCommand implements SubCommand { return "updateTopic"; } - @Override public String commandDesc() { return "Update or create topic"; } - @Override public Options buildCommandlineOptions(Options options) { Option opt = new Option("b", "brokerAddr", true, "create topic to which broker"); @@ -85,7 +81,6 @@ public class UpdateTopicSubCommand implements SubCommand { return options; } - @Override public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); @@ -142,7 +137,7 @@ public class UpdateTopicSubCommand implements SubCommand { String orderConf = brokerName + ":" + topicConfig.getWriteQueueNums(); defaultMQAdminExt.createOrUpdateOrderConf(topicConfig.getTopicName(), orderConf, false); System.out.printf(String.format("set broker orderConf. isOrder=%s, orderConf=[%s]", - isOrder, orderConf.toString())); + isOrder, orderConf.toString())); } System.out.printf("create topic to %s success.%n", addr); System.out.printf("%s", topicConfig); @@ -154,7 +149,7 @@ public class UpdateTopicSubCommand implements SubCommand { defaultMQAdminExt.start(); Set masterSet = - CommandUtil.fetchMasterAddrByClusterName(defaultMQAdminExt, clusterName); + CommandUtil.fetchMasterAddrByClusterName(defaultMQAdminExt, clusterName); for (String addr : masterSet) { defaultMQAdminExt.createAndUpdateTopicConfig(addr, topicConfig); System.out.printf("create topic to %s success.%n", addr); @@ -162,18 +157,18 @@ public class UpdateTopicSubCommand implements SubCommand { if (isOrder) { Set brokerNameSet = - CommandUtil.fetchBrokerNameByClusterName(defaultMQAdminExt, clusterName); + CommandUtil.fetchBrokerNameByClusterName(defaultMQAdminExt, clusterName); StringBuilder orderConf = new StringBuilder(); String splitor = ""; for (String s : brokerNameSet) { orderConf.append(splitor).append(s).append(":") - .append(topicConfig.getWriteQueueNums()); + .append(topicConfig.getWriteQueueNums()); splitor = ";"; } defaultMQAdminExt.createOrUpdateOrderConf(topicConfig.getTopicName(), - orderConf.toString(), true); + orderConf.toString(), true); System.out.printf(String.format("set cluster orderConf. isOrder=%s, orderConf=[%s]", - isOrder, orderConf.toString())); + isOrder, orderConf.toString())); } System.out.printf("%s", topicConfig); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/monitor/DefaultMonitorListener.java b/tools/src/main/java/org/apache/rocketmq/tools/monitor/DefaultMonitorListener.java index 9bcb2df7..63b81f8b 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/monitor/DefaultMonitorListener.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/monitor/DefaultMonitorListener.java @@ -6,60 +6,52 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.tools.monitor; -import org.apache.rocketmq.client.log.ClientLogger; -import org.apache.rocketmq.common.protocol.body.ConsumerRunningInfo; -import org.slf4j.Logger; - import java.util.Iterator; import java.util.Map.Entry; import java.util.TreeMap; - +import org.apache.rocketmq.client.log.ClientLogger; +import org.apache.rocketmq.common.protocol.body.ConsumerRunningInfo; +import org.slf4j.Logger; public class DefaultMonitorListener implements MonitorListener { private final static String LOG_PREFIX = "[MONITOR] "; private final static String LOG_NOTIFY = LOG_PREFIX + " [NOTIFY] "; private final Logger log = ClientLogger.getLog(); - public DefaultMonitorListener() { } - @Override public void beginRound() { log.info(LOG_PREFIX + "=========================================beginRound"); } - @Override public void reportUndoneMsgs(UndoneMsgs undoneMsgs) { log.info(String.format(LOG_PREFIX + "reportUndoneMsgs: %s", undoneMsgs)); } - @Override public void reportFailedMsgs(FailedMsgs failedMsgs) { log.info(String.format(LOG_PREFIX + "reportFailedMsgs: %s", failedMsgs)); } - @Override public void reportDeleteMsgsEvent(DeleteMsgsEvent deleteMsgsEvent) { log.info(String.format(LOG_PREFIX + "reportDeleteMsgsEvent: %s", deleteMsgsEvent)); } - @Override public void reportConsumerRunningInfo(TreeMap criTable) { @@ -67,12 +59,11 @@ public class DefaultMonitorListener implements MonitorListener { boolean result = ConsumerRunningInfo.analyzeSubscription(criTable); if (!result) { log.info(String.format(LOG_NOTIFY - + "reportConsumerRunningInfo: ConsumerGroup: %s, Subscription different", criTable - .firstEntry().getValue().getProperties().getProperty("consumerGroup"))); + + "reportConsumerRunningInfo: ConsumerGroup: %s, Subscription different", criTable + .firstEntry().getValue().getProperties().getProperty("consumerGroup"))); } } - { Iterator> it = criTable.entrySet().iterator(); while (it.hasNext()) { @@ -80,16 +71,15 @@ public class DefaultMonitorListener implements MonitorListener { String result = ConsumerRunningInfo.analyzeProcessQueue(next.getKey(), next.getValue()); if (!result.isEmpty()) { log.info(String.format(LOG_NOTIFY - + "reportConsumerRunningInfo: ConsumerGroup: %s, ClientId: %s, %s", - criTable.firstEntry().getValue().getProperties().getProperty("consumerGroup"), - next.getKey(), - result)); + + "reportConsumerRunningInfo: ConsumerGroup: %s, ClientId: %s, %s", + criTable.firstEntry().getValue().getProperties().getProperty("consumerGroup"), + next.getKey(), + result)); } } } } - @Override public void endRound() { log.info(LOG_PREFIX + "=========================================endRound"); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/monitor/DeleteMsgsEvent.java b/tools/src/main/java/org/apache/rocketmq/tools/monitor/DeleteMsgsEvent.java index 5db446fa..3270286c 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/monitor/DeleteMsgsEvent.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/monitor/DeleteMsgsEvent.java @@ -6,48 +6,42 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.tools.monitor; import org.apache.rocketmq.common.protocol.topic.OffsetMovedEvent; - public class DeleteMsgsEvent { private OffsetMovedEvent offsetMovedEvent; private long eventTimestamp; - public OffsetMovedEvent getOffsetMovedEvent() { return offsetMovedEvent; } - public void setOffsetMovedEvent(OffsetMovedEvent offsetMovedEvent) { this.offsetMovedEvent = offsetMovedEvent; } - public long getEventTimestamp() { return eventTimestamp; } - public void setEventTimestamp(long eventTimestamp) { this.eventTimestamp = eventTimestamp; } - @Override public String toString() { return "DeleteMsgsEvent [offsetMovedEvent=" + offsetMovedEvent + ", eventTimestamp=" + eventTimestamp - + "]"; + + "]"; } } diff --git a/tools/src/main/java/org/apache/rocketmq/tools/monitor/FailedMsgs.java b/tools/src/main/java/org/apache/rocketmq/tools/monitor/FailedMsgs.java index 4c4e91c1..bf639847 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/monitor/FailedMsgs.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/monitor/FailedMsgs.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.tools.monitor; @@ -22,40 +22,33 @@ public class FailedMsgs { private String topic; private long failedMsgsTotalRecently; - public String getConsumerGroup() { return consumerGroup; } - public void setConsumerGroup(String consumerGroup) { this.consumerGroup = consumerGroup; } - public String getTopic() { return topic; } - public void setTopic(String topic) { this.topic = topic; } - public long getFailedMsgsTotalRecently() { return failedMsgsTotalRecently; } - public void setFailedMsgsTotalRecently(long failedMsgsTotalRecently) { this.failedMsgsTotalRecently = failedMsgsTotalRecently; } - @Override public String toString() { return "FailedMsgs [consumerGroup=" + consumerGroup + ", topic=" + topic - + ", failedMsgsTotalRecently=" + failedMsgsTotalRecently + "]"; + + ", failedMsgsTotalRecently=" + failedMsgsTotalRecently + "]"; } } diff --git a/tools/src/main/java/org/apache/rocketmq/tools/monitor/MonitorConfig.java b/tools/src/main/java/org/apache/rocketmq/tools/monitor/MonitorConfig.java index fbe6c3c4..e60d3176 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/monitor/MonitorConfig.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/monitor/MonitorConfig.java @@ -6,42 +6,37 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.tools.monitor; import org.apache.rocketmq.common.MixAll; - public class MonitorConfig { private String namesrvAddr = System.getProperty(MixAll.NAMESRV_ADDR_PROPERTY, - System.getenv(MixAll.NAMESRV_ADDR_ENV)); + System.getenv(MixAll.NAMESRV_ADDR_ENV)); private int roundInterval = 1000 * 60; - public String getNamesrvAddr() { return namesrvAddr; } - public void setNamesrvAddr(String namesrvAddr) { this.namesrvAddr = namesrvAddr; } - public int getRoundInterval() { return roundInterval; } - public void setRoundInterval(int roundInterval) { this.roundInterval = roundInterval; } diff --git a/tools/src/main/java/org/apache/rocketmq/tools/monitor/MonitorListener.java b/tools/src/main/java/org/apache/rocketmq/tools/monitor/MonitorListener.java index a60a2732..17f85ce9 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/monitor/MonitorListener.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/monitor/MonitorListener.java @@ -17,9 +17,8 @@ package org.apache.rocketmq.tools.monitor; -import org.apache.rocketmq.common.protocol.body.ConsumerRunningInfo; - import java.util.TreeMap; +import org.apache.rocketmq.common.protocol.body.ConsumerRunningInfo; public interface MonitorListener { void beginRound(); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/monitor/MonitorService.java b/tools/src/main/java/org/apache/rocketmq/tools/monitor/MonitorService.java index 8c368fe2..d9c4cf8b 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/monitor/MonitorService.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/monitor/MonitorService.java @@ -6,17 +6,26 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.tools.monitor; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map.Entry; +import java.util.Random; +import java.util.TreeMap; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; import org.apache.rocketmq.client.consumer.DefaultMQPullConsumer; import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; import org.apache.rocketmq.client.consumer.PullResult; @@ -43,17 +52,10 @@ import org.apache.rocketmq.remoting.exception.RemotingException; import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; import org.slf4j.Logger; -import java.util.*; -import java.util.Map.Entry; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; - - public class MonitorService { private final Logger log = ClientLogger.getLog(); private final ScheduledExecutorService scheduledExecutorService = Executors - .newSingleThreadScheduledExecutor(new ThreadFactoryImpl("MonitorService")); + .newSingleThreadScheduledExecutor(new ThreadFactoryImpl("MonitorService")); private final MonitorConfig monitorConfig; @@ -61,10 +63,9 @@ public class MonitorService { private final DefaultMQAdminExt defaultMQAdminExt; private final DefaultMQPullConsumer defaultMQPullConsumer = new DefaultMQPullConsumer( - MixAll.TOOLS_CONSUMER_GROUP); + MixAll.TOOLS_CONSUMER_GROUP); private final DefaultMQPushConsumer defaultMQPushConsumer = new DefaultMQPushConsumer( - MixAll.MONITOR_CONSUMER_GROUP); - + MixAll.MONITOR_CONSUMER_GROUP); public MonitorService(MonitorConfig monitorConfig, MonitorListener monitorListener, RPCHook rpcHook) { this.monitorConfig = monitorConfig; @@ -87,10 +88,10 @@ public class MonitorService { @Override public ConsumeConcurrentlyStatus consumeMessage(List msgs, - ConsumeConcurrentlyContext context) { + ConsumeConcurrentlyContext context) { try { OffsetMovedEvent ome = - OffsetMovedEvent.decode(msgs.get(0).getBody(), OffsetMovedEvent.class); + OffsetMovedEvent.decode(msgs.get(0).getBody(), OffsetMovedEvent.class); DeleteMsgsEvent deleteMsgsEvent = new DeleteMsgsEvent(); deleteMsgsEvent.setOffsetMovedEvent(ome); @@ -107,27 +108,18 @@ public class MonitorService { } } - - private String instanceName() { - String name = - System.currentTimeMillis() + new Random().nextInt() + this.monitorConfig.getNamesrvAddr(); - - return "MonitorService_" + name.hashCode(); - } - public static void main(String[] args) throws MQClientException { main0(args, null); } public static void main0(String[] args, RPCHook rpcHook) throws MQClientException { final MonitorService monitorService = - new MonitorService(new MonitorConfig(), new DefaultMonitorListener(), rpcHook); + new MonitorService(new MonitorConfig(), new DefaultMonitorListener(), rpcHook); monitorService.start(); Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { private volatile boolean hasShutdown = false; - @Override public void run() { synchronized (this) { @@ -140,6 +132,13 @@ public class MonitorService { }, "ShutdownHook")); } + private String instanceName() { + String name = + System.currentTimeMillis() + new Random().nextInt() + this.monitorConfig.getNamesrvAddr(); + + return "MonitorService_" + name.hashCode(); + } + public void start() throws MQClientException { this.defaultMQPullConsumer.start(); this.defaultMQAdminExt.start(); @@ -181,7 +180,6 @@ public class MonitorService { // log.error("reportUndoneMsgs Exception", e); } - try { this.reportConsumerRunningInfo(consumerGroup); } catch (Exception e) { @@ -228,7 +226,6 @@ public class MonitorService { } } - { Iterator> it = csByTopic.entrySet().iterator(); while (it.hasNext()) { @@ -245,7 +242,7 @@ public class MonitorService { } public void reportConsumerRunningInfo(final String consumerGroup) throws InterruptedException, - MQBrokerException, RemotingException, MQClientException { + MQBrokerException, RemotingException, MQClientException { ConsumerConnection cc = defaultMQAdminExt.examineConsumerConnectionInfo(consumerGroup); TreeMap infoMap = new TreeMap(); for (Connection c : cc.getConnectionSet()) { @@ -257,7 +254,7 @@ public class MonitorService { try { ConsumerRunningInfo info = - defaultMQAdminExt.getConsumerRunningInfo(consumerGroup, clientId, false); + defaultMQAdminExt.getConsumerRunningInfo(consumerGroup, clientId, false); infoMap.put(clientId, info); } catch (Exception e) { } @@ -296,7 +293,7 @@ public class MonitorService { switch (pull.getPullStatus()) { case FOUND: long delay = - pull.getMsgFoundList().get(0).getStoreTimestamp() - ow.getLastTimestamp(); + pull.getMsgFoundList().get(0).getStoreTimestamp() - ow.getLastTimestamp(); if (delay > delayMax) { delayMax = delay; } diff --git a/tools/src/main/java/org/apache/rocketmq/tools/monitor/UndoneMsgs.java b/tools/src/main/java/org/apache/rocketmq/tools/monitor/UndoneMsgs.java index ac549af4..abc0cb97 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/monitor/UndoneMsgs.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/monitor/UndoneMsgs.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.tools.monitor; @@ -27,61 +27,50 @@ public class UndoneMsgs { private long undoneMsgsDelayTimeMills; - public String getConsumerGroup() { return consumerGroup; } - public void setConsumerGroup(String consumerGroup) { this.consumerGroup = consumerGroup; } - public String getTopic() { return topic; } - public void setTopic(String topic) { this.topic = topic; } - public long getUndoneMsgsTotal() { return undoneMsgsTotal; } - public void setUndoneMsgsTotal(long undoneMsgsTotal) { this.undoneMsgsTotal = undoneMsgsTotal; } - public long getUndoneMsgsSingleMQ() { return undoneMsgsSingleMQ; } - public void setUndoneMsgsSingleMQ(long undoneMsgsSingleMQ) { this.undoneMsgsSingleMQ = undoneMsgsSingleMQ; } - public long getUndoneMsgsDelayTimeMills() { return undoneMsgsDelayTimeMills; } - public void setUndoneMsgsDelayTimeMills(long undoneMsgsDelayTimeMills) { this.undoneMsgsDelayTimeMills = undoneMsgsDelayTimeMills; } - @Override public String toString() { return "UndoneMsgs [consumerGroup=" + consumerGroup + ", topic=" + topic + ", undoneMsgsTotal=" - + undoneMsgsTotal + ", undoneMsgsSingleMQ=" + undoneMsgsSingleMQ - + ", undoneMsgsDelayTimeMills=" + undoneMsgsDelayTimeMills + "]"; + + undoneMsgsTotal + ", undoneMsgsSingleMQ=" + undoneMsgsSingleMQ + + ", undoneMsgsDelayTimeMills=" + undoneMsgsDelayTimeMills + "]"; } } -- GitLab