@Override
 public void rollbackCurrentTX() throws Exception {
   recoverContext();
   try {
     serverSession.rollback(false);
   } finally {
     resetContext();
   }
 }
 @Override
 public void close() throws Exception {
   recoverContext();
   try {
     serverSession.close(false);
   } finally {
     resetContext();
   }
 }
 @Override
 public void commitCurrentTX() throws Exception {
   recoverContext();
   try {
     serverSession.commit();
   } finally {
     resetContext();
   }
 }
 @Override
 public void createTemporaryQueue(String queueName) throws Exception {
   serverSession.createQueue(
       SimpleString.toSimpleString(queueName),
       SimpleString.toSimpleString(queueName),
       null,
       true,
       false);
 }
  @Override
  public void serverSend(
      final Receiver receiver,
      final Delivery delivery,
      String address,
      int messageFormat,
      ByteBuf messageEncoded)
      throws Exception {
    EncodedMessage encodedMessage =
        new EncodedMessage(
            messageFormat,
            messageEncoded.array(),
            messageEncoded.arrayOffset(),
            messageEncoded.writerIndex());

    ServerMessage message = manager.getConverter().inbound(encodedMessage);
    // use the address on the receiver if not null, if null let's hope it was set correctly on the
    // message
    if (address != null) {
      message.setAddress(new SimpleString(address));
    }

    recoverContext();

    try {
      serverSession.send(message, false);

      manager
          .getServer()
          .getStorageManager()
          .afterCompleteOperations(
              new IOCallback() {
                @Override
                public void done() {
                  synchronized (connection.getLock()) {
                    delivery.settle();
                    connection.flush();
                  }
                }

                @Override
                public void onError(int errorCode, String errorMessage) {
                  synchronized (connection.getLock()) {
                    receiver.setCondition(
                        new ErrorCondition(
                            AmqpError.ILLEGAL_STATE, errorCode + ":" + errorMessage));
                    connection.flush();
                  }
                }
              });
    } finally {
      resetContext();
    }
  }
  @Override
  public boolean queueQuery(String queueName) throws Exception {
    boolean queryResult = false;

    QueueQueryResult queueQuery =
        serverSession.executeQueueQuery(SimpleString.toSimpleString(queueName));

    if (queueQuery.isExists()) {
      queryResult = true;
    } else {
      if (queueQuery.isAutoCreateJmsQueues()) {
        serverSession.createQueue(
            new SimpleString(queueName), new SimpleString(queueName), null, false, true);
        queryResult = true;
      } else {
        queryResult = false;
      }
    }

    return queryResult;
  }
  @Override
  public Object createSender(
      ProtonPlugSender protonSender, String queue, String filer, boolean browserOnly)
      throws Exception {
    long consumerID = consumerIDGenerator.generateID();

    ServerConsumer consumer =
        serverSession.createConsumer(
            consumerID,
            SimpleString.toSimpleString(queue),
            SimpleString.toSimpleString(filer),
            browserOnly);

    // AMQP handles its own flow control for when it's started
    consumer.setStarted(true);

    consumer.setProtocolContext(protonSender);

    return consumer;
  }
 private void recoverContext() {
   manager.getServer().getStorageManager().setContext(serverSession.getSessionContext());
 }
 @Override
 public Binary getCurrentTXID() {
   return new Binary(ByteUtil.longToBytes(serverSession.getCurrentTransaction().getID()));
 }