/**
   * 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);

    ConsumerId info = (ConsumerId) o;
    info.setConnectionId(tightUnmarshalString(dataIn, bs));
    info.setSessionId(tightUnmarshalLong(wireFormat, dataIn, bs));
    info.setValue(tightUnmarshalLong(wireFormat, dataIn, bs));
  }
  /**
   * 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 looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn)
      throws IOException {
    super.looseUnmarshal(wireFormat, o, dataIn);

    ConsumerId info = (ConsumerId) o;
    info.setConnectionId(looseUnmarshalString(dataIn));
    info.setSessionId(looseUnmarshalLong(wireFormat, dataIn));
    info.setValue(looseUnmarshalLong(wireFormat, dataIn));
  }
  @Override
  protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    ConsumerId info = (ConsumerId) object;

    info.setConnectionId("ConnectionId:1");
    info.setSessionId(1);
    info.setValue(2);
  }
  /**
   * 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);

    ConsumerId info = (ConsumerId) o;
    tightMarshalString2(info.getConnectionId(), dataOut, bs);
    tightMarshalLong2(wireFormat, info.getSessionId(), dataOut, bs);
    tightMarshalLong2(wireFormat, info.getValue(), dataOut, bs);
  }
  /** Write the booleans that this object uses to a BooleanStream */
  public void looseMarshal(OpenWireFormat wireFormat, Object o, DataOutput dataOut)
      throws IOException {

    ConsumerId info = (ConsumerId) o;

    super.looseMarshal(wireFormat, o, dataOut);
    looseMarshalString(info.getConnectionId(), dataOut);
    looseMarshalLong(wireFormat, info.getSessionId(), dataOut);
    looseMarshalLong(wireFormat, info.getValue(), dataOut);
  }
  /** Write the booleans that this object uses to a BooleanStream */
  public int tightMarshal1(OpenWireFormat wireFormat, Object o, BooleanStream bs)
      throws IOException {

    ConsumerId info = (ConsumerId) o;

    int rc = super.tightMarshal1(wireFormat, o, bs);
    rc += tightMarshalString1(info.getConnectionId(), bs);
    rc += tightMarshalLong1(wireFormat, info.getSessionId(), bs);
    rc += tightMarshalLong1(wireFormat, info.getValue(), bs);

    return rc + 0;
  }
 public void addConsumerBrokerExchange(
     ConsumerId id, AMQSession amqSession, Map<ActiveMQDestination, AMQConsumer> consumerMap) {
   AMQConsumerBrokerExchange result = consumerExchanges.get(id);
   if (result == null) {
     if (consumerMap.size() == 1) {
       result =
           new AMQSingleConsumerBrokerExchange(amqSession, consumerMap.values().iterator().next());
     } else {
       result = new AMQCompositeConsumerBrokerExchange(amqSession, consumerMap);
     }
     synchronized (consumerExchanges) {
       result.setConnectionContext(context);
       SessionState ss = state.getSessionState(id.getParentId());
       if (ss != null) {
         ConsumerState cs = ss.getConsumerState(id);
         if (cs != null) {
           ConsumerInfo info = cs.getInfo();
           if (info != null) {
             if (info.getDestination() != null && info.getDestination().isPattern()) {
               result.setWildcard(true);
             }
           }
         }
       }
       consumerExchanges.put(id, result);
     }
   }
 }
  @Override
  public Response processRemoveConsumer(ConsumerId id, long lastDeliveredSequenceId)
      throws Exception {
    SessionId sessionId = id.getParentId();
    SessionState ss = state.getSessionState(sessionId);
    if (ss == null) {
      throw new IllegalStateException(
          "Cannot remove a consumer from a session that had not been registered: " + sessionId);
    }
    ConsumerState consumerState = ss.removeConsumer(id);
    if (consumerState == null) {
      throw new IllegalStateException(
          "Cannot remove a consumer that had not been registered: " + id);
    }
    ConsumerInfo info = consumerState.getInfo();
    info.setLastDeliveredSequenceId(lastDeliveredSequenceId);

    AMQConsumerBrokerExchange consumerBrokerExchange = consumerExchanges.get(id);

    consumerBrokerExchange.removeConsumer();

    removeConsumerBrokerExchange(id);

    return null;
  }