提交 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 {
return commitLog;
}
public GetMessageResult getMessage(final String group, final String topic, final int queueId, final long offset, final int maxMsgNums,
final MessageFilter messageFilter) {
public GetMessageResult getMessage(final String group, final String topic, final int queueId, final long offset,
final int maxMsgNums,
final MessageFilter messageFilter) {
if (this.shutdown) {
log.warn("message store has shutdown, so getMessage is forbidden");
return null;
......@@ -717,22 +718,27 @@ public class DefaultMessageStore implements MessageStore {
long minLogicOffset = logicQueue.getMinLogicOffset();
SelectMappedBufferResult result = logicQueue.getIndexBuffer(minLogicOffset / ConsumeQueue.CQ_STORE_UNIT_SIZE);
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 getStoreTime(result);
}
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
public long getEarliestMessageTime() {
final long minPhyOffset = this.getMinPhyOffset();
......@@ -745,17 +751,7 @@ public class DefaultMessageStore implements MessageStore {
ConsumeQueue logicQueue = this.findConsumeQueue(topic, queueId);
if (logicQueue != null) {
SelectMappedBufferResult result = logicQueue.getIndexBuffer(consumeQueueOffset);
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 ignored) {
} finally {
result.release();
}
}
return getStoreTime(result);
}
return -1;
......@@ -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>();
if (this.shutdown) {
return messageIds;
......
......@@ -77,20 +77,7 @@ public class DefaultMessageStoreTest {
assertTrue(load);
master.start();
try {
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();
}
verifyThatMasterIsFunctional(totalMsgs, master);
}
public MessageExtBrokerInner buildMessage() {
......@@ -121,6 +108,10 @@ public class DefaultMessageStoreTest {
assertTrue(load);
master.start();
verifyThatMasterIsFunctional(totalMsgs, master);
}
private void verifyThatMasterIsFunctional(long totalMsgs, MessageStore master) {
try {
for (long i = 0; i < totalMsgs; i++) {
master.putMessage(buildMessage());
......@@ -171,7 +162,7 @@ public class DefaultMessageStoreTest {
private class MyMessageArrivingListener implements MessageArrivingListener {
@Override
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.
先完成此消息的编辑!
想要评论请 注册