Search in sources :

Example 1 with ActiveMQExceptionMessage

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

the class ServerSessionPacketHandler method slowPacketHandler.

// This is being separated from onMessagePacket as JIT was more efficient with a small method for the
// hot executions.
private void slowPacketHandler(final Packet packet) {
    final byte type = packet.getType();
    storageManager.setContext(session.getSessionContext());
    Packet response = null;
    boolean flush = false;
    boolean closeChannel = false;
    boolean requiresResponse = false;
    try {
        try {
            switch(type) {
                case SESS_SEND_LARGE:
                    {
                        SessionSendLargeMessage message = (SessionSendLargeMessage) packet;
                        sendLarge(message.getLargeMessage());
                        break;
                    }
                case SESS_SEND_CONTINUATION:
                    {
                        SessionSendContinuationMessage message = (SessionSendContinuationMessage) packet;
                        requiresResponse = message.isRequiresResponse();
                        sendContinuations(message.getPacketSize(), message.getMessageBodySize(), message.getBody(), message.isContinues());
                        if (requiresResponse) {
                            response = new NullResponseMessage();
                        }
                        break;
                    }
                case SESS_CREATECONSUMER:
                    {
                        SessionCreateConsumerMessage request = (SessionCreateConsumerMessage) packet;
                        requiresResponse = request.isRequiresResponse();
                        session.createConsumer(request.getID(), request.getQueueName(), request.getFilterString(), request.isBrowseOnly());
                        if (requiresResponse) {
                            // We send back queue information on the queue as a response- this allows the queue to
                            // be automatically recreated on failover
                            QueueQueryResult queueQueryResult = session.executeQueueQuery(request.getQueueName());
                            if (channel.supports(PacketImpl.SESS_QUEUEQUERY_RESP_V3)) {
                                response = new SessionQueueQueryResponseMessage_V3(queueQueryResult);
                            } else if (channel.supports(PacketImpl.SESS_QUEUEQUERY_RESP_V2)) {
                                response = new SessionQueueQueryResponseMessage_V2(queueQueryResult);
                            } else {
                                response = new SessionQueueQueryResponseMessage(queueQueryResult);
                            }
                        }
                        break;
                    }
                case CREATE_ADDRESS:
                    {
                        CreateAddressMessage request = (CreateAddressMessage) packet;
                        requiresResponse = request.isRequiresResponse();
                        session.createAddress(request.getAddress(), request.getRoutingTypes(), request.isAutoCreated());
                        if (requiresResponse) {
                            response = new NullResponseMessage();
                        }
                        break;
                    }
                case CREATE_QUEUE:
                    {
                        CreateQueueMessage request = (CreateQueueMessage) packet;
                        requiresResponse = request.isRequiresResponse();
                        session.createQueue(request.getAddress(), request.getQueueName(), RoutingType.MULTICAST, request.getFilterString(), request.isTemporary(), request.isDurable());
                        if (requiresResponse) {
                            response = new NullResponseMessage();
                        }
                        break;
                    }
                case CREATE_QUEUE_V2:
                    {
                        CreateQueueMessage_V2 request = (CreateQueueMessage_V2) packet;
                        requiresResponse = request.isRequiresResponse();
                        session.createQueue(request.getAddress(), request.getQueueName(), request.getRoutingType(), request.getFilterString(), request.isTemporary(), request.isDurable(), request.getMaxConsumers(), request.isPurgeOnNoConsumers(), request.isExclusive(), request.isLastValue(), request.isAutoCreated());
                        if (requiresResponse) {
                            response = new NullResponseMessage();
                        }
                        break;
                    }
                case CREATE_SHARED_QUEUE:
                    {
                        CreateSharedQueueMessage request = (CreateSharedQueueMessage) packet;
                        requiresResponse = request.isRequiresResponse();
                        session.createSharedQueue(request.getAddress(), request.getQueueName(), request.isDurable(), request.getFilterString());
                        if (requiresResponse) {
                            response = new NullResponseMessage();
                        }
                        break;
                    }
                case CREATE_SHARED_QUEUE_V2:
                    {
                        CreateSharedQueueMessage_V2 request = (CreateSharedQueueMessage_V2) packet;
                        requiresResponse = request.isRequiresResponse();
                        session.createSharedQueue(request.getAddress(), request.getQueueName(), request.getRoutingType(), request.getFilterString(), request.isDurable(), request.getMaxConsumers(), request.isPurgeOnNoConsumers(), request.isExclusive(), request.isLastValue());
                        if (requiresResponse) {
                            response = new NullResponseMessage();
                        }
                        break;
                    }
                case DELETE_QUEUE:
                    {
                        requiresResponse = true;
                        SessionDeleteQueueMessage request = (SessionDeleteQueueMessage) packet;
                        session.deleteQueue(request.getQueueName());
                        response = new NullResponseMessage();
                        break;
                    }
                case SESS_QUEUEQUERY:
                    {
                        requiresResponse = true;
                        SessionQueueQueryMessage request = (SessionQueueQueryMessage) packet;
                        QueueQueryResult result = session.executeQueueQuery(request.getQueueName());
                        if (result.isExists() && remotingConnection.getChannelVersion() < PacketImpl.ADDRESSING_CHANGE_VERSION) {
                            result.setAddress(SessionQueueQueryMessage.getOldPrefixedAddress(result.getAddress(), result.getRoutingType()));
                        }
                        if (channel.supports(PacketImpl.SESS_QUEUEQUERY_RESP_V3)) {
                            response = new SessionQueueQueryResponseMessage_V3(result);
                        } else if (channel.supports(PacketImpl.SESS_QUEUEQUERY_RESP_V2)) {
                            response = new SessionQueueQueryResponseMessage_V2(result);
                        } else {
                            response = new SessionQueueQueryResponseMessage(result);
                        }
                        break;
                    }
                case SESS_BINDINGQUERY:
                    {
                        requiresResponse = true;
                        SessionBindingQueryMessage request = (SessionBindingQueryMessage) packet;
                        final int clientVersion = remotingConnection.getChannelVersion();
                        BindingQueryResult result = session.executeBindingQuery(request.getAddress());
                        /* if the session is JMS and it's from an older client then we need to add the old prefix to the queue
                   * names otherwise the older client won't realize the queue exists and will try to create it and receive
                   * an error
                   */
                        if (result.isExists() && clientVersion < PacketImpl.ADDRESSING_CHANGE_VERSION && session.getMetaData(ClientSession.JMS_SESSION_IDENTIFIER_PROPERTY) != null) {
                            final List<SimpleString> queueNames = result.getQueueNames();
                            if (!queueNames.isEmpty()) {
                                final List<SimpleString> convertedQueueNames = request.convertQueueNames(clientVersion, queueNames);
                                if (convertedQueueNames != queueNames) {
                                    result = new BindingQueryResult(result.isExists(), result.getAddressInfo(), convertedQueueNames, result.isAutoCreateQueues(), result.isAutoCreateAddresses(), result.isDefaultPurgeOnNoConsumers(), result.getDefaultMaxConsumers(), result.isDefaultExclusive(), result.isDefaultLastValue());
                                }
                            }
                        }
                        if (channel.supports(PacketImpl.SESS_BINDINGQUERY_RESP_V4)) {
                            response = new SessionBindingQueryResponseMessage_V4(result.isExists(), result.getQueueNames(), result.isAutoCreateQueues(), result.isAutoCreateAddresses(), result.isDefaultPurgeOnNoConsumers(), result.getDefaultMaxConsumers(), result.isDefaultExclusive(), result.isDefaultLastValue());
                        } else if (channel.supports(PacketImpl.SESS_BINDINGQUERY_RESP_V3)) {
                            response = new SessionBindingQueryResponseMessage_V3(result.isExists(), result.getQueueNames(), result.isAutoCreateQueues(), result.isAutoCreateAddresses());
                        } else if (channel.supports(PacketImpl.SESS_BINDINGQUERY_RESP_V2)) {
                            response = new SessionBindingQueryResponseMessage_V2(result.isExists(), result.getQueueNames(), result.isAutoCreateQueues());
                        } else {
                            response = new SessionBindingQueryResponseMessage(result.isExists(), result.getQueueNames());
                        }
                        break;
                    }
                case SESS_EXPIRED:
                    {
                        SessionExpireMessage message = (SessionExpireMessage) packet;
                        session.expire(message.getConsumerID(), message.getMessageID());
                        break;
                    }
                case SESS_COMMIT:
                    {
                        requiresResponse = true;
                        session.commit();
                        response = new NullResponseMessage();
                        break;
                    }
                case SESS_ROLLBACK:
                    {
                        requiresResponse = true;
                        session.rollback(((RollbackMessage) packet).isConsiderLastMessageAsDelivered());
                        response = new NullResponseMessage();
                        break;
                    }
                case SESS_XA_COMMIT:
                    {
                        requiresResponse = true;
                        SessionXACommitMessage message = (SessionXACommitMessage) packet;
                        session.xaCommit(message.getXid(), message.isOnePhase());
                        response = new SessionXAResponseMessage(false, XAResource.XA_OK, null);
                        break;
                    }
                case SESS_XA_END:
                    {
                        requiresResponse = true;
                        SessionXAEndMessage message = (SessionXAEndMessage) packet;
                        session.xaEnd(message.getXid());
                        response = new SessionXAResponseMessage(false, XAResource.XA_OK, null);
                        break;
                    }
                case SESS_XA_FORGET:
                    {
                        requiresResponse = true;
                        SessionXAForgetMessage message = (SessionXAForgetMessage) packet;
                        session.xaForget(message.getXid());
                        response = new SessionXAResponseMessage(false, XAResource.XA_OK, null);
                        break;
                    }
                case SESS_XA_JOIN:
                    {
                        requiresResponse = true;
                        SessionXAJoinMessage message = (SessionXAJoinMessage) packet;
                        session.xaJoin(message.getXid());
                        response = new SessionXAResponseMessage(false, XAResource.XA_OK, null);
                        break;
                    }
                case SESS_XA_RESUME:
                    {
                        requiresResponse = true;
                        SessionXAResumeMessage message = (SessionXAResumeMessage) packet;
                        session.xaResume(message.getXid());
                        response = new SessionXAResponseMessage(false, XAResource.XA_OK, null);
                        break;
                    }
                case SESS_XA_ROLLBACK:
                    {
                        requiresResponse = true;
                        SessionXARollbackMessage message = (SessionXARollbackMessage) packet;
                        session.xaRollback(message.getXid());
                        response = new SessionXAResponseMessage(false, XAResource.XA_OK, null);
                        break;
                    }
                case SESS_XA_START:
                    {
                        requiresResponse = true;
                        SessionXAStartMessage message = (SessionXAStartMessage) packet;
                        session.xaStart(message.getXid());
                        response = new SessionXAResponseMessage(false, XAResource.XA_OK, null);
                        break;
                    }
                case SESS_XA_FAILED:
                    {
                        requiresResponse = true;
                        SessionXAAfterFailedMessage message = (SessionXAAfterFailedMessage) packet;
                        session.xaFailed(message.getXid());
                        // no response on this case
                        break;
                    }
                case SESS_XA_SUSPEND:
                    {
                        requiresResponse = true;
                        session.xaSuspend();
                        response = new SessionXAResponseMessage(false, XAResource.XA_OK, null);
                        break;
                    }
                case SESS_XA_PREPARE:
                    {
                        requiresResponse = true;
                        SessionXAPrepareMessage message = (SessionXAPrepareMessage) packet;
                        session.xaPrepare(message.getXid());
                        response = new SessionXAResponseMessage(false, XAResource.XA_OK, null);
                        break;
                    }
                case SESS_XA_INDOUBT_XIDS:
                    {
                        requiresResponse = true;
                        List<Xid> xids = session.xaGetInDoubtXids();
                        response = new SessionXAGetInDoubtXidsResponseMessage(xids);
                        break;
                    }
                case SESS_XA_GET_TIMEOUT:
                    {
                        requiresResponse = true;
                        int timeout = session.xaGetTimeout();
                        response = new SessionXAGetTimeoutResponseMessage(timeout);
                        break;
                    }
                case SESS_XA_SET_TIMEOUT:
                    {
                        requiresResponse = true;
                        SessionXASetTimeoutMessage message = (SessionXASetTimeoutMessage) packet;
                        session.xaSetTimeout(message.getTimeoutSeconds());
                        response = new SessionXASetTimeoutResponseMessage(true);
                        break;
                    }
                case SESS_START:
                    {
                        session.start();
                        break;
                    }
                case SESS_STOP:
                    {
                        requiresResponse = true;
                        session.stop();
                        response = new NullResponseMessage();
                        break;
                    }
                case SESS_CLOSE:
                    {
                        requiresResponse = true;
                        session.close(false);
                        // removeConnectionListeners();
                        response = new NullResponseMessage();
                        flush = true;
                        closeChannel = true;
                        break;
                    }
                case SESS_INDIVIDUAL_ACKNOWLEDGE:
                    {
                        SessionIndividualAcknowledgeMessage message = (SessionIndividualAcknowledgeMessage) packet;
                        requiresResponse = message.isRequiresResponse();
                        session.individualAcknowledge(message.getConsumerID(), message.getMessageID());
                        if (requiresResponse) {
                            response = new NullResponseMessage();
                        }
                        break;
                    }
                case SESS_CONSUMER_CLOSE:
                    {
                        requiresResponse = true;
                        SessionConsumerCloseMessage message = (SessionConsumerCloseMessage) packet;
                        session.closeConsumer(message.getConsumerID());
                        response = new NullResponseMessage();
                        break;
                    }
                case SESS_FORCE_CONSUMER_DELIVERY:
                    {
                        SessionForceConsumerDelivery message = (SessionForceConsumerDelivery) packet;
                        session.forceConsumerDelivery(message.getConsumerID(), message.getSequence());
                        break;
                    }
                case PacketImpl.SESS_ADD_METADATA:
                    {
                        response = new NullResponseMessage();
                        SessionAddMetaDataMessage message = (SessionAddMetaDataMessage) packet;
                        session.addMetaData(message.getKey(), message.getData());
                        break;
                    }
                case PacketImpl.SESS_ADD_METADATA2:
                    {
                        requiresResponse = true;
                        SessionAddMetaDataMessageV2 message = (SessionAddMetaDataMessageV2) packet;
                        if (message.isRequiresConfirmations()) {
                            response = new NullResponseMessage();
                        }
                        session.addMetaData(message.getKey(), message.getData());
                        break;
                    }
                case PacketImpl.SESS_UNIQUE_ADD_METADATA:
                    {
                        requiresResponse = true;
                        SessionUniqueAddMetaDataMessage message = (SessionUniqueAddMetaDataMessage) packet;
                        if (session.addUniqueMetaData(message.getKey(), message.getData())) {
                            response = new NullResponseMessage();
                        } else {
                            response = new ActiveMQExceptionMessage(ActiveMQMessageBundle.BUNDLE.duplicateMetadata(message.getKey(), message.getData()));
                        }
                        break;
                    }
            }
        } catch (ActiveMQIOErrorException e) {
            response = onActiveMQIOErrorExceptionWhileHandlePacket(e, requiresResponse, response, this.session);
        } catch (ActiveMQXAException e) {
            response = onActiveMQXAExceptionWhileHandlePacket(e, requiresResponse, response);
        } catch (ActiveMQQueueMaxConsumerLimitReached e) {
            response = onActiveMQQueueMaxConsumerLimitReachedWhileHandlePacket(e, requiresResponse, response);
        } catch (ActiveMQException e) {
            response = onActiveMQExceptionWhileHandlePacket(e, requiresResponse, response);
        } catch (Throwable t) {
            response = onCatchThrowableWhileHandlePacket(t, requiresResponse, response, this.session);
        }
        sendResponse(packet, response, flush, closeChannel);
    } finally {
        storageManager.clearContext();
    }
}
Also used : SessionXAGetInDoubtXidsResponseMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionXAGetInDoubtXidsResponseMessage) SessionUniqueAddMetaDataMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionUniqueAddMetaDataMessage) SessionXASetTimeoutResponseMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionXASetTimeoutResponseMessage) SessionCreateConsumerMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionCreateConsumerMessage) SessionExpireMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionExpireMessage) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) CreateQueueMessage_V2(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.CreateQueueMessage_V2) List(java.util.List) ActiveMQXAException(org.apache.activemq.artemis.core.exception.ActiveMQXAException) RollbackMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.RollbackMessage) SessionXARollbackMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionXARollbackMessage) SessionXAResponseMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionXAResponseMessage) CreateAddressMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.CreateAddressMessage) ActiveMQExceptionMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ActiveMQExceptionMessage) SessionXAResumeMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionXAResumeMessage) SessionAddMetaDataMessageV2(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionAddMetaDataMessageV2) SessionXAStartMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionXAStartMessage) ActiveMQIOErrorException(org.apache.activemq.artemis.api.core.ActiveMQIOErrorException) SessionAddMetaDataMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionAddMetaDataMessage) SessionConsumerCloseMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionConsumerCloseMessage) SessionQueueQueryResponseMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionQueueQueryResponseMessage) SessionXAGetTimeoutResponseMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionXAGetTimeoutResponseMessage) SessionXACommitMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionXACommitMessage) BindingQueryResult(org.apache.activemq.artemis.core.server.BindingQueryResult) SessionXASetTimeoutMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionXASetTimeoutMessage) SessionSendContinuationMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendContinuationMessage) SessionXAAfterFailedMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionXAAfterFailedMessage) SessionXAJoinMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionXAJoinMessage) CreateSharedQueueMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.CreateSharedQueueMessage) NullResponseMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.NullResponseMessage) CreateSharedQueueMessage_V2(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.CreateSharedQueueMessage_V2) QueueQueryResult(org.apache.activemq.artemis.core.server.QueueQueryResult) SessionIndividualAcknowledgeMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionIndividualAcknowledgeMessage) SessionDeleteQueueMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionDeleteQueueMessage) SessionForceConsumerDelivery(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionForceConsumerDelivery) SessionBindingQueryResponseMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionBindingQueryResponseMessage) SessionXARollbackMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionXARollbackMessage) CreateQueueMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.CreateQueueMessage) SessionBindingQueryMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionBindingQueryMessage) SessionSendLargeMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendLargeMessage) SessionQueueQueryResponseMessage_V2(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionQueueQueryResponseMessage_V2) SessionQueueQueryResponseMessage_V3(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionQueueQueryResponseMessage_V3) SessionBindingQueryResponseMessage_V2(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionBindingQueryResponseMessage_V2) SessionBindingQueryResponseMessage_V3(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionBindingQueryResponseMessage_V3) SessionXAEndMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionXAEndMessage) ActiveMQQueueMaxConsumerLimitReached(org.apache.activemq.artemis.api.core.ActiveMQQueueMaxConsumerLimitReached) SessionQueueQueryMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionQueueQueryMessage) SessionXAPrepareMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionXAPrepareMessage) SessionBindingQueryResponseMessage_V4(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionBindingQueryResponseMessage_V4) SessionXAForgetMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionXAForgetMessage)

