Skip to content

Commit

Permalink
ROCKETMQ-18 Clean code closes apache#21
Browse files Browse the repository at this point in the history
  • Loading branch information
dongeforever authored and lollipopjin committed Dec 29, 2016
1 parent 6672256 commit 167cce0
Show file tree
Hide file tree
Showing 64 changed files with 208 additions and 258 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ private void printMasterAndSlaveDiff() {
long diff = this.messageStore.slaveFallBehindMuch();

// XXX: warn and notify me
log.info("slave fall behind master, how much, {} bytes", diff);
log.info("Slave fall behind master: {} bytes", diff);
}

public Broker2Client getBroker2Client() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,8 @@ public static BrokerController createBrokerController(String[] args) {
if (null != namesrvAddr) {
try {
String[] addrArray = namesrvAddr.split(";");
if (addrArray != null) {
for (String addr : addrArray) {
RemotingUtil.string2SocketAddress(addr);
}
for (String addr : addrArray) {
RemotingUtil.string2SocketAddress(addr);
}
} catch (Exception e) {
System.out.printf(
Expand Down Expand Up @@ -211,13 +209,13 @@ public static BrokerController createBrokerController(String[] args) {
@Override
public void run() {
synchronized (this) {
log.info("shutdown hook was invoked, " + this.shutdownTimes.incrementAndGet());
log.info("Shutdown hook was invoked, {}", this.shutdownTimes.incrementAndGet());
if (!this.hasShutdown) {
this.hasShutdown = true;
long begineTime = System.currentTimeMillis();
controller.shutdown();
long consumingTimeTotal = System.currentTimeMillis() - begineTime;
log.info("shutdown hook over, consuming time total(ms): " + consumingTimeTotal);
log.info("Shutdown hook over, consuming total time(ms): {}", consumingTimeTotal);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ public ConcurrentHashMap<Channel, ClientChannelInfo> getChannelInfoTable() {
}

public List<Channel> getAllChannel() {
List<Channel> result = new ArrayList<Channel>();
List<Channel> result = new ArrayList<>();

result.addAll(this.channelInfoTable.keySet());

return result;
}

public List<String> getAllClientId() {
List<String> result = new ArrayList<String>();
List<String> result = new ArrayList<>();

Iterator<Entry<Channel, ClientChannelInfo>> it = this.channelInfoTable.entrySet().iterator();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public void scanNotActiveChannel() {
}

public HashSet<String> queryTopicConsumeByWho(final String topic) {
HashSet<String> groups = new HashSet<String>();
HashSet<String> groups = new HashSet<>();
Iterator<Entry<String, ConsumerGroupInfo>> it = this.consumerTable.entrySet().iterator();
while (it.hasNext()) {
Entry<String, ConsumerGroupInfo> entry = it.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void registerProducer(final String group, final ClientChannelInfo clientC
try {
HashMap<Channel, ClientChannelInfo> channelTable = this.groupChannelTable.get(group);
if (null == channelTable) {
channelTable = new HashMap<Channel, ClientChannelInfo>();
channelTable = new HashMap<>();
this.groupChannelTable.put(group, channelTable);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public RemotingCommand resetOffset(String topic, String group, long timeStamp, b
}

private List<MessageQueueForC> convertOffsetTable2OffsetList(Map<MessageQueue, Long> table) {
List<MessageQueueForC> list = new ArrayList<MessageQueueForC>();
List<MessageQueueForC> list = new ArrayList<>();
for (Entry<MessageQueue, Long> entry : table.entrySet()) {
MessageQueue mq = entry.getKey();
MessageQueueForC tmp =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public boolean tryLock(final String group, final MessageQueue mq, final String c
try {
ConcurrentHashMap<MessageQueue, LockEntry> groupValue = this.mqLockTable.get(group);
if (null == groupValue) {
groupValue = new ConcurrentHashMap<MessageQueue, LockEntry>(32);
groupValue = new ConcurrentHashMap<>(32);
this.mqLockTable.put(group, groupValue);
}

Expand Down Expand Up @@ -132,7 +132,7 @@ public Set<MessageQueue> tryLockBatch(final String group, final Set<MessageQueue
try {
ConcurrentHashMap<MessageQueue, LockEntry> groupValue = this.mqLockTable.get(group);
if (null == groupValue) {
groupValue = new ConcurrentHashMap<MessageQueue, LockEntry>(32);
groupValue = new ConcurrentHashMap<>(32);
this.mqLockTable.put(group, groupValue);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public void doChannelCloseEvent(final String remoteAddr, final Channel channel)
}

public List<String> buildNewFilterServerList() {
List<String> addr = new ArrayList<String>();
List<String> addr = new ArrayList<>();
Iterator<Entry<Channel, FilterServerInfo>> it = this.filterServerTable.entrySet().iterator();
while (it.hasNext()) {
Entry<Channel, FilterServerInfo> next = it.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public static void callShell(final String shellString, final Logger log) {
String[] cmdArray = splitShellString(shellString);
process = Runtime.getRuntime().exec(cmdArray);
process.waitFor();
log.info("callShell: <{}> OK", shellString);
log.info("CallShell: <{}> OK", shellString);
} catch (Throwable e) {
log.error("callShell: readLine IOException, " + shellString, e);
log.error("CallShell: readLine IOException, {}", shellString, e);
} finally {
if (null != process)
process.destroy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ private void cleanExpiredRequest() {
}
}
}

public void shutdown() {
this.scheduledExecutorService.shutdown();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.List;

public class ManyPullRequest {
private final ArrayList<PullRequest> pullRequestList = new ArrayList<PullRequest>();
private final ArrayList<PullRequest> pullRequestList = new ArrayList<>();

public synchronized void addPullRequest(final PullRequest pullRequest) {
this.pullRequestList.add(pullRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private String buildKey(final String topic, final int queueId) {

@Override
public void run() {
log.info(this.getServiceName() + " service started");
log.info("{} service started", this.getServiceName());
while (!this.isStopped()) {
try {
if (this.brokerController.getBrokerConfig().isLongPollingEnable()) {
Expand All @@ -85,7 +85,7 @@ public void run() {
}
}

log.info(this.getServiceName() + " service end");
log.info("{} service end", this.getServiceName());
}

@Override
Expand All @@ -96,7 +96,7 @@ public String getServiceName() {
private void checkHoldRequest() {
for (String key : this.pullRequestTable.keySet()) {
String[] kArray = key.split(TOPIC_QUEUEID_SEPARATOR);
if (kArray != null && 2 == kArray.length) {
if (2 == kArray.length) {
String topic = kArray[0];
int queueId = Integer.parseInt(kArray[1]);
final long offset = this.brokerController.getMessageStore().getMaxOffsetInQuque(topic, queueId);
Expand Down Expand Up @@ -127,9 +127,8 @@ public void notifyMessageArriving(final String topic, final int queueId, final l
newestOffset = this.brokerController.getMessageStore().getMaxOffsetInQuque(topic, queueId);
}

Long tmp = tagsCode;
if (newestOffset > request.getPullFromThisOffset()) {
if (this.messageFilter.isMessageMatched(request.getSubscriptionData(), tmp)) {
if (this.messageFilter.isMessageMatched(request.getSubscriptionData(), tagsCode)) {
try {
this.brokerController.getPullMessageProcessor().excuteRequestWhenWakeup(request.getClientChannel(),
request.getRequestCommand());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public String fetchNameServerAddr() {
String addrs = this.topAddressing.fetchNSAddr();
if (addrs != null) {
if (!addrs.equals(this.nameSrvAddr)) {
log.info("name server address changed, old: " + this.nameSrvAddr + " new: " + addrs);
log.info("name server address changed, old: {} new: {}", this.nameSrvAddr, addrs);
this.updateNameServerAddressList(addrs);
this.nameSrvAddr = addrs;
return nameSrvAddr;
Expand Down Expand Up @@ -121,7 +121,7 @@ public RegisterBrokerResult registerBrokerAll(

log.info("register broker to name server {} OK", namesrvAddr);
} catch (Exception e) {
log.warn("registerBroker Exception, " + namesrvAddr, e);
log.warn("registerBroker Exception, {}", namesrvAddr, e);
}
}
}
Expand Down Expand Up @@ -199,7 +199,7 @@ public void unregisterBrokerAll(
this.unregisterBroker(namesrvAddr, clusterName, brokerAddr, brokerName, brokerId);
log.info("unregisterBroker OK, NamesrvAddr: {}", namesrvAddr);
} catch (Exception e) {
log.warn("unregisterBroker Exception, " + namesrvAddr, e);
log.warn("unregisterBroker Exception, {}", namesrvAddr, e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,12 @@ protected RemotingCommand msgContentCheck(final ChannelHandlerContext ctx,
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());
log.warn("putMessage message topic length too long {}", requestHeader.getTopic().length());
response.setCode(ResponseCode.MESSAGE_ILLEGAL);
return response;
}
if (requestHeader.getProperties() != null && requestHeader.getProperties().length() > Short.MAX_VALUE) {
log.warn("putMessage message properties length too long "
+ requestHeader.getProperties().length());
log.warn("putMessage message properties length too long {}", requestHeader.getProperties().length());
response.setCode(ResponseCode.MESSAGE_ILLEGAL);
return response;
}
Expand Down Expand Up @@ -188,8 +187,7 @@ protected RemotingCommand msgCheck(final ChannelHandlerContext ctx,
}
}

log.warn("the topic " + requestHeader.getTopic() + " not exist, producer: "
+ ctx.channel().remoteAddress());
log.warn("the topic {} not exist, producer: {}", requestHeader.getTopic(), ctx.channel().remoteAddress());
topicConfig = this.brokerController.getTopicConfigManager().createTopicInSendMessageMethod(//
requestHeader.getTopic(), //
requestHeader.getDefaultTopic(), //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ private RemotingCommand getAllTopicConfig(ChannelHandlerContext ctx, RemotingCom
return response;
}
} else {
log.error("No topic in this broker, client: " + ctx.channel().remoteAddress());
log.error("No topic in this broker, client: {}", ctx.channel().remoteAddress());
response.setCode(ResponseCode.SYSTEM_ERROR);
response.setRemark("No topic in this broker");
return response;
Expand All @@ -290,7 +290,7 @@ private RemotingCommand updateBrokerConfig(ChannelHandlerContext ctx, RemotingCo
String bodyStr = new String(body, MixAll.DEFAULT_CHARSET);
Properties properties = MixAll.string2Properties(bodyStr);
if (properties != null) {
log.info("updateBrokerConfig, new config: " + properties + " client: " + ctx.channel().remoteAddress());
log.info("updateBrokerConfig, new config: [{}] client: {} ", properties, ctx.channel().remoteAddress());
this.brokerController.getConfiguration().update(properties);
if (properties.containsKey("brokerPermission")) {
this.brokerController.registerBrokerAll(false, false);
Expand Down Expand Up @@ -476,7 +476,7 @@ private RemotingCommand getAllSubscriptionGroup(ChannelHandlerContext ctx, Remot
return response;
}
} else {
log.error("No subscription group in this broker, client: " + ctx.channel().remoteAddress());
log.error("No subscription group in this broker, client:{} ", ctx.channel().remoteAddress());
response.setCode(ResponseCode.SYSTEM_ERROR);
response.setRemark("No subscription group in this broker");
return response;
Expand Down Expand Up @@ -718,7 +718,7 @@ private RemotingCommand getAllConsumerOffset(ChannelHandlerContext ctx, Remoting
return response;
}
} else {
log.error("No consumer offset in this broker, client: " + ctx.channel().remoteAddress());
log.error("No consumer offset in this broker, client: {} ", ctx.channel().remoteAddress());
response.setCode(ResponseCode.SYSTEM_ERROR);
response.setRemark("No consumer offset in this broker");
return response;
Expand All @@ -745,7 +745,7 @@ private RemotingCommand getAllDelayOffset(ChannelHandlerContext ctx, RemotingCom
return response;
}
} else {
log.error("No delay offset in this broker, client: " + ctx.channel().remoteAddress());
log.error("No delay offset in this broker, client: {} ", ctx.channel().remoteAddress());
response.setCode(ResponseCode.SYSTEM_ERROR);
response.setRemark("No delay offset in this broker");
return response;
Expand Down
Loading

0 comments on commit 167cce0

Please sign in to comment.