com.hazelcast.core.Hazelcast.getAllHazelcastInstances()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(6.4k)|赞(0)|评价(0)|浏览(217)

本文整理了Java中com.hazelcast.core.Hazelcast.getAllHazelcastInstances()方法的一些代码示例,展示了Hazelcast.getAllHazelcastInstances()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Hazelcast.getAllHazelcastInstances()方法的具体详情如下:
包路径:com.hazelcast.core.Hazelcast
类名称:Hazelcast
方法名:getAllHazelcastInstances

Hazelcast.getAllHazelcastInstances介绍

[英]Returns all active/running HazelcastInstances on this JVM.

To shutdown all running HazelcastInstances (all members on this JVM) call #shutdownAll().
[中]返回此JVM上所有活动/正在运行的HazelCast实例。
要关闭所有正在运行的HazelcastInstances(此JVM上的所有成员),请调用#shutdownAll()。

代码示例

代码示例来源:origin: dsukhoroslov/bagri

public static HazelcastInstance findDefaultInstance() {
  HazelcastInstance hzInstance = null;
  Set<HazelcastInstance> instances = Hazelcast.getAllHazelcastInstances();
  for (HazelcastInstance instance: instances) {
    if (hzInstance == null) {
      hzInstance = instance;
    } else {
      if (hz_instance.equals(hzInstance.getName())) {
        hzInstance = instance;
      }
    }
  }
  return hzInstance;
}

代码示例来源:origin: spring-projects/spring-integration-extensions

private boolean isEventAcceptable(final InetSocketAddress socketAddress) {
  final Set<HazelcastInstance> hazelcastInstanceSet = Hazelcast.getAllHazelcastInstances();
  final Set<SocketAddress> localSocketAddressesSet = getLocalSocketAddresses(hazelcastInstanceSet);
  return localSocketAddressesSet.isEmpty() ||
      (!localSocketAddressesSet.isEmpty()
          && (localSocketAddressesSet.contains(socketAddress) ||
          isEventComingFromNonRegisteredHazelcastInstance(hazelcastInstanceSet.iterator().next(),
              localSocketAddressesSet, socketAddress)));
}

代码示例来源:origin: dsukhoroslov/bagri

@Override
public Boolean call() throws Exception {
  logger.trace("call.enter; reloading module: {}", module);
  // refresh module in every found schemas..
  boolean result = false;
  for (HazelcastInstance hz: Hazelcast.getAllHazelcastInstances()) {
    SchemaRepositoryImpl repo = (SchemaRepositoryImpl) hz.getUserContext().get(ctx_repo);
    logger.debug("call; got repo: {} on instance: {}", repo, hz);
    if (repo != null) {
      repo.updateModule(module);
      result = true;
    }
  }
  logger.trace("call.exit; returning: {}", result);
  return result;
}

代码示例来源:origin: dsukhoroslov/bagri

@Override
public CompositeData call() throws Exception {
  MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
  if (type == InfoType.memory) {
    ObjectName memName = new ObjectName("java.lang:type=Memory");
    return (CompositeData) mbs.getAttribute(memName, "HeapMemoryUsage");
  } else if (type == InfoType.timing) {
    ObjectName osName = new ObjectName("java.lang:type=Runtime");
    Map<String, Object> times = new HashMap<String, Object>(2);
    long time = (Long) mbs.getAttribute(osName, "StartTime");
    times.put("StartTime",  new Date(time).toString());
    time = (Long) mbs.getAttribute(osName, "Uptime");
    times.put("Uptime", DateUtils.getDuration(time));
    return JMXUtils.mapToComposite("Timings", "Timing info", times);
  } else {
    Set<HazelcastInstance> instances = Hazelcast.getAllHazelcastInstances();
    Map<String, Object> clients = new HashMap<String, Object>();
    for (HazelcastInstance hzInstance: instances) {
      for (Client client: hzInstance.getClientService().getConnectedClients()) {
        clients.put(client.getUuid(), client.getSocketAddress().toString());
      }
    }
    return JMXUtils.mapToComposite("Clients", "Clients info", clients);
  }
}

