use of com.hazelcast.spi.EventRegistration in project hazelcast by hazelcast.
the class ClientServiceProxy method addClientListener.
@Override
public String addClientListener(ClientListener clientListener) {
checkNotNull(clientListener, "clientListener should not be null");
EventService eventService = nodeEngine.getEventService();
EventRegistration registration = eventService.registerLocalListener(ClientEngineImpl.SERVICE_NAME, ClientEngineImpl.SERVICE_NAME, clientListener);
return registration.getId();
}
use of com.hazelcast.spi.EventRegistration in project hazelcast by hazelcast.
the class ClientEngineImpl method sendClientEvent.
private void sendClientEvent(ClientEvent event) {
final EventService eventService = nodeEngine.getEventService();
final Collection<EventRegistration> regs = eventService.getRegistrations(SERVICE_NAME, SERVICE_NAME);
String uuid = event.getUuid();
eventService.publishEvent(SERVICE_NAME, regs, event, uuid.hashCode());
}
use of com.hazelcast.spi.EventRegistration in project hazelcast by hazelcast.
the class AbstractCacheService method publishCachePartitionLostEvent.
protected void publishCachePartitionLostEvent(String cacheName, int partitionId) {
Collection<EventRegistration> registrations = new LinkedList<EventRegistration>();
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.spi.EventRegistration 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.spi.EventRegistration in project hazelcast by hazelcast.
the class ListAddListenerMessageTask method call.
@Override
protected Object call() {
ClientEndpoint endpoint = getEndpoint();
Data partitionKey = serializationService.toData(parameters.name);
ItemListener listener = createItemListener(endpoint, partitionKey);
EventService eventService = clientEngine.getEventService();
CollectionEventFilter filter = new CollectionEventFilter(parameters.includeValue);
EventRegistration registration;
if (parameters.localOnly) {
registration = eventService.registerLocalListener(getServiceName(), parameters.name, filter, listener);
} else {
registration = eventService.registerListener(getServiceName(), parameters.name, filter, listener);
}
String registrationId = registration.getId();
endpoint.addListenerDestroyAction(getServiceName(), parameters.name, registrationId);
return registrationId;
}
Aggregations