Search in sources :

Example 1 with CachePartitionLostEventFilter

use of com.hazelcast.cache.impl.event.CachePartitionLostEventFilter in project hazelcast by hazelcast.

the class CacheAddPartitionLostListenerMessageTask method call.

@Override
protected Object call() {
    final ClientEndpoint endpoint = getEndpoint();
    CachePartitionLostListener listener = new CachePartitionLostListener() {

        @Override
        public void partitionLost(CachePartitionLostEvent event) {
            if (endpoint.isAlive()) {
                ClientMessage eventMessage = CacheAddPartitionLostListenerCodec.encodeCachePartitionLostEvent(event.getPartitionId(), event.getMember().getUuid());
                sendClientMessage(null, eventMessage);
            }
        }
    };
    InternalCachePartitionLostListenerAdapter listenerAdapter = new InternalCachePartitionLostListenerAdapter(listener);
    EventFilter filter = new CachePartitionLostEventFilter();
    CacheService service = getService(CacheService.SERVICE_NAME);
    EventService eventService = service.getNodeEngine().getEventService();
    EventRegistration registration;
    if (parameters.localOnly) {
        registration = eventService.registerLocalListener(ICacheService.SERVICE_NAME, parameters.name, filter, listenerAdapter);
    } else {
        registration = eventService.registerListener(ICacheService.SERVICE_NAME, parameters.name, filter, listenerAdapter);
    }
    String registrationId = registration.getId();
    endpoint.addListenerDestroyAction(CacheService.SERVICE_NAME, parameters.name, registrationId);
    return registrationId;
}
Also used : CachePartitionLostListener(com.hazelcast.cache.impl.event.CachePartitionLostListener) EventRegistration(com.hazelcast.spi.EventRegistration) CachePartitionLostEvent(com.hazelcast.cache.impl.event.CachePartitionLostEvent) EventService(com.hazelcast.spi.EventService) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientEndpoint(com.hazelcast.client.ClientEndpoint) CachePartitionLostEventFilter(com.hazelcast.cache.impl.event.CachePartitionLostEventFilter) CachePartitionLostEventFilter(com.hazelcast.cache.impl.event.CachePartitionLostEventFilter) EventFilter(com.hazelcast.spi.EventFilter) InternalCachePartitionLostListenerAdapter(com.hazelcast.cache.impl.event.InternalCachePartitionLostListenerAdapter) CacheService(com.hazelcast.cache.impl.CacheService) ICacheService(com.hazelcast.cache.impl.ICacheService)

Example 2 with CachePartitionLostEventFilter

use of com.hazelcast.cache.impl.event.CachePartitionLostEventFilter in project hazelcast by hazelcast.

the class CacheDataSerializerHook method createFactory.

