コード例 #1
0
    public static void main(String[] args) throws Exception {
        HazelcastInstance hz = Hazelcast.newHazelcastInstance();
        Cluster cluster = hz.getCluster();

        cluster.addMembershipListener(new MembershipListener() {
            @Override
            public void memberAdded(MembershipEvent membershipEvent) {
                System.out.println( "********** MemberAdded " + membershipEvent );
            }

            @Override
            public void memberRemoved(MembershipEvent membershipEvent) {
                System.out.println( "********** MemberRemoved " + membershipEvent );
            }

            @Override
            public void memberAttributeChanged(MemberAttributeEvent memberAttributeEvent) {
                System.out.println( "********** MemberAttributeChanged " + memberAttributeEvent );
            }
        });
Member localMember = cluster.getLocalMember();
        System.out.println ( "********** my inetAddress= " + localMember.getInetSocketAddress() );


    }
コード例 #2
0
 @Start
 public void startHazel() {
   Config configApp = new Config();
   configApp.getGroupConfig().setName("KGroup_HazelGroup_" + getName());
   configApp.setInstanceName("KGroup_HazelGroup_" + getNodeName());
   hazelInstance = Hazelcast.newHazelcastInstance(configApp);
   Cluster cluster = hazelInstance.getCluster();
   cluster.addMembershipListener(this);
 }
コード例 #3
0
 private void initMembershipListener() {
   for (MembershipListener membershipListener : listeners.values()) {
     if (membershipListener instanceof InitialMembershipListener) {
       // TODO: needs sync with membership events...
       final Cluster cluster = client.getCluster();
       ((InitialMembershipListener) membershipListener)
           .init(new InitialMembershipEvent(cluster, cluster.getMembers()));
     }
   }
 }
コード例 #4
0
  @Test
  public void testShutdownCluster() throws Exception {
    ShutdownClusterRequest request = new ShutdownClusterRequest();

    cluster.getClusterState();
    JsonObject jsonObject = new JsonObject();
    request.writeResponse(managementCenterService, jsonObject);

    JsonObject result = (JsonObject) jsonObject.get("result");
    assertEquals("SUCCESS", request.readResponse(result));

    assertTrueEventually(
        new AssertTask() {
          @Override
          public void run() throws Exception {
            assertFalse(lifecycleService.isRunning());
          }
        });
  }