Search in sources :

Example 1 with ClientMessageReadHandler

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);
}
Also used : ClientMessageReadHandler(com.hazelcast.client.impl.protocol.util.ClientMessageReadHandler) ClientMessageReadHandler(com.hazelcast.client.impl.protocol.util.ClientMessageReadHandler) ReadHandler(com.hazelcast.internal.networking.ReadHandler) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientConnectionManager(com.hazelcast.client.connection.ClientConnectionManager)

Example 2 with ClientMessageReadHandler

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]++;
        }
    }
}
Also used : ClientMessageReadHandler(com.hazelcast.client.impl.protocol.util.ClientMessageReadHandler) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 3 with ClientMessageReadHandler

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()));
    }
}
Also used : ClientMessageReadHandler(com.hazelcast.client.impl.protocol.util.ClientMessageReadHandler) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with ClientMessageReadHandler

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()));
    }
}
Also used : ClientMessageReadHandler(com.hazelcast.client.impl.protocol.util.ClientMessageReadHandler) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)4 ClientMessageReadHandler (com.hazelcast.client.impl.protocol.util.ClientMessageReadHandler)4 ParallelTest (com.hazelcast.test.annotation.ParallelTest)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 Test (org.junit.Test)3 ClientConnectionManager (com.hazelcast.client.connection.ClientConnectionManager)1 ReadHandler (com.hazelcast.internal.networking.ReadHandler)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1