Example 2 with ActiveMQExceptionMessage

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

the class ServerSessionPacketHandler method onCatchThrowableWhileHandlePacket.

private static Packet onCatchThrowableWhileHandlePacket(Throwable t, boolean requiresResponse, Packet response, ServerSession session) {
    session.markTXFailed(t);
    if (requiresResponse) {
        ActiveMQServerLogger.LOGGER.sendingUnexpectedExceptionToClient(t);
        ActiveMQException activeMQInternalErrorException = new ActiveMQInternalErrorException();
        activeMQInternalErrorException.initCause(t);
        response = new ActiveMQExceptionMessage(activeMQInternalErrorException);
    } else {
        ActiveMQServerLogger.LOGGER.caughtException(t);
    }
    return response;
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQExceptionMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ActiveMQExceptionMessage) ActiveMQInternalErrorException(org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException)

Example 3 with ActiveMQExceptionMessage

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

the class ServerSessionPacketHandler method onActiveMQExceptionWhileHandlePacket.

private static Packet onActiveMQExceptionWhileHandlePacket(ActiveMQException e, boolean requiresResponse, Packet response) {
    if (requiresResponse) {
        logger.debug("Sending exception to client", e);
        response = new ActiveMQExceptionMessage(e);
    } else {
        if (e.getType() == ActiveMQExceptionType.QUEUE_EXISTS) {
            logger.debug("Caught exception", e);
        } else {
            ActiveMQServerLogger.LOGGER.caughtException(e);
        }
    }
    return response;
}
Also used : ActiveMQExceptionMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ActiveMQExceptionMessage)

