CacheEventHandler(NodeEngine nodeEngine) { this.nodeEngine = nodeEngine; GroupProperties groupProperties = nodeEngine.getGroupProperties(); invalidationMessageBatchEnabled = groupProperties.getBoolean(CACHE_INVALIDATION_MESSAGE_BATCH_ENABLED); if (invalidationMessageBatchEnabled) { invalidationMessageBatchSize = groupProperties.getInteger(CACHE_INVALIDATION_MESSAGE_BATCH_SIZE); int invalidationMessageBatchFreq = groupProperties.getInteger(CACHE_INVALIDATION_MESSAGE_BATCH_FREQUENCY_SECONDS); ExecutionService executionService = nodeEngine.getExecutionService(); CacheBatchInvalidationMessageSender batchInvalidationMessageSender = new CacheBatchInvalidationMessageSender(); cacheBatchInvalidationMessageSenderScheduler = executionService.scheduleWithRepetition( ICacheService.SERVICE_NAME + ":cacheBatchInvalidationMessageSender", batchInvalidationMessageSender, invalidationMessageBatchFreq, invalidationMessageBatchFreq, TimeUnit.SECONDS); } LifecycleService lifecycleService = nodeEngine.getHazelcastInstance().getLifecycleService(); lifecycleService.addLifecycleListener( new LifecycleListener() { @Override public void stateChanged(LifecycleEvent event) { if (event.getState() == LifecycleEvent.LifecycleState.SHUTTING_DOWN) { invalidateAllCaches(); } } }); }
protected AbstractEvictableRecordStore(MapContainer mapContainer, int partitionId) { super(mapContainer, partitionId); NodeEngine nodeEngine = mapServiceContext.getNodeEngine(); GroupProperties groupProperties = nodeEngine.getGroupProperties(); expiryDelayMillis = groupProperties.getMillis(GroupProperty.MAP_EXPIRY_DELAY_SECONDS); evictor = mapContainer.getEvictor(); }
Joiner createJoiner() { JoinConfig join = config.getNetworkConfig().getJoin(); join.verify(); if (groupProperties.getBoolean(GroupProperty.DISCOVERY_SPI_ENABLED)) { // TODO: Auto-Upgrade Multicast+AWS configuration! logger.info("Activating Discovery SPI Joiner"); return new DiscoveryJoiner(this, discoveryService); } else { if (join.getMulticastConfig().isEnabled() && multicastService != null) { logger.info("Creating MulticastJoiner"); return new MulticastJoiner(this); } else if (join.getTcpIpConfig().isEnabled()) { logger.info("Creating TcpIpJoiner"); return new TcpIpJoiner(this); } else if (join.getAwsConfig().isEnabled()) { Class clazz; try { logger.info("Creating AWSJoiner"); clazz = Class.forName("com.hazelcast.cluster.impl.TcpIpJoinerOverAWS"); Constructor constructor = clazz.getConstructor(Node.class); return (Joiner) constructor.newInstance(this); } catch (Exception e) { throw ExceptionUtil.rethrow(e); } } } return null; }
public Node(HazelcastInstanceImpl hazelcastInstance, Config config, NodeContext nodeContext) { this.hazelcastInstance = hazelcastInstance; this.config = config; this.configClassLoader = config.getClassLoader(); this.groupProperties = new GroupProperties(config); this.buildInfo = BuildInfoProvider.getBuildInfo(); String loggingType = groupProperties.getString(GroupProperty.LOGGING_TYPE); loggingService = new LoggingServiceImpl(config.getGroupConfig().getName(), loggingType, buildInfo); final AddressPicker addressPicker = nodeContext.createAddressPicker(this); try { addressPicker.pickAddress(); } catch (Throwable e) { throw ExceptionUtil.rethrow(e); } final ServerSocketChannel serverSocketChannel = addressPicker.getServerSocketChannel(); try { address = addressPicker.getPublicAddress(); final Map<String, Object> memberAttributes = findMemberAttributes(config.getMemberAttributeConfig().asReadOnly()); localMember = new MemberImpl( address, true, createMemberUuid(address), hazelcastInstance, memberAttributes); loggingService.setThisMember(localMember); logger = loggingService.getLogger(Node.class.getName()); hazelcastThreadGroup = new HazelcastThreadGroup(hazelcastInstance.getName(), logger, configClassLoader); nodeExtension = NodeExtensionFactory.create(configClassLoader); nodeExtension.beforeStart(this); serializationService = nodeExtension.createSerializationService(); securityContext = config.getSecurityConfig().isEnabled() ? nodeExtension.getSecurityContext() : null; nodeEngine = new NodeEngineImpl(this); clientEngine = new ClientEngineImpl(this); connectionManager = nodeContext.createConnectionManager(this, serverSocketChannel); partitionService = new InternalPartitionServiceImpl(this); clusterService = new ClusterServiceImpl(this); textCommandService = new TextCommandServiceImpl(this); nodeExtension.printNodeInfo(this); multicastService = createMulticastService(addressPicker.getBindAddress(), this, config, logger); discoveryService = createDiscoveryService(config); initializeListeners(config); joiner = nodeContext.createJoiner(this); } catch (Throwable e) { try { serverSocketChannel.close(); } catch (Throwable ignored) { } throw ExceptionUtil.rethrow(e); } }
void start() { nodeEngine.start(); connectionManager.start(); if (config.getNetworkConfig().getJoin().getMulticastConfig().isEnabled()) { final Thread multicastServiceThread = new Thread( hazelcastThreadGroup.getInternalThreadGroup(), multicastService, hazelcastThreadGroup.getThreadNamePrefix("MulticastThread")); multicastServiceThread.start(); } if (groupProperties.getBoolean(GroupProperty.DISCOVERY_SPI_ENABLED)) { discoveryService.start(); } if (groupProperties.getBoolean(GroupProperty.SHUTDOWNHOOK_ENABLED)) { logger.finest("Adding ShutdownHook"); Runtime.getRuntime().addShutdownHook(shutdownHookThread); } state = NodeState.ACTIVE; join(); int clusterSize = clusterService.getSize(); if (config.getNetworkConfig().isPortAutoIncrement() && address.getPort() >= config.getNetworkConfig().getPort() + clusterSize) { StringBuilder sb = new StringBuilder("Config seed port is "); sb.append(config.getNetworkConfig().getPort()); sb.append(" and cluster size is "); sb.append(clusterSize); sb.append(". Some of the ports seem occupied!"); logger.warning(sb.toString()); } try { managementCenterService = new ManagementCenterService(hazelcastInstance); } catch (Exception e) { logger.warning("ManagementCenterService could not be constructed!", e); } nodeExtension.afterStart(this); versionCheck.check(this, getBuildInfo().getVersion(), buildInfo.isEnterprise()); }
public void join() { if (joiner == null) { logger.warning("No join method is enabled! Starting standalone."); setAsMaster(); return; } try { masterAddress = null; joined.set(false); clusterService.reset(); joiner.join(); } catch (Throwable e) { logger.severe("Error while joining the cluster!", e); } if (!joined()) { long maxJoinTimeMillis = groupProperties.getMillis(GroupProperty.MAX_JOIN_SECONDS); logger.severe("Could not join cluster in " + maxJoinTimeMillis + " ms. Shutting down now!"); shutdownNodeByFiringEvents(Node.this, true); } }
public void shutdown(final boolean terminate) { long start = Clock.currentTimeMillis(); if (logger.isFinestEnabled()) { logger.finest("We are being asked to shutdown when state = " + state); } if (!STATE.compareAndSet(this, NodeState.ACTIVE, NodeState.SHUTTING_DOWN)) { waitIfAlreadyShuttingDown(); return; } if (!terminate) { final int maxWaitSeconds = groupProperties.getSeconds(GroupProperty.GRACEFUL_SHUTDOWN_MAX_WAIT); if (!partitionService.prepareToSafeShutdown(maxWaitSeconds, TimeUnit.SECONDS)) { logger.warning( "Graceful shutdown could not be completed in " + maxWaitSeconds + " seconds!"); } clusterService.sendShutdownMessage(); } else { logger.warning("Terminating forcefully..."); } // set the joined=false first so that // threads do not process unnecessary // events, such as remove address joined.set(false); setMasterAddress(null); try { if (groupProperties.getBoolean(GroupProperty.SHUTDOWNHOOK_ENABLED)) { Runtime.getRuntime().removeShutdownHook(shutdownHookThread); } discoveryService.destroy(); logger.info("Shutting down connection manager..."); connectionManager.shutdown(); } catch (Throwable ignored) { } versionCheck.shutdown(); if (managementCenterService != null) { managementCenterService.shutdown(); } textCommandService.stop(); if (multicastService != null) { logger.info("Shutting down multicast service..."); multicastService.stop(); } logger.info("Shutting down connection manager..."); connectionManager.shutdown(); logger.info("Shutting down node engine..."); nodeEngine.shutdown(terminate); if (securityContext != null) { securityContext.destroy(); } nodeExtension.destroy(); logger.finest("Destroying serialization service..."); serializationService.destroy(); hazelcastThreadGroup.destroy(); logger.info( "Hazelcast Shutdown is completed in " + (Clock.currentTimeMillis() - start) + " ms."); state = NodeState.SHUT_DOWN; }