public DataSerializableFactory createFactory() {
    ConstructorFunction<Integer, IdentifiedDataSerializable>[] constructors = new ConstructorFunction[LEN];
    constructors[GET] = arg -> new CacheGetOperation();
    constructors[CONTAINS_KEY] = arg -> new CacheContainsKeyOperation();
    constructors[PUT] = arg -> new CachePutOperation();
    constructors[PUT_IF_ABSENT] = arg -> new CachePutIfAbsentOperation();
    constructors[REMOVE] = arg -> new CacheRemoveOperation();
    constructors[GET_AND_REMOVE] = arg -> new CacheGetAndRemoveOperation();
    constructors[REPLACE] = arg -> new CacheReplaceOperation();
    constructors[GET_AND_REPLACE] = arg -> new CacheGetAndReplaceOperation();
    constructors[PUT_BACKUP] = arg -> new CachePutBackupOperation();
    constructors[PUT_ALL_BACKUP] = arg -> new CachePutAllBackupOperation();
    constructors[REMOVE_BACKUP] = arg -> new CacheRemoveBackupOperation();
    constructors[SIZE] = arg -> new CacheSizeOperation();
    constructors[SIZE_FACTORY] = arg -> new CacheSizeOperationFactory();
    constructors[CLEAR_FACTORY] = arg -> new CacheClearOperationFactory();
    constructors[GET_ALL] = arg -> new CacheGetAllOperation();
    constructors[GET_ALL_FACTORY] = arg -> new CacheGetAllOperationFactory();
    constructors[LOAD_ALL] = arg -> new CacheLoadAllOperation();
    constructors[LOAD_ALL_FACTORY] = arg -> new CacheLoadAllOperationFactory();
    constructors[EXPIRY_POLICY] = arg -> new HazelcastExpiryPolicy();
    constructors[KEY_ITERATOR] = arg -> new CacheFetchKeysOperation();
    constructors[KEY_ITERATION_RESULT] = arg -> new CacheKeysWithCursor();
    constructors[ENTRY_PROCESSOR] = arg -> new CacheEntryProcessorOperation();
    constructors[CLEAR_RESPONSE] = arg -> new CacheClearResponse();
    constructors[GET_CONFIG] = arg -> new CacheGetConfigOperation();
    constructors[MANAGEMENT_CONFIG] = arg -> new CacheManagementConfigOperation();
    constructors[LISTENER_REGISTRATION] = arg -> new CacheListenerRegistrationOperation();
    constructors[DESTROY_CACHE] = arg -> new CacheDestroyOperation();
    constructors[CACHE_EVENT_DATA] = arg -> new CacheEventDataImpl();
    constructors[CACHE_EVENT_DATA_SET] = arg -> new CacheEventSet();
    constructors[BACKUP_ENTRY_PROCESSOR] = arg -> new CacheBackupEntryProcessorOperation();
    constructors[CLEAR] = arg -> new CacheClearOperation();
    constructors[CLEAR_BACKUP] = arg -> new CacheClearBackupOperation();
    constructors[REMOVE_ALL] = arg -> new CacheRemoveAllOperation();
    constructors[REMOVE_ALL_BACKUP] = arg -> new CacheRemoveAllBackupOperation();
    constructors[REMOVE_ALL_FACTORY] = arg -> new CacheRemoveAllOperationFactory();
    constructors[PUT_ALL] = arg -> new CachePutAllOperation();
    constructors[ENTRY_ITERATOR] = arg -> new CacheFetchEntriesOperation();
    constructors[ENTRY_ITERATION_RESULT] = arg -> new CacheEntriesWithCursor();
    constructors[CACHE_PARTITION_LOST_EVENT_FILTER] = arg -> new CachePartitionLostEventFilter();
    constructors[DEFAULT_CACHE_ENTRY_VIEW] = arg -> new DefaultCacheEntryView();
    constructors[CACHE_REPLICATION] = arg -> new CacheReplicationOperation();
    constructors[CACHE_POST_JOIN] = arg -> new OnJoinCacheOperation();
    constructors[CACHE_DATA_RECORD] = arg -> new CacheDataRecord();
    constructors[CACHE_OBJECT_RECORD] = arg -> new CacheObjectRecord();
    constructors[CACHE_PARTITION_EVENT_DATA] = arg -> new CachePartitionEventData();
    constructors[CACHE_INVALIDATION_METADATA] = arg -> new CacheGetInvalidationMetaDataOperation();
    constructors[CACHE_INVALIDATION_METADATA_RESPONSE] = arg -> new CacheGetInvalidationMetaDataOperation.MetaDataResponse();
    constructors[CACHE_ASSIGN_AND_GET_UUIDS] = arg -> new CacheAssignAndGetUuidsOperation();
    constructors[CACHE_ASSIGN_AND_GET_UUIDS_FACTORY] = arg -> new CacheAssignAndGetUuidsOperationFactory();
    constructors[CACHE_NEAR_CACHE_STATE_HOLDER] = arg -> new CacheNearCacheStateHolder();
    constructors[CACHE_EVENT_LISTENER_ADAPTOR] = arg -> new CacheEventListenerAdaptor();
    constructors[EVENT_JOURNAL_SUBSCRIBE_OPERATION] = arg -> new CacheEventJournalSubscribeOperation();
    constructors[EVENT_JOURNAL_READ_OPERATION] = arg -> new CacheEventJournalReadOperation<>();
    constructors[EVENT_JOURNAL_DESERIALIZING_CACHE_EVENT] = arg -> new DeserializingEventJournalCacheEvent<>();
    constructors[EVENT_JOURNAL_INTERNAL_CACHE_EVENT] = arg -> new InternalEventJournalCacheEvent();
    constructors[EVENT_JOURNAL_READ_RESULT_SET] = arg -> new CacheEventJournalReadResultSetImpl<>();
    constructors[PRE_JOIN_CACHE_CONFIG] = arg -> new PreJoinCacheConfig();
    constructors[CACHE_BROWSER_ENTRY_VIEW] = arg -> new GetCacheEntryViewEntryProcessor.CacheBrowserEntryView();
    constructors[GET_CACHE_ENTRY_VIEW_PROCESSOR] = arg -> new GetCacheEntryViewEntryProcessor();
    constructors[MERGE_FACTORY] = arg -> new CacheMergeOperationFactory();
    constructors[MERGE] = arg -> new CacheMergeOperation();
    constructors[ADD_CACHE_CONFIG_OPERATION] = arg -> new AddCacheConfigOperation();
    constructors[SET_EXPIRY_POLICY] = arg -> new CacheSetExpiryPolicyOperation();
    constructors[SET_EXPIRY_POLICY_BACKUP] = arg -> new CacheSetExpiryPolicyBackupOperation();
    constructors[EXPIRE_BATCH_BACKUP] = arg -> new CacheExpireBatchBackupOperation();
    constructors[CACHE_CONFIG] = arg -> new CacheConfig<>();
    return new ArrayDataSerializableFactory(constructors);
}
Also used : CacheGetOperation(com.hazelcast.cache.impl.operation.CacheGetOperation) CacheLoadAllOperation(com.hazelcast.cache.impl.operation.CacheLoadAllOperation) CacheRemoveAllOperationFactory(com.hazelcast.cache.impl.operation.CacheRemoveAllOperationFactory) HazelcastExpiryPolicy(com.hazelcast.cache.HazelcastExpiryPolicy) CacheAssignAndGetUuidsOperationFactory(com.hazelcast.client.impl.protocol.task.cache.CacheAssignAndGetUuidsOperationFactory) AddCacheConfigOperation(com.hazelcast.cache.impl.operation.AddCacheConfigOperation) GetCacheEntryViewEntryProcessor(com.hazelcast.internal.management.operation.GetCacheEntryViewEntryProcessor) CacheGetAndRemoveOperation(com.hazelcast.cache.impl.operation.CacheGetAndRemoveOperation) CacheGetAllOperationFactory(com.hazelcast.cache.impl.operation.CacheGetAllOperationFactory) CacheEntryProcessorOperation(com.hazelcast.cache.impl.operation.CacheEntryProcessorOperation) CacheRemoveAllOperation(com.hazelcast.cache.impl.operation.CacheRemoveAllOperation) CacheAssignAndGetUuidsOperation(com.hazelcast.client.impl.protocol.task.cache.CacheAssignAndGetUuidsOperation) CacheMergeOperationFactory(com.hazelcast.cache.impl.operation.CacheMergeOperationFactory) CachePutOperation(com.hazelcast.cache.impl.operation.CachePutOperation) CacheReplicationOperation(com.hazelcast.cache.impl.operation.CacheReplicationOperation) CacheEventJournalSubscribeOperation(com.hazelcast.cache.impl.journal.CacheEventJournalSubscribeOperation) CacheClearOperation(com.hazelcast.cache.impl.operation.CacheClearOperation) CachePutAllBackupOperation(com.hazelcast.cache.impl.operation.CachePutAllBackupOperation) CacheSetExpiryPolicyBackupOperation(com.hazelcast.cache.impl.operation.CacheSetExpiryPolicyBackupOperation) CacheSizeOperationFactory(com.hazelcast.cache.impl.operation.CacheSizeOperationFactory) InternalEventJournalCacheEvent(com.hazelcast.cache.impl.journal.InternalEventJournalCacheEvent) CacheGetAndReplaceOperation(com.hazelcast.cache.impl.operation.CacheGetAndReplaceOperation) DefaultCacheEntryView(com.hazelcast.cache.impl.merge.entry.DefaultCacheEntryView) CacheExpireBatchBackupOperation(com.hazelcast.cache.impl.operation.CacheExpireBatchBackupOperation) CacheRemoveBackupOperation(com.hazelcast.cache.impl.operation.CacheRemoveBackupOperation) CacheGetAllOperation(com.hazelcast.cache.impl.operation.CacheGetAllOperation) OnJoinCacheOperation(com.hazelcast.cache.impl.operation.OnJoinCacheOperation) CacheObjectRecord(com.hazelcast.cache.impl.record.CacheObjectRecord) CacheDestroyOperation(com.hazelcast.cache.impl.operation.CacheDestroyOperation) CacheNearCacheStateHolder(com.hazelcast.cache.impl.operation.CacheNearCacheStateHolder) CacheLoadAllOperationFactory(com.hazelcast.cache.impl.operation.CacheLoadAllOperationFactory) CacheSizeOperation(com.hazelcast.cache.impl.operation.CacheSizeOperation) CacheClearBackupOperation(com.hazelcast.cache.impl.operation.CacheClearBackupOperation) CachePutIfAbsentOperation(com.hazelcast.cache.impl.operation.CachePutIfAbsentOperation) CacheFetchEntriesOperation(com.hazelcast.cache.impl.operation.CacheFetchEntriesOperation) CacheGetInvalidationMetaDataOperation(com.hazelcast.cache.impl.operation.CacheGetInvalidationMetaDataOperation) CacheRemoveAllBackupOperation(com.hazelcast.cache.impl.operation.CacheRemoveAllBackupOperation) CacheListenerRegistrationOperation(com.hazelcast.cache.impl.operation.CacheListenerRegistrationOperation) CacheContainsKeyOperation(com.hazelcast.cache.impl.operation.CacheContainsKeyOperation) CachePutBackupOperation(com.hazelcast.cache.impl.operation.CachePutBackupOperation) CacheRemoveOperation(com.hazelcast.cache.impl.operation.CacheRemoveOperation) CacheFetchKeysOperation(com.hazelcast.cache.impl.operation.CacheFetchKeysOperation) CacheClearOperationFactory(com.hazelcast.cache.impl.operation.CacheClearOperationFactory) ConstructorFunction(com.hazelcast.internal.util.ConstructorFunction) CacheBackupEntryProcessorOperation(com.hazelcast.cache.impl.operation.CacheBackupEntryProcessorOperation) CacheReplaceOperation(com.hazelcast.cache.impl.operation.CacheReplaceOperation) CacheManagementConfigOperation(com.hazelcast.cache.impl.operation.CacheManagementConfigOperation) CacheSetExpiryPolicyOperation(com.hazelcast.cache.impl.operation.CacheSetExpiryPolicyOperation) CacheDataRecord(com.hazelcast.cache.impl.record.CacheDataRecord) CacheGetConfigOperation(com.hazelcast.cache.impl.operation.CacheGetConfigOperation) CachePutAllOperation(com.hazelcast.cache.impl.operation.CachePutAllOperation) CachePartitionLostEventFilter(com.hazelcast.cache.impl.event.CachePartitionLostEventFilter) ArrayDataSerializableFactory(com.hazelcast.internal.serialization.impl.ArrayDataSerializableFactory) CacheMergeOperation(com.hazelcast.cache.impl.operation.CacheMergeOperation)

