use of com.hazelcast.client.impl.protocol.util.ClientMessageReadHandler in project hazelcast by hazelcast.
the class ClientSocketReaderInitializer method init.
@Override
public void init(final ClientConnection connection, SocketReader reader) throws IOException {
reader.initInputBuffer(IOUtil.newByteBuffer(bufferSize, direct));
ReadHandler readHandler = new ClientMessageReadHandler(reader.getNormalFramesReadCounter(), new ClientMessageReadHandler.MessageHandler() {
private final ClientConnectionManager connectionManager = connection.getConnectionManager();
@Override
public void handleMessage(ClientMessage message) {
connectionManager.handleClientMessage(message, connection);
}
});
reader.initReadHandler(readHandler);
}
use of com.hazelcast.client.impl.protocol.util.ClientMessageReadHandler in project hazelcast by hazelcast.
the class ClientMessageSplitAndBuildTest method splitAndBuild_multipleMessages.
@Test
public void splitAndBuild_multipleMessages() throws Exception {
int FRAME_SIZE = 50;
int NUMBER_OF_MESSAGES = 5;
List<List<ClientMessage>> framedClientMessages = new ArrayList<List<ClientMessage>>(NUMBER_OF_MESSAGES);
final List<ClientMessage> expectedClientMessages = new ArrayList<ClientMessage>();
for (int id = 0; id < NUMBER_OF_MESSAGES; id++) {
String s = UUID.randomUUID().toString();
ClientMessage expectedClientMessage = ClientAuthenticationCodec.encodeRequest(s, s, s, s, true, s, (byte) 1, BuildInfoProvider.BUILD_INFO.getVersion());
expectedClientMessage.addFlag(ClientMessage.BEGIN_AND_END_FLAGS);
expectedClientMessage.setCorrelationId(id);
expectedClientMessages.add(expectedClientMessage);
framedClientMessages.add(ClientMessageSplitter.getSubFrames(FRAME_SIZE, expectedClientMessage));
}
ClientMessageReadHandler clientMessageReadHandler = new ClientMessageReadHandler(readCounter, new ClientMessageReadHandler.MessageHandler() {
@Override
public void handleMessage(ClientMessage message) {
int correlationId = (int) message.getCorrelationId();
message.addFlag(ClientMessage.BEGIN_AND_END_FLAGS);
assertEquals(expectedClientMessages.get(correlationId), message);
}
});
int[] currentFrameIndex = new int[NUMBER_OF_MESSAGES];
for (int nFinishedMessages = 0; nFinishedMessages < NUMBER_OF_MESSAGES; ) {
for (int i = 0; i < NUMBER_OF_MESSAGES; i++) {
List<ClientMessage> clientMessageFrames = framedClientMessages.get(i);
if (currentFrameIndex[i] >= clientMessageFrames.size()) {
nFinishedMessages++;
break;
}
ClientMessage subFrame = clientMessageFrames.get(currentFrameIndex[i]);
clientMessageReadHandler.onRead(ByteBuffer.wrap(subFrame.buffer().byteArray(), 0, subFrame.getFrameLength()));
currentFrameIndex[i]++;
}
}
}
use of com.hazelcast.client.impl.protocol.util.ClientMessageReadHandler in project hazelcast by hazelcast.
the class ClientMessageSplitAndBuildTest method splitAndBuild.
@Test
public void splitAndBuild() throws Exception {
int FRAME_SIZE = 50;
String s = UUID.randomUUID().toString();
final ClientMessage expectedClientMessage = ClientAuthenticationCodec.encodeRequest(s, s, s, s, true, s, (byte) 1, BuildInfoProvider.BUILD_INFO.getVersion());
expectedClientMessage.addFlag(ClientMessage.BEGIN_AND_END_FLAGS);
List<ClientMessage> subFrames = ClientMessageSplitter.getSubFrames(FRAME_SIZE, expectedClientMessage);
ClientMessageReadHandler clientMessageReadHandler = new ClientMessageReadHandler(readCounter, new ClientMessageReadHandler.MessageHandler() {
@Override
public void handleMessage(ClientMessage message) {
message.addFlag(ClientMessage.BEGIN_AND_END_FLAGS);
assertEquals(expectedClientMessage, message);
}
});
for (ClientMessage subFrame : subFrames) {
clientMessageReadHandler.onRead(ByteBuffer.wrap(subFrame.buffer().byteArray(), 0, subFrame.getFrameLength()));
}
}
use of com.hazelcast.client.impl.protocol.util.ClientMessageReadHandler in project hazelcast by hazelcast.
the class ClientMessageSplitAndBuildTest method splitAndBuild_whenMessageIsAlreadySmallerThanFrameSize.
@Test
public void splitAndBuild_whenMessageIsAlreadySmallerThanFrameSize() throws Exception {
String s = UUID.randomUUID().toString();
final ClientMessage expectedClientMessage = ClientAuthenticationCodec.encodeRequest(s, s, s, s, true, s, (byte) 1, BuildInfoProvider.BUILD_INFO.getVersion());
expectedClientMessage.addFlag(ClientMessage.BEGIN_AND_END_FLAGS);
List<ClientMessage> subFrames = ClientMessageSplitter.getSubFrames(expectedClientMessage.getFrameLength() + 1, expectedClientMessage);
ClientMessageReadHandler clientMessageReadHandler = new ClientMessageReadHandler(readCounter, new ClientMessageReadHandler.MessageHandler() {
@Override
public void handleMessage(ClientMessage message) {
message.addFlag(ClientMessage.BEGIN_AND_END_FLAGS);
assertEquals(expectedClientMessage, message);
}
});
for (ClientMessage subFrame : subFrames) {
clientMessageReadHandler.onRead(ByteBuffer.wrap(subFrame.buffer().byteArray(), 0, subFrame.getFrameLength()));
}
}
Aggregations