@Override public RET call() throws Exception { threadInitializer.initThread(); try { LifeCycleManager.beforeRequest(request); try { Factory.setSessionFactory(sessionFactory, SessionType.CURRENT); return inner.call(); } catch (Exception e) { System.err.println("Error while executing " + inner.getClass().getName()); e.printStackTrace(); throw e; } finally { LifeCycleManager.afterRequest(); } } finally { threadInitializer.termThread(); } }
/** * Determines the sessionType under which the current runnable should run. The first non-null * value of the following list is returned * * <ul> * <li>If the runnable implements <code>IDominoRunnable</code>: result of <code>getSessionType * </code> * <li>the value of {@link SessionType} Annotation * <li>DominoSessionType.DEFAULT * </ul> * * @param task the runnable to determine the DominoSessionType */ protected synchronized void init(final Object task) { threadInitializer = ServiceLocator.findApplicationService(ThreadInitializerFactory.class).create(); request = LifeCycleManager.getCurrentRequest(); if (request == null) { request = new RequestImpl("DominoTasklet: " + task.getClass().getName()); } else { request = request.clone("DominoTasklet: " + task.getClass().getName()); } DominoTasklet annot = task.getClass().getAnnotation(DominoTasklet.class); if (annot != null) { if (sessionFactory == null) { switch (annot.session()) { case CLONE: sessionFactory = Factory.getSessionFactory(SessionType.CURRENT); break; case CLONE_FULL_ACCESS: sessionFactory = Factory.getSessionFactory(SessionType.CURRENT_FULL_ACCESS); break; case FULL_ACCESS: sessionFactory = Factory.getSessionFactory(SessionType.FULL_ACCESS); break; case NATIVE: sessionFactory = Factory.getSessionFactory(SessionType.NATIVE); break; case NONE: sessionFactory = null; break; case SIGNER: sessionFactory = Factory.getSessionFactory(SessionType.SIGNER); break; case SIGNER_FULL_ACCESS: sessionFactory = Factory.getSessionFactory(SessionType.SIGNER_FULL_ACCESS); break; case TRUSTED: sessionFactory = Factory.getSessionFactory(SessionType.TRUSTED); break; default: break; } if ((annot.session() != DominoTasklet.Session.NONE) && sessionFactory == null) { throw new IllegalStateException("Could not create a Fatory for " + annot.session()); } } } }