public DefaultParticipantDatabase(
      final Timer timer, String id, ParticipantEventListener eventListener) {
    this.id = id;
    this.listener = eventListener;

    this.receivers = new ArrayList<RtpParticipant>();
    this.members = new HashMap<Long, RtpParticipant>();

    this.lock = new ReentrantReadWriteLock();

    this.timeoutAfterNoPacketsReceived = TIMEOUT_AFTER_NO_PACKETS_RECEIVED;
    this.timeoutAfterByeAndNoPacketsReceived = TIMEOUT_AFTER_BYE_AND_NO_PACKETS_RECEIVED;

    // Add the cleaner.
    timer.newTimeout(
        new TimerTask() {
          @Override
          public void run(Timeout timeout) throws Exception {
            cleanup();
            timer.newTimeout(this, 10, TimeUnit.SECONDS);
          }
        },
        10,
        TimeUnit.SECONDS);
  }
  public void stop() {
    log.info("Shutting down proxy");
    if (stopped.get()) {
      log.info("Already stopped");
      return;
    }
    stopped.set(true);

    log.info("Closing all channels...");

    // See http://static.netty.io/3.5/guide/#start.12

    final ChannelGroupFuture future = allChannels.close();
    future.awaitUninterruptibly(10 * 1000);

    if (!future.isCompleteSuccess()) {
      final Iterator<ChannelFuture> iter = future.iterator();
      while (iter.hasNext()) {
        final ChannelFuture cf = iter.next();
        if (!cf.isSuccess()) {
          log.warn("Cause of failure for {} is {}", cf.getChannel(), cf.getCause());
        }
      }
    }
    log.info("Stopping timer");
    timer.stop();
    serverChannelFactory.releaseExternalResources();
    clientChannelFactory.releaseExternalResources();

    log.info("Done shutting down proxy");
  }
 private void scheduleReconnect() {
   /*
    * Ensure you are the only one mucking with connections If you find someone
    * else is doing so, then you don't get a turn We trust this other person to
    * do the needful
    */
   if (lock.tryAcquire()) {
     long currentTime = System.currentTimeMillis();
     // Check how long it has been since we reconnected
     try {
       if ((currentTime - connectRequestTime) / 1000 > backoffSeconds) {
         connectRequestTime = currentTime;
         timer.newTimeout(
             new TimerTask() {
               public void run(Timeout timeout) throws Exception {
                 channelSetter.connect();
               }
             },
             backoffSeconds,
             TimeUnit.SECONDS);
       }
     } finally {
       lock.release();
     }
   }
 }
Esempio n. 4
0
 private void initialize(ChannelHandlerContext ctx) {
   State state = new State();
   ctx.setAttachment(state);
   if (timeoutMillis > 0) {
     state.timeout =
         timer.newTimeout(new ReadTimeoutTask(ctx), timeoutMillis, TimeUnit.MILLISECONDS);
   }
 }
Esempio n. 5
0
  @Override
  protected void doStop() throws Exception {
    if (timer != null) {
      timer.stop();
      timer = null;
    }
    if (executorService != null) {
      getCamelContext().getExecutorServiceManager().shutdownNow(executorService);
      executorService = null;
    }

    super.doStop();
  }
  public void close() {
    if (closed.compareAndSet(false, true)) {
      try {
        channelManager.close();

        // FIXME shouldn't close if not allowed
        config.executorService().shutdown();

        if (allowStopNettyTimer) nettyTimer.stop();

      } catch (Throwable t) {
        LOGGER.warn("Unexpected error on close", t);
      }
    }
  }
Esempio n. 7
0
 @Override
 protected void doStop() throws Exception {
   timer.stop();
   timer = null;
   super.doStop();
 }
 @Override
 public void dispose() {
   timer.stop();
 }
Esempio n. 9
0
 /**
  * Stops the {@link Timer} which was specified in the constructor of this handler. You should not
  * call this method if the {@link Timer} is in use by other objects.
  */
 @Override
 public void releaseExternalResources() {
   timer.stop();
 }