Search in sources :

Example 6 with Connection

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;
}
Also used : CoreRemotingConnection(org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) Connection(org.apache.activemq.artemis.spi.core.remoting.Connection)

Example 7 with Connection

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);
}
Also used : RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) CoreRemotingConnection(org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection) Connection(org.apache.activemq.artemis.spi.core.remoting.Connection) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Example 8 with Connection

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;
}
Also used : CloseListener(org.apache.activemq.artemis.core.remoting.CloseListener) FailureListener(org.apache.activemq.artemis.core.remoting.FailureListener) NettyConnection(org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnection) Connection(org.apache.activemq.artemis.spi.core.remoting.Connection)

Example 9 with Connection

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;
    }
}
Also used : BaseConnectionLifeCycleListener(org.apache.activemq.artemis.spi.core.remoting.BaseConnectionLifeCycleListener) ClientConnectionLifeCycleListener(org.apache.activemq.artemis.spi.core.remoting.ClientConnectionLifeCycleListener) ConnectionLifeCycleListener(org.apache.activemq.artemis.spi.core.remoting.ConnectionLifeCycleListener) Connection(org.apache.activemq.artemis.spi.core.remoting.Connection)

Example 10 with Connection

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);
}
Also used : ActiveMQComponent(org.apache.activemq.artemis.core.server.ActiveMQComponent) HashMap(java.util.HashMap) NettyAcceptor(org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptor) Connection(org.apache.activemq.artemis.spi.core.remoting.Connection) ServerConnectionLifeCycleListener(org.apache.activemq.artemis.spi.core.remoting.ServerConnectionLifeCycleListener) BufferHandler(org.apache.activemq.artemis.spi.core.remoting.BufferHandler) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ProtocolManager(org.apache.activemq.artemis.spi.core.protocol.ProtocolManager) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Aggregations

Connection (org.apache.activemq.artemis.spi.core.remoting.Connection)11 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)4 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)4 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)3 CoreRemotingConnection (org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection)3 HashMap (java.util.HashMap)2 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 NettyAcceptor (org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptor)2 NettyConnection (org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnection)2 ActiveMQComponent (org.apache.activemq.artemis.core.server.ActiveMQComponent)2 ClusterConnection (org.apache.activemq.artemis.core.server.cluster.ClusterConnection)2 Notification (org.apache.activemq.artemis.core.server.management.Notification)2 ProtocolManager (org.apache.activemq.artemis.spi.core.protocol.ProtocolManager)2 BufferHandler (org.apache.activemq.artemis.spi.core.remoting.BufferHandler)2 ServerConnectionLifeCycleListener (org.apache.activemq.artemis.spi.core.remoting.ServerConnectionLifeCycleListener)2 TypedProperties (org.apache.activemq.artemis.utils.collections.TypedProperties)2 Test (org.junit.Test)2 Channel (io.netty.channel.Channel)1 ChannelHandler (io.netty.channel.ChannelHandler)1 ServerChannel (io.netty.channel.ServerChannel)1