Search in sources :

Example 1 with PortableReadResultSet

use of com.hazelcast.ringbuffer.impl.client.PortableReadResultSet in project hazelcast by hazelcast.

the class ReadManyOperationTest method whenEnoughItemsAvailableAndReturnPortable.

@Test
public void whenEnoughItemsAvailableAndReturnPortable() throws Exception {
    long startSequence = ringbuffer.tailSequence() + 1;
    ReadManyOperation op = new ReadManyOperation(ringbuffer.getName(), startSequence, 1, 3, null, true);
    op.setNodeEngine(nodeEngine);
    ringbuffer.add("item1");
    ringbuffer.add("item2");
    ringbuffer.add("item3");
    ringbuffer.add("item4");
    ringbuffer.add("item5");
    assertFalse(op.shouldWait());
    HeapData response = assertInstanceOf(HeapData.class, op.getResponse());
    PortableReadResultSet readResultSet = serializationService.toObject(response);
    assertEquals(startSequence + 3, op.sequence);
    assertEquals(3, readResultSet.readCount());
    assertEquals(3, readResultSet.getDataItems().size());
    readResultSet.setSerializationService(serializationService);
    assertIterableEquals(readResultSet, "item1", "item2", "item3");
}
Also used : PortableReadResultSet(com.hazelcast.ringbuffer.impl.client.PortableReadResultSet) HeapData(com.hazelcast.internal.serialization.impl.HeapData) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with PortableReadResultSet

use of com.hazelcast.ringbuffer.impl.client.PortableReadResultSet in project hazelcast by hazelcast.

the class ReadManyOperation method getResponse.

@Override
public Object getResponse() {
    if (returnPortable) {
        List<Data> items = new ArrayList<Data>(resultSet.size());
        for (int k = 0; k < resultSet.size(); k++) {
            items.add(resultSet.getDataItems()[k]);
        }
        PortableReadResultSet portableReadResultSet = new PortableReadResultSet(resultSet.readCount(), items);
        return getNodeEngine().toData(portableReadResultSet);
    }
    return resultSet;
}
Also used : ArrayList(java.util.ArrayList) PortableReadResultSet(com.hazelcast.ringbuffer.impl.client.PortableReadResultSet) Data(com.hazelcast.nio.serialization.Data)

Example 3 with PortableReadResultSet

use of com.hazelcast.ringbuffer.impl.client.PortableReadResultSet in project hazelcast by hazelcast.

the class ClientRingbufferProxy method onInitialize.

@Override
protected void onInitialize() {
    String partitionKey = StringPartitioningStrategy.getPartitionKey(name);
    partitionId = getContext().getPartitionService().getPartitionId(partitionKey);
    final SerializationService serializationService = getContext().getSerializationService();
    readManyAsyncResponseDecoder = new ClientMessageDecoder() {

        @Override
        public PortableReadResultSet decodeClientMessage(ClientMessage clientMessage) {
            final RingbufferReadManyCodec.ResponseParameters responseParameters = RingbufferReadManyCodec.decodeResponse(clientMessage);
            PortableReadResultSet readResultSet = new PortableReadResultSet(responseParameters.readCount, responseParameters.items);
            readResultSet.setSerializationService(serializationService);
            return readResultSet;
        }
    };
}
Also used : ClientMessageDecoder(com.hazelcast.client.impl.ClientMessageDecoder) PortableReadResultSet(com.hazelcast.ringbuffer.impl.client.PortableReadResultSet) SerializationService(com.hazelcast.spi.serialization.SerializationService) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Aggregations

PortableReadResultSet (com.hazelcast.ringbuffer.impl.client.PortableReadResultSet)3 ClientMessageDecoder (com.hazelcast.client.impl.ClientMessageDecoder)1 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)1 HeapData (com.hazelcast.internal.serialization.impl.HeapData)1 Data (com.hazelcast.nio.serialization.Data)1 SerializationService (com.hazelcast.spi.serialization.SerializationService)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1