use of org.apache.activemq.artemis.api.core.Interceptor in project activemq-artemis by apache.
the class ServerLocatorImpl method fromInterceptors.
private String fromInterceptors(final List<Interceptor> interceptors) {
StringBuffer buffer = new StringBuffer();
boolean first = true;
for (Interceptor value : interceptors) {
if (!first) {
buffer.append(",");
}
first = false;
buffer.append(value.getClass().getName());
}
return buffer.toString();
}
use of org.apache.activemq.artemis.api.core.Interceptor in project activemq-artemis by apache.
the class ReattachTest method testOverflowCredits.
/*
* Test failure on connection, but server is still up so should immediately reconnect
*/
@Test
public void testOverflowCredits() throws Exception {
final long retryInterval = 500;
final double retryMultiplier = 1d;
final int reconnectAttempts = 1;
locator.setRetryInterval(retryInterval).setRetryIntervalMultiplier(retryMultiplier).setReconnectAttempts(reconnectAttempts).setConfirmationWindowSize(1024 * 1024).setProducerWindowSize(1000);
final AtomicInteger count = new AtomicInteger(0);
Interceptor intercept = new Interceptor() {
@Override
public boolean intercept(Packet packet, RemotingConnection connection) throws ActiveMQException {
System.out.println("Intercept..." + packet.getClass().getName());
if (packet instanceof SessionProducerCreditsMessage) {
SessionProducerCreditsMessage credit = (SessionProducerCreditsMessage) packet;
System.out.println("Credits: " + credit.getCredits());
if (count.incrementAndGet() == 2) {
System.out.println("Failing");
connection.fail(new ActiveMQException(ActiveMQExceptionType.UNSUPPORTED_PACKET, "bye"));
return false;
}
}
return true;
}
};
locator.addIncomingInterceptor(intercept);
ClientSessionFactoryInternal sf = (ClientSessionFactoryInternal) createSessionFactory(locator);
ClientSession session = sf.createSession(false, true, true);
session.createQueue(ReattachTest.ADDRESS, ReattachTest.ADDRESS, null, false);
ClientProducer producer = session.createProducer(ReattachTest.ADDRESS);
final int numMessages = 10;
for (int i = 0; i < numMessages; i++) {
ClientMessage message = session.createMessage(ActiveMQTextMessage.TYPE, false, 0, System.currentTimeMillis(), (byte) 1);
message.putIntProperty(new SimpleString("count"), i);
message.getBodyBuffer().writeBytes(new byte[5000]);
producer.send(message);
}
session.close();
sf.close();
}
use of org.apache.activemq.artemis.api.core.Interceptor in project activemq-artemis by apache.
the class FailoverTest method testCommitDidNotOccurUnblockedAndResend.
@Test(timeout = 120000)
public void testCommitDidNotOccurUnblockedAndResend() throws Exception {
locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true).setReconnectAttempts(300).setRetryInterval(100);
sf = createSessionFactoryAndWaitForTopology(locator, 2);
final ClientSession session = createSession(sf, false, false);
session.createQueue(FailoverTestBase.ADDRESS, RoutingType.MULTICAST, FailoverTestBase.ADDRESS, null, true);
ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);
sendMessages(session, producer, NUM_MESSAGES);
class Committer extends Thread {
@Override
public void run() {
Interceptor interceptor = new DelayInterceptor3();
try {
liveServer.addInterceptor(interceptor);
session.commit();
} catch (ActiveMQTransactionRolledBackException trbe) {
// Ok - now we retry the commit after removing the interceptor
liveServer.removeInterceptor(interceptor);
try {
session.commit();
failed = false;
} catch (ActiveMQException e2) {
}
} catch (ActiveMQTransactionOutcomeUnknownException toue) {
// Ok - now we retry the commit after removing the interceptor
liveServer.removeInterceptor(interceptor);
try {
session.commit();
failed = false;
} catch (ActiveMQException e2) {
}
} catch (ActiveMQException e) {
// ignore
}
}
volatile boolean failed = true;
}
Committer committer = new Committer();
committer.start();
crash(session);
committer.join();
Assert.assertFalse("commiter failed should be false", committer.failed);
session.close();
ClientSession session2 = createSession(sf, false, false);
producer = session2.createProducer(FailoverTestBase.ADDRESS);
// We now try and resend the messages since we get a transaction rolled back exception
sendMessages(session2, producer, NUM_MESSAGES);
session2.commit();
ClientConsumer consumer = session2.createConsumer(FailoverTestBase.ADDRESS);
session2.start();
receiveMessages(consumer);
ClientMessage message = consumer.receiveImmediate();
Assert.assertNull("expecting null message", message);
}
use of org.apache.activemq.artemis.api.core.Interceptor in project activemq-artemis by apache.
the class FailoverOnFlowControlTest method testOverflowSend.
@Test
public void testOverflowSend() throws Exception {
ServerLocator locator = getServerLocator().setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setReconnectAttempts(300).setProducerWindowSize(1000).setRetryInterval(100);
final ArrayList<ClientSession> sessionList = new ArrayList<>();
Interceptor interceptorClient = new Interceptor() {
AtomicInteger count = new AtomicInteger(0);
@Override
public boolean intercept(Packet packet, RemotingConnection connection) throws ActiveMQException {
log.debug("Intercept..." + packet.getClass().getName());
if (packet instanceof SessionProducerCreditsMessage) {
SessionProducerCreditsMessage credit = (SessionProducerCreditsMessage) packet;
log.debug("Credits: " + credit.getCredits());
if (count.incrementAndGet() == 2) {
log.debug("### crashing server");
try {
InVMConnection.setFlushEnabled(false);
crash(false, sessionList.get(0));
} catch (Exception e) {
e.printStackTrace();
} finally {
InVMConnection.setFlushEnabled(true);
}
return false;
}
}
return true;
}
};
locator.addIncomingInterceptor(interceptorClient);
ClientSessionFactoryInternal sf = createSessionFactoryAndWaitForTopology(locator, 2);
ClientSession session = sf.createSession(true, true);
sessionList.add(session);
session.createQueue(ADDRESS, ADDRESS, null, true);
ClientProducer producer = session.createProducer(ADDRESS);
final int numMessages = 10;
for (int i = 0; i < numMessages; i++) {
ClientMessage message = session.createMessage(true);
message.getBodyBuffer().writeBytes(new byte[5000]);
message.putIntProperty("counter", i);
producer.send(message);
}
session.close();
}
use of org.apache.activemq.artemis.api.core.Interceptor in project activemq-artemis by apache.
the class XaTimeoutTest method testTimeoutOnXACall.
// HORNETQ-1117 - Test that will timeout on a XA transaction and then will perform another XA operation
@Test
public void testTimeoutOnXACall() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
class SomeInterceptor implements Interceptor {
/* (non-Javadoc)
* @see Interceptor#intercept(org.apache.activemq.artemis.core.protocol.core.Packet, RemotingConnection)
*/
@Override
public boolean intercept(Packet packet, RemotingConnection connection) throws ActiveMQException {
if (packet instanceof SessionXAStartMessage) {
try {
latch.await(1, TimeUnit.MINUTES);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return true;
}
}
server.getRemotingService().addIncomingInterceptor(new SomeInterceptor());
ServerLocator locatorTimeout = createInVMNonHALocator().setCallTimeout(300);
ClientSessionFactory factoryTimeout = locatorTimeout.createSessionFactory();
final ClientSession sessionTimeout = factoryTimeout.createSession(true, false, false);
Xid xid = newXID();
boolean expectedException = false;
try {
sessionTimeout.start(xid, XAResource.TMNOFLAGS);
} catch (Exception e) {
expectedException = true;
e.printStackTrace();
}
assertTrue(expectedException);
// this will release the interceptor and the next response will be out of sync unless we do something about
latch.countDown();
sessionTimeout.setTransactionTimeout(30);
sessionTimeout.close();
factoryTimeout.close();
locatorTimeout.close();
}
Aggregations