use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.
the class ActiveMQServerImpl method createSession.
@Override
public ServerSession createSession(final String name, final String username, final String password, final int minLargeMessageSize, final RemotingConnection connection, final boolean autoCommitSends, final boolean autoCommitAcks, final boolean preAcknowledge, final boolean xa, final String defaultAddress, final SessionCallback callback, final boolean autoCreateQueues, final OperationContext context, final Map<SimpleString, RoutingType> prefixes) throws Exception {
String validatedUser = "";
if (securityStore != null) {
validatedUser = securityStore.authenticate(username, password, connection);
}
checkSessionLimit(validatedUser);
callBrokerPlugins(hasBrokerPlugins() ? plugin -> plugin.beforeCreateSession(name, username, minLargeMessageSize, connection, autoCommitSends, autoCommitAcks, preAcknowledge, xa, defaultAddress, callback, autoCreateQueues, context, prefixes) : null);
final ServerSessionImpl session = internalCreateSession(name, username, password, validatedUser, minLargeMessageSize, connection, autoCommitSends, autoCommitAcks, preAcknowledge, xa, defaultAddress, callback, context, autoCreateQueues, prefixes);
sessions.put(name, session);
callBrokerPlugins(hasBrokerPlugins() ? plugin -> plugin.afterCreateSession(session) : null);
return session;
}
use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.
the class ActiveMQServerImpl method destroyConnectionWithSessionMetadata.
@Override
public String destroyConnectionWithSessionMetadata(String metaKey, String parameterValue) throws Exception {
StringBuffer operationsExecuted = new StringBuffer();
try {
operationsExecuted.append("**************************************************************************************************\n");
operationsExecuted.append(ActiveMQMessageBundle.BUNDLE.destroyConnectionWithSessionMetadataHeader(metaKey, parameterValue) + "\n");
Set<ServerSession> allSessions = getSessions();
ServerSession sessionFound = null;
for (ServerSession session : allSessions) {
try {
String value = session.getMetaData(metaKey);
if (value != null && value.equals(parameterValue)) {
sessionFound = session;
operationsExecuted.append(ActiveMQMessageBundle.BUNDLE.destroyConnectionWithSessionMetadataClosingConnection(sessionFound.toString()) + "\n");
RemotingConnection conn = session.getRemotingConnection();
if (conn != null) {
conn.fail(ActiveMQMessageBundle.BUNDLE.destroyConnectionWithSessionMetadataSendException(metaKey, parameterValue));
}
session.close(true);
sessions.remove(session.getName());
}
} catch (Throwable e) {
ActiveMQServerLogger.LOGGER.unableDestroyConnectionWithSessionMetadata(e);
}
}
if (sessionFound == null) {
operationsExecuted.append(ActiveMQMessageBundle.BUNDLE.destroyConnectionWithSessionMetadataNoSessionFound(metaKey, parameterValue) + "\n");
}
operationsExecuted.append("**************************************************************************************************");
return operationsExecuted.toString();
} finally {
// This operation is critical for the knowledge of the admin, so we need to add info logs for later knowledge
ActiveMQServerLogger.LOGGER.onDestroyConnectionWithSessionMetadata(operationsExecuted.toString());
}
}
use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection 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();
}
}
use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection 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();
}
}
use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.
the class GroupingTest method testGroupingRollbackOnClose.
@Test
@BMRules(rules = { @BMRule(name = "trace clientsessionimpl commit", targetClass = "org.apache.activemq.artemis.core.server.impl.ServerSessionImpl", targetMethod = "rollback", targetLocation = "EXIT", action = "org.apache.activemq.artemis.tests.extras.byteman.GroupingTest.pause();") })
public void testGroupingRollbackOnClose() throws Exception {
Connection sendConnection = null;
Connection connection = null;
Connection connection2 = null;
try {
ActiveMQConnectionFactory fact = (ActiveMQConnectionFactory) getCF();
fact.setReconnectAttempts(0);
// fact.setConsumerWindowSize(1000);
// fact.setTransactionBatchSize(0);
connection = fact.createConnection();
RemotingConnection rc = server.getRemotingService().getConnections().iterator().next();
connection2 = fact.createConnection();
sendConnection = fact.createConnection();
final Session sendSession = sendConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
Session session2 = connection2.createSession(true, Session.SESSION_TRANSACTED);
final MessageProducer producer = sendSession.createProducer(queue);
MessageConsumer consumer1 = session.createConsumer(queue);
MessageConsumer consumer2 = session2.createConsumer(queue);
connection.start();
connection2.start();
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
for (int j = 0; j < 10000; j++) {
TextMessage message = sendSession.createTextMessage();
message.setText("Message" + j);
message.setStringProperty("JMSXGroupID", "foo");
producer.send(message);
}
} catch (JMSException e) {
e.printStackTrace();
}
}
});
t.start();
// consume 5 msgs from 1st first consumer
for (int j = 0; j < 5; j++) {
TextMessage tm = (TextMessage) consumer1.receive(10000);
assertNotNull(tm);
assertEquals("Message" + j, tm.getText());
assertEquals(tm.getStringProperty("JMSXGroupID"), "foo");
}
pause = true;
rc.fail(new ActiveMQNotConnectedException());
pause = false;
for (int j = 0; j < 10000; j++) {
TextMessage tm = (TextMessage) consumer2.receive(5000);
assertNotNull(tm);
assertEquals("Message" + j, tm.getText());
assertEquals(tm.getStringProperty("JMSXGroupID"), "foo");
}
} finally {
if (sendConnection != null) {
sendConnection.close();
}
if (connection2 != null) {
connection2.close();
}
}
}
Aggregations