Search in sources :

Example 1 with Closeable

use of org.apache.activemq.artemis.Closeable in project activemq-artemis by apache.

the class ServerSessionImpl method doClose.

protected void doClose(final boolean failed) throws Exception {
    if (callback != null) {
        callback.close(failed);
    }
    synchronized (this) {
        if (!closed) {
            if (server.hasBrokerPlugins()) {
                server.callBrokerPlugins(plugin -> plugin.beforeCloseSession(this, failed));
            }
        }
        this.setStarted(false);
        if (closed)
            return;
        if (tx != null && tx.getXid() == null) {
            try {
                rollback(failed, false);
            } catch (Exception e) {
                ActiveMQServerLogger.LOGGER.unableToRollbackOnClose(e);
            }
        }
    }
    // putting closing of consumers outside the sync block
    // https://issues.jboss.org/browse/HORNETQ-1141
    Set<ServerConsumer> consumersClone = new HashSet<>(consumers.values());
    for (ServerConsumer consumer : consumersClone) {
        try {
            consumer.close(failed);
        } catch (Throwable e) {
            ActiveMQServerLogger.LOGGER.unableToCloseConsumer(e);
            try {
                consumer.removeItself();
            } catch (Throwable e2) {
                ActiveMQServerLogger.LOGGER.unableToRemoveConsumer(e2);
            }
        }
    }
    consumers.clear();
    producers.clear();
    if (closeables != null) {
        for (Closeable closeable : closeables) {
            closeable.close(failed);
        }
    }
    synchronized (this) {
        server.removeSession(name);
        remotingConnection.removeFailureListener(this);
        if (callback != null) {
            callback.closed();
        }
        closed = true;
        if (server.hasBrokerPlugins()) {
            server.callBrokerPlugins(plugin -> plugin.afterCloseSession(this, failed));
        }
    }
}
Also used : Closeable(org.apache.activemq.artemis.Closeable) ServerConsumer(org.apache.activemq.artemis.core.server.ServerConsumer) ActiveMQXAException(org.apache.activemq.artemis.core.exception.ActiveMQXAException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) XAException(javax.transaction.xa.XAException) ActiveMQNonExistentQueueException(org.apache.activemq.artemis.api.core.ActiveMQNonExistentQueueException) ActiveMQIOErrorException(org.apache.activemq.artemis.api.core.ActiveMQIOErrorException) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 XAException (javax.transaction.xa.XAException)1 Closeable (org.apache.activemq.artemis.Closeable)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1 ActiveMQIOErrorException (org.apache.activemq.artemis.api.core.ActiveMQIOErrorException)1 ActiveMQIllegalStateException (org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException)1 ActiveMQNonExistentQueueException (org.apache.activemq.artemis.api.core.ActiveMQNonExistentQueueException)1 ActiveMQXAException (org.apache.activemq.artemis.core.exception.ActiveMQXAException)1 ServerConsumer (org.apache.activemq.artemis.core.server.ServerConsumer)1