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);
}
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);
}
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);
}
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();
}
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);
}
Aggregations