use of javax.jms.JMSContext in project Payara by payara.
the class AbstractJMSContextManager method cleanup.
// Close and remove the JMSContext instances
@PreDestroy
public synchronized void cleanup() {
ServiceLocator serviceLocator = Globals.get(ServiceLocator.class);
InvocationManager invMgr = serviceLocator.getService(InvocationManager.class);
ComponentInvocation currentInv = invMgr.getCurrentInvocation();
for (Entry<String, JMSContextEntry> entry : contexts.entrySet()) {
JMSContextEntry contextEntry = entry.getValue();
String ipId = contextEntry.getInjectionPointId();
JMSContext context = contextEntry.getCtx();
if (context != null) {
ComponentInvocation inv = contextEntry.getComponentInvocation();
if (inv != null && currentInv != inv)
invMgr.preInvoke(inv);
try {
context.close();
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, localStrings.getLocalString("JMSContext.impl.close", "Closed JMSContext instance associated with id {0}: {1}.", ipId, context.toString()));
}
} catch (Exception e) {
logger.log(Level.SEVERE, localStrings.getLocalString("JMSContext.impl.close.failure", "Failed to close JMSContext instance associated with id {0}: {1}.", ipId, context.toString()), e);
} finally {
if (inv != null && currentInv != inv)
invMgr.postInvoke(inv);
}
}
}
contexts.clear();
}
use of javax.jms.JMSContext in project Payara by payara.
the class AbstractJMSContextManager method createContext.
protected JMSContext createContext(String ipId, JMSContextMetadata metadata, ConnectionFactory connectionFactory) {
int sessionMode = metadata.getSessionMode();
String userName = metadata.getUserName();
JMSContext context = null;
if (userName == null) {
context = connectionFactory.createContext(sessionMode);
} else {
String password = metadata.getPassword();
context = connectionFactory.createContext(userName, password, sessionMode);
}
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, localStrings.getLocalString("JMSContext.impl.create", "Created new JMSContext instance associated with id {0}: {1}.", ipId, context.toString()));
}
return context;
}
use of javax.jms.JMSContext in project Payara by payara.
the class AbstractJMSContextManager method getContext.
public synchronized JMSContext getContext(String ipId, String id, JMSContextMetadata metadata, ConnectionFactory connectionFactory) {
JMSContextEntry contextEntry = contexts.get(id);
JMSContext context = null;
if (contextEntry == null) {
context = createContext(ipId, metadata, connectionFactory);
ServiceLocator serviceLocator = Globals.get(ServiceLocator.class);
InvocationManager invMgr = serviceLocator.getService(InvocationManager.class);
contexts.put(id, new JMSContextEntry(ipId, context, invMgr.getCurrentInvocation()));
} else {
context = contextEntry.getCtx();
}
return context;
}
use of javax.jms.JMSContext in project eap-additional-testsuite by jboss-set.
the class ExportImportJournalTestCase method receiveMessage.
protected static void receiveMessage(Context ctx, String destinationLookup, boolean expectReceivedMessage, String expectedText) throws NamingException {
ConnectionFactory cf = (ConnectionFactory) ctx.lookup("jms/RemoteConnectionFactory");
assertNotNull(cf);
Destination destination = (Destination) ctx.lookup(destinationLookup);
assertNotNull(destination);
try (JMSContext context = cf.createContext("guest", "guest")) {
JMSConsumer consumer = context.createConsumer(destination);
String text = consumer.receiveBody(String.class, 5000);
if (expectReceivedMessage) {
assertNotNull(text);
assertEquals(expectedText, text);
} else {
assertNull("should not have received any message", text);
}
}
}
use of javax.jms.JMSContext in project eap-additional-testsuite by jboss-set.
the class ExportImportJournalTestCase method sendMessage.
protected static void sendMessage(Context ctx, String destinationLookup, String text) throws NamingException, JMSException {
ConnectionFactory cf = (ConnectionFactory) ctx.lookup("jms/RemoteConnectionFactory");
assertNotNull(cf);
Destination destination = (Destination) ctx.lookup(destinationLookup);
assertNotNull(destination);
try (JMSContext context = cf.createContext("guest", "guest")) {
TextMessage message = context.createTextMessage(text);
message.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
context.createProducer().send(destination, message);
}
}
Aggregations