Repository: activemq Updated Branches: refs/heads/master d206621a7 -> 4c838c5fa
NO-JIRA Add a close method to the session Project: http://git-wip-us.apache.org/repos/asf/activemq/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/4c838c5f Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/4c838c5f Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/4c838c5f Branch: refs/heads/master Commit: 4c838c5fa3c83782b1bfaa069f2beb7a87a7beaa Parents: d206621 Author: Timothy Bish <[email protected]> Authored: Thu Oct 20 17:49:26 2016 -0400 Committer: Timothy Bish <[email protected]> Committed: Thu Oct 20 17:49:40 2016 -0400 ---------------------------------------------------------------------- .../transport/amqp/client/AmqpSession.java | 26 ++++++++++++++++++++ 1 file changed, 26 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq/blob/4c838c5f/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/client/AmqpSession.java ---------------------------------------------------------------------- diff --git a/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/client/AmqpSession.java b/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/client/AmqpSession.java index 3804603..7cb745c 100644 --- a/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/client/AmqpSession.java +++ b/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/client/AmqpSession.java @@ -16,7 +16,9 @@ */ package org.apache.activemq.transport.amqp.client; +import java.io.IOException; import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLong; 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 String sessionId; private final AmqpTransactionContext txContext; + private final AtomicBoolean closed = new AtomicBoolean(); /** * Create a new session instance. @@ -54,6 +57,29 @@ public class AmqpSession extends AmqpAbstractResource<Session> { } /** + * 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. * * @return a newly created sender that is ready for use.
