ByteBuffer.allocate(Math.min(this.metaConfig.getMaxTransferSize(), request.getMaxSize()));
set.read(byteBuffer);
byte[] bytes = this.getBytesFromBuffer(byteBuffer);
// If filter is not null,we filter the messages by it.
if (filter != null) {
MessageIterator it = new MessageIterator(topic, bytes);
// reuse the buffer.
byteBuffer.clear();
while (it.hasNext()) {
Message msg = it.next();
try {
if (filter.accept(group, msg)) {
ByteBuffer msgBuf = it.getCurrentMsgBuf();
// Append current message buffer to result
// buffer.
byteBuffer.put(msgBuf);
}
}
catch (Exception e) {
log.error("Filter message for consumer failed,topic=" + topic + ",group=" + group
+ ",filterClass=" + filter.getClass().getCanonicalName(), e);
}
}
// re-new the byte array.
bytes = this.getBytesFromBuffer(byteBuffer);
// All these messages are not acceptable,move forward
// offset.
if (bytes.length == 0) {
return new BooleanCommand(HttpStatus.Moved, String.valueOf(request.getOffset()
+ it.getOffset()), request.getOpaque());
}
}
return new DataCommand(bytes, request.getOpaque(), true);
}
}