Search in sources :

Example 1 with ClientSessionInternal

use of org.apache.activemq.artemis.core.client.impl.ClientSessionInternal in project activemq-artemis by apache.

the class BridgeImpl method nodeUP.

// To be called by the topology update
// This logic will be updated on the cluster connection
protected void nodeUP(TopologyMember member, boolean last) {
    ClientSessionInternal sessionToUse = session;
    RemotingConnection connectionToUse = sessionToUse != null ? sessionToUse.getConnection() : null;
    if (member != null && this.targetNodeID != null && this.targetNodeID.equals(member.getNodeId())) {
        // this could be an update of the topology say after a backup started
        BridgeImpl.this.targetNode = member;
    } else {
        // we don't need synchronization here, but we need to make sure we won't get a NPE on races
        if (connectionToUse != null && member.isMember(connectionToUse)) {
            this.targetNode = member;
            this.targetNodeID = member.getNodeId();
        }
    }
}
Also used : ClientSessionInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionInternal) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)

Example 2 with ClientSessionInternal

use of org.apache.activemq.artemis.core.client.impl.ClientSessionInternal in project activemq-artemis by apache.

the class ActiveMQRAXAResource method start.

/**
 * Start
 *
 * @param xid   A global transaction identifier
 * @param flags One of TMNOFLAGS, TMJOIN, or TMRESUME
 * @throws XAException An error has occurred
 */
@Override
public void start(final Xid xid, final int flags) throws XAException {
    if (ActiveMQRAXAResource.trace) {
        ActiveMQRALogger.LOGGER.trace("start(" + xid + ", " + flags + ")");
    }
    managedConnection.lock();
    ClientSessionInternal sessionInternal = (ClientSessionInternal) xaResource;
    try {
        try {
            // this resets any tx stuff, we assume here that the tm and jca layer are well behaved when it comes to this
            sessionInternal.resetIfNeeded();
        } catch (ActiveMQException e) {
            ActiveMQRALogger.LOGGER.problemResettingXASession(e);
            XAException xaException = new XAException(XAException.XAER_RMFAIL);
            xaException.initCause(e);
            throw xaException;
        }
        xaResource.start(xid, flags);
    } finally {
        managedConnection.setInManagedTx(true);
        managedConnection.unlock();
    }
}
Also used : ClientSessionInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionInternal) XAException(javax.transaction.xa.XAException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException)

Example 3 with ClientSessionInternal

use of org.apache.activemq.artemis.core.client.impl.ClientSessionInternal in project activemq-artemis by apache.

the class ActiveMQConnection method signalStopToAllSessions.

public synchronized void signalStopToAllSessions() {
    for (ActiveMQSession session : sessions) {
        ClientSession coreSession = session.getCoreSession();
        if (coreSession instanceof ClientSessionInternal) {
            ClientSessionInternal internalSession = (ClientSessionInternal) coreSession;
            internalSession.setStopSignal();
        }
    }
}
Also used : ClientSessionInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionInternal) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession)

Example 4 with ClientSessionInternal

use of org.apache.activemq.artemis.core.client.impl.ClientSessionInternal in project activemq-artemis by apache.

the class FailureDeadlockTest method testDeadlock.

// https://jira.jboss.org/jira/browse/JBMESSAGING-1702
// Test that two failures concurrently executing and calling the same exception listener
// don't deadlock
@Test
public void testDeadlock() throws Exception {
    for (int i = 0; i < 100; i++) {
        final Connection conn1 = cf1.createConnection();
        Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
        RemotingConnection rc1 = ((ClientSessionInternal) ((ActiveMQSession) sess1).getCoreSession()).getConnection();
        final Connection conn2 = cf2.createConnection();
        Session sess2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
        RemotingConnection rc2 = ((ClientSessionInternal) ((ActiveMQSession) sess2).getCoreSession()).getConnection();
        ExceptionListener listener1 = new ExceptionListener() {

            @Override
            public void onException(final JMSException exception) {
                try {
                    conn2.close();
                } catch (Exception e) {
                    FailureDeadlockTest.log.error("Failed to close connection2", e);
                }
            }
        };
        conn1.setExceptionListener(listener1);
        conn2.setExceptionListener(listener1);
        Failer f1 = new Failer(rc1);
        Failer f2 = new Failer(rc2);
        f1.start();
        f2.start();
        f1.join();
        f2.join();
        conn1.close();
        conn2.close();
    }
}
Also used : ClientSessionInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionInternal) Connection(javax.jms.Connection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) ExceptionListener(javax.jms.ExceptionListener) JMSException(javax.jms.JMSException) JMSException(javax.jms.JMSException) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) Session(javax.jms.Session) ActiveMQSession(org.apache.activemq.artemis.jms.client.ActiveMQSession) Test(org.junit.Test)

Example 5 with ClientSessionInternal

use of org.apache.activemq.artemis.core.client.impl.ClientSessionInternal in project activemq-artemis by apache.

the class FailureDeadlockTest method testUsingDeadConnection.

// https://jira.jboss.org/jira/browse/JBMESSAGING-1703
// Make sure that failing a connection removes it from the connection manager and can't be returned in a subsequent
// call
@Test
public void testUsingDeadConnection() throws Exception {
    for (int i = 0; i < 100; i++) {
        final Connection conn1 = cf1.createConnection();
        Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
        RemotingConnection rc1 = ((ClientSessionInternal) ((ActiveMQSession) sess1).getCoreSession()).getConnection();
        rc1.fail(new ActiveMQNotConnectedException("blah"));
        try {
            conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
            Assert.fail("should throw exception");
        } catch (JMSException e) {
        // pass
        }
        conn1.close();
    }
}
Also used : ClientSessionInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionInternal) Connection(javax.jms.Connection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) JMSException(javax.jms.JMSException) Session(javax.jms.Session) ActiveMQSession(org.apache.activemq.artemis.jms.client.ActiveMQSession) Test(org.junit.Test)

Aggregations

ClientSessionInternal (org.apache.activemq.artemis.core.client.impl.ClientSessionInternal)46 Test (org.junit.Test)35 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)21 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)20 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)19 ActiveMQNotConnectedException (org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException)17 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)13 Connection (javax.jms.Connection)12 Session (javax.jms.Session)12 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)11 ClientSessionFactoryInternal (org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal)11 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)10 MessageConsumer (javax.jms.MessageConsumer)8 MessageProducer (javax.jms.MessageProducer)8 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)8 CountDownLatch (java.util.concurrent.CountDownLatch)7 TextMessage (javax.jms.TextMessage)7 ActiveMQSession (org.apache.activemq.artemis.jms.client.ActiveMQSession)7 XAConnection (javax.jms.XAConnection)5 XASession (javax.jms.XASession)5