Search in sources :

Example 1 with ReadResultSetImpl

use of com.hazelcast.ringbuffer.impl.ReadResultSetImpl in project hazelcast by hazelcast.

the class MapEventJournalReadTask method encodeResponse.

@Override
protected ClientMessage encodeResponse(Object response) {
    // we are not deserializing the whole content, only the enclosing portable. The actual items remain un
    final ReadResultSetImpl resultSet = nodeEngine.getSerializationService().toObject(response);
    final List<Data> items = new ArrayList<Data>(resultSet.size());
    final long[] seqs = new long[resultSet.size()];
    final Data[] dataItems = resultSet.getDataItems();
    for (int k = 0; k < resultSet.size(); k++) {
        items.add(dataItems[k]);
        seqs[k] = resultSet.getSequence(k);
    }
    return MapEventJournalReadCodec.encodeResponse(resultSet.readCount(), items, seqs, resultSet.getNextSequenceToReadFrom());
}
Also used : ArrayList(java.util.ArrayList) Data(com.hazelcast.internal.serialization.Data) ReadResultSetImpl(com.hazelcast.ringbuffer.impl.ReadResultSetImpl)

Example 2 with ReadResultSetImpl

use of com.hazelcast.ringbuffer.impl.ReadResultSetImpl in project hazelcast by hazelcast.

the class CacheEventJournalReadTask method encodeResponse.

@Override
protected ClientMessage encodeResponse(Object response) {
    // we are not deserializing the whole content, only the enclosing portable. The actual items remain un
    final ReadResultSetImpl resultSet = nodeEngine.getSerializationService().toObject(response);
    final List<Data> items = new ArrayList<Data>(resultSet.size());
    final long[] seqs = new long[resultSet.size()];
    final Data[] dataItems = resultSet.getDataItems();
    for (int k = 0; k < resultSet.size(); k++) {
        items.add(dataItems[k]);
        seqs[k] = resultSet.getSequence(k);
    }
    return CacheEventJournalReadCodec.encodeResponse(resultSet.readCount(), items, seqs, resultSet.getNextSequenceToReadFrom());
}
Also used : ArrayList(java.util.ArrayList) Data(com.hazelcast.internal.serialization.Data) ReadResultSetImpl(com.hazelcast.ringbuffer.impl.ReadResultSetImpl)

Example 3 with ReadResultSetImpl

use of com.hazelcast.ringbuffer.impl.ReadResultSetImpl in project hazelcast by hazelcast.

the class ClientMapProxy method readFromEventJournal.

@Override
public <T> InternalCompletableFuture<ReadResultSet<T>> readFromEventJournal(long startSequence, int minSize, int maxSize, int partitionId, java.util.function.Predicate<? super EventJournalMapEvent<K, V>> predicate, java.util.function.Function<? super EventJournalMapEvent<K, V>, ? extends T> projection) {
    if (maxSize < minSize) {
        throw new IllegalArgumentException("maxSize " + maxSize + " must be greater or equal to minSize " + minSize);
    }
    final SerializationService ss = getSerializationService();
    final ClientMessage request = MapEventJournalReadCodec.encodeRequest(name, startSequence, minSize, maxSize, ss.toData(predicate), ss.toData(projection));
    final ClientInvocationFuture fut = new ClientInvocation(getClient(), request, getName(), partitionId).invoke();
    return new ClientDelegatingFuture<>(fut, ss, message -> {
        MapEventJournalReadCodec.ResponseParameters params = MapEventJournalReadCodec.decodeResponse(message);
        ReadResultSetImpl resultSet = new ReadResultSetImpl<>(params.readCount, params.items, params.itemSeqs, params.nextSeq);
        resultSet.setSerializationService(getSerializationService());
        return resultSet;
    });
}
Also used : ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) SerializationService(com.hazelcast.internal.serialization.SerializationService) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) MapEventJournalReadCodec(com.hazelcast.client.impl.protocol.codec.MapEventJournalReadCodec) ReadResultSetImpl(com.hazelcast.ringbuffer.impl.ReadResultSetImpl) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 4 with ReadResultSetImpl

use of com.hazelcast.ringbuffer.impl.ReadResultSetImpl in project hazelcast by hazelcast.

the class ReadManyOperationTest method whenMinimumNumberOfItemsAvailable.

@Test
public void whenMinimumNumberOfItemsAvailable() {
    long startSequence = ringbuffer.tailSequence() + 1;
    ReadManyOperation op = getReadManyOperation(startSequence, 3, 3, null);
    ringbuffer.add("item1");
    ringbuffer.add("item2");
    ringbuffer.add("item3");
    assertFalse(op.shouldWait());
    ReadResultSetImpl response = getReadResultSet(op);
    assertEquals(startSequence + 3, op.sequence);
    assertEquals(asList("item1", "item2", "item3"), response);
    assertEquals(3, response.getNextSequenceToReadFrom());
}
Also used : ReadResultSetImpl(com.hazelcast.ringbuffer.impl.ReadResultSetImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with ReadResultSetImpl

use of com.hazelcast.ringbuffer.impl.ReadResultSetImpl in project hazelcast by hazelcast.

the class ReadManyOperationTest method whenEnoughItemsAvailable.

@Test
public void whenEnoughItemsAvailable() {
    long startSequence = ringbuffer.tailSequence() + 1;
    ReadManyOperation op = getReadManyOperation(startSequence, 1, 3, null);
    ringbuffer.add("item1");
    ringbuffer.add("item2");
    ringbuffer.add("item3");
    ringbuffer.add("item4");
    ringbuffer.add("item5");
    assertFalse(op.shouldWait());
    ReadResultSetImpl response = getReadResultSet(op);
    assertEquals(startSequence + 3, op.sequence);
    assertEquals(asList("item1", "item2", "item3"), response);
    assertEquals(3, response.readCount());
    assertEquals(3, response.getNextSequenceToReadFrom());
}
Also used : ReadResultSetImpl(com.hazelcast.ringbuffer.impl.ReadResultSetImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

ReadResultSetImpl (com.hazelcast.ringbuffer.impl.ReadResultSetImpl)20 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)14 QuickTest (com.hazelcast.test.annotation.QuickTest)14 Test (org.junit.Test)14 Data (com.hazelcast.internal.serialization.Data)3 ArrayList (java.util.ArrayList)3 IFunction (com.hazelcast.core.IFunction)2 ClientDelegatingFuture (com.hazelcast.client.impl.ClientDelegatingFuture)1 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)1 CacheEventJournalReadCodec (com.hazelcast.client.impl.protocol.codec.CacheEventJournalReadCodec)1 ResponseParameters (com.hazelcast.client.impl.protocol.codec.CacheEventJournalSubscribeCodec.ResponseParameters)1 MapEventJournalReadCodec (com.hazelcast.client.impl.protocol.codec.MapEventJournalReadCodec)1 RingbufferReadManyCodec (com.hazelcast.client.impl.protocol.codec.RingbufferReadManyCodec)1 ClientInvocation (com.hazelcast.client.impl.spi.impl.ClientInvocation)1 ClientInvocationFuture (com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)1 EventJournalInitialSubscriberState (com.hazelcast.internal.journal.EventJournalInitialSubscriberState)1 SerializationService (com.hazelcast.internal.serialization.SerializationService)1