Search in sources :

Example 1 with Channel

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

the class ActiveMQClientProtocolManager method createSessionContext.

public SessionContext createSessionContext(Version clientVersion, String name, String username, String password, boolean xa, boolean autoCommitSends, boolean autoCommitAcks, boolean preAcknowledge, int minLargeMessageSize, int confirmationWindowSize) throws ActiveMQException {
    if (!isAlive())
        throw ActiveMQClientMessageBundle.BUNDLE.clientSessionClosed();
    Channel sessionChannel = null;
    CreateSessionResponseMessage response = null;
    boolean retry;
    do {
        retry = false;
        Lock lock = null;
        try {
            lock = lockSessionCreation();
            // We now set a flag saying createSession is executing
            synchronized (inCreateSessionGuard) {
                if (!isAlive())
                    throw ActiveMQClientMessageBundle.BUNDLE.clientSessionClosed();
                inCreateSession = true;
                inCreateSessionLatch = new CountDownLatch(1);
            }
            long sessionChannelID = connection.generateChannelID();
            Packet request = newCreateSessionPacket(clientVersion, name, username, password, xa, autoCommitSends, autoCommitAcks, preAcknowledge, minLargeMessageSize, confirmationWindowSize, sessionChannelID);
            try {
                // channel1 reference here has to go away
                response = (CreateSessionResponseMessage) getChannel1().sendBlocking(request, PacketImpl.CREATESESSION_RESP);
            } catch (ActiveMQException cause) {
                if (!isAlive())
                    throw cause;
                if (cause.getType() == ActiveMQExceptionType.UNBLOCKED) {
                    // This means the thread was blocked on create session and failover unblocked it
                    // so failover could occur
                    retry = true;
                    continue;
                } else {
                    throw cause;
                }
            }
            sessionChannel = connection.getChannel(sessionChannelID, confirmationWindowSize);
        } catch (Throwable t) {
            if (lock != null) {
                lock.unlock();
                lock = null;
            }
            if (t instanceof ActiveMQException) {
                throw (ActiveMQException) t;
            } else {
                throw ActiveMQClientMessageBundle.BUNDLE.failedToCreateSession(t);
            }
        } finally {
            if (lock != null) {
                lock.unlock();
            }
            // Execution has finished so notify any failover thread that may be waiting for us to be done
            inCreateSession = false;
            inCreateSessionLatch.countDown();
        }
    } while (retry);
    sessionChannel.getConnection().setChannelVersion(response.getServerVersion());
    return newSessionContext(name, confirmationWindowSize, sessionChannel, response);
}
Also used : Packet(org.apache.activemq.artemis.core.protocol.core.Packet) CreateSessionResponseMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.CreateSessionResponseMessage) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) Channel(org.apache.activemq.artemis.core.protocol.core.Channel) CountDownLatch(java.util.concurrent.CountDownLatch) Lock(java.util.concurrent.locks.Lock)

Example 2 with Channel

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

the class RemotingConnectionImpl method disconnect.

@Override
public void disconnect(String scaleDownNodeID, final boolean criticalError) {
    Channel channel0 = getChannel(ChannelImpl.CHANNEL_ID.PING.id, -1);
    // And we remove all channels from the connection, this ensures no more packets will be processed after this
    // method is
    // complete
    Set<Channel> allChannels = new HashSet<>(channels.values());
    if (!criticalError) {
        removeAllChannels();
    } else {
        // We can't hold a lock if a critical error is happening...
        // as other threads will be holding the lock while hanging on IO
        channels.clear();
    }
    if (!criticalError) {
        for (Channel channel : allChannels) {
            channel.flushConfirmations();
        }
    }
    Packet disconnect;
    if (channel0.supports(PacketImpl.DISCONNECT_V2)) {
        disconnect = new DisconnectMessage_V2(nodeID, scaleDownNodeID);
    } else {
        disconnect = new DisconnectMessage(nodeID);
    }
    channel0.sendAndFlush(disconnect);
}
Also used : Packet(org.apache.activemq.artemis.core.protocol.core.Packet) DisconnectMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.DisconnectMessage) Channel(org.apache.activemq.artemis.core.protocol.core.Channel) DisconnectMessage_V2(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.DisconnectMessage_V2) HashSet(java.util.HashSet)

Example 3 with Channel

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

the class CoreProtocolManager method createConnectionEntry.

