Search in sources :

Example 1 with EventJournalInitialSubscriberState

use of com.hazelcast.internal.journal.EventJournalInitialSubscriberState in project hazelcast by hazelcast.

the class MapEventJournalSubscribeOperation method runInternal.

@Override
protected void runInternal() {
    final MapEventJournal eventJournal = mapServiceContext.getEventJournal();
    final long newestSequence = eventJournal.newestSequence(namespace, getPartitionId());
    final long oldestSequence = eventJournal.oldestSequence(namespace, getPartitionId());
    response = new EventJournalInitialSubscriberState(oldestSequence, newestSequence);
}
Also used : EventJournalInitialSubscriberState(com.hazelcast.internal.journal.EventJournalInitialSubscriberState)

Example 2 with EventJournalInitialSubscriberState

use of com.hazelcast.internal.journal.EventJournalInitialSubscriberState in project hazelcast by hazelcast.

the class CacheEventJournalSubscribeOperation method run.

@Override
public void run() {
    final CacheService service = getService();
    final CacheEventJournal eventJournal = service.getEventJournal();
    final long newestSequence = eventJournal.newestSequence(namespace, getPartitionId());
    final long oldestSequence = eventJournal.oldestSequence(namespace, getPartitionId());
    response = new EventJournalInitialSubscriberState(oldestSequence, newestSequence);
}
Also used : EventJournalInitialSubscriberState(com.hazelcast.internal.journal.EventJournalInitialSubscriberState) CacheService(com.hazelcast.cache.impl.CacheService) ICacheService(com.hazelcast.cache.impl.ICacheService)

Example 3 with EventJournalInitialSubscriberState

use of com.hazelcast.internal.journal.EventJournalInitialSubscriberState in project hazelcast by hazelcast.

the class ClientMapProxy method subscribeToEventJournal.

@Override
public InternalCompletableFuture<EventJournalInitialSubscriberState> subscribeToEventJournal(int partitionId) {
    final ClientMessage request = MapEventJournalSubscribeCodec.encodeRequest(name);
    final ClientInvocationFuture fut = new ClientInvocation(getClient(), request, getName(), partitionId).invoke();
    return new ClientDelegatingFuture<>(fut, getSerializationService(), message -> {
        ResponseParameters resp = MapEventJournalSubscribeCodec.decodeResponse(message);
        return new EventJournalInitialSubscriberState(resp.oldestSequence, resp.newestSequence);
    });
}
Also used : EventJournalInitialSubscriberState(com.hazelcast.internal.journal.EventJournalInitialSubscriberState) ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) ResponseParameters(com.hazelcast.client.impl.protocol.codec.MapEventJournalSubscribeCodec.ResponseParameters) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 4 with EventJournalInitialSubscriberState

use of com.hazelcast.internal.journal.EventJournalInitialSubscriberState in project hazelcast by hazelcast.

the class AbstractEventJournalBounceTest method getEventJournalEvents.

private <T> LinkedList<T> getEventJournalEvents(EventJournalReader<T> reader) {
    final LinkedList<T> events = new LinkedList<T>();
    for (int i = 1; i < TEST_PARTITION_COUNT; i++) {
        try {
            final EventJournalInitialSubscriberState state = reader.subscribeToEventJournal(i).toCompletableFuture().get();
            final ReadResultSet<T> partitionEvents = reader.readFromEventJournal(state.getOldestSequence(), 1, (int) (state.getNewestSequence() - state.getOldestSequence() + 1), i, new TruePredicate<T>(), new IdentityFunction<T>()).toCompletableFuture().get();
            for (T event : partitionEvents) {
                events.add(event);
            }
        } catch (Exception e) {
            throw rethrow(e);
        }
    }
    return events;
}
Also used : EventJournalInitialSubscriberState(com.hazelcast.internal.journal.EventJournalInitialSubscriberState) PARTITION_COUNT(com.hazelcast.spi.properties.ClusterProperty.PARTITION_COUNT) PARTITION_OPERATION_THREAD_COUNT(com.hazelcast.spi.properties.ClusterProperty.PARTITION_OPERATION_THREAD_COUNT) GENERIC_OPERATION_THREAD_COUNT(com.hazelcast.spi.properties.ClusterProperty.GENERIC_OPERATION_THREAD_COUNT) EVENT_THREAD_COUNT(com.hazelcast.spi.properties.ClusterProperty.EVENT_THREAD_COUNT) LinkedList(java.util.LinkedList)

Example 5 with EventJournalInitialSubscriberState

use of com.hazelcast.internal.journal.EventJournalInitialSubscriberState in project hazelcast by hazelcast.

the class AbstractEventJournalBasicTest method skipEventsWhenFallenBehind.

@Test
public void skipEventsWhenFallenBehind() throws Exception {
    final EventJournalTestContext<String, Integer, EJ_TYPE> context = createContext();
    final int count = 1000;
    assertEventJournalSize(context.dataAdapter, 0);
    for (int i = 0; i < count; i++) {
        context.dataAdapter.put(randomPartitionKey(), i);
    }
    final EventJournalInitialSubscriberState state = subscribeToEventJournal(context.dataAdapter, partitionId);
    assertEquals(500, state.getOldestSequence());
    assertEquals(999, state.getNewestSequence());
    assertEventJournalSize(context.dataAdapter, 500);
    final int startSequence = 0;
    final ReadResultSet<EJ_TYPE> resultSet = readFromEventJournal(context.dataAdapter, startSequence, 1, partitionId, TRUE_PREDICATE, IDENTITY_FUNCTION).toCompletableFuture().get();
    assertEquals(1, resultSet.size());
    assertEquals(1, resultSet.readCount());
    assertNotEquals(startSequence + resultSet.readCount(), resultSet.getNextSequenceToReadFrom());
    assertEquals(501, resultSet.getNextSequenceToReadFrom());
    final long lostCount = resultSet.getNextSequenceToReadFrom() - resultSet.readCount() - startSequence;
    assertEquals(500, lostCount);
}
Also used : EventJournalInitialSubscriberState(com.hazelcast.internal.journal.EventJournalInitialSubscriberState) Test(org.junit.Test)

Aggregations

EventJournalInitialSubscriberState (com.hazelcast.internal.journal.EventJournalInitialSubscriberState)8 Test (org.junit.Test)3 CacheService (com.hazelcast.cache.impl.CacheService)1 ICacheService (com.hazelcast.cache.impl.ICacheService)1 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 ResponseParameters (com.hazelcast.client.impl.protocol.codec.MapEventJournalSubscribeCodec.ResponseParameters)1 ClientInvocation (com.hazelcast.client.impl.spi.impl.ClientInvocation)1 ClientInvocationFuture (com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)1 Config (com.hazelcast.config.Config)1 EventJournalConfig (com.hazelcast.config.EventJournalConfig)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 Node (com.hazelcast.instance.impl.Node)1 ObjectNamespace (com.hazelcast.internal.services.ObjectNamespace)1 ExceptionUtil.rethrow (com.hazelcast.internal.util.ExceptionUtil.rethrow)1 MapUtil.createHashMap (com.hazelcast.internal.util.MapUtil.createHashMap)1 SetUtil (com.hazelcast.internal.util.SetUtil)1 EventType (com.hazelcast.journal.EventJournalEventAdapter.EventType)1