@Override public void passivateObject(Session<I, R> session) throws Exception { session.passivate(); }
/** * Destroys this session. If the session was not yet passivated, it will be passivated in * advance. While the session is destroyed, the ExecutorService is shutdown and the * SessionContext is destroyed. After the session is destroyed it is unusable! * */ public void destroy() { switch (state) { case PROCESSED: // We can destroy the session but it was not yet passivated. To stay in sync with the // state lifeCycle we passivate first passivate(); break; case DESTROYED: LOG.warn("Failed destroying session. Session has already been destroyed!"); return; case NEW: case ACTIVATED: LOG.warn("Session is destroy before it was processed."); break; case FAILURE: case PASSIVATED: default: break; } state = State.DESTROYED; sessionContext = null; // NOPMD }
/** * Marks the session as failed and passivates it. * * @param cause * The root cause of failure. * @throws SessionException * If diagnosis fails with errors. */ private void failure(DiagnosisEngineException cause) throws SessionException { // enter failure state state = State.FAILURE; // ensure that Session gets passivated to enable reuse passivate(); // Propagate the cause of failure throw new SessionException("Diagnosis Session failed with error(s)", cause); }
@Test(dataProvider = "allStates") public void testFromDifferentStates(State state) throws IllegalArgumentException, IllegalAccessException { stateField.set(session, state); session.passivate(); assertThat(session.getState(), equalTo(Session.State.PASSIVATED)); verify(sessionContext, times(1)).passivate(); } }