/** * Destroys any {@link #ensureHazelcastInstance() implicitly created} backing {@code HazelcastInstance}. If the * backing Hazelcast was not implicitly created (i.e. because it was configured externally and supplied via * {@link #setHazelcastInstance(com.hazelcast.core.HazelcastInstance) setHazelcastInstance}), this method does * nothing. * * @throws Exception if there is a problem shutting down */ public void destroy() throws Exception { if (this.implicitlyCreated) { try { this.hazelcastInstance.getLifecycleService().shutdown(); } catch (Throwable t) { if (log.isWarnEnabled()) { log.warn("Unable to cleanly shutdown implicitly created HazelcastInstance. " + "Ignoring (shutting down)...", t); } } finally { this.hazelcastInstance = null; this.implicitlyCreated = false; } } }
HazelcastInstance instance = Hazelcast.newHazelcastInstance(config); instance.getLifecycleService().shutdown();
public void destroy() { if (hazelcastInstance != null) { hazelcastInstance.getLifecycleService().shutdown(); } }
private String registerLifecycleListener() { return hazelcastInstance.getLifecycleService().addLifecycleListener(new LifecycleListener() { @Override public void stateChanged(LifecycleEvent event) { if (event.getState() == LifecycleEvent.LifecycleState.SHUTTING_DOWN) { onShuttingDown(); } } }); }
void stop() { try { running = false; es.shutdown(); es.awaitTermination(10, TimeUnit.SECONDS); esStats.shutdown(); hazelcast.getLifecycleService().shutdown(); } catch (Throwable t) { t.printStackTrace(); } }
public void destroy() { if (hazelcastInstance != null) { hazelcastInstance.getLifecycleService().shutdown(); } }
@Override protected void doStop() throws Exception { //noop if (useLocalHzInstance) { hzInstance.getLifecycleService().shutdown(); } }
public void destroy() { if (instance != null) { instance.getLifecycleService().shutdown(); } }
@Override public void destroy() throws Exception { if (hz != null) { LOGGER.info("HzCluster.destroy() invoked, shutting down Hazelcast instance..."); CLUSTER = null; hz.getLifecycleService().shutdown(); hz = null; LOGGER.info("HzCluster.destroy(): Hazelcast instance shut down complete"); } }
@Override public void stop() { if (instance != null && instance.getLifecycleService().isRunning()) { instance.getLifecycleService().shutdown(); } }
private void deregisterLifecycleListener() { LifecycleService lifecycleService = hazelcastInstance.getLifecycleService(); try { lifecycleService.removeLifecycleListener(lifecycleListenerRegistrationId); } catch (HazelcastInstanceNotActiveException e) { // if hazelcastInstance is already terminated, // `lifecycleService.removeLifecycleListener()` will throw a // HazelcastInstanceNotActiveException, which we can safely ignore // (see TerminatedLifecycleService) ignore(e); } }
private static void fillHazelcastMapWithUsers() { Random random = new Random(); HazelcastInstance client = HazelcastClient.newHazelcastClient(); IMap<String, User> users = client.getMap("users"); for (int i = 0; i < 10; i++) { String name = "user-" + i; User user = new User(name, random.nextInt(80), random.nextInt(10000)); users.put(name, user); } client.getLifecycleService().shutdown(); } }
public static void main(String[] args) { final HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(); final HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(); System.out.println("Instance-1 members: " + instance1.getCluster().getMembers()); System.out.println("Instance-2 members: " + instance2.getCluster().getMembers()); // shutdown cluster instance2.getCluster().shutdown(); System.out.println("Instance-1: Is running?: " + instance1.getLifecycleService().isRunning()); System.out.println("Instance-2: Is running?: " + instance2.getLifecycleService().isRunning()); } }
private Thread shutdownHookThread(NodeEngine nodeEngine) { return new Thread(() -> { String policy = nodeEngine.getProperties().getString(SHUTDOWNHOOK_POLICY); if (policy.equals("TERMINATE")) { jetInstance.getHazelcastInstance().getLifecycleService().terminate(); } else { jetInstance.shutdown(); } }, "jet.ShutdownThread"); } }
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; }
@Override public void shutdown() { ExecutionService executionService = nodeEngine.getExecutionService(); executionService.shutdownExecutor(invalidationExecutorName); HazelcastInstance node = nodeEngine.getHazelcastInstance(); LifecycleService lifecycleService = node.getLifecycleService(); lifecycleService.removeLifecycleListener(nodeShutdownListenerId); invalidationQueues.clear(); super.shutdown(); }
@Override public void shutdown() { ExecutionService executionService = nodeEngine.getExecutionService(); executionService.shutdownExecutor(invalidationExecutorName); HazelcastInstance node = nodeEngine.getHazelcastInstance(); LifecycleService lifecycleService = node.getLifecycleService(); lifecycleService.removeLifecycleListener(nodeShutdownListenerId); invalidationQueues.clear(); super.shutdown(); }
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; }
private void testClientEventByChannelAndGroupName(final PollableChannel channel, final String groupName) { final HazelcastInstance client = getHazelcastClientByGroupName(groupName); Message<?> msg = channel.receive(HazelcastInboundChannelAdapterTestUtils.TIMEOUT); verifyClientEvent(msg); client.getLifecycleService().terminate(); msg = channel.receive(HazelcastInboundChannelAdapterTestUtils.TIMEOUT); verifyClientEvent(msg); }