Example 3 with CachePartitionLostEventFilter

use of com.hazelcast.cache.impl.event.CachePartitionLostEventFilter in project hazelcast by hazelcast.

the class AbstractCacheService method publishCachePartitionLostEvent.

protected void publishCachePartitionLostEvent(String cacheName, int partitionId) {
    Collection<EventRegistration> registrations = new LinkedList<>();
    for (EventRegistration registration : getRegistrations(cacheName)) {
        if (registration.getFilter() instanceof CachePartitionLostEventFilter) {
            registrations.add(registration);
        }
    }
    if (registrations.isEmpty()) {
        return;
    }
    Member member = nodeEngine.getLocalMember();
    CacheEventData eventData = new CachePartitionEventData(cacheName, partitionId, member);
    EventService eventService = nodeEngine.getEventService();
    eventService.publishEvent(SERVICE_NAME, registrations, eventData, partitionId);
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventService(com.hazelcast.spi.impl.eventservice.EventService) CachePartitionLostEventFilter(com.hazelcast.cache.impl.event.CachePartitionLostEventFilter) Member(com.hazelcast.cluster.Member) LinkedList(java.util.LinkedList)

Example 4 with CachePartitionLostEventFilter

use of com.hazelcast.cache.impl.event.CachePartitionLostEventFilter in project hazelcast by hazelcast.

the class CacheProxy method addPartitionLostListener.

@Override
public UUID addPartitionLostListener(CachePartitionLostListener listener) {
    checkNotNull(listener, "CachePartitionLostListener can't be null");
    EventFilter filter = new CachePartitionLostEventFilter();
    listener = injectDependencies(listener);
    InternalCachePartitionLostListenerAdapter listenerAdapter = new InternalCachePartitionLostListenerAdapter(listener);
    EventRegistration registration = getService().getNodeEngine().getEventService().registerListener(AbstractCacheService.SERVICE_NAME, name, filter, listenerAdapter);
    return registration.getId();
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) CachePartitionLostEventFilter(com.hazelcast.cache.impl.event.CachePartitionLostEventFilter) CachePartitionLostEventFilter(com.hazelcast.cache.impl.event.CachePartitionLostEventFilter) EventFilter(com.hazelcast.spi.impl.eventservice.EventFilter) InternalCachePartitionLostListenerAdapter(com.hazelcast.cache.impl.event.InternalCachePartitionLostListenerAdapter)

Example 5 with CachePartitionLostEventFilter

use of com.hazelcast.cache.impl.event.CachePartitionLostEventFilter in project hazelcast by hazelcast.

the class CacheAddPartitionLostListenerMessageTask method processInternal.

@Override
protected CompletableFuture<UUID> processInternal() {
    CachePartitionLostListener listener = event -> {
        if (endpoint.isAlive()) {
            ClientMessage eventMessage = CacheAddPartitionLostListenerCodec.encodeCachePartitionLostEvent(event.getPartitionId(), event.getMember().getUuid());
            sendClientMessage(null, eventMessage);
        }
    };
    InternalCachePartitionLostListenerAdapter listenerAdapter = new InternalCachePartitionLostListenerAdapter(listener);
    EventFilter filter = new CachePartitionLostEventFilter();
    CacheService service = getService(CacheService.SERVICE_NAME);
    EventService eventService = service.getNodeEngine().getEventService();
    if (parameters.localOnly) {
        return newCompletedFuture(eventService.registerLocalListener(ICacheService.SERVICE_NAME, parameters.name, filter, listenerAdapter).getId());
    }
    return eventService.registerListenerAsync(ICacheService.SERVICE_NAME, parameters.name, filter, listenerAdapter).thenApplyAsync(EventRegistration::getId, CALLER_RUNS);
}
Also used : CALLER_RUNS(com.hazelcast.internal.util.ConcurrencyUtil.CALLER_RUNS) InternalCompletableFuture.newCompletedFuture(com.hazelcast.spi.impl.InternalCompletableFuture.newCompletedFuture) Connection(com.hazelcast.internal.nio.Connection) CachePartitionLostEventFilter(com.hazelcast.cache.impl.event.CachePartitionLostEventFilter) EventService(com.hazelcast.spi.impl.eventservice.EventService) InternalCachePartitionLostListenerAdapter(com.hazelcast.cache.impl.event.InternalCachePartitionLostListenerAdapter) CompletableFuture(java.util.concurrent.CompletableFuture) EventFilter(com.hazelcast.spi.impl.eventservice.EventFilter) EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) UUID(java.util.UUID) Node(com.hazelcast.instance.impl.Node) AbstractAddListenerMessageTask(com.hazelcast.client.impl.protocol.task.AbstractAddListenerMessageTask) CachePartitionLostListener(com.hazelcast.cache.impl.event.CachePartitionLostListener) CacheService(com.hazelcast.cache.impl.CacheService) ICacheService(com.hazelcast.cache.impl.ICacheService) Permission(java.security.Permission) CacheAddPartitionLostListenerCodec(com.hazelcast.client.impl.protocol.codec.CacheAddPartitionLostListenerCodec) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) CachePartitionLostListener(com.hazelcast.cache.impl.event.CachePartitionLostListener) EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventService(com.hazelcast.spi.impl.eventservice.EventService) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) CachePartitionLostEventFilter(com.hazelcast.cache.impl.event.CachePartitionLostEventFilter) CachePartitionLostEventFilter(com.hazelcast.cache.impl.event.CachePartitionLostEventFilter) EventFilter(com.hazelcast.spi.impl.eventservice.EventFilter) InternalCachePartitionLostListenerAdapter(com.hazelcast.cache.impl.event.InternalCachePartitionLostListenerAdapter) CacheService(com.hazelcast.cache.impl.CacheService) ICacheService(com.hazelcast.cache.impl.ICacheService)

