Refine search
/** * 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; } } }
Config config = new Config(); config.setProperty("hazelcast.logging.type", "slf4j"); HazelcastInstance hazelcast = Hazelcast.newHazelcastInstance(config); hazelcast.getLifecycleService().shutdown();
mapConfig.setName(NAME).setQuorumName(NAME); Config config = new Config(); config.addMapConfig(mapConfig); config.addQuorumConfig(quorumConfig); HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config); HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(config); IMap<String, String> map = instance1.getMap(NAME); instance2.getLifecycleService().shutdown(); Hazelcast.shutdownAll();
public static void main(String[] args) { Config config = new Config(); config.getMapConfig("map0").setBackupCount(0); config.getMapConfig("map1").setBackupCount(1); HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config); HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(config); IMap<Object, Object> map0 = instance1.getMap("map0"); map0.put(0, 0); IMap<Object, Object> map1 = instance1.getMap("map1"); map1.addPartitionLostListener(new MapPartitionLostListener() { @Override instance2.getLifecycleService().terminate();
public static void main(String[] args) { HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(null); HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(null); // initialize partitions instance1.getMap("map1").put(0, 0); instance1.getPartitionService().addPartitionLostListener(new PartitionLostListener() { @Override public void partitionLost(PartitionLostEvent event) { System.out.println("Instance2 has lost a partition for data with 0 backup! " + event); } }); instance2.getLifecycleService().terminate(); } }
Config cfg = new Config(); cfg.setProperty(GroupProperty.LOGGING_TYPE.getName(), "log4j"); cfg.setProperty(GroupProperty.SHUTDOWNHOOK_ENABLED.getName(), "false"); cfg.setProperty(GroupProperty.REST_ENABLED.getName(), "false"); hazelcastInstance = Hazelcast.newHazelcastInstance(cfg); self = hazelcastInstance.getCluster().getLocalMember(); hazelcastInstance.getCluster().addMembershipListener(this); hazelcastInstance.getLifecycleService().addLifecycleListener(this);
config.setClassLoader(getClass().getClassLoader()); hazelcastInstance = Hazelcast.newHazelcastInstance(config); hazelcastInstance.getClientService().addClientListener(myClientListener); String uuid = hazelcastInstance.getCluster().getLocalMember().getUuid(); log.info("Server {} is ready", uuid); countDownLatch.countDown(); if (hazelcastInstance.getLifecycleService().isRunning()) { hazelcastInstance.shutdown();
public static void main(String[] args) throws Exception { final HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(); final HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(); final IQueue<String> queue = instance1.getQueue("queueWithQuorum"); final ILock lock = instance1.getLock("lockWithQuorum"); instance2.getLifecycleService().shutdown(); Hazelcast.shutdownAll();
public static void main(String[] args) throws Exception { HazelcastInstance[] instances = new HazelcastInstance[3]; instances[0] = Hazelcast.newHazelcastInstance(); instances[1] = Hazelcast.newHazelcastInstance(); instances[2] = Hazelcast.newHazelcastInstance(); String key = generateKeyOwnedBy(instances[1]); IScheduledExecutorService scheduler = instances[0].getScheduledExecutorService("scheduler"); IScheduledFuture<String> future = scheduler.scheduleOnKeyOwner(new EchoTask("My Task"), key, 5, TimeUnit.SECONDS); instances[1].getLifecycleService().terminate(); Object result = future.get(); System.out.println("Result: " + result); future.dispose(); Hazelcast.shutdownAll(); } }
String cacheName2 = "myCache2"; HazelcastInstance serverInstance1 = Hazelcast.newHazelcastInstance(new Config()); HazelcastInstance serverInstance2 = Hazelcast.newHazelcastInstance(new Config()); serverInstance2.getLifecycleService().terminate(); Hazelcast.shutdownAll();
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()); } }
public static void main(String[] args) throws URISyntaxException { System.setProperty("hazelcast.jcache.provider.type", "server"); System.setProperty("hazelcast.config", "classpath:hazelcast-quorum.xml"); // this creates a cluster with 1 node HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(); // this creates a new node and joins the cluster creating a cluster with 2 nodes CacheManager cacheManager = Caching.getCachingProvider().getCacheManager(); // Quorum will succeed Cache<String, String> cache = cacheManager.getCache(CACHE_NAME); cache.put("key", "we have the quorum"); System.out.println("Quorum is satisfied, so the following put will throw no exception"); System.out.println("Shutdown one instance, so there won't be enough members for quorum presence"); instance1.getLifecycleService().shutdown(); // Quorum will fail System.out.println("The following put operation will fail"); try { cache.put("key2", "will not succeed"); } catch (Exception expected) { System.out.println("Put operation failed with expected QuorumException: " + expected.getMessage()); } Hazelcast.shutdownAll(); } }
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); } }
@Override public void stop() { log.info( String.format( "HazelcastCoreTopologyService stopping and unbinding from %s", config.get( CoreEdgeClusterSettings.discovery_listen_address ) ) ); try { hazelcastInstance.getCluster().removeMembershipListener( membershipRegistrationId ); hazelcastInstance.getMap( EDGE_SERVER_BOLT_ADDRESS_MAP_NAME ).removeEntryListener( mapRegistrationId ); hazelcastInstance.getLifecycleService().terminate(); } catch ( Throwable e ) { log.warn( "Failed to stop Hazelcast", e ); } finally { jobHandle.cancel( true ); } }
IMap<Object, Object> countsMap = client.getMap("counts"); System.out.println(entry.getKey() + ": " + entry.getValue()); client.getLifecycleService().terminate(); ctx.stop();
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(); } }
@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 protected void doStop() { if (this.hazelcastInstance.getLifecycleService().isRunning()) { String id = this.hazelcastRegisteredListenerIdMap.remove(ClusterMonitorType.MEMBERSHIP); if (id != null) { this.hazelcastInstance.getCluster().removeMembershipListener(id); } id = this.hazelcastRegisteredListenerIdMap.remove(ClusterMonitorType.DISTRIBUTED_OBJECT); if (id != null) { this.hazelcastInstance.removeDistributedObjectListener(id); } id = this.hazelcastRegisteredListenerIdMap.remove(ClusterMonitorType.MIGRATION); if (id != null) { this.hazelcastInstance.getPartitionService().removeMigrationListener(id); } id = this.hazelcastRegisteredListenerIdMap.remove(ClusterMonitorType.LIFECYCLE); if (id != null) { this.hazelcastInstance.getLifecycleService().removeLifecycleListener(id); } id = this.hazelcastRegisteredListenerIdMap.remove(ClusterMonitorType.CLIENT); if (id != null) { this.hazelcastInstance.getClientService().removeClientListener(id); } } }
/** * Destroy void. */ public void destroy() { if (hazelcastInstance != null) { try { hazelcastInstance.getLifecycleService().shutdown(); es.shutdown(); } catch (Exception e) { LOGGER.warning("Unexpected error occurred.", e); } } }
@Override public void shutdown() { if(h != null) { h.shutdown(); h.getLifecycleService().shutdown(); } if(resource != null) resource.shutdown(); }