Search in sources :

Example 6 with CoreRemotingConnection

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

the class ReplicationTest method testConnectIntoNonBackup.

@Test
public void testConnectIntoNonBackup() throws Exception {
    setupServer(false);
    try {
        ClientSessionFactory sf = createSessionFactory(locator);
        manager = new ReplicationManager((CoreRemotingConnection) sf.getConnection(), sf.getServerLocator().getCallTimeout(), sf.getServerLocator().getCallTimeout(), factory);
        addActiveMQComponent(manager);
        manager.start();
        Assert.fail("Exception was expected");
    } catch (ActiveMQNotConnectedException nce) {
    // ok
    } catch (ActiveMQException expected) {
        fail("Invalid Exception type:" + expected.getType());
    }
}
Also used : ReplicationManager(org.apache.activemq.artemis.core.replication.ReplicationManager) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) CoreRemotingConnection(org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) Test(org.junit.Test)

Example 7 with CoreRemotingConnection

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

the class ActiveMQSessionContext method sendSessionSendContinuationMessage.

private static int sendSessionSendContinuationMessage(Channel channel, Message msgI, long messageBodySize, boolean sendBlocking, boolean lastChunk, byte[] chunk, SendAcknowledgementHandler messageHandler) throws ActiveMQException {
    final boolean requiresResponse = lastChunk && sendBlocking;
    final SessionSendContinuationMessage chunkPacket = new SessionSendContinuationMessage(msgI, chunk, !lastChunk, requiresResponse, messageBodySize, messageHandler);
    final int expectedEncodeSize = chunkPacket.expectedEncodeSize();
    // perform a weak form of flow control to avoid OOM on tight loops
    final CoreRemotingConnection connection = channel.getConnection();
    final long blockingCallTimeoutMillis = Math.max(0, connection.getBlockingCallTimeout());
    final long startFlowControl = System.nanoTime();
    try {
        final boolean isWritable = connection.blockUntilWritable(expectedEncodeSize, blockingCallTimeoutMillis);
        if (!isWritable) {
            final long endFlowControl = System.nanoTime();
            final long elapsedFlowControl = endFlowControl - startFlowControl;
            final long elapsedMillis = TimeUnit.NANOSECONDS.toMillis(elapsedFlowControl);
            ActiveMQClientLogger.LOGGER.timeoutStreamingLargeMessage();
            logger.debug("try to write " + expectedEncodeSize + " bytes after blocked " + elapsedMillis + " ms on a not writable connection: [" + connection.getID() + "]");
        }
        if (requiresResponse) {
            // When sending it blocking, only the last chunk will be blocking.
            channel.sendBlocking(chunkPacket, PacketImpl.NULL_RESPONSE);
        } else {
            channel.send(chunkPacket);
        }
        return chunkPacket.getPacketSize();
    } catch (Throwable e) {
        throw new ActiveMQException(e.getMessage());
    }
}
Also used : SessionSendContinuationMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendContinuationMessage) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) CoreRemotingConnection(org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection)

Example 8 with CoreRemotingConnection

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

the class RemotingServiceImpl method freeze.

@Override
public synchronized void freeze(final String scaleDownNodeID, final CoreRemotingConnection connectionToKeepOpen) {
    if (!started)
        return;
    failureCheckAndFlushThread.close(false);
    HashMap<Object, ConnectionEntry> connectionEntries = new HashMap<>(connections);
    // complete then send a disconnect packet
    for (Entry<Object, ConnectionEntry> entry : connectionEntries.entrySet()) {
        RemotingConnection conn = entry.getValue().connection;
        if (conn.equals(connectionToKeepOpen))
            continue;
        if (logger.isTraceEnabled()) {
            logger.trace("Sending connection.disconnection packet to " + conn);
        }
        if (!conn.isClient()) {
            conn.disconnect(scaleDownNodeID, false);
            removeConnection(entry.getKey());
        }
    }
}
Also used : ConnectionEntry(org.apache.activemq.artemis.spi.core.protocol.ConnectionEntry) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) CoreRemotingConnection(org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)

Aggregations

CoreRemotingConnection (org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection)8 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)3 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)2 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)2 SessionFailureListener (org.apache.activemq.artemis.api.core.client.SessionFailureListener)2 ConnectionEntry (org.apache.activemq.artemis.spi.core.protocol.ConnectionEntry)2 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Executor (java.util.concurrent.Executor)1 ActiveMQNotConnectedException (org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException)1 Interceptor (org.apache.activemq.artemis.api.core.Interceptor)1 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)1 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)1 Configuration (org.apache.activemq.artemis.core.config.Configuration)1 ServerPacketDecoder (org.apache.activemq.artemis.core.protocol.ServerPacketDecoder)1 Channel (org.apache.activemq.artemis.core.protocol.core.Channel)1