private String registerLifecycleListener() { return hazelcastInstance.getLifecycleService().addLifecycleListener(new LifecycleListener() { @Override public void stateChanged(LifecycleEvent event) { if (event.getState() == LifecycleEvent.LifecycleState.SHUTTING_DOWN) { onShuttingDown(); } } }); }
private String registerLifecycleListener() { return hazelcastInstance.getLifecycleService().addLifecycleListener(new LifecycleListener() { @Override public void stateChanged(LifecycleEvent event) { if (event.getState() == LifecycleEvent.LifecycleState.SHUTTING_DOWN) { onShuttingDown(); } } }); }
/** * Sends remaining invalidation events in this invalidator's queues to the recipients. */ private String registerNodeShutdownListener() { HazelcastInstance node = nodeEngine.getHazelcastInstance(); LifecycleService lifecycleService = node.getLifecycleService(); return lifecycleService.addLifecycleListener(new LifecycleListener() { @Override public void stateChanged(LifecycleEvent event) { if (event.getState() == SHUTTING_DOWN) { Set<Map.Entry<String, InvalidationQueue<Invalidation>>> entries = invalidationQueues.entrySet(); for (Map.Entry<String, InvalidationQueue<Invalidation>> entry : entries) { pollAndSendInvalidations(entry.getKey(), entry.getValue()); } } } }); }
/** * Sends remaining invalidation events in this invalidator's queues to the recipients. */ private String registerNodeShutdownListener() { HazelcastInstance node = nodeEngine.getHazelcastInstance(); LifecycleService lifecycleService = node.getLifecycleService(); return lifecycleService.addLifecycleListener(new LifecycleListener() { @Override public void stateChanged(LifecycleEvent event) { if (event.getState() == SHUTTING_DOWN) { Set<Map.Entry<String, InvalidationQueue<Invalidation>>> entries = invalidationQueues.entrySet(); for (Map.Entry<String, InvalidationQueue<Invalidation>> entry : entries) { pollAndSendInvalidations(entry.getKey(), entry.getValue()); } } } }); }
private static HazelcastInstance loadExistingInstance(ClusteredSessionService sessionService, String instanceName) throws ServletException { LOGGER.info("Using existing Hazelcast instance with name [" + instanceName + "] for session replication"); HazelcastInstance instance = Hazelcast.getHazelcastInstanceByName(instanceName); if (instance == null) { throw new ServletException("Hazelcast instance with name [" + instanceName + "] could not be found."); } instance.getLifecycleService().addLifecycleListener(new ClientLifecycleListener(sessionService)); return instance; }
private static HazelcastInstance loadExistingClient(ClusteredSessionService sessionService, String instanceName) throws ServletException { LOGGER.info("Using existing Hazelcast client instance with name [" + instanceName + "] for session replication"); HazelcastInstance client = HazelcastClient.getHazelcastClientByName(instanceName); if (client == null) { throw new ServletException("Hazelcast client instance with name [" + instanceName + "] could not be found."); } client.getLifecycleService().addLifecycleListener(new ClientLifecycleListener(sessionService)); return client; } }
private static HazelcastInstance loadExistingInstance(ClusteredSessionService sessionService, String instanceName) throws ServletException { LOGGER.info("Using existing Hazelcast instance with name [" + instanceName + "] for session replication"); HazelcastInstance instance = Hazelcast.getHazelcastInstanceByName(instanceName); if (instance == null) { throw new ServletException("Hazelcast instance with name [" + instanceName + "] could not be found."); } instance.getLifecycleService().addLifecycleListener(new ClientLifecycleListener(sessionService)); return instance; }
private static HazelcastInstance loadExistingClient(ClusteredSessionService sessionService, String instanceName) throws ServletException { LOGGER.info("Using existing Hazelcast client instance with name [" + instanceName + "] for session replication"); HazelcastInstance client = HazelcastClient.getHazelcastClientByName(instanceName); if (client == null) { throw new ServletException("Hazelcast client instance with name [" + instanceName + "] could not be found."); } client.getLifecycleService().addLifecycleListener(new ClientLifecycleListener(sessionService)); return client; } }
@Override public void init(NodeEngine nodeEngine, Properties properties) { logger.info("init; got properties: {}", properties); this.nodeEngine = nodeEngine; this.schemaName = properties.getProperty(pn_schema_name); this.popClusterSize = Integer.parseInt(properties.getProperty(pn_schema_population_size, "0")); this.useCatalog = Boolean.parseBoolean(properties.getProperty(pn_schema_population_use_catalog, "true")); if (useCatalog) { String dataPath = properties.getProperty(pn_schema_store_data_path); String nodeNum = properties.getProperty(pn_node_instance); int buffSize = 2048*100; String bSize = properties.getProperty(pn_schema_population_buffer_size); if (bSize != null) { buffSize = Integer.parseInt(bSize); } logger.info("init; will open doc store from path: {}; instance: {}; buffer size: {} docs", dataPath, nodeNum, buffSize); catalog = new DocumentMemoryStore(dataPath, nodeNum, buffSize); } nodeEngine.getPartitionService().addMigrationListener(this); nodeEngine.getHazelcastInstance().getCluster().addMembershipListener(this); nodeEngine.getHazelcastInstance().getLifecycleService().addLifecycleListener(this); nodeEngine.getHazelcastInstance().getUserContext().put(ctx_popService, this); }
@Override protected void doStart() { final HazelcastClusterMonitorListener clusterMonitorListener = new HazelcastClusterMonitorListener(); if (this.monitorTypes.contains(ClusterMonitorType.MEMBERSHIP.name())) { final String registrationId = this.hazelcastInstance.getCluster() .addMembershipListener(clusterMonitorListener); this.hazelcastRegisteredListenerIdMap.put(ClusterMonitorType.MEMBERSHIP, registrationId); } if (this.monitorTypes.contains(ClusterMonitorType.DISTRIBUTED_OBJECT.name())) { final String registrationId = this.hazelcastInstance .addDistributedObjectListener(clusterMonitorListener); this.hazelcastRegisteredListenerIdMap.put(ClusterMonitorType.DISTRIBUTED_OBJECT, registrationId); } if (this.monitorTypes.contains(ClusterMonitorType.MIGRATION.name())) { final String registrationId = this.hazelcastInstance.getPartitionService() .addMigrationListener(clusterMonitorListener); this.hazelcastRegisteredListenerIdMap.put(ClusterMonitorType.MIGRATION, registrationId); } if (this.monitorTypes.contains(ClusterMonitorType.LIFECYCLE.name())) { final String registrationId = this.hazelcastInstance.getLifecycleService() .addLifecycleListener(clusterMonitorListener); this.hazelcastRegisteredListenerIdMap.put(ClusterMonitorType.LIFECYCLE, registrationId); } if (this.monitorTypes.contains(ClusterMonitorType.CLIENT.name())) { final String registrationId = this.hazelcastInstance.getClientService() .addClientListener(clusterMonitorListener); this.hazelcastRegisteredListenerIdMap.put(ClusterMonitorType.CLIENT, registrationId); } }
public DistributedRegistry(String registryName, Object nodeInfo, HazelcastInstance hzInstance, int minutesToCheckRegister, int oldestMembersLeading) { this.registryName = registryName; this.nodeInfo = nodeInfo; this.hzInstance = hzInstance; hzInstance.getCluster().addMembershipListener(new MyListener()); hzInstance.getLifecycleService().addLifecycleListener(new RestartListener()); this.minutesToCheckRegister = minutesToCheckRegister; this.oldestMembersLeading = oldestMembersLeading; }
@SuppressWarnings("checkstyle:magicnumber") @SuppressFBWarnings({"EI_EXPOSE_REP2"}) public ExpirationManager(ClearExpiredRecordsTask task, NodeEngine nodeEngine) { this.task = task; this.nodeEngine = nodeEngine; this.globalTaskScheduler = nodeEngine.getExecutionService().getGlobalTaskScheduler(); this.taskPeriodSeconds = checkPositive(task.getTaskPeriodSeconds(), "taskPeriodSeconds should be a positive number"); this.lifecycleService = getHazelcastInstance().getLifecycleService(); this.lifecycleListenerId = lifecycleService.addLifecycleListener(this); this.partitionService = getHazelcastInstance().getPartitionService(); this.partitionLostListenerId = partitionService.addPartitionLostListener(this); }
@SuppressWarnings("checkstyle:magicnumber") @SuppressFBWarnings({"EI_EXPOSE_REP2"}) public ExpirationManager(ClearExpiredRecordsTask task, NodeEngine nodeEngine) { this.task = task; this.nodeEngine = nodeEngine; this.globalTaskScheduler = nodeEngine.getExecutionService().getGlobalTaskScheduler(); this.taskPeriodSeconds = checkPositive(task.getTaskPeriodSeconds(), "taskPeriodSeconds should be a positive number"); this.lifecycleService = getHazelcastInstance().getLifecycleService(); this.lifecycleListenerId = lifecycleService.addLifecycleListener(this); this.partitionService = getHazelcastInstance().getPartitionService(); this.partitionLostListenerId = partitionService.addPartitionLostListener(this); }
private void initializeCluster(Config config) { if (clusterInitialized.compareAndSet(false, true)) { clusterInstance = Hazelcast.newHazelcastInstance(config); if (clusterInstance == null) { throw new RuntimeException("Unable to initialize the cluster"); } Cluster cluster = clusterInstance.getCluster(); cluster.addMembershipListener(this.membershipListener); clusterInstance.getLifecycleService().addLifecycleListener(new LifecycleListener() { @Override public void stateChanged(LifecycleEvent event) { if (event.getState() == SHUTTING_DOWN) { removeMember(localNodeId); } } }); // Register a listener for Hazelcast logging events LoggingService loggingService = clusterInstance.getLoggingService(); loggingService.addLogListener(Level.FINEST, this); this.collectionsFactory = new ClusterCollectionsFactory(clusterInstance); localNodeId = getMemberId(cluster.getLocalMember()); IMap<MemberId, String> instanceKeyMap = collectionsFactory.getMap(INSTANCE_KEY_MAP); instanceKeyMap.put(localNodeId, localInstanceKey); IMap<String, Collection<String>> balancerMap = collectionsFactory.getMap(BALANCER_MAP_NAME); addBalancerMapEntryListeners(balancerMap); } }
protected static CountDownLatch simulateSplitBrain(HazelcastInstance h1, HazelcastInstance h2) { SampleMemberShipListener memberShipListener = new SampleMemberShipListener(1); h2.getCluster().addMembershipListener(memberShipListener); SampleLifeCycleListener lifeCycleListener = new SampleLifeCycleListener(1); h2.getLifecycleService().addLifecycleListener(lifeCycleListener); closeConnectionBetween(h1, h2); assertOpenEventually(memberShipListener.latch); assertClusterSizeEventually(1, h1); assertClusterSizeEventually(1, h2); return lifeCycleListener.latch; }
protected void start() { BackoffTimer hazeltaskTimer = new BackoffTimer(hazeltaskConfig.getTopologyName(), hazeltaskConfig.getThreadFactory().named("timertasks")); setupDistributedExecutor(hazeltaskConfig.getHazelcast(), topology, hazeltaskTimer, executorConfig, executor, topologyService, executorTopologyService, localExeutorService, executorMetrics); //if autoStart... we need to start if(executorConfig.isAutoStart()) { final LifecycleService lifecycleService = hazeltaskConfig.getHazelcast().getLifecycleService(); LifecycleListener autoStartListener = new LifecycleListener() { public void stateChanged(LifecycleEvent event) { if(event.getState() == LifecycleState.STARTED) { log.info(topology.getName()+" Hazeltask instance is starting up due to Hazelcast startup"); executor.startup(); } else if (event.getState() == LifecycleState.SHUTTING_DOWN) { log.info(topology.getName()+" Hazeltask instance is shutting down due to Hazelcast shutdown"); executor.shutdown(); } } }; lifecycleService.addLifecycleListener(autoStartListener); if(lifecycleService.isRunning()) { log.info(topology.getName()+" Hazeltask instance is starting up"); executor.startup(); } } }
hazelcastInstance.getLifecycleService().addLifecycleListener(this);
@Override public void onStart() { logger.info("Plugin:active: logPartitions:" + logPartitions); connectionObservable.addConnectionListener(new ConnectionListenerImpl()); hazelcastInstance.getCluster().addMembershipListener(new MembershipListenerImpl()); if (logPartitions) { hazelcastInstance.getPartitionService().addMigrationListener(new MigrationListenerImpl()); } hazelcastInstance.getLifecycleService().addLifecycleListener(new LifecycleListenerImpl()); if (nodeExtension != null) { nodeExtension.registerListener(new ClusterVersionListenerImpl()); } }
@Override public void onStart() { logger.info("Plugin:active: logPartitions:" + logPartitions); connectionObservable.addConnectionListener(new ConnectionListenerImpl()); hazelcastInstance.getCluster().addMembershipListener(new MembershipListenerImpl()); if (logPartitions) { hazelcastInstance.getPartitionService().addMigrationListener(new MigrationListenerImpl()); } hazelcastInstance.getLifecycleService().addLifecycleListener(new LifecycleListenerImpl()); if (nodeExtension != null) { nodeExtension.registerListener(new ClusterVersionListenerImpl()); } }