public void dispatchAsync(Command message) {
   if (!stopping.get()) {
     if (taskRunner == null) {
       dispatchSync(message);
     } else {
       synchronized (dispatchQueue) {
         dispatchQueue.add(message);
       }
       try {
         taskRunner.wakeup();
       } catch (InterruptedException e) {
         Thread.currentThread().interrupt();
       }
     }
   } else {
     if (message.isMessageDispatch()) {
       MessageDispatch md = (MessageDispatch) message;
       TransmitCallback sub = md.getTransmitCallback();
       protocolManager.postProcessDispatch(md);
       if (sub != null) {
         sub.onFailure();
       }
     }
   }
 }
Exemplo n.º 2
0
  @Override
  public void stop() throws Exception {
    try {
      synchronized (reconnectMutex) {
        ServiceStopper ss = new ServiceStopper();

        if (!started) {
          return;
        }
        started = false;
        disposed = true;
        connected = false;

        for (Iterator<FanoutTransportHandler> iter = transports.iterator(); iter.hasNext(); ) {
          FanoutTransportHandler th = iter.next();
          if (th.transport != null) {
            ss.stop(th.transport);
          }
        }

        LOG.debug("Stopped: " + this);
        ss.throwFirstException();
      }
    } finally {
      reconnectTask.shutdown();
      reconnectTaskFactory.shutdownNow();
    }
  }
Exemplo n.º 3
0
 public void reconnect() {
   LOG.debug("Waking up reconnect task");
   try {
     reconnectTask.wakeup();
   } catch (InterruptedException e) {
     Thread.currentThread().interrupt();
   }
 }
  protected void doStop() throws Exception {
    this.acceptorUsed.onStopped(this);
    /*
     * What's a duplex bridge? try { synchronized (this) { if (duplexBridge !=
     * null) { duplexBridge.stop(); } } } catch (Exception ignore) {
     * LOG.trace("Exception caught stopping. This exception is ignored.",
     * ignore); }
     */
    try {
      getTransportConnection().close();
    } catch (Exception e) {
      // log
    }

    if (taskRunner != null) {
      taskRunner.shutdown(1);
      taskRunner = null;
    }

    active = false;
    // Run the MessageDispatch callbacks so that message references get
    // cleaned up.
    synchronized (dispatchQueue) {
      for (Iterator<Command> iter = dispatchQueue.iterator(); iter.hasNext(); ) {
        Command command = iter.next();
        if (command.isMessageDispatch()) {
          MessageDispatch md = (MessageDispatch) command;
          TransmitCallback sub = md.getTransmitCallback();
          protocolManager.postProcessDispatch(md);
          if (sub != null) {
            sub.onFailure();
          }
        }
      }
      dispatchQueue.clear();
    }
    //
    // Remove all logical connection associated with this connection
    // from the broker.
    if (!protocolManager.isStopped()) {
      context.getStopping().set(true);
      try {
        processRemoveConnection(state.getInfo().getConnectionId(), 0L);
      } catch (Throwable ignore) {
        ignore.printStackTrace();
      }
    }
  }