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