Search in sources :

Example 6 with ReadResultSetImpl

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

the class ReadManyOperation method shouldWait.

@Override
public boolean shouldWait() {
    if (resultSet == null) {
        resultSet = new ReadResultSetImpl(minSize, maxSize, getNodeEngine().getHazelcastInstance(), filter);
        sequence = startSequence;
    }
    RingbufferContainer ringbuffer = getRingBufferContainer();
    if (minSize == 0) {
        if (!ringbuffer.shouldWait(sequence)) {
            sequence = ringbuffer.readMany(sequence, resultSet);
        }
        return false;
    }
    if (resultSet.isMinSizeReached()) {
        // enough items have been read, we are done.
        return false;
    }
    if (ringbuffer.shouldWait(sequence)) {
        // the sequence is not readable
        return true;
    }
    sequence = ringbuffer.readMany(sequence, resultSet);
    return !resultSet.isMinSizeReached();
}
Also used : RingbufferContainer(com.hazelcast.ringbuffer.impl.RingbufferContainer) ReadResultSetImpl(com.hazelcast.ringbuffer.impl.ReadResultSetImpl)

Example 7 with ReadResultSetImpl

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

the class RingbufferReadManyMessageTask method encodeResponse.

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

Example 8 with ReadResultSetImpl

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

the class ReadManyOperationTest method whenOneAfterTail.

@Test
public void whenOneAfterTail() throws Exception {
    ringbuffer.add("tail");
    ReadManyOperation op = new ReadManyOperation(ringbuffer.getName(), ringbuffer.tailSequence() + 1, 1, 1, null);
    op.setNodeEngine(nodeEngine);
    // since there is an item, we don't need to wait
    boolean shouldWait = op.shouldWait();
    assertTrue(shouldWait);
    ReadResultSetImpl response = getReadResultSet(op);
    assertEquals(0, response.readCount());
}
Also used : ReadResultSetImpl(com.hazelcast.ringbuffer.impl.ReadResultSetImpl) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 9 with ReadResultSetImpl

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

the class ReadManyOperationTest method whenOneAfterTailAndBufferEmpty.

@Test
public void whenOneAfterTailAndBufferEmpty() throws Exception {
    ReadManyOperation op = new ReadManyOperation(ringbuffer.getName(), ringbuffer.tailSequence() + 1, 1, 1, null);
    op.setNodeEngine(nodeEngine);
    // since there is an item, we don't need to wait
    boolean shouldWait = op.shouldWait();
    assertTrue(shouldWait);
    ReadResultSetImpl response = getReadResultSet(op);
    assertEquals(0, response.readCount());
    assertEquals(0, response.size());
}
Also used : ReadResultSetImpl(com.hazelcast.ringbuffer.impl.ReadResultSetImpl) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

ReadResultSetImpl (com.hazelcast.ringbuffer.impl.ReadResultSetImpl)9 ParallelTest (com.hazelcast.test.annotation.ParallelTest)7 QuickTest (com.hazelcast.test.annotation.QuickTest)7 Test (org.junit.Test)7 IFunction (com.hazelcast.core.IFunction)1 Data (com.hazelcast.nio.serialization.Data)1 RingbufferContainer (com.hazelcast.ringbuffer.impl.RingbufferContainer)1 ArrayList (java.util.ArrayList)1