Search in sources :

Example 1 with ReattachSessionResponseMessage

use of org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReattachSessionResponseMessage in project activemq-artemis by apache.

the class ActiveMQPacketHandler method handleReattachSession.

private void handleReattachSession(final ReattachSessionMessage request) {
    Packet response = null;
    try {
        if (!server.isStarted()) {
            response = new ReattachSessionResponseMessage(-1, false);
        }
        logger.debug("Reattaching request from " + connection.getRemoteAddress());
        ServerSessionPacketHandler sessionHandler = protocolManager.getSessionHandler(request.getName());
        // HORNETQ-720 XXX ataylor?
        if (/*!server.checkActivate() || */
        sessionHandler == null) {
            response = new ReattachSessionResponseMessage(-1, false);
        } else {
            if (sessionHandler.getChannel().getConfirmationWindowSize() == -1) {
                // Even though session exists, we can't reattach since confi window size == -1,
                // i.e. we don't have a resend cache for commands, so we just close the old session
                // and let the client recreate
                ActiveMQServerLogger.LOGGER.reattachRequestFailed(connection.getRemoteAddress());
                sessionHandler.closeListeners();
                sessionHandler.close();
                response = new ReattachSessionResponseMessage(-1, false);
            } else {
                // Reconnect the channel to the new connection
                int serverLastConfirmedCommandID = sessionHandler.transferConnection(connection, request.getLastConfirmedCommandID());
                response = new ReattachSessionResponseMessage(serverLastConfirmedCommandID, true);
            }
        }
    } catch (Exception e) {
        ActiveMQServerLogger.LOGGER.failedToReattachSession(e);
        response = new ActiveMQExceptionMessage(new ActiveMQInternalErrorException());
    }
    channel1.send(response);
}
Also used : ServerSessionPacketHandler(org.apache.activemq.artemis.core.protocol.core.ServerSessionPacketHandler) Packet(org.apache.activemq.artemis.core.protocol.core.Packet) ActiveMQExceptionMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ActiveMQExceptionMessage) ActiveMQInternalErrorException(org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException) ReattachSessionResponseMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReattachSessionResponseMessage) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQClusterSecurityException(org.apache.activemq.artemis.api.core.ActiveMQClusterSecurityException) ActiveMQInternalErrorException(org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException) ActiveMQSecurityException(org.apache.activemq.artemis.api.core.ActiveMQSecurityException)

Example 2 with ReattachSessionResponseMessage

use of org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReattachSessionResponseMessage in project activemq-artemis by apache.

the class ActiveMQSessionContext method reattachOnNewConnection.

@Override
public boolean reattachOnNewConnection(RemotingConnection newConnection) throws ActiveMQException {
    this.remotingConnection = newConnection;
    sessionChannel.transferConnection((CoreRemotingConnection) newConnection);
    Packet request = new ReattachSessionMessage(name, sessionChannel.getLastConfirmedCommandID());
    Channel channel1 = getCoreConnection().getChannel(1, -1);
    ReattachSessionResponseMessage response = (ReattachSessionResponseMessage) channel1.sendBlocking(request, PacketImpl.REATTACH_SESSION_RESP);
    if (response.isReattached()) {
        ActiveMQClientLogger.LOGGER.replayingCommands(sessionChannel.getID(), response.getLastConfirmedCommandID());
        // The session was found on the server - we reattached transparently ok
        sessionChannel.replayCommands(response.getLastConfirmedCommandID());
        return true;
    } else {
        ActiveMQClientLogger.LOGGER.reconnectCreatingNewSession(sessionChannel.getID());
        sessionChannel.clearCommands();
        return false;
    }
}
Also used : Packet(org.apache.activemq.artemis.core.protocol.core.Packet) ReattachSessionMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReattachSessionMessage) Channel(org.apache.activemq.artemis.core.protocol.core.Channel) ReattachSessionResponseMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReattachSessionResponseMessage)

Aggregations

Packet (org.apache.activemq.artemis.core.protocol.core.Packet)2 ReattachSessionResponseMessage (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReattachSessionResponseMessage)2 ActiveMQClusterSecurityException (org.apache.activemq.artemis.api.core.ActiveMQClusterSecurityException)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1 ActiveMQInternalErrorException (org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException)1 ActiveMQSecurityException (org.apache.activemq.artemis.api.core.ActiveMQSecurityException)1 Channel (org.apache.activemq.artemis.core.protocol.core.Channel)1 ServerSessionPacketHandler (org.apache.activemq.artemis.core.protocol.core.ServerSessionPacketHandler)1 ActiveMQExceptionMessage (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ActiveMQExceptionMessage)1 ReattachSessionMessage (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReattachSessionMessage)1