The IsisContext class (in nof-core) is responsible for locating the current execution context. @see IsisSessionFactory
919293949596979899100101
public void onRequestHandlerExecuted(RequestCycle cycle, IRequestHandler handler) { if(LOG.isDebugEnabled()) { LOG.debug("onRequestHandlerExecuted: handler: " + handler); } final IsisSession session = getIsisContext().getSessionInstance(); if (session != null) { try { // will commit (or abort) the transaction; // an abort will cause the exception to be thrown. getTransactionManager().endTransaction();
123124125126127128129130131132133
/** * It is not possible to throw exceptions here, hence use of {@link #onRequestHandlerExecuted(RequestCycle, IRequestHandler)}. */ @Override public synchronized void onEndRequest(RequestCycle cycle) { final IsisSession session = getIsisContext().getSessionInstance(); if (session != null) { try { // belt and braces getTransactionManager().endTransaction(); } finally {
313314315316317318319320321322323324
*/ return null; } private void debugDisplayContext(final String selector, final DebugBuilder debug) { final IsisSession d = IsisContext.getSession(selector); if (d != null) { d.debugAll(debug); } else { debug.appendln("No context: " + selector); } }
326327328329330331332333334335
private void debugListContexts(final DebugBuilder debug) { final String[] contextIds = IsisContext.getInstance().allSessionIds(); for (final String contextId : contextIds) { debug.appendln(contextId); debug.appendln("-----"); final IsisSession d = IsisContext.getSession(contextId); d.debug(debug); debug.appendln(); } }
384385386387388389390391
// /////////////////////////////////////////////////////////// // Static Convenience methods (session scoped) // /////////////////////////////////////////////////////////// public static boolean inSession() { final IsisSession session = getInstance().getSessionInstance(); return session != null; }
392393394395396397398399400401402
/** * Convenience method returning the current {@link IsisSession}. */ public static IsisSession getSession() { final IsisSession session = getInstance().getSessionInstance(); if (session == null) { throw new IllegalStateException("No Session opened for this thread"); } return session; }
8081828384858687888990
} @Override public IsisSession openSessionInstance(final AuthenticationSession authenticationSession) { applySessionClosePolicy(); final IsisSession newSession = getSessionFactoryInstance().openSession(authenticationSession); if (isCurrentThreadServer()) { serverSession = newSession; } else { clientSession = newSession; }
9596979899100101102103104
// Session // ////////////////////////////////////////////// @Override public void closeAllSessionsInstance() { final IsisSession sessionInstance = getSessionInstance(); if (sessionInstance != null) { sessionInstance.closeAll(); } }
59606162636465666768
protected void shutdownAllThreads() { synchronized (sessionsByThread) { int i = 0; for (final Thread thread : sessionsByThread.keySet()) { LOG.info("Shutting down thread: " + i++); final IsisSession data = sessionsByThread.get(thread); data.closeAll(); } } }
79808182838485868788
@Override public String[] allSessionIds() { final String[] ids = new String[sessionsByThread.size()]; int i = 0; for (final Thread thread : sessionsByThread.keySet()) { final IsisSession data = sessionsByThread.get(thread); ids[i++] = data.getId(); } return ids; }