Example 4 with ActiveMQExceptionMessage

use of org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ActiveMQExceptionMessage 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 5 with ActiveMQExceptionMessage

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

the class ChannelImpl method sendBlocking.

/**
 * Due to networking issues or server issues the server may take longer to answer than expected.. the client may timeout the call throwing an exception
 * and the client could eventually retry another call, but the server could then answer a previous command issuing a class-cast-exception.
 * The expectedPacket will be used to filter out undesirable packets that would belong to previous calls.
 */
@Override
public Packet sendBlocking(final Packet packet, final int reconnectID, byte expectedPacket) throws ActiveMQException {
    String interceptionResult = invokeInterceptors(packet, interceptors, connection);
    if (interceptionResult != null) {
        if (logger.isTraceEnabled()) {
            logger.trace("RemotingConnectionID=" + (connection == null ? "NULL" : connection.getID()) + " interceptionResult=" + interceptionResult);
        }
        // if we don't throw an exception here the client might not unblock
        throw ActiveMQClientMessageBundle.BUNDLE.interceptorRejectedPacket(interceptionResult);
    }
    if (closed) {
        if (logger.isTraceEnabled()) {
            logger.trace("RemotingConnectionID=" + (connection == null ? "NULL" : connection.getID()) + " closed.");
        }
        throw ActiveMQClientMessageBundle.BUNDLE.connectionDestroyed();
    }
    if (connection.getBlockingCallTimeout() == -1) {
        if (logger.isTraceEnabled()) {
            logger.trace("RemotingConnectionID=" + (connection == null ? "NULL" : connection.getID()) + " Cannot do a blocking call timeout on a server side connection");
        }
        throw new IllegalStateException("Cannot do a blocking call timeout on a server side connection");
    }
    // E.g. blocking acknowledge() from inside a message handler at some time as other operation on main thread
    synchronized (sendBlockingLock) {
        packet.setChannelID(id);
        final ActiveMQBuffer buffer = packet.encode(connection);
        lock.lock();
        try {
            if (failingOver) {
                waitForFailOver("RemotingConnectionID=" + (connection == null ? "NULL" : connection.getID()) + " timed-out waiting for fail-over condition on blocking send");
            }
            response = null;
            if (resendCache != null && packet.isRequiresConfirmations()) {
                addResendPacket(packet);
            }
            checkReconnectID(reconnectID);
            if (logger.isTraceEnabled()) {
                logger.trace("RemotingConnectionID=" + (connection == null ? "NULL" : connection.getID()) + " Sending blocking " + packet);
            }
            connection.getTransportConnection().write(buffer, false, false);
            long toWait = connection.getBlockingCallTimeout();
            long start = System.currentTimeMillis();
            while (!closed && (response == null || (response.getType() != PacketImpl.EXCEPTION && response.getType() != expectedPacket)) && toWait > 0) {
                try {
                    sendCondition.await(toWait, TimeUnit.MILLISECONDS);
                } catch (InterruptedException e) {
                    throw new ActiveMQInterruptedException(e);
                }
                if (response != null && response.getType() != PacketImpl.EXCEPTION && response.getType() != expectedPacket) {
                    ActiveMQClientLogger.LOGGER.packetOutOfOrder(response, new Exception("trace"));
                }
                if (closed) {
                    break;
                }
                final long now = System.currentTimeMillis();
                toWait -= now - start;
                start = now;
            }
            if (closed && toWait > 0 && response == null) {
                Throwable cause = ActiveMQClientMessageBundle.BUNDLE.connectionDestroyed();
                throw ActiveMQClientMessageBundle.BUNDLE.unblockingACall(cause);
            }
            if (response == null) {
                throw ActiveMQClientMessageBundle.BUNDLE.timedOutSendingPacket(connection.getBlockingCallTimeout(), packet.getType());
            }
            if (response.getType() == PacketImpl.EXCEPTION) {
                final ActiveMQExceptionMessage mem = (ActiveMQExceptionMessage) response;
                ActiveMQException e = mem.getException();
                e.fillInStackTrace();
                throw e;
            }
        } finally {
            lock.unlock();
        }
        return response;
    }
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQExceptionMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ActiveMQExceptionMessage) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Aggregations

