use of org.apache.stanbol.ontologymanager.servicesapi.session.NonReferenceableSessionException in project stanbol by apache.
the class SessionManagerImpl method destroySession.
@Override
public synchronized void destroySession(String sessionID) {
try {
Session ses = sessionsByID.get(sessionID);
if (ses == null)
log.warn("Tried to destroy nonexisting session {} . Could it have been previously destroyed?", sessionID);
else {
ses.close();
if (ses instanceof SessionImpl)
((SessionImpl) ses).state = State.ZOMBIE;
// Make session no longer referenceable
removeSession(ses);
fireSessionDestroyed(ses);
}
} catch (NonReferenceableSessionException e) {
log.warn("Tried to kick a dead horse on session \"{}\" which was already in a zombie state.", sessionID);
}
}
use of org.apache.stanbol.ontologymanager.servicesapi.session.NonReferenceableSessionException in project stanbol by apache.
the class TestSessions method testSessionCreationDestruction.
@Test
public void testSessionCreationDestruction() throws Exception {
int size = 100;
int initialSize = sessionManager.getRegisteredSessionIDs().size();
Set<Session> sessions = new HashSet<Session>();
// Create and open many sessions.
synchronized (sessionManager) {
for (int i = 0; i < size; i++) {
Session ses = sessionManager.createSession();
ses.open();
sessions.add(ses);
}
// Check that 500 sessions have been created
assertEquals(initialSize + size, sessionManager.getRegisteredSessionIDs().size());
}
boolean open = true;
for (Session ses : sessions) open &= ses.getSessionState() == State.ACTIVE;
// Check that all created sessions have been opened
assertTrue(open);
// Kill 'em all, to quote Metallica
synchronized (sessionManager) {
for (Session ses : sessions) sessionManager.destroySession(ses.getID());
assertEquals(initialSize, sessionManager.getRegisteredSessionIDs().size());
}
// Check that they are all zombies
boolean zombi = true;
for (Session ses : sessions) zombi &= ses.getSessionState() == State.ZOMBIE;
assertTrue(zombi);
// Try to resurrect them (hopefully failing)
boolean resurrect = false;
for (Session ses : sessions) try {
ses.open();
resurrect |= true;
} catch (NonReferenceableSessionException e) {
resurrect |= false;
continue;
}
assertFalse(resurrect);
}
Aggregations