@Override
public ConnectionEntry createConnectionEntry(final Acceptor acceptorUsed, final Connection connection) {
    final Configuration config = server.getConfiguration();
    Executor connectionExecutor = server.getExecutorFactory().getExecutor();
    final CoreRemotingConnection rc = new RemotingConnectionImpl(new ServerPacketDecoder(), connection, incomingInterceptors, outgoingInterceptors, config.isAsyncConnectionExecutionEnabled() ? connectionExecutor : null, server.getNodeID());
    Channel channel1 = rc.getChannel(CHANNEL_ID.SESSION.id, -1);
    ChannelHandler handler = new ActiveMQPacketHandler(this, server, channel1, rc);
    channel1.setHandler(handler);
    long ttl = ActiveMQClient.DEFAULT_CONNECTION_TTL;
    if (config.getConnectionTTLOverride() != -1) {
        ttl = config.getConnectionTTLOverride();
    }
    final ConnectionEntry entry = new ConnectionEntry(rc, connectionExecutor, System.currentTimeMillis(), ttl);
    final Channel channel0 = rc.getChannel(ChannelImpl.CHANNEL_ID.PING.id, -1);
    channel0.setHandler(new LocalChannelHandler(config, entry, channel0, acceptorUsed, rc));
    server.getClusterManager().addClusterChannelHandler(rc.getChannel(CHANNEL_ID.CLUSTER.id, -1), acceptorUsed, rc, server.getActivation());
    return entry;
}
Also used : Executor(java.util.concurrent.Executor) Configuration(org.apache.activemq.artemis.core.config.Configuration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) ConnectionEntry(org.apache.activemq.artemis.spi.core.protocol.ConnectionEntry) CoreRemotingConnection(org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection) Channel(org.apache.activemq.artemis.core.protocol.core.Channel) ChannelHandler(org.apache.activemq.artemis.core.protocol.core.ChannelHandler) ServerPacketDecoder(org.apache.activemq.artemis.core.protocol.ServerPacketDecoder)

Example 4 with Channel

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

the class BackupSyncDelay method intercept.

@Override
public boolean intercept(Packet packet, RemotingConnection connection) throws ActiveMQException {
    if (packet.getType() == PacketImpl.BACKUP_REGISTRATION) {
        try {
            SharedNothingBackupActivation activation = (SharedNothingBackupActivation) backup.getActivation();
            ReplicationEndpoint repEnd = activation.getReplicationEndpoint();
            handler.addSubHandler(repEnd);
            Channel repChannel = repEnd.getChannel();
            repChannel.setHandler(handler);
            handler.setChannel(repChannel);
            live.getRemotingService().removeIncomingInterceptor(this);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    return true;
}
Also used : ReplicationEndpoint(org.apache.activemq.artemis.core.replication.ReplicationEndpoint) Channel(org.apache.activemq.artemis.core.protocol.core.Channel) SharedNothingBackupActivation(org.apache.activemq.artemis.core.server.impl.SharedNothingBackupActivation) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException)

Example 5 with Channel

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

Channel (org.apache.activemq.artemis.core.protocol.core.Channel)12 Packet (org.apache.activemq.artemis.core.protocol.core.Packet)5 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)4 CreateSessionResponseMessage (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.CreateSessionResponseMessage)3 HashSet (java.util.HashSet)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Executor (java.util.concurrent.Executor)1 Lock (java.util.concurrent.locks.Lock)1 ActiveMQClusterSecurityException (org.apache.activemq.artemis.api.core.ActiveMQClusterSecurityException)1 ActiveMQIncompatibleClientServerException (org.apache.activemq.artemis.api.core.ActiveMQIncompatibleClientServerException)1 ActiveMQInternalErrorException (org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException)1 ActiveMQRemoteDisconnectException (org.apache.activemq.artemis.api.core.ActiveMQRemoteDisconnectException)1 ActiveMQSecurityException (org.apache.activemq.artemis.api.core.ActiveMQSecurityException)1 RoutingType (org.apache.activemq.artemis.api.core.RoutingType)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)1 Configuration (org.apache.activemq.artemis.core.config.Configuration)1 OperationContext (org.apache.activemq.artemis.core.persistence.OperationContext)1 ServerPacketDecoder (org.apache.activemq.artemis.core.protocol.ServerPacketDecoder)1 ChannelHandler (org.apache.activemq.artemis.core.protocol.core.ChannelHandler)1