protected void processDispatch(Command command) throws IOException {
   MessageDispatch messageDispatch =
       (MessageDispatch) (command.isMessageDispatch() ? command : null);
   try {
     if (!stopping.get()) {
       if (messageDispatch != null) {
         protocolManager.preProcessDispatch(messageDispatch);
       }
       dispatch(command);
     }
   } catch (IOException e) {
     if (messageDispatch != null) {
       TransmitCallback sub = messageDispatch.getTransmitCallback();
       protocolManager.postProcessDispatch(messageDispatch);
       if (sub != null) {
         sub.onFailure();
       }
       messageDispatch = null;
       throw e;
     }
   } finally {
     if (messageDispatch != null) {
       TransmitCallback sub = messageDispatch.getTransmitCallback();
       protocolManager.postProcessDispatch(messageDispatch);
       if (sub != null) {
         sub.onSuccess();
       }
     }
   }
 }
 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();
       }
     }
   }
 }
 public void handleDeliverNullDispatch() {
   MessageDispatch md = new MessageDispatch();
   md.setConsumerId(getId());
   md.setDestination(actualDest);
   session.deliverMessage(md);
   windowAvailable.decrementAndGet();
 }
  @Override
  public void browseFinished() {
    MessageDispatch md = new MessageDispatch();
    md.setConsumerId(info.getConsumerId());
    md.setMessage(null);
    md.setDestination(null);

    session.deliverMessage(md);
  }
  /**
   * Write a object instance to data output stream
   *
   * @param o the instance to be marshaled
   * @param dataOut the output stream
   * @throws IOException thrown if an error occurs
   */
  public void tightMarshal2(
      OpenWireFormat wireFormat, Object o, DataOutput dataOut, BooleanStream bs)
      throws IOException {
    super.tightMarshal2(wireFormat, o, dataOut, bs);

    MessageDispatch info = (MessageDispatch) o;
    tightMarshalCachedObject2(wireFormat, (DataStructure) info.getConsumerId(), dataOut, bs);
    tightMarshalCachedObject2(wireFormat, (DataStructure) info.getDestination(), dataOut, bs);
    tightMarshalNestedObject2(wireFormat, (DataStructure) info.getMessage(), dataOut, bs);
    dataOut.writeInt(info.getRedeliveryCounter());
  }
  /** Write the booleans that this object uses to a BooleanStream */
  public void looseMarshal(OpenWireFormat wireFormat, Object o, DataOutput dataOut)
      throws IOException {

    MessageDispatch info = (MessageDispatch) o;

    super.looseMarshal(wireFormat, o, dataOut);
    looseMarshalCachedObject(wireFormat, (DataStructure) info.getConsumerId(), dataOut);
    looseMarshalCachedObject(wireFormat, (DataStructure) info.getDestination(), dataOut);
    looseMarshalNestedObject(wireFormat, (DataStructure) info.getMessage(), dataOut);
    dataOut.writeInt(info.getRedeliveryCounter());
  }
  /** Write the booleans that this object uses to a BooleanStream */
  public int tightMarshal1(OpenWireFormat wireFormat, Object o, BooleanStream bs)
      throws IOException {

    MessageDispatch info = (MessageDispatch) o;

    int rc = super.tightMarshal1(wireFormat, o, bs);
    rc += tightMarshalCachedObject1(wireFormat, (DataStructure) info.getConsumerId(), bs);
    rc += tightMarshalCachedObject1(wireFormat, (DataStructure) info.getDestination(), bs);
    rc += tightMarshalNestedObject1(wireFormat, (DataStructure) info.getMessage(), bs);

    return rc + 4;
  }
  /**
   * Un-marshal an object instance from the data input stream
   *
   * @param o the object to un-marshal
   * @param dataIn the data input stream to build the object from
   * @throws IOException
   */
  public void tightUnmarshal(
      OpenWireFormat wireFormat, Object o, DataInput dataIn, BooleanStream bs) throws IOException {
    super.tightUnmarshal(wireFormat, o, dataIn, bs);

    MessageDispatch info = (MessageDispatch) o;
    info.setConsumerId(
        (org.apache.activemq.command.ConsumerId) tightUnmarsalCachedObject(wireFormat, dataIn, bs));
    info.setDestination(
        (org.apache.activemq.command.ActiveMQDestination)
            tightUnmarsalCachedObject(wireFormat, dataIn, bs));
    info.setMessage(
        (org.apache.activemq.command.Message) tightUnmarsalNestedObject(wireFormat, dataIn, bs));
    info.setRedeliveryCounter(dataIn.readInt());
  }
  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();
      }
    }
  }
  public void deliverMessage(MessageDispatch dispatch) {
    Message m = dispatch.getMessage();
    if (m != null) {
      long endTime = System.currentTimeMillis();
      m.setBrokerOutTime(endTime);
    }

    protocolManager.send(this, dispatch);
  }
Пример #11
0
 public int handleDeliver(ServerMessage message, int deliveryCount) {
   MessageDispatch dispatch;
   try {
     if (messagePullHandler != null && !messagePullHandler.checkForcedConsumer(message)) {
       return 0;
     }
     // decrement deliveryCount as AMQ client tends to add 1.
     dispatch = OpenWireMessageConverter.createMessageDispatch(message, deliveryCount - 1, this);
     int size = dispatch.getMessage().getSize();
     this.deliveringRefs.add(
         new MessageInfo(dispatch.getMessage().getMessageId(), message.getMessageID(), size));
     session.deliverMessage(dispatch);
     windowAvailable.decrementAndGet();
     return size;
   } catch (IOException e) {
     return 0;
   } catch (Throwable t) {
     return 0;
   }
 }
  public static MessageDispatch createMessageDispatch(
      MessageReference reference, ServerMessage message, AMQConsumer consumer)
      throws IOException, JMSException {
    ActiveMQMessage amqMessage =
        toAMQMessage(
            reference, message, consumer.getMarshaller(), consumer.getOpenwireDestination());

    // we can use core message id for sequenceId
    amqMessage.getMessageId().setBrokerSequenceId(message.getMessageID());
    MessageDispatch md = new MessageDispatch();
    md.setConsumerId(consumer.getId());
    md.setRedeliveryCounter(reference.getDeliveryCount() - 1);
    md.setDeliverySequenceId(amqMessage.getMessageId().getBrokerSequenceId());
    md.setMessage(amqMessage);
    ActiveMQDestination destination = amqMessage.getDestination();
    md.setDestination(destination);

    return md;
  }
/**