Search in sources :

Example 6 with Packet

use of org.apache.activemq.artemis.core.protocol.core.Packet in project activemq-artemis by apache.

the class ServerPacketDecoder method slowPathDecode.

// separating for performance reasons
private Packet slowPathDecode(ActiveMQBuffer in, byte packetType, CoreRemotingConnection connection) {
    Packet packet;
    switch(packetType) {
        case SESS_SEND_LARGE:
            {
                packet = new SessionSendLargeMessage(new CoreMessage());
                break;
            }
        case REPLICATION_APPEND:
            {
                packet = new ReplicationAddMessage();
                break;
            }
        case REPLICATION_APPEND_TX:
            {
                packet = new ReplicationAddTXMessage();
                break;
            }
        case REPLICATION_DELETE:
            {
                packet = new ReplicationDeleteMessage();
                break;
            }
        case REPLICATION_DELETE_TX:
            {
                packet = new ReplicationDeleteTXMessage();
                break;
            }
        case REPLICATION_PREPARE:
            {
                packet = new ReplicationPrepareMessage();
                break;
            }
        case REPLICATION_COMMIT_ROLLBACK:
            {
                packet = new ReplicationCommitMessage();
                break;
            }
        case REPLICATION_RESPONSE:
            {
                packet = new ReplicationResponseMessage();
                break;
            }
        case REPLICATION_RESPONSE_V2:
            {
                packet = new ReplicationResponseMessageV2();
                break;
            }
        case REPLICATION_PAGE_WRITE:
            {
                packet = new ReplicationPageWriteMessage();
                break;
            }
        case REPLICATION_PAGE_EVENT:
            {
                packet = new ReplicationPageEventMessage();
                break;
            }
        case REPLICATION_LARGE_MESSAGE_BEGIN:
            {
                packet = new ReplicationLargeMessageBeginMessage();
                break;
            }
        case REPLICATION_LARGE_MESSAGE_END:
            {
                packet = new ReplicationLargeMessageEndMessage();
                break;
            }
        case REPLICATION_LARGE_MESSAGE_WRITE:
            {
                packet = new ReplicationLargeMessageWriteMessage();
                break;
            }
        case PacketImpl.BACKUP_REGISTRATION:
            {
                packet = new BackupRegistrationMessage();
                break;
            }
        case PacketImpl.BACKUP_REGISTRATION_FAILED:
            {
                packet = new BackupReplicationStartFailedMessage();
                break;
            }
        case PacketImpl.REPLICATION_START_FINISH_SYNC:
            {
                packet = new ReplicationStartSyncMessage();
                break;
            }
        case PacketImpl.REPLICATION_SYNC_FILE:
            {
                packet = new ReplicationSyncFileMessage();
                break;
            }
        case PacketImpl.REPLICATION_SCHEDULED_FAILOVER:
            {
                packet = new ReplicationLiveIsStoppingMessage();
                break;
            }
        case CLUSTER_CONNECT:
            {
                packet = new ClusterConnectMessage();
                break;
            }
        case CLUSTER_CONNECT_REPLY:
            {
                packet = new ClusterConnectReplyMessage();
                break;
            }
        case NODE_ANNOUNCE:
            {
                packet = new NodeAnnounceMessage();
                break;
            }
        case BACKUP_REQUEST:
            {
                packet = new BackupRequestMessage();
                break;
            }
        case BACKUP_REQUEST_RESPONSE:
            {
                packet = new BackupResponseMessage();
                break;
            }
        case QUORUM_VOTE:
            {
                packet = new QuorumVoteMessage();
                break;
            }
        case QUORUM_VOTE_REPLY:
            {
                packet = new QuorumVoteReplyMessage();
                break;
            }
        case SCALEDOWN_ANNOUNCEMENT:
            {
                packet = new ScaleDownAnnounceMessage();
                break;
            }
        default:
            {
                packet = super.decode(packetType, connection);
            }
    }
    packet.decode(in);
    return packet;
}
Also used : QuorumVoteMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.QuorumVoteMessage) ReplicationAddTXMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationAddTXMessage) ReplicationLargeMessageWriteMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationLargeMessageWriteMessage) ReplicationLargeMessageBeginMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationLargeMessageBeginMessage) BackupRequestMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.BackupRequestMessage) ReplicationCommitMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationCommitMessage) ReplicationPageWriteMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationPageWriteMessage) ReplicationLargeMessageEndMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationLargeMessageEndMessage) ReplicationAddMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationAddMessage) BackupResponseMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.BackupResponseMessage) ReplicationLiveIsStoppingMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationLiveIsStoppingMessage) SessionSendLargeMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendLargeMessage) BackupRegistrationMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.BackupRegistrationMessage) Packet(org.apache.activemq.artemis.core.protocol.core.Packet) ClusterConnectReplyMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ClusterConnectReplyMessage) BackupReplicationStartFailedMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.BackupReplicationStartFailedMessage) ReplicationDeleteMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationDeleteMessage) ScaleDownAnnounceMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ScaleDownAnnounceMessage) QuorumVoteReplyMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.QuorumVoteReplyMessage) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) ReplicationPageEventMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationPageEventMessage) NodeAnnounceMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.NodeAnnounceMessage) ReplicationSyncFileMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationSyncFileMessage) ClusterConnectMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ClusterConnectMessage) ReplicationPrepareMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationPrepareMessage) ReplicationDeleteTXMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationDeleteTXMessage) ReplicationStartSyncMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationStartSyncMessage) ReplicationResponseMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationResponseMessage) ReplicationResponseMessageV2(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationResponseMessageV2)

