Search in sources :

Example 1 with SessionListener

use of org.apache.stanbol.ontologymanager.servicesapi.session.SessionListener 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 SessionListener

use of org.apache.stanbol.ontologymanager.servicesapi.session.SessionListener in project stanbol by apache.

the class SessionManagerImpl method activate.

/**
     * Called within both OSGi and non-OSGi environments.
     * 
     * @param configuration
     * @throws IOException
     */
protected void activate(Dictionary<String, Object> configuration) throws IOException {
    long before = System.currentTimeMillis();
    me = this;
    // Parse configuration
    id = (String) configuration.get(SessionManager.ID);
    if (id == null)
        id = _ID_DEFAULT;
    String s = null;
    try {
        setDefaultNamespace(offline.getDefaultOntologyNetworkNamespace());
    } catch (Exception e) {
        log.warn("Invalid namespace {}. Setting to default value {}", offline.getDefaultOntologyNetworkNamespace(), _ONTOLOGY_NETWORK_NS_DEFAULT);
        setDefaultNamespace(IRI.create(_ONTOLOGY_NETWORK_NS_DEFAULT));
    }
    try {
        s = (String) configuration.get(SessionManager.MAX_ACTIVE_SESSIONS);
        maxSessions = Integer.parseInt(s);
    } catch (Exception e) {
        log.warn("Invalid session limit {}. Setting to default value {}", configuration.get(SessionManager.MAX_ACTIVE_SESSIONS), _MAX_ACTIVE_SESSIONS_DEFAULT);
        maxSessions = _MAX_ACTIVE_SESSIONS_DEFAULT;
    }
    if (id == null || id.isEmpty()) {
        log.warn("The Ontology Network Manager configuration does not define a ID for the Ontology Network Manager");
    }
    idgen = new TimestampedSessionIDGenerator();
    Object connectivityPolicy = configuration.get(SessionManager.CONNECTIVITY_POLICY);
    if (connectivityPolicy == null) {
        this.connectivityPolicyString = _CONNECTIVITY_POLICY_DEFAULT;
    } else {
        this.connectivityPolicyString = connectivityPolicy.toString();
    }
    // Add listeners
    if (ontologyProvider instanceof SessionListener)
        this.addSessionListener((SessionListener) ontologyProvider);
    this.addSessionListener(ontologyProvider.getOntologyNetworkDescriptor());
    if (scopeRegistry != null)
        scopeRegistry.addScopeRegistrationListener(this);
    // Rebuild sessions
    rebuildSessions();
    log.debug(SessionManager.class + " activated. Time : {} ms.", System.currentTimeMillis() - before);
}
Also used : TimestampedSessionIDGenerator(org.apache.stanbol.ontologymanager.core.session.TimestampedSessionIDGenerator) SessionManager(org.apache.stanbol.ontologymanager.servicesapi.session.SessionManager) SessionListener(org.apache.stanbol.ontologymanager.servicesapi.session.SessionListener) 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)

Aggregations

DuplicateSessionIDException (org.apache.stanbol.ontologymanager.servicesapi.session.DuplicateSessionIDException)2 SessionListener (org.apache.stanbol.ontologymanager.servicesapi.session.SessionListener)2 IOException (java.io.IOException)1 TimestampedSessionIDGenerator (org.apache.stanbol.ontologymanager.core.session.TimestampedSessionIDGenerator)1 SessionImpl (org.apache.stanbol.ontologymanager.multiplexer.clerezza.impl.SessionImpl)1 MissingOntologyException (org.apache.stanbol.ontologymanager.servicesapi.collector.MissingOntologyException)1 OntologyCollectorListener (org.apache.stanbol.ontologymanager.servicesapi.collector.OntologyCollectorListener)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 Session (org.apache.stanbol.ontologymanager.servicesapi.session.Session)1 SessionLimitException (org.apache.stanbol.ontologymanager.servicesapi.session.SessionLimitException)1 SessionManager (org.apache.stanbol.ontologymanager.servicesapi.session.SessionManager)1 IRI (org.semanticweb.owlapi.model.IRI)1 OWLOntologyStorageException (org.semanticweb.owlapi.model.OWLOntologyStorageException)1