NO-JIRA Add a close method to the session

This commit is contained in:
Timothy Bish 2016-10-20 17:49:26 -04:00
parent d206621a73
commit 4c838c5fa3
1 changed files with 26 additions and 0 deletions

View File

@ -16,7 +16,9 @@
*/ */
package org.apache.activemq.transport.amqp.client; package org.apache.activemq.transport.amqp.client;
import java.io.IOException;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import org.apache.activemq.transport.amqp.client.util.AsyncResult; import org.apache.activemq.transport.amqp.client.util.AsyncResult;
@ -38,6 +40,7 @@ public class AmqpSession extends AmqpAbstractResource<Session> {
private final AmqpConnection connection; private final AmqpConnection connection;
private final String sessionId; private final String sessionId;
private final AmqpTransactionContext txContext; private final AmqpTransactionContext txContext;
private final AtomicBoolean closed = new AtomicBoolean();
/** /**
* Create a new session instance. * Create a new session instance.
@ -53,6 +56,29 @@ public class AmqpSession extends AmqpAbstractResource<Session> {
this.txContext = new AmqpTransactionContext(this); this.txContext = new AmqpTransactionContext(this);
} }
/**
* Close the receiver, a closed receiver will throw exceptions if any further send
* calls are made.
*
* @throws IOException if an error occurs while closing the receiver.
*/
public void close() throws IOException {
if (closed.compareAndSet(false, true)) {
final ClientFuture request = new ClientFuture();
getScheduler().execute(new Runnable() {
@Override
public void run() {
checkClosed();
close(request);
pumpToProtonTransport(request);
}
});
request.sync();
}
}
/** /**
* Create an anonymous sender. * Create an anonymous sender.
* *