Example #1
0
  /** terminate this context */
  public synchronized void term() {
    clientScheduleService.stop();

    for (IConnection conn : connections.values()) {
      conn.close();
    }

    connections = null;

    // we need to release resources associated with client channel factory
    clientChannelFactory.releaseExternalResources();
  }
  @Test
  public void testRemoveMessageFuture() throws Exception {
    HashedWheelTimer timer = getTimer();
    RequestManager requestManager = new RequestManager(timer);
    try {
      RequestPacket packet = new RequestPacket(1, new byte[0]);
      DefaultFuture future = requestManager.register(packet, 2000);

      future.setFailure(new RuntimeException());

      Future nullFuture = requestManager.removeMessageFuture(packet.getRequestId());
      Assert.assertNull(nullFuture);

    } finally {
      requestManager.close();
      timer.stop();
    }
  }
  @Test
  public void testRegisterRequest() throws Exception {
    HashedWheelTimer timer = getTimer();
    RequestManager requestManager = new RequestManager(timer);
    try {
      RequestPacket packet = new RequestPacket(new byte[0]);
      Future future = requestManager.register(packet, 50);
      Thread.sleep(200);

      Assert.assertTrue(future.isReady());
      Assert.assertFalse(future.isSuccess());
      Assert.assertTrue(future.getCause().getMessage().contains("timeout"));
      logger.debug(future.getCause().getMessage());
    } finally {
      requestManager.close();
      timer.stop();
    }
  }
  /** {@inheritDoc} */
  public void destroy() {
    if (isClosed.getAndSet(true)) return;
    timer.stop();

    for (Map.Entry<Channel, Timeout> e : trackedIdleConnections.entrySet()) {
      close(e.getKey());
      e.getValue().cancel();
    }
    trackedIdleConnections.clear();

    try {
      Iterator<Map.Entry<String, ConcurrentLinkedQueue<Channel>>> i =
          connectionsPool.entrySet().iterator();
      while (i.hasNext()) {
        for (Channel channel : i.next().getValue()) {
          close(channel);
        }
      }
    } finally {
      connectionsPool.clear();
    }
  }
Example #5
0
  @Override
  public void stop() {

    if (sharedHttpServers != null) {
      for (HttpServer server : sharedHttpServers.values()) {
        server.close();
      }
      sharedHttpServers = null;
    }

    if (sharedNetServers != null) {
      for (NetServer server : sharedNetServers.values()) {
        server.close();
      }
      sharedNetServers = null;
    }

    if (timer != null) {
      timer.stop();
      timer = null;
    }

    if (eventBus != null) {
      eventBus.close(null);
    }

    if (backgroundPool != null) {
      backgroundPool.shutdown();
    }

    if (acceptorPool != null) {
      acceptorPool.shutdown();
    }

    try {
      if (backgroundPool != null) {
        backgroundPool.awaitTermination(20, TimeUnit.SECONDS);
        backgroundPool = null;
      }
    } catch (InterruptedException ex) {
      // ignore
    }

    try {
      if (acceptorPool != null) {
        acceptorPool.awaitTermination(20, TimeUnit.SECONDS);
        acceptorPool = null;
      }
    } catch (InterruptedException ex) {
      // ignore
    }

    // log.info("Release external resources from worker pool");
    if (corePool != null) {
      corePool.releaseExternalResources();
      corePool = null;
    }
    // log.info("Release external resources: done");

    setContext(null);
  }
 //    @Test
 public void testTimerStartTiming() throws InterruptedException {
   HashedWheelTimer timer = new HashedWheelTimer(1000, TimeUnit.MILLISECONDS);
   timer.start();
   timer.stop();
 }