@Test
  public void testHeartbeatResumedEvent() throws InterruptedException {
    hazelcastFactory.newHazelcastInstance();
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(getClientConfig());
    final HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance();

    // make sure client is connected to instance2
    String keyOwnedByInstance2 = generateKeyOwnedBy(instance2);
    IMap<String, String> map = client.getMap(randomString());
    map.put(keyOwnedByInstance2, randomString());

    HazelcastClientInstanceImpl clientImpl = getHazelcastClientInstanceImpl(client);
    ClientConnectionManager connectionManager = clientImpl.getConnectionManager();
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    connectionManager.addConnectionHeartbeatListener(
        new ConnectionHeartbeatListener() {
          @Override
          public void heartbeatResumed(Connection connection) {
            assertEquals(
                instance2.getCluster().getLocalMember().getAddress(), connection.getEndPoint());
            countDownLatch.countDown();
          }

          @Override
          public void heartbeatStopped(Connection connection) {}
        });

    blockMessagesFromInstance(instance2, client);
    sleepMillis(HEARTBEAT_TIMEOUT_MILLIS * 2);
    unblockMessagesFromInstance(instance2, client);

    assertOpenEventually(countDownLatch);
  }
 public ClientInvocationServiceSupport(HazelcastClientInstanceImpl client) {
   this.client = client;
   this.connectionManager = client.getConnectionManager();
   this.executionService = client.getClientExecutionService();
   connectionManager.addConnectionListener(this);
   connectionManager.addConnectionHeartbeatListener(this);
   this.partitionService = client.getClientPartitionService();
   responseThread =
       new ResponseThread(
           client.getThreadGroup(),
           client.getName() + ".response-",
           client.getClientConfig().getClassLoader());
   responseThread.start();
 }
示例#3
0
 void doShutdown() {
   CLIENTS.remove(id);
   executionService.shutdown();
   partitionService.stop();
   clusterService.stop();
   transactionManager.shutdown();
   connectionManager.shutdown();
   proxyManager.destroy();
   serializationService.destroy();
 }
  @Test
  public void testHeartbeatStoppedEvent() throws InterruptedException {
    HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(getClientConfig());

    HazelcastClientInstanceImpl clientImpl = getHazelcastClientInstanceImpl(client);
    ClientConnectionManager connectionManager = clientImpl.getConnectionManager();
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    connectionManager.addConnectionHeartbeatListener(
        new ConnectionHeartbeatListener() {
          @Override
          public void heartbeatResumed(Connection connection) {}

          @Override
          public void heartbeatStopped(Connection connection) {
            countDownLatch.countDown();
          }
        });

    blockMessagesFromInstance(instance, client);
    assertOpenEventually(countDownLatch);
  }
示例#5
0
  private Connection getTargetOrOwnerConnection(final Address target) throws IOException {
    if (target == null) {
      throw new IOException("Not able to setup owner connection!");
    }

    final ClientConnectionManager connectionManager = client.getConnectionManager();
    Connection connection = connectionManager.getConnection(target);
    if (connection == null) {
      final Address ownerConnectionAddress =
          client.getClientClusterService().getOwnerConnectionAddress();
      if (ownerConnectionAddress == null) {
        throw new IOException("Not able to setup owner connection!");
      }

      connection = connectionManager.getConnection(ownerConnectionAddress);
      if (connection == null) {
        throw new IOException("Client is not connected to member " + target);
      }
    }

    return connection;
  }
示例#6
0
 private void start() {
   lifecycleService.setStarted();
   connectionManager.start();
   try {
     clusterService.start();
   } catch (IllegalStateException e) {
     // there was an authentication failure (todo: perhaps use an AuthenticationException
     // ??)
     lifecycleService.shutdown();
     throw e;
   }
   loadBalancer.init(getCluster(), config);
   partitionService.start();
 }
 @Override
 public void cleanConnectionResources(ClientConnection connection) {
   if (connectionManager.isAlive()) {
     try {
       executionService.execute(new CleanResourcesTask(connection));
     } catch (RejectedExecutionException e) {
       logger.warning("Execution rejected ", e);
     }
   } else {
     cleanResources(
         new ConstructorFunction<Object, Throwable>() {
           @Override
           public Throwable createNew(Object arg) {
             return new HazelcastClientNotActiveException("Client is shutting down!");
           }
         },
         connection);
   }
 }