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;
}
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);
}
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);
}
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();
}
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);
}
Aggregations