提交 ffad6566 编写于 作者: R Ritabrata Moitra 提交者: yukon

[ROCKETMQ-209]Remove duplicated code in class MQClientAPIImpl

Author: Ritabrata Moitra <rmoitra@thoughtworks.com>

Closes #134 from Ritabrata-TW/master.
上级 ccc2235a
...@@ -413,8 +413,9 @@ public class DefaultMessageStore implements MessageStore { ...@@ -413,8 +413,9 @@ public class DefaultMessageStore implements MessageStore {
return commitLog; return commitLog;
} }
public GetMessageResult getMessage(final String group, final String topic, final int queueId, final long offset, final int maxMsgNums, public GetMessageResult getMessage(final String group, final String topic, final int queueId, final long offset,
final MessageFilter messageFilter) { final int maxMsgNums,
final MessageFilter messageFilter) {
if (this.shutdown) { if (this.shutdown) {
log.warn("message store has shutdown, so getMessage is forbidden"); log.warn("message store has shutdown, so getMessage is forbidden");
return null; return null;
...@@ -717,22 +718,27 @@ public class DefaultMessageStore implements MessageStore { ...@@ -717,22 +718,27 @@ public class DefaultMessageStore implements MessageStore {
long minLogicOffset = logicQueue.getMinLogicOffset(); long minLogicOffset = logicQueue.getMinLogicOffset();
SelectMappedBufferResult result = logicQueue.getIndexBuffer(minLogicOffset / ConsumeQueue.CQ_STORE_UNIT_SIZE); SelectMappedBufferResult result = logicQueue.getIndexBuffer(minLogicOffset / ConsumeQueue.CQ_STORE_UNIT_SIZE);
if (result != null) { return getStoreTime(result);
try {
final long phyOffset = result.getByteBuffer().getLong();
final int size = result.getByteBuffer().getInt();
long storeTime = this.getCommitLog().pickupStoreTimestamp(phyOffset, size);
return storeTime;
} catch (Exception e) {
} finally {
result.release();
}
}
} }
return -1; return -1;
} }
private long getStoreTime(SelectMappedBufferResult result) {
if (result != null) {
try {
final long phyOffset = result.getByteBuffer().getLong();
final int size = result.getByteBuffer().getInt();
long storeTime = this.getCommitLog().pickupStoreTimestamp(phyOffset, size);
return storeTime;
} catch (Exception e) {
} finally {
result.release();
}
}
return -1;
}
@Override @Override
public long getEarliestMessageTime() { public long getEarliestMessageTime() {
final long minPhyOffset = this.getMinPhyOffset(); final long minPhyOffset = this.getMinPhyOffset();
...@@ -745,17 +751,7 @@ public class DefaultMessageStore implements MessageStore { ...@@ -745,17 +751,7 @@ public class DefaultMessageStore implements MessageStore {
ConsumeQueue logicQueue = this.findConsumeQueue(topic, queueId); ConsumeQueue logicQueue = this.findConsumeQueue(topic, queueId);
if (logicQueue != null) { if (logicQueue != null) {
SelectMappedBufferResult result = logicQueue.getIndexBuffer(consumeQueueOffset); SelectMappedBufferResult result = logicQueue.getIndexBuffer(consumeQueueOffset);
if (result != null) { return getStoreTime(result);
try {
final long phyOffset = result.getByteBuffer().getLong();
final int size = result.getByteBuffer().getInt();
long storeTime = this.getCommitLog().pickupStoreTimestamp(phyOffset, size);
return storeTime;
} catch (Exception ignored) {
} finally {
result.release();
}
}
} }
return -1; return -1;
...@@ -955,7 +951,8 @@ public class DefaultMessageStore implements MessageStore { ...@@ -955,7 +951,8 @@ public class DefaultMessageStore implements MessageStore {
} }
} }
public Map<String, Long> getMessageIds(final String topic, final int queueId, long minOffset, long maxOffset, SocketAddress storeHost) { public Map<String, Long> getMessageIds(final String topic, final int queueId, long minOffset, long maxOffset,
SocketAddress storeHost) {
Map<String, Long> messageIds = new HashMap<String, Long>(); Map<String, Long> messageIds = new HashMap<String, Long>();
if (this.shutdown) { if (this.shutdown) {
return messageIds; return messageIds;
......
...@@ -77,20 +77,7 @@ public class DefaultMessageStoreTest { ...@@ -77,20 +77,7 @@ public class DefaultMessageStoreTest {
assertTrue(load); assertTrue(load);
master.start(); master.start();
try { verifyThatMasterIsFunctional(totalMsgs, master);
for (long i = 0; i < totalMsgs; i++) {
master.putMessage(buildMessage());
}
for (long i = 0; i < totalMsgs; i++) {
GetMessageResult result = master.getMessage("GROUP_A", "TOPIC_A", 0, i, 1024 * 1024, null);
assertThat(result).isNotNull();
result.release();
}
} finally {
master.shutdown();
master.destroy();
}
} }
public MessageExtBrokerInner buildMessage() { public MessageExtBrokerInner buildMessage() {
...@@ -121,6 +108,10 @@ public class DefaultMessageStoreTest { ...@@ -121,6 +108,10 @@ public class DefaultMessageStoreTest {
assertTrue(load); assertTrue(load);
master.start(); master.start();
verifyThatMasterIsFunctional(totalMsgs, master);
}
private void verifyThatMasterIsFunctional(long totalMsgs, MessageStore master) {
try { try {
for (long i = 0; i < totalMsgs; i++) { for (long i = 0; i < totalMsgs; i++) {
master.putMessage(buildMessage()); master.putMessage(buildMessage());
...@@ -171,7 +162,7 @@ public class DefaultMessageStoreTest { ...@@ -171,7 +162,7 @@ public class DefaultMessageStoreTest {
private class MyMessageArrivingListener implements MessageArrivingListener { private class MyMessageArrivingListener implements MessageArrivingListener {
@Override @Override
public void arriving(String topic, int queueId, long logicOffset, long tagsCode, long msgStoreTime, public void arriving(String topic, int queueId, long logicOffset, long tagsCode, long msgStoreTime,
byte[] filterBitMap, Map<String, String> properties) { byte[] filterBitMap, Map<String, String> properties) {
} }
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册