use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.
the class ProtonClientConnectionManager method connectionException.
@Override
public void connectionException(Object connectionID, ActiveMQException me) {
RemotingConnection connection = connectionMap.get(connectionID);
if (connection != null) {
log.info("Connection " + connection.getRemoteAddress() + " exception: " + me.getMessage());
connection.fail(me);
} else {
log.error("Connection with id " + connectionID + " not found in connectionException");
}
}
use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.
the class ProtonClientConnectionManager method connectionReadyForWrites.
@Override
public void connectionReadyForWrites(Object connectionID, boolean ready) {
RemotingConnection connection = connectionMap.get(connectionID);
if (connection != null) {
log.info("Connection " + connection.getRemoteAddress() + " ready");
connection.getTransportConnection().fireReady(true);
} else {
log.error("Connection with id " + connectionID + " not found in connectionReadyForWrites()!");
}
}
use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.
the class ProtonServerReceiverContext method initialise.
@Override
public void initialise() throws Exception {
super.initialise();
org.apache.qpid.proton.amqp.messaging.Target target = (org.apache.qpid.proton.amqp.messaging.Target) receiver.getRemoteTarget();
// Match the settlement mode of the remote instead of relying on the default of MIXED.
receiver.setSenderSettleMode(receiver.getRemoteSenderSettleMode());
// We don't currently support SECOND so enforce that the answer is anlways FIRST
receiver.setReceiverSettleMode(ReceiverSettleMode.FIRST);
RoutingType defRoutingType;
if (target != null) {
if (target.getDynamic()) {
// if dynamic we have to create the node (queue) and set the address on the target, the node is temporary and
// will be deleted on closing of the session
address = SimpleString.toSimpleString(sessionSPI.tempQueueName());
defRoutingType = getRoutingType(target.getCapabilities(), address);
try {
sessionSPI.createTemporaryQueue(address, defRoutingType);
} catch (ActiveMQSecurityException e) {
throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.securityErrorCreatingTempDestination(e.getMessage());
} catch (Exception e) {
throw new ActiveMQAMQPInternalErrorException(e.getMessage(), e);
}
expiryPolicy = target.getExpiryPolicy() != null ? target.getExpiryPolicy() : TerminusExpiryPolicy.LINK_DETACH;
target.setAddress(address.toString());
} else {
// the target will have an address unless the remote is requesting an anonymous
// relay in which case the address in the incoming message's to field will be
// matched on receive of the message.
address = SimpleString.toSimpleString(target.getAddress());
if (address != null && !address.isEmpty()) {
defRoutingType = getRoutingType(target.getCapabilities(), address);
try {
if (!sessionSPI.bindingQuery(address, defRoutingType)) {
throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.addressDoesntExist();
}
} catch (ActiveMQAMQPNotFoundException e) {
throw e;
} catch (Exception e) {
log.debug(e.getMessage(), e);
throw new ActiveMQAMQPInternalErrorException(e.getMessage(), e);
}
try {
sessionSPI.check(address, CheckType.SEND, new SecurityAuth() {
@Override
public String getUsername() {
String username = null;
SASLResult saslResult = connection.getSASLResult();
if (saslResult != null) {
username = saslResult.getUser();
}
return username;
}
@Override
public String getPassword() {
String password = null;
SASLResult saslResult = connection.getSASLResult();
if (saslResult != null) {
if (saslResult instanceof PlainSASLResult) {
password = ((PlainSASLResult) saslResult).getPassword();
}
}
return password;
}
@Override
public RemotingConnection getRemotingConnection() {
return connection.connectionCallback.getProtonConnectionDelegate();
}
});
} catch (ActiveMQSecurityException e) {
throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.securityErrorCreatingProducer(e.getMessage());
}
}
}
Symbol[] remoteDesiredCapabilities = receiver.getRemoteDesiredCapabilities();
if (remoteDesiredCapabilities != null) {
List<Symbol> list = Arrays.asList(remoteDesiredCapabilities);
if (list.contains(AmqpSupport.DELAYED_DELIVERY)) {
receiver.setOfferedCapabilities(new Symbol[] { AmqpSupport.DELAYED_DELIVERY });
}
}
}
flow(amqpCredits, minCreditRefresh);
}
use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.
the class SessionClosedOnRemotingConnectionFailureTest method testSessionClosedOnRemotingConnectionFailure.
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testSessionClosedOnRemotingConnectionFailure() throws Exception {
List<TransportConfiguration> connectorConfigs = new ArrayList<>();
connectorConfigs.add(new TransportConfiguration(INVM_CONNECTOR_FACTORY));
jmsServer.createConnectionFactory("cffoo", false, JMSFactoryType.CF, registerConnectors(server, connectorConfigs), null, ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD, ActiveMQClient.DEFAULT_CONNECTION_TTL, ActiveMQClient.DEFAULT_CALL_TIMEOUT, ActiveMQClient.DEFAULT_CALL_FAILOVER_TIMEOUT, ActiveMQClient.DEFAULT_CACHE_LARGE_MESSAGE_CLIENT, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, ActiveMQClient.DEFAULT_COMPRESS_LARGE_MESSAGES, ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE, ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE, ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE, ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE, ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND, ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND, ActiveMQClient.DEFAULT_AUTO_GROUP, ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE, ActiveMQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS, ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_RETRY_INTERVAL, ActiveMQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER, ActiveMQClient.DEFAULT_MAX_RETRY_INTERVAL, 0, ActiveMQClient.DEFAULT_FAILOVER_ON_INITIAL_CONNECTION, null, "/cffoo");
cf = (ConnectionFactory) namingContext.lookup("/cffoo");
Connection conn = cf.createConnection();
Queue queue = createQueue("testQueue");
try {
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer prod = session.createProducer(queue);
MessageConsumer cons = session.createConsumer(queue);
conn.start();
prod.send(session.createMessage());
Assert.assertNotNull(cons.receive());
// Now fail the underlying connection
RemotingConnection connection = ((ClientSessionInternal) ((ActiveMQSession) session).getCoreSession()).getConnection();
connection.fail(new ActiveMQNotConnectedException());
try {
prod.send(session.createMessage());
Assert.fail("Should throw exception");
} catch (JMSException e) {
// assertEquals(ActiveMQException.OBJECT_CLOSED, e.getCode());
}
try {
cons.receive();
Assert.fail("Should throw exception");
} catch (JMSException e) {
// assertEquals(ActiveMQException.OBJECT_CLOSED, e.getCode());
}
session.close();
conn.close();
} finally {
try {
conn.close();
} catch (Throwable igonred) {
}
}
}
use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.
the class JMSReconnectTest method testReconnectOrReattachSameNode.
private void testReconnectOrReattachSameNode(boolean reattach) throws Exception {
ActiveMQConnectionFactory jbcf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));
jbcf.setBlockOnDurableSend(true);
jbcf.setBlockOnNonDurableSend(true);
jbcf.setReconnectAttempts(-1);
if (reattach) {
jbcf.setConfirmationWindowSize(1024 * 1024);
}
// Note we set consumer window size to a value so we can verify that consumer credit re-sending
// works properly on failover
// The value is small enough that credits will have to be resent several time
final int numMessages = 10;
final int bodySize = 1000;
jbcf.setConsumerWindowSize(numMessages * bodySize / 10);
Connection conn = jbcf.createConnection();
MyExceptionListener listener = new MyExceptionListener();
conn.setExceptionListener(listener);
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
ClientSession coreSession = ((ActiveMQSession) sess).getCoreSession();
RemotingConnection coreConn = ((ClientSessionInternal) coreSession).getConnection();
SimpleString jmsQueueName = new SimpleString("myqueue");
coreSession.createQueue(jmsQueueName, RoutingType.ANYCAST, jmsQueueName, null, true);
Queue queue = sess.createQueue("myqueue");
MessageProducer producer = sess.createProducer(queue);
producer.setDeliveryMode(DeliveryMode.PERSISTENT);
MessageConsumer consumer = sess.createConsumer(queue);
byte[] body = RandomUtil.randomBytes(bodySize);
for (int i = 0; i < numMessages; i++) {
BytesMessage bm = sess.createBytesMessage();
bm.writeBytes(body);
producer.send(bm);
}
conn.start();
Thread.sleep(2000);
ActiveMQException me = new ActiveMQNotConnectedException();
coreConn.fail(me);
for (int i = 0; i < numMessages; i++) {
BytesMessage bm = (BytesMessage) consumer.receive(1000);
Assert.assertNotNull(bm);
Assert.assertEquals(body.length, bm.getBodyLength());
}
TextMessage tm = (TextMessage) consumer.receiveNoWait();
Assert.assertNull(tm);
conn.close();
Assert.assertNotNull(listener.e);
Assert.assertTrue(me == listener.e.getCause());
}
Aggregations