use of org.apache.activemq.artemis.spi.core.remoting.Connection in project activemq-artemis by apache.
the class ClientSessionFactoryImpl method openTransportConnection.
protected Connection openTransportConnection(final Connector connector) {
connector.start();
Connection transportConnection = connector.createConnection();
if (transportConnection == null) {
if (logger.isDebugEnabled()) {
logger.debug("Connector towards " + connector + " failed");
}
try {
connector.close();
} catch (Throwable t) {
}
}
return transportConnection;
}
use of org.apache.activemq.artemis.spi.core.remoting.Connection in project activemq-artemis by apache.
the class ActiveMQSessionContext method sendPacketWithoutLock.
private void sendPacketWithoutLock(final Channel parameterChannel, final Packet packet) {
packet.setChannelID(parameterChannel.getID());
Connection conn = parameterChannel.getConnection().getTransportConnection();
ActiveMQBuffer buffer = packet.encode(this.getCoreConnection());
conn.write(buffer, false, false);
}
use of org.apache.activemq.artemis.spi.core.remoting.Connection in project activemq-artemis by apache.
the class ServerSessionPacketHandler method internaltransferConnection.
private int internaltransferConnection(final CoreRemotingConnection newConnection, final int lastReceivedCommandID) {
// We need to disable delivery on all the consumers while the transfer is occurring- otherwise packets might get
// delivered
// after the channel has transferred but *before* packets have been replayed - this will give the client the wrong
// sequence of packets.
// It is not sufficient to just stop the session, since right after stopping the session, another session start
// might be executed
// before we have transferred the connection, leaving it in a started state
session.setTransferring(true);
List<CloseListener> closeListeners = remotingConnection.removeCloseListeners();
List<FailureListener> failureListeners = remotingConnection.removeFailureListeners();
// Note. We do not destroy the replicating connection here. In the case the live server has really crashed
// then the connection will get cleaned up anyway when the server ping timeout kicks in.
// In the case the live server is really still up, i.e. a split brain situation (or in tests), then closing
// the replicating connection will cause the outstanding responses to be be replayed on the live server,
// if these reach the client who then subsequently fails over, on reconnection to backup, it will have
// received responses that the backup did not know about.
channel.transferConnection(newConnection);
newConnection.syncIDGeneratorSequence(remotingConnection.getIDGeneratorSequence());
Connection oldTransportConnection = remotingConnection.getTransportConnection();
remotingConnection = newConnection;
remotingConnection.setCloseListeners(closeListeners);
remotingConnection.setFailureListeners(failureListeners);
int serverLastReceivedCommandID = channel.getLastConfirmedCommandID();
channel.replayCommands(lastReceivedCommandID);
channel.setTransferring(false);
session.setTransferring(false);
// We do this because the old connection could be out of credits on netty
// this will force anything to resume after the reattach through the ReadyListener callbacks
oldTransportConnection.fireReady(true);
return serverLastReceivedCommandID;
}
use of org.apache.activemq.artemis.spi.core.remoting.Connection in project activemq-artemis by apache.
the class InVMConnector method createConnection.
@Override
public Connection createConnection() {
if (InVMConnector.failOnCreateConnection) {
InVMConnector.incFailures();
logger.debug("Returning null on InVMConnector for tests");
// For testing only
return null;
}
if (acceptor == null) {
return null;
}
if (acceptor.getConnectionsAllowed() == -1 || acceptor.getConnectionCount() < acceptor.getConnectionsAllowed()) {
Connection conn = internalCreateConnection(acceptor.getHandler(), new Listener(), acceptor.getExecutorFactory().getExecutor());
acceptor.connect((String) conn.getID(), handler, this, executorFactory.getExecutor());
return conn;
} else {
if (logger.isDebugEnabled()) {
logger.debug(new StringBuilder().append("Connection limit of ").append(acceptor.getConnectionsAllowed()).append(" reached. Refusing connection."));
}
return null;
}
}
use of org.apache.activemq.artemis.spi.core.remoting.Connection in project activemq-artemis by apache.
the class NettyAcceptorTest method testStartStop.
@Test
public void testStartStop() throws Exception {
BufferHandler handler = new BufferHandler() {
@Override
public void bufferReceived(final Object connectionID, final ActiveMQBuffer buffer) {
}
};
Map<String, Object> params = new HashMap<>();
ServerConnectionLifeCycleListener listener = new ServerConnectionLifeCycleListener() {
@Override
public void connectionException(final Object connectionID, final ActiveMQException me) {
}
@Override
public void connectionDestroyed(final Object connectionID) {
}
@Override
public void connectionCreated(final ActiveMQComponent component, final Connection connection, final ProtocolManager protocol) {
}
@Override
public void connectionReadyForWrites(Object connectionID, boolean ready) {
}
};
pool2 = Executors.newScheduledThreadPool(ActiveMQDefaultConfiguration.getDefaultScheduledThreadPoolMaxSize(), ActiveMQThreadFactory.defaultThreadFactory());
NettyAcceptor acceptor = new NettyAcceptor("netty", null, params, handler, listener, pool2, new HashMap<String, ProtocolManager>());
addActiveMQComponent(acceptor);
acceptor.start();
Assert.assertTrue(acceptor.isStarted());
acceptor.stop();
Assert.assertFalse(acceptor.isStarted());
ActiveMQTestBase.checkFreePort(TransportConstants.DEFAULT_PORT);
acceptor.start();
Assert.assertTrue(acceptor.isStarted());
acceptor.stop();
Assert.assertFalse(acceptor.isStarted());
ActiveMQTestBase.checkFreePort(TransportConstants.DEFAULT_PORT);
pool2.shutdown();
pool2.awaitTermination(1, TimeUnit.SECONDS);
}
Aggregations