private void sendMemberAttributeEvent( MemberImpl member, MemberAttributeOperationType operationType, String key, Object value) { final MemberAttributeServiceEvent event = new MemberAttributeServiceEvent(this, member, operationType, key, value); MemberAttributeEvent attributeEvent = new MemberAttributeEvent(this, member, operationType, key, value); Collection<MembershipAwareService> membershipAwareServices = nodeEngine.getServices(MembershipAwareService.class); if (membershipAwareServices != null && !membershipAwareServices.isEmpty()) { for (final MembershipAwareService service : membershipAwareServices) { // service events should not block each other nodeEngine .getExecutionService() .execute( ExecutionService.SYSTEM_EXECUTOR, new Runnable() { public void run() { service.memberAttributeChanged(event); } }); } } EventService eventService = nodeEngine.getEventService(); Collection<EventRegistration> registrations = eventService.getRegistrations(SERVICE_NAME, SERVICE_NAME); for (EventRegistration reg : registrations) { eventService.publishEvent(SERVICE_NAME, reg, attributeEvent, reg.getId().hashCode()); } }
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()); }
private void sendMembershipEventNotifications( MemberImpl member, Set<Member> members, final boolean added) { int eventType = added ? MembershipEvent.MEMBER_ADDED : MembershipEvent.MEMBER_REMOVED; MembershipEvent membershipEvent = new MembershipEvent(this, member, eventType, members); Collection<MembershipAwareService> membershipAwareServices = nodeEngine.getServices(MembershipAwareService.class); if (membershipAwareServices != null && !membershipAwareServices.isEmpty()) { final MembershipServiceEvent event = new MembershipServiceEvent(membershipEvent); for (final MembershipAwareService service : membershipAwareServices) { nodeEngine .getExecutionService() .execute( MEMBERSHIP_EVENT_EXECUTOR_NAME, new Runnable() { public void run() { if (added) { service.memberAdded(event); } else { service.memberRemoved(event); } } }); } } EventService eventService = nodeEngine.getEventService(); Collection<EventRegistration> registrations = eventService.getRegistrations(SERVICE_NAME, SERVICE_NAME); for (EventRegistration reg : registrations) { eventService.publishEvent(SERVICE_NAME, reg, membershipEvent, reg.getId().hashCode()); } }
String addClientListener(ClientListener clientListener) { final EventRegistration registration = nodeEngine .getEventService() .registerLocalListener(SERVICE_NAME, SERVICE_NAME, clientListener); return registration.getId(); }
private void sendClientEvent(ClientEndpoint endpoint) { if (endpoint.isFirstConnection()) { final EventService eventService = nodeEngine.getEventService(); final Collection<EventRegistration> regs = eventService.getRegistrations(SERVICE_NAME, SERVICE_NAME); eventService.publishEvent(SERVICE_NAME, regs, endpoint, endpoint.getUuid().hashCode()); } }
private void initializeListeners(Config config) { for (final ListenerConfig listenerCfg : config.getListenerConfigs()) { Object listener = listenerCfg.getImplementation(); if (listener == null) { try { listener = ClassLoaderUtil.newInstance(configClassLoader, listenerCfg.getClassName()); } catch (Exception e) { logger.severe(e); } } if (listener instanceof HazelcastInstanceAware) { ((HazelcastInstanceAware) listener).setHazelcastInstance(hazelcastInstance); } boolean known = false; if (listener instanceof DistributedObjectListener) { final ProxyServiceImpl proxyService = (ProxyServiceImpl) nodeEngine.getProxyService(); proxyService.addProxyListener((DistributedObjectListener) listener); known = true; } if (listener instanceof MembershipListener) { clusterService.addMembershipListener((MembershipListener) listener); known = true; } if (listener instanceof MigrationListener) { partitionService.addMigrationListener((MigrationListener) listener); known = true; } if (listener instanceof PartitionLostListener) { partitionService.addPartitionLostListener((PartitionLostListener) listener); known = true; } if (listener instanceof LifecycleListener) { hazelcastInstance.lifecycleService.addLifecycleListener((LifecycleListener) listener); known = true; } if (listener instanceof ClientListener) { String serviceName = ClientEngineImpl.SERVICE_NAME; nodeEngine.getEventService().registerLocalListener(serviceName, serviceName, listener); known = true; } if (listener != null && !known) { final String error = "Unknown listener type: " + listener.getClass(); Throwable t = new IllegalArgumentException(error); logger.warning(error, t); } } }
public String addMembershipListener(MembershipListener listener) { checkNotNull(listener, "listener cannot be null"); EventService eventService = nodeEngine.getEventService(); EventRegistration registration; if (listener instanceof InitialMembershipListener) { lock.lock(); try { ((InitialMembershipListener) listener).init(new InitialMembershipEvent(this, getMembers())); registration = eventService.registerLocalListener(SERVICE_NAME, SERVICE_NAME, listener); } finally { lock.unlock(); } } else { registration = eventService.registerLocalListener(SERVICE_NAME, SERVICE_NAME, listener); } return registration.getId(); }
public boolean removeMembershipListener(String registrationId) { checkNotNull(registrationId, "registrationId cannot be null"); EventService eventService = nodeEngine.getEventService(); return eventService.deregisterListener(SERVICE_NAME, SERVICE_NAME, registrationId); }
@Override public EventService getEventService() { return nodeEngine.getEventService(); }
boolean removeClientListener(String registrationId) { return nodeEngine .getEventService() .deregisterListener(SERVICE_NAME, SERVICE_NAME, registrationId); }