Example 7 with Packet

use of org.apache.activemq.artemis.core.protocol.core.Packet 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 8 with Packet

use of org.apache.activemq.artemis.core.protocol.core.Packet in project activemq-artemis by apache.

the class ActiveMQSessionContext method xaStart.

@Override
public void xaStart(Xid xid, int flags) throws XAException, ActiveMQException {
    Packet packet;
    if (flags == XAResource.TMJOIN) {
        packet = new SessionXAJoinMessage(xid);
    } else if (flags == XAResource.TMRESUME) {
        packet = new SessionXAResumeMessage(xid);
    } else if (flags == XAResource.TMNOFLAGS) {
        // Don't need to flush since the previous end will have done this
        packet = new SessionXAStartMessage(xid);
    } else {
        throw new XAException(XAException.XAER_INVAL);
    }
    SessionXAResponseMessage response = (SessionXAResponseMessage) sessionChannel.sendBlocking(packet, PacketImpl.SESS_XA_RESP);
    if (response.isError()) {
        ActiveMQClientLogger.LOGGER.errorCallingStart(response.getMessage(), response.getResponseCode());
        throw new XAException(response.getResponseCode());
    }
}
Also used : SessionXAResponseMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionXAResponseMessage) Packet(org.apache.activemq.artemis.core.protocol.core.Packet) XAException(javax.transaction.xa.XAException) SessionXAJoinMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionXAJoinMessage) SessionXAResumeMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionXAResumeMessage) SessionXAStartMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionXAStartMessage)

Example 9 with Packet

use of org.apache.activemq.artemis.core.protocol.core.Packet in project activemq-artemis by apache.

the class ChannelImpl method clearUpTo.

private void clearUpTo(final int lastReceivedCommandID) {
    final int numberToClear = 1 + lastReceivedCommandID - firstStoredCommandID;
    if (logger.isTraceEnabled()) {
        logger.trace("RemotingConnectionID=" + (connection == null ? "NULL" : connection.getID()) + " ChannelImpl::clearUpTo lastReceived commandID=" + lastReceivedCommandID + " first commandID=" + firstStoredCommandID + " number to clear " + numberToClear);
    }
    for (int i = 0; i < numberToClear; i++) {
        final Packet packet = resendCache.poll();
        if (packet == null) {
            ActiveMQClientLogger.LOGGER.cannotFindPacketToClear(lastReceivedCommandID, firstStoredCommandID);
            firstStoredCommandID = lastReceivedCommandID + 1;
            return;
        }
        if (logger.isTraceEnabled()) {
            logger.trace("RemotingConnectionID=" + connection.getID() + " ChannelImpl::clearUpTo confirming " + packet + " towards " + commandConfirmationHandler);
        }
        if (commandConfirmationHandler != null) {
            commandConfirmationHandler.commandConfirmed(packet);
        }
    }
    firstStoredCommandID += numberToClear;
}
Also used : Packet(org.apache.activemq.artemis.core.protocol.core.Packet)

Example 10 with Packet

use of org.apache.activemq.artemis.core.protocol.core.Packet in project activemq-artemis by apache.

the class ChannelImpl method flushConfirmations.

// Needs to be synchronized since can be called by remoting service timer thread too for timeout flush
@Override
public synchronized void flushConfirmations() {
    if (resendCache != null && receivedBytes != 0) {
        receivedBytes = 0;
        final Packet confirmed = new PacketsConfirmedMessage(lastConfirmedCommandID.get());
        confirmed.setChannelID(id);
        if (logger.isTraceEnabled()) {
            logger.trace("RemotingConnectionID=" + (connection == null ? "NULL" : connection.getID()) + " ChannelImpl::flushConfirmation flushing confirmation " + confirmed);
        }
        doWrite(confirmed);
    }
}
Also used : Packet(org.apache.activemq.artemis.core.protocol.core.Packet) PacketsConfirmedMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.PacketsConfirmedMessage)

Aggregations

Packet (org.apache.activemq.artemis.core.protocol.core.Packet)35 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)16 Interceptor (org.apache.activemq.artemis.api.core.Interceptor)11 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)11 CountDownLatch (java.util.concurrent.CountDownLatch)10 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)10 Test (org.junit.Test)10 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)8 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)7 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)5 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)5 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)5 Channel (org.apache.activemq.artemis.core.protocol.core.Channel)5 ArrayList (java.util.ArrayList)3 XAException (javax.transaction.xa.XAException)3 ActiveMQInternalErrorException (org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException)3 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)3 CreateSessionResponseMessage (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.CreateSessionResponseMessage)3 SessionProducerCreditsMessage (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionProducerCreditsMessage)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2