public LocalMultiMapStats createStats(String name) {
    LocalMultiMapStatsImpl stats = getLocalMultiMapStatsImpl(name);
    long ownedEntryCount = 0;
    long backupEntryCount = 0;
    long hits = 0;
    long lockedEntryCount = 0;
    ClusterServiceImpl clusterService = (ClusterServiceImpl) nodeEngine.getClusterService();

    Address thisAddress = clusterService.getThisAddress();
    for (int i = 0; i < nodeEngine.getPartitionService().getPartitionCount(); i++) {
      InternalPartition partition = nodeEngine.getPartitionService().getPartition(i);
      MultiMapPartitionContainer partitionContainer = getPartitionContainer(i);
      MultiMapContainer multiMapContainer = partitionContainer.getCollectionContainer(name);
      if (multiMapContainer == null) {
        continue;
      }
      Address owner = partition.getOwnerOrNull();
      if (owner != null) {
        if (owner.equals(thisAddress)) {
          lockedEntryCount += multiMapContainer.getLockedCount();
          for (MultiMapWrapper wrapper : multiMapContainer.getMultiMapWrappers().values()) {
            hits += wrapper.getHits();
            ownedEntryCount += wrapper.getCollection(false).size();
          }
        } else {
          int backupCount = multiMapContainer.getConfig().getTotalBackupCount();
          for (int j = 1; j <= backupCount; j++) {
            Address replicaAddress = partition.getReplicaAddress(j);
            int memberSize = nodeEngine.getClusterService().getMembers().size();

            int tryCount = REPLICA_ADDRESS_TRY_COUNT;
            // wait if the partition table is not updated yet
            while (memberSize > backupCount && replicaAddress == null && tryCount-- > 0) {
              try {
                Thread.sleep(REPLICA_ADDRESS_SLEEP_WAIT_MILLIS);
              } catch (InterruptedException e) {
                throw ExceptionUtil.rethrow(e);
              }
              replicaAddress = partition.getReplicaAddress(j);
            }

            if (replicaAddress != null && replicaAddress.equals(thisAddress)) {
              for (MultiMapWrapper wrapper : multiMapContainer.getMultiMapWrappers().values()) {
                backupEntryCount += wrapper.getCollection(false).size();
              }
            }
          }
        }
      }
    }
    stats.setOwnedEntryCount(ownedEntryCount);
    stats.setBackupEntryCount(backupEntryCount);
    stats.setHits(hits);
    stats.setLockedEntryCount(lockedEntryCount);
    return stats;
  }
示例#2
0
  public Map<String, String> phoneHome(Node hazelcastNode, String version, boolean isEnterprise) {

    String downloadId = "source";
    InputStream is = null;
    try {
      is = getClass().getClassLoader().getResourceAsStream("hazelcast-download.properties");
      if (is != null) {
        final Properties properties = new Properties();
        properties.load(is);
        downloadId = properties.getProperty("hazelcastDownloadId");
      }
    } catch (IOException ignored) {
      EmptyStatement.ignore(ignored);
    } finally {
      IOUtil.closeResource(is);
    }

    // Calculate native memory usage from native memory config
    NativeMemoryConfig memoryConfig = hazelcastNode.getConfig().getNativeMemoryConfig();
    final ClusterServiceImpl clusterService = hazelcastNode.getClusterService();
    long totalNativeMemorySize =
        clusterService.getSize(DATA_MEMBER_SELECTOR) * memoryConfig.getSize().bytes();
    String nativeMemoryParameter =
        (isEnterprise) ? Long.toString(MemoryUnit.BYTES.toGigaBytes(totalNativeMemorySize)) : "0";
    // Calculate connected clients to the cluster.
    Map<ClientType, Integer> clusterClientStats =
        hazelcastNode.clientEngine.getConnectedClientStats();
    RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();

    Long clusterUpTime = clusterService.getClusterClock().getClusterUpTime();

    PhoneHomeParameterCreator parameterCreator = new PhoneHomeParameterCreator();
    parameterCreator.addParam("version", version);
    parameterCreator.addParam("m", hazelcastNode.getLocalMember().getUuid());
    parameterCreator.addParam("e", Boolean.toString(isEnterprise));
    parameterCreator.addParam("l", MD5Util.toMD5String(hazelcastNode.getConfig().getLicenseKey()));
    parameterCreator.addParam("p", downloadId);
    parameterCreator.addParam("c", clusterService.getClusterId());
    parameterCreator.addParam("crsz", convertToLetter(clusterService.getMembers().size()));
    parameterCreator.addParam(
        "cssz", convertToLetter(hazelcastNode.clientEngine.getClientEndpointCount()));
    parameterCreator.addParam("hdgb", nativeMemoryParameter);
    parameterCreator.addParam("ccpp", Integer.toString(clusterClientStats.get(ClientType.CPP)));
    parameterCreator.addParam("cdn", Integer.toString(clusterClientStats.get(ClientType.CSHARP)));
    parameterCreator.addParam("cjv", Integer.toString(clusterClientStats.get(ClientType.JAVA)));
    parameterCreator.addParam("cuptm", Long.toString(clusterUpTime));
    parameterCreator.addParam("nuptm", Long.toString(runtimeMxBean.getUptime()));
    String urlStr = BASE_PHONE_HOME_URL + parameterCreator.build();
    fetchWebService(urlStr);

    return parameterCreator.getParameters();
  }
示例#3
0
 public JoinMessage createSplitBrainJoinMessage() {
   return new JoinMessage(
       Packet.VERSION,
       buildInfo.getBuildNumber(),
       address,
       localMember.getUuid(),
       createConfigCheck(),
       clusterService.getMemberAddresses());
 }
示例#4
0
 private void initializeListeners(Config config) {
   for (final ListenerConfig listenerCfg : config.getListenerConfigs()) {
     Object listener = listenerCfg.getImplementation();
     if (listener == null) {
       try {
         listener = ClassLoaderUtil.newInstance(configClassLoader, listenerCfg.getClassName());
       } catch (Exception e) {
         logger.severe(e);
       }
     }
     if (listener instanceof HazelcastInstanceAware) {
       ((HazelcastInstanceAware) listener).setHazelcastInstance(hazelcastInstance);
     }
     boolean known = false;
     if (listener instanceof DistributedObjectListener) {
       final ProxyServiceImpl proxyService = (ProxyServiceImpl) nodeEngine.getProxyService();
       proxyService.addProxyListener((DistributedObjectListener) listener);
       known = true;
     }
     if (listener instanceof MembershipListener) {
       clusterService.addMembershipListener((MembershipListener) listener);
       known = true;
     }
     if (listener instanceof MigrationListener) {
       partitionService.addMigrationListener((MigrationListener) listener);
       known = true;
     }
     if (listener instanceof PartitionLostListener) {
       partitionService.addPartitionLostListener((PartitionLostListener) listener);
       known = true;
     }
     if (listener instanceof LifecycleListener) {
       hazelcastInstance.lifecycleService.addLifecycleListener((LifecycleListener) listener);
       known = true;
     }
     if (listener instanceof ClientListener) {
       String serviceName = ClientEngineImpl.SERVICE_NAME;
       nodeEngine.getEventService().registerLocalListener(serviceName, serviceName, listener);
       known = true;
     }
     if (listener != null && !known) {
       final String error = "Unknown listener type: " + listener.getClass();
       Throwable t = new IllegalArgumentException(error);
       logger.warning(error, t);
     }
   }
 }
示例#5
0
  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());
  }
示例#6
0
  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);
    }
  }
示例#7
0
  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;
  }