use of org.apache.stanbol.ontologymanager.servicesapi.session.DuplicateSessionIDException in project stanbol by apache.
the class SessionManagerImpl method createSession.
@Override
public synchronized Session createSession(String sessionID) throws DuplicateSessionIDException, SessionLimitException {
/*
* Throw the duplicate ID exception first, in case developers decide to reuse the existing session
* before creating a new one.
*/
if (sessionsByID.containsKey(sessionID))
throw new DuplicateSessionIDException(sessionID);
checkSessionLimit();
IRI ns = IRI.create(getDefaultNamespace() + getID() + "/");
Session session = new SessionImpl(sessionID, ns, ontologyProvider);
// Have the ontology provider listen to ontology events
if (ontologyProvider instanceof OntologyCollectorListener)
session.addOntologyCollectorListener((OntologyCollectorListener) ontologyProvider);
if (ontologyProvider instanceof SessionListener)
session.addSessionListener((SessionListener) ontologyProvider);
Multiplexer multiplexer = ontologyProvider.getOntologyNetworkDescriptor();
session.addOntologyCollectorListener(multiplexer);
session.addSessionListener(multiplexer);
ConnectivityPolicy policy;
try {
policy = ConnectivityPolicy.valueOf(connectivityPolicyString);
} catch (IllegalArgumentException e) {
log.warn("The value {}", connectivityPolicyString);
log.warn(" -- configured as default ConnectivityPolicy does not match any value of the Enumeration!");
log.warn(" -- Setting the default policy as defined by the {}.", ConnectivityPolicy.class);
policy = ConnectivityPolicy.valueOf(_CONNECTIVITY_POLICY_DEFAULT);
}
session.setConnectivityPolicy(policy);
addSession(session);
fireSessionCreated(session);
return session;
}
use of org.apache.stanbol.ontologymanager.servicesapi.session.DuplicateSessionIDException in project stanbol by apache.
the class SessionManagerImpl method createSession.
@Override
public Session createSession() throws SessionLimitException {
checkSessionLimit();
Set<String> exclude = getRegisteredSessionIDs();
Session session = null;
while (session == null) try {
session = createSession(idgen.createSessionID(exclude));
} catch (DuplicateSessionIDException e) {
exclude.add(e.getDuplicateID());
continue;
}
return session;
}
use of org.apache.stanbol.ontologymanager.servicesapi.session.DuplicateSessionIDException in project stanbol by apache.
the class SessionManagerImpl method rebuildSessions.
private void rebuildSessions() {
if (ontologyProvider == null) {
log.warn("No ontology provider supplied. Cannot rebuild sessions");
return;
}
OntologyNetworkConfiguration struct = ontologyProvider.getOntologyNetworkConfiguration();
for (String sessionId : struct.getSessionIDs()) {
long before = System.currentTimeMillis();
log.debug("Rebuilding session with ID \"{}\"", sessionId);
Session session;
try {
session = createSession(sessionId);
} catch (DuplicateSessionIDException e) {
log.warn("Session \"{}\" already exists and will be reused.", sessionId);
session = getSession(sessionId);
} catch (SessionLimitException e) {
log.error("Cannot create session {}. Session limit of {} reached.", sessionId, getActiveSessionLimit());
break;
}
// Register even if some ontologies were to fail to be restored afterwards.
sessionsByID.put(sessionId, session);
// Restored sessions are inactive at first.
session.setActive(false);
for (OWLOntologyID key : struct.getOntologyKeysForSession(sessionId)) try {
session.addOntology(new StoredOntologySource(key));
} catch (MissingOntologyException ex) {
log.error("Could not find an ontology with public key {} to be managed by session \"{}\". Proceeding to next ontology.", key, sessionId);
continue;
} catch (Exception ex) {
log.error("Exception caught while trying to add ontology with public key " + key + " to rebuilt session \"" + sessionId + "\". Proceeding to next ontology.", ex);
continue;
}
for (String scopeId : struct.getAttachedScopes(sessionId)) {
/*
* The scope is attached by reference, so we won't have to bother checking if the scope has
* been rebuilt by then (which could not happen if the SessionManager is being activated
* first).
*/
session.attachScope(scopeId);
}
log.info("Session \"{}\" rebuilt in {} ms.", sessionId, System.currentTimeMillis() - before);
}
}
Aggregations