if (m != null) {
return m; // already created, return
}
Map<String, Context> sessionContext = new ConcurrentHashMap<String, Context>(contextFactories.size());
for (ContextFactory<Context> config : contextFactories.values()) {
Context context = config.createContext();
context.start();
sessionContext.put(context.getName(), context);
}
List<Context> shutdownQueue = new ArrayList<Context>();
contexts.put(key, sessionContext);
destroyQueues.put(key, shutdownQueue);
// initialize eager components. Note this cannot be done when we initially create each context since a component may
// contain a forward reference to a component which has not been instantiated
for (Context context : sessionContext.values()) {
if (context instanceof AtomicContext) {
AtomicContext atomic = (AtomicContext) context;
if (atomic.isEagerInit()) {
atomic.init(); // Notify the instance
synchronized (shutdownQueue) {
shutdownQueue.add(context);
}
}
}
context.addListener(this);
}
return sessionContext;
}