代码示例来源:origin: net.kuujo/xync

/**
 * Returns the Vert.x Hazelcast instance.
 *
 * @return The Vert.x Hazelcast instance.
 */
public static HazelcastInstance getHazelcastInstance() {
 for (HazelcastInstance instance : Hazelcast.getAllHazelcastInstances()) {
  MapConfig map = instance.getConfig().findMapConfig("subs");
  if (map != null && map.getName().equals("subs")) {
   return instance;
  }
 }
 return null;
}

代码示例来源:origin: spring-projects/spring-integration-extensions

@Override
public void afterSingletonsInstantiated() {
  if (this.hazelcastInstance == null) {
    if (!Hazelcast.getAllHazelcastInstances().isEmpty()) {
      HazelcastInstance hazelcastInstance = Hazelcast.getAllHazelcastInstances().iterator().next();
      hazelcastInstance.getCluster().addMembershipListener(new HazelcastMembershipListener());
      syncConfigurationMultiMap(hazelcastInstance);
    }
    else {
      logger.warn("No HazelcastInstances for MembershipListener registration");
    }
  }
  else {
    syncConfigurationMultiMap(this.hazelcastInstance);
    this.hazelcastInstance.getCluster().addMembershipListener(new HazelcastMembershipListener());
  }
}

代码示例来源:origin: dsukhoroslov/bagri

@Override
public void run() {
  logger.info("run.enter; about to stop schemas: {}", Arrays.toString(schemas));
  HazelcastInstance hzSystem = null;
  Set<HazelcastInstance> instances = Hazelcast.getAllHazelcastInstances();
  logger.info("run; instances: {}", instances);
  int cnt = 0;
  for (HazelcastInstance instance: instances) {
    if (matchNames(instance.getName(), hz_instance)) {
      hzSystem = instance;
    } else if (shutdownInstance(instance)) {
      instance.shutdown();
      cnt++;
    }
  }
  logger.info("run.exit; instances stopped: {}", cnt);
  if (schemas.length == 0 || (hzSystem != null && instances.size() - cnt == 1)) {
    if ("admin".equals(hzSystem.getCluster().getLocalMember().getStringAttribute(pn_cluster_node_role))) {
      // close all open clients to cache nodes!
      for (HazelcastInstance client: HazelcastClient.getAllHazelcastClients()) {
        client.shutdown();
      }
    }
    hzSystem.shutdown();
    logger.info("run.exit; admin instance terminated as well");
    System.exit(0);
  }
}

代码示例来源:origin: spring-projects/spring-integration-extensions

@Override
public void memberRemoved(MembershipEvent membershipEvent) {
  SocketAddress removedMemberSocketAddress = membershipEvent.getMember().getSocketAddress();
  Set<HazelcastInstance> hazelcastLocalInstanceSet = Hazelcast.getAllHazelcastInstances();
  if (!hazelcastLocalInstanceSet.isEmpty()) {
    HazelcastInstance hazelcastInstance = hazelcastLocalInstanceSet.iterator().next();

代码示例来源:origin: spring-projects/spring-integration-extensions

private void syncConfigurationMultiMap(HazelcastInstance hazelcastInstance) {
  Lock lock = hazelcastInstance.getLock(SPRING_INTEGRATION_INTERNAL_CLUSTER_LOCK);
  lock.lock();
  try {
    MultiMap<SocketAddress, SocketAddress> multiMap = hazelcastInstance
        .getMultiMap(SPRING_INTEGRATION_INTERNAL_CLUSTER_MULTIMAP);
    for (HazelcastInstance localInstance : Hazelcast.getAllHazelcastInstances()) {
      SocketAddress localInstanceSocketAddress = localInstance.getLocalEndpoint().getSocketAddress();
      if (multiMap.size() == 0) {
        multiMap.put(localInstanceSocketAddress, localInstanceSocketAddress);
      }
      else {
        multiMap.put(multiMap.keySet().iterator().next(), localInstanceSocketAddress);
      }
    }
  }
  finally {
    lock.unlock();
  }
}

相关文章