use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.
the class ActiveMQServerControlImpl method closeConnectionsForUser.
@Override
public boolean closeConnectionsForUser(final String userName) {
boolean closed = false;
checkStarted();
clearIO();
try {
for (ServerSession serverSession : server.getSessions()) {
if (serverSession.getUsername() != null && serverSession.getUsername().equals(userName)) {
RemotingConnection connection = null;
for (RemotingConnection potentialConnection : remotingService.getConnections()) {
if (potentialConnection.getID().toString().equals(serverSession.getConnectionID().toString())) {
connection = potentialConnection;
}
}
if (connection != null) {
remotingService.removeConnection(connection.getID());
connection.fail(ActiveMQMessageBundle.BUNDLE.connectionsForUserClosedByManagement(userName));
closed = true;
}
}
}
} finally {
blockOnIO();
}
return closed;
}
use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.
the class ActiveMQServerControlImpl method listConsumersAsJSON.
@Override
public String listConsumersAsJSON(String connectionID) throws Exception {
checkStarted();
clearIO();
try {
JsonArrayBuilder array = JsonLoader.createArrayBuilder();
Set<RemotingConnection> connections = server.getRemotingService().getConnections();
for (RemotingConnection connection : connections) {
if (connectionID.equals(connection.getID().toString())) {
List<ServerSession> sessions = server.getSessions(connectionID);
for (ServerSession session : sessions) {
Set<ServerConsumer> consumers = session.getServerConsumers();
for (ServerConsumer consumer : consumers) {
JsonObject obj = toJSONObject(consumer);
if (obj != null) {
array.add(obj);
}
}
}
}
}
return array.build().toString();
} finally {
blockOnIO();
}
}
use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.
the class ConsumerTest method testAcksWithSmallSendWindow.
@Test
public void testAcksWithSmallSendWindow() throws Exception {
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession session = sf.createSession(false, true, true);
ClientProducer producer = session.createProducer(QUEUE);
final int numMessages = 100;
for (int i = 0; i < numMessages; i++) {
ClientMessage message = createTextMessage(session, "m" + i);
producer.send(message);
}
session.close();
sf.close();
final CountDownLatch latch = new CountDownLatch(numMessages);
server.getRemotingService().addIncomingInterceptor(new Interceptor() {
@Override
public boolean intercept(final Packet packet, final RemotingConnection connection) throws ActiveMQException {
if (packet.getType() == PacketImpl.SESS_ACKNOWLEDGE) {
latch.countDown();
}
return true;
}
});
ServerLocator locator = createInVMNonHALocator().setConfirmationWindowSize(100).setAckBatchSize(-1);
ClientSessionFactory sfReceive = createSessionFactory(locator);
ClientSession sessionRec = sfReceive.createSession(false, true, true);
ClientConsumer consumer = sessionRec.createConsumer(QUEUE);
consumer.setMessageHandler(new MessageHandler() {
@Override
public void onMessage(final ClientMessage message) {
try {
message.acknowledge();
} catch (ActiveMQException e) {
e.printStackTrace();
}
}
});
sessionRec.start();
Assert.assertTrue(latch.await(60, TimeUnit.SECONDS));
sessionRec.close();
locator.close();
}
use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.
the class ProducerTest method testProducerWithSmallWindowSizeAndLargeMessage.
@Test
public void testProducerWithSmallWindowSizeAndLargeMessage() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
server.getRemotingService().addIncomingInterceptor(new Interceptor() {
@Override
public boolean intercept(final Packet packet, final RemotingConnection connection) throws ActiveMQException {
if (packet.getType() == PacketImpl.SESS_SEND) {
latch.countDown();
}
return true;
}
});
ServerLocator locator = createInVMNonHALocator().setConfirmationWindowSize(100);
ClientSessionFactory cf = locator.createSessionFactory();
ClientSession session = cf.createSession(false, true, true);
ClientProducer producer = session.createProducer(QUEUE);
ClientMessage message = session.createMessage(true);
byte[] body = new byte[1000];
message.getBodyBuffer().writeBytes(body);
producer.send(message);
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
session.close();
locator.close();
}
use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.
the class RemotingServiceImpl method connectionDestroyed.
@Override
public void connectionDestroyed(final Object connectionID) {
if (logger.isTraceEnabled()) {
logger.trace("Connection removed " + connectionID + " from server " + this.server, new Exception("trace"));
}
ConnectionEntry conn = connections.get(connectionID);
if (conn != null && !conn.connection.isSupportReconnect()) {
RemotingConnection removedConnection = removeConnection(connectionID);
if (removedConnection != null) {
try {
if (server.hasBrokerPlugins()) {
server.callBrokerPlugins(plugin -> plugin.afterDestroyConnection(removedConnection));
}
} catch (ActiveMQException t) {
logger.warn("Error executing afterDestroyConnection plugin method: {}", t.getMessage(), t);
conn.connection.fail(t);
return;
}
}
conn.connection.fail(new ActiveMQRemoteDisconnectException());
}
}
Aggregations