private void initializeListeners(Config config) { for (final ListenerConfig listenerCfg : config.getListenerConfigs()) { Object listener = listenerCfg.getImplementation(); if (listener == null) { try { listener = Serializer.newInstance(Serializer.loadClass(listenerCfg.getClassName())); } catch (Exception e) { logger.log(Level.SEVERE, e.getMessage(), e); } } if (listener instanceof InstanceListener) { factory.addInstanceListener((InstanceListener) listener); } else if (listener instanceof MembershipListener) { clusterImpl.addMembershipListener((MembershipListener) listener); } else if (listener instanceof MigrationListener) { concurrentMapManager.partitionServiceImpl.addMigrationListener((MigrationListener) listener); } else if (listener != null) { final String error = "Unknown listener type: " + listener.getClass(); Throwable t = new IllegalArgumentException(error); logger.log(Level.WARNING, error, t); } } }
public void notifyListeners(Packet packet) { String id = (String) toObject(packet.getKey()); int i = (Integer) toObject(packet.getValue()); InstanceEvent.InstanceEventType instanceEventType = (i == 0) ? InstanceEvent.InstanceEventType.CREATED : InstanceEvent.InstanceEventType.DESTROYED; InstanceEvent event = new InstanceEvent(instanceEventType, (Instance) client.getClientProxy(id)); for (final InstanceListener listener : instanceListeners) { switch (instanceEventType) { case CREATED: listener.instanceCreated(event); break; case DESTROYED: listener.instanceDestroyed(event); break; default: break; } } }
private void initializeListeners(Config config) { for (final ListenerConfig listenerCfg : config.getListenerConfigs()) { Object listener = listenerCfg.getImplementation(); if (listener == null) { try { listener = Serializer.newInstance(Serializer.loadClass(listenerCfg.getClassName())); } catch (Exception e) { logger.log(Level.SEVERE, e.getMessage(), e); } } if (listener instanceof InstanceListener) { factory.addInstanceListener((InstanceListener) listener); } else if (listener instanceof MembershipListener) { clusterImpl.addMembershipListener((MembershipListener) listener); } else if (listener instanceof MigrationListener) { concurrentMapManager.partitionServiceImpl.addMigrationListener((MigrationListener) listener); } else if (listener instanceof LifecycleListener) { factory.lifecycleService.addLifecycleListener((LifecycleListener) listener); } else if (listener != null) { final String error = "Unknown listener type: " + listener.getClass(); Throwable t = new IllegalArgumentException(error); logger.log(Level.WARNING, error, t); } } }
public InstanceListenerManager(HazelcastClient client) { this.client = client; final ClientConfig clientConfig = client.getClientConfig(); if (clientConfig != null) { for (Object listener : clientConfig.getListeners()) { if (listener instanceof InstanceListener) { registerListener((InstanceListener) listener); } } } }
public void registerListener(InstanceListener listener) { this.instanceListeners.add(listener); }
public void removeListener(InstanceListener instanceListener) { this.instanceListeners.remove(instanceListener); }