예제 #1
0
 @Override
 public List<PartitionQuery<K, T>> getPartitions(Query<K, T> query) throws IOException {
   List<PartitionQuery<K, T>> partitions = new ArrayList<>();
   try {
     Member[] clusterMembers = new Member[hazelcastInstance.getCluster().getMembers().size()];
     this.hazelcastInstance.getCluster().getMembers().toArray(clusterMembers);
     for (Member member : clusterMembers) {
       JCacheResult<K, T> result = ((JCacheResult<K, T>) query.execute());
       ConcurrentSkipListSet<K> memberOwnedCacheEntries = new ConcurrentSkipListSet<>();
       while (result.next()) {
         K key = result.getKey();
         Partition partition = hazelcastInstance.getPartitionService().getPartition(key);
         if (partition.getOwner().getUuid().equals(member.getUuid())) {
           memberOwnedCacheEntries.add(key);
         }
       }
       PartitionQueryImpl<K, T> partition =
           new PartitionQueryImpl<>(
               query,
               memberOwnedCacheEntries.first(),
               memberOwnedCacheEntries.last(),
               member.getSocketAddress().getHostString());
       partition.setConf(this.getConf());
       partitions.add(partition);
     }
   } catch (java.lang.Exception ex) {
     LOG.error(
         "Exception occurred while partitioning the query based on Hazelcast partitions.", ex);
     return null;
   }
   LOG.info("Query is partitioned to {} number of partitions.", partitions.size());
   return partitions;
 }
 @Test
 public void testInstance() {
   assertNotNull(instance);
   final Set<Member> members = instance.getCluster().getMembers();
   assertEquals(1, members.size());
   final Member member = members.iterator().next();
   final InetSocketAddress inetSocketAddress = member.getSocketAddress();
   assertEquals(5700, inetSocketAddress.getPort());
   assertEquals("test-instance", config.getInstanceName());
   assertEquals("HAZELCAST_ENTERPRISE_LICENSE_KEY", config.getLicenseKey());
 }
  /**
   * This is triggered when a new member joined to the cluster.
   *
   * @param membershipEvent contains the information about the added node.
   */
  @Override
  public void memberAdded(MembershipEvent membershipEvent) {
    Member member = membershipEvent.getMember();
    log.info(
        "Handling cluster gossip: New member joined to the cluster. Member Socket Address:"
            + member.getSocketAddress()
            + " UUID:"
            + member.getUuid());

    ClusterResourceHolder.getInstance().getClusterManager().memberAdded();
  }
 /**
  * This is triggered when a node left the cluster.
  *
  * @param membershipEvent contains the information about the removed node.
  */
 @Override
 public void memberRemoved(MembershipEvent membershipEvent) {
   Member member = membershipEvent.getMember();
   log.info(
       "Handling cluster gossip: A member left the cluster. Member Socket Address:"
           + member.getSocketAddress()
           + " UUID:"
           + member.getUuid());
   ClusterManager clusterManager = ClusterResourceHolder.getInstance().getClusterManager();
   try {
     clusterManager.memberRemoved(member);
   } catch (Exception e) {
     log.error("Error while handling node removal, NodeID:" + clusterManager.getNodeId(member), e);
   }
 }