Search in sources :

Example 1 with DuplicateSessionIDException

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;
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) ConnectivityPolicy(org.apache.stanbol.ontologymanager.servicesapi.ontology.OWLExportable.ConnectivityPolicy) OntologyCollectorListener(org.apache.stanbol.ontologymanager.servicesapi.collector.OntologyCollectorListener) Multiplexer(org.apache.stanbol.ontologymanager.servicesapi.ontology.Multiplexer) SessionImpl(org.apache.stanbol.ontologymanager.multiplexer.clerezza.impl.SessionImpl) SessionListener(org.apache.stanbol.ontologymanager.servicesapi.session.SessionListener) DuplicateSessionIDException(org.apache.stanbol.ontologymanager.servicesapi.session.DuplicateSessionIDException) Session(org.apache.stanbol.ontologymanager.servicesapi.session.Session)

Example 2 with DuplicateSessionIDException

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;
}
Also used : Session(org.apache.stanbol.ontologymanager.servicesapi.session.Session) DuplicateSessionIDException(org.apache.stanbol.ontologymanager.servicesapi.session.DuplicateSessionIDException)

Example 3 with DuplicateSessionIDException

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);
    }
}
Also used : MissingOntologyException(org.apache.stanbol.ontologymanager.servicesapi.collector.MissingOntologyException) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) SessionLimitException(org.apache.stanbol.ontologymanager.servicesapi.session.SessionLimitException) StoredOntologySource(org.apache.stanbol.ontologymanager.servicesapi.io.StoredOntologySource) NonReferenceableSessionException(org.apache.stanbol.ontologymanager.servicesapi.session.NonReferenceableSessionException) MissingOntologyException(org.apache.stanbol.ontologymanager.servicesapi.collector.MissingOntologyException) SessionLimitException(org.apache.stanbol.ontologymanager.servicesapi.session.SessionLimitException) OWLOntologyStorageException(org.semanticweb.owlapi.model.OWLOntologyStorageException) IOException(java.io.IOException) DuplicateSessionIDException(org.apache.stanbol.ontologymanager.servicesapi.session.DuplicateSessionIDException) OntologyNetworkConfiguration(org.apache.stanbol.ontologymanager.ontonet.api.OntologyNetworkConfiguration) Session(org.apache.stanbol.ontologymanager.servicesapi.session.Session) DuplicateSessionIDException(org.apache.stanbol.ontologymanager.servicesapi.session.DuplicateSessionIDException)

Aggregations

DuplicateSessionIDException (org.apache.stanbol.ontologymanager.servicesapi.session.DuplicateSessionIDException)3 Session (org.apache.stanbol.ontologymanager.servicesapi.session.Session)3 IOException (java.io.IOException)1 SessionImpl (org.apache.stanbol.ontologymanager.multiplexer.clerezza.impl.SessionImpl)1 OntologyNetworkConfiguration (org.apache.stanbol.ontologymanager.ontonet.api.OntologyNetworkConfiguration)1 MissingOntologyException (org.apache.stanbol.ontologymanager.servicesapi.collector.MissingOntologyException)1 OntologyCollectorListener (org.apache.stanbol.ontologymanager.servicesapi.collector.OntologyCollectorListener)1 StoredOntologySource (org.apache.stanbol.ontologymanager.servicesapi.io.StoredOntologySource)1 Multiplexer (org.apache.stanbol.ontologymanager.servicesapi.ontology.Multiplexer)1 ConnectivityPolicy (org.apache.stanbol.ontologymanager.servicesapi.ontology.OWLExportable.ConnectivityPolicy)1 NonReferenceableSessionException (org.apache.stanbol.ontologymanager.servicesapi.session.NonReferenceableSessionException)1 SessionLimitException (org.apache.stanbol.ontologymanager.servicesapi.session.SessionLimitException)1 SessionListener (org.apache.stanbol.ontologymanager.servicesapi.session.SessionListener)1 IRI (org.semanticweb.owlapi.model.IRI)1 OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)1 OWLOntologyStorageException (org.semanticweb.owlapi.model.OWLOntologyStorageException)1