mirror of https://github.com/apache/activemq.git
NO-JIRA Add a close method to the session
This commit is contained in:
parent
d206621a73
commit
4c838c5fa3
|
@ -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.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue