// 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();
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();
}