ActiveMQExceptionMessage (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ActiveMQExceptionMessage)10 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)6 ActiveMQInternalErrorException (org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException)3 ActiveMQClusterSecurityException (org.apache.activemq.artemis.api.core.ActiveMQClusterSecurityException)2 ActiveMQSecurityException (org.apache.activemq.artemis.api.core.ActiveMQSecurityException)2 Packet (org.apache.activemq.artemis.core.protocol.core.Packet)2 ServerSessionPacketHandler (org.apache.activemq.artemis.core.protocol.core.ServerSessionPacketHandler)2 IOException (java.io.IOException)1 List (java.util.List)1 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)1 ActiveMQIOErrorException (org.apache.activemq.artemis.api.core.ActiveMQIOErrorException)1 ActiveMQInterruptedException (org.apache.activemq.artemis.api.core.ActiveMQInterruptedException)1 ActiveMQQueueMaxConsumerLimitReached (org.apache.activemq.artemis.api.core.ActiveMQQueueMaxConsumerLimitReached)1 RoutingType (org.apache.activemq.artemis.api.core.RoutingType)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 ActiveMQXAException (org.apache.activemq.artemis.core.exception.ActiveMQXAException)1 OperationContext (org.apache.activemq.artemis.core.persistence.OperationContext)1 Channel (org.apache.activemq.artemis.core.protocol.core.Channel)1 PacketImpl (org.apache.activemq.artemis.core.protocol.core.impl.PacketImpl)1 CreateAddressMessage (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.CreateAddressMessage)1