Search in sources :

Example 1 with Packet

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

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

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

the class CoreSessionCallback method sendProducerCreditsFailMessage.

@Override
public void sendProducerCreditsFailMessage(int credits, SimpleString address) {
    Packet packet = new SessionProducerCreditsFailMessage(credits, address);
    channel.send(packet);
}
Also used : Packet(org.apache.activemq.artemis.core.protocol.core.Packet) SessionProducerCreditsFailMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionProducerCreditsFailMessage)

Example 4 with Packet

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

the class CoreSessionCallback method sendLargeMessageContinuation.

@Override
public int sendLargeMessageContinuation(ServerConsumer consumer, byte[] body, boolean continues, boolean requiresResponse) {
    Packet packet = new SessionReceiveContinuationMessage(consumer.getID(), body, continues, requiresResponse);
    channel.send(packet);
    return packet.getPacketSize();
}
Also used : Packet(org.apache.activemq.artemis.core.protocol.core.Packet) SessionReceiveContinuationMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionReceiveContinuationMessage)

Example 5 with Packet

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

the class CoreSessionCallback method sendProducerCreditsMessage.

@Override
public void sendProducerCreditsMessage(int credits, SimpleString address) {
    Packet packet = new SessionProducerCreditsMessage(credits, address);
    channel.send(packet);
}
Also used : Packet(org.apache.activemq.artemis.core.protocol.core.Packet) SessionProducerCreditsMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionProducerCreditsMessage)

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