use of org.apache.activemq.artemis.api.core.client.ClientSessionFactory in project candlepin by candlepin.
the class ActiveMQContextListener method cleanupOldQueues.
/**
* Remove any old message queues that have a 0 message count in them.
* This lets us not worry about changing around the registered listeners.
*/
private void cleanupOldQueues() {
log.debug("Cleaning old message queues");
try {
String[] queues = activeMQServer.getActiveMQServer().getActiveMQServerControl().getQueueNames();
ServerLocator locator = ActiveMQClient.createServerLocatorWithoutHA(new TransportConfiguration(InVMConnectorFactory.class.getName()));
ClientSessionFactory factory = locator.createSessionFactory();
ClientSession session = factory.createSession(true, true);
session.start();
for (int i = 0; i < queues.length; i++) {
long msgCount = session.queueQuery(new SimpleString(queues[i])).getMessageCount();
if (msgCount == 0) {
log.debug(String.format("found queue '%s' with 0 messages. deleting", queues[i]));
session.deleteQueue(queues[i]);
} else {
log.debug(String.format("found queue '%s' with %d messages. kept", queues[i], msgCount));
}
}
session.stop();
session.close();
} catch (Exception e) {
log.error("Problem cleaning old message queues:", e);
throw new RuntimeException("Problem cleaning message queue", e);
}
}
use of org.apache.activemq.artemis.api.core.client.ClientSessionFactory in project candlepin by candlepin.
the class EventSinkImplTest method eventSinkShouldThrowExceptionWhenSessionCreationFailsInConstructor.
/**
*Set up the {@link ClientSessionFactory} to throw an exception when
* {@link ClientSessionFactory#createSession()} is called.
* Make sure, we throw up our hands saying "I am not dealing with this".
* @throws Exception
*/
@Test(expected = RuntimeException.class)
public void eventSinkShouldThrowExceptionWhenSessionCreationFailsInConstructor() throws Exception {
final ClientSessionFactory csFactory = mock(ClientSessionFactory.class);
doThrow(new ActiveMQException()).when(csFactory.createSession());
createEventSink(csFactory);
fail("Runtime exception should have been thrown.");
}
use of org.apache.activemq.artemis.api.core.client.ClientSessionFactory in project activemq-artemis by apache.
the class ServerLocatorImpl method notifyNodeUp.
@Override
public void notifyNodeUp(long uniqueEventID, final String nodeID, final String backupGroupName, final String scaleDownGroupName, final Pair<TransportConfiguration, TransportConfiguration> connectorPair, final boolean last) {
if (logger.isTraceEnabled()) {
logger.trace("NodeUp " + this + "::nodeID=" + nodeID + ", connectorPair=" + connectorPair, new Exception("trace"));
}
TopologyMemberImpl member = new TopologyMemberImpl(nodeID, backupGroupName, scaleDownGroupName, connectorPair.getA(), connectorPair.getB());
topology.updateMember(uniqueEventID, nodeID, member);
TopologyMember actMember = topology.getMember(nodeID);
if (actMember != null && actMember.getLive() != null && actMember.getBackup() != null) {
HashSet<ClientSessionFactory> clonedFactories = new HashSet<>();
synchronized (factories) {
clonedFactories.addAll(factories);
}
for (ClientSessionFactory factory : clonedFactories) {
((ClientSessionFactoryInternal) factory).setBackupConnector(actMember.getLive(), actMember.getBackup());
}
}
updateArraysAndPairs(uniqueEventID);
if (last) {
receivedTopology = true;
}
}
use of org.apache.activemq.artemis.api.core.client.ClientSessionFactory in project activemq-artemis by apache.
the class ClientConsumerImpl method handleLargeMessage.
@Override
public synchronized void handleLargeMessage(final ClientLargeMessageInternal clientLargeMessage, long largeMessageSize) throws Exception {
if (closing) {
// This is ok - we just ignore the message
return;
}
// Flow control for the first packet, we will have others
File largeMessageCache = null;
if (session.isCacheLargeMessageClient()) {
largeMessageCache = File.createTempFile("tmp-large-message-" + clientLargeMessage.getMessageID() + "-", ".tmp");
largeMessageCache.deleteOnExit();
}
ClientSessionFactory sf = session.getSessionFactory();
ServerLocator locator = sf.getServerLocator();
long callTimeout = locator.getCallTimeout();
currentLargeMessageController = new LargeMessageControllerImpl(this, largeMessageSize, callTimeout, largeMessageCache);
if (clientLargeMessage.isCompressed()) {
clientLargeMessage.setLargeMessageController(new CompressedLargeMessageControllerImpl(currentLargeMessageController));
} else {
clientLargeMessage.setLargeMessageController(currentLargeMessageController);
}
handleRegularMessage(clientLargeMessage);
}
use of org.apache.activemq.artemis.api.core.client.ClientSessionFactory in project activemq-artemis by apache.
the class XmlDataImporter method process.
public void process(InputStream inputStream, String host, int port, boolean transactional) throws Exception {
HashMap<String, Object> connectionParams = new HashMap<>();
connectionParams.put(TransportConstants.HOST_PROP_NAME, host);
connectionParams.put(TransportConstants.PORT_PROP_NAME, Integer.toString(port));
ServerLocator serverLocator = ActiveMQClient.createServerLocatorWithoutHA(new TransportConfiguration(NettyConnectorFactory.class.getName(), connectionParams));
ClientSessionFactory sf = serverLocator.createSessionFactory();
ClientSession session;
ClientSession managementSession;
if (user != null || password != null) {
session = sf.createSession(user, password, false, !transactional, true, false, 0);
managementSession = sf.createSession(user, password, false, true, true, false, 0);
} else {
session = sf.createSession(false, !transactional, true);
managementSession = sf.createSession(false, true, true);
}
localSession = true;
process(inputStream, session, managementSession);
}
Aggregations