Aggregations

CachePartitionLostEventFilter (com.hazelcast.cache.impl.event.CachePartitionLostEventFilter)6 InternalCachePartitionLostListenerAdapter (com.hazelcast.cache.impl.event.InternalCachePartitionLostListenerAdapter)3 CacheService (com.hazelcast.cache.impl.CacheService)2 ICacheService (com.hazelcast.cache.impl.ICacheService)2 CachePartitionLostListener (com.hazelcast.cache.impl.event.CachePartitionLostListener)2 EventFilter (com.hazelcast.spi.impl.eventservice.EventFilter)2 EventRegistration (com.hazelcast.spi.impl.eventservice.EventRegistration)2 HazelcastExpiryPolicy (com.hazelcast.cache.HazelcastExpiryPolicy)1 CachePartitionLostEvent (com.hazelcast.cache.impl.event.CachePartitionLostEvent)1 CacheEventJournalSubscribeOperation (com.hazelcast.cache.impl.journal.CacheEventJournalSubscribeOperation)1 InternalEventJournalCacheEvent (com.hazelcast.cache.impl.journal.InternalEventJournalCacheEvent)1 DefaultCacheEntryView (com.hazelcast.cache.impl.merge.entry.DefaultCacheEntryView)1 AddCacheConfigOperation (com.hazelcast.cache.impl.operation.AddCacheConfigOperation)1 CacheBackupEntryProcessorOperation (com.hazelcast.cache.impl.operation.CacheBackupEntryProcessorOperation)1 CacheClearBackupOperation (com.hazelcast.cache.impl.operation.CacheClearBackupOperation)1 CacheClearOperation (com.hazelcast.cache.impl.operation.CacheClearOperation)1 CacheClearOperationFactory (com.hazelcast.cache.impl.operation.CacheClearOperationFactory)1 CacheContainsKeyOperation (com.hazelcast.cache.impl.operation.CacheContainsKeyOperation)1 CacheDestroyOperation (com.hazelcast.cache.impl.operation.CacheDestroyOperation)1 CacheEntryProcessorOperation (com.hazelcast.cache.impl.operation.CacheEntryProcessorOperation)1