Search in sources :

Example 1 with Session

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

the class OntologyManagerInputProvider method getFromOntoMgr.

private OWLOntology getFromOntoMgr() throws IOException {
    try {
        Scope scope = null;
        synchronized (onManager) {
            scope = onManager.getScope(this.scopeId);
        }
        if (scope == null) {
            log.error("Scope {} cannot be retrieved", this.scopeId);
            throw new IOException("Scope " + this.scopeId + " cannot be retrieved");
        }
        Session session = null;
        if (sessionManager != null)
            synchronized (sessionManager) {
                session = sessionManager.getSession(sessionId);
            }
        if (session == null)
            log.warn("Session {} cannot be retrieved. Ignoring.", this.sessionId);
        final Set<OWLOntology> set = new HashSet<OWLOntology>();
        set.add(scope.export(OWLOntology.class, true));
        if (session != null)
            set.add(session.export(OWLOntology.class, true));
        if (set.size() == 1)
            return set.iterator().next();
        OWLOntologyMerger merger = new OWLOntologyMerger(new OWLOntologySetProvider() {

            @Override
            public Set<OWLOntology> getOntologies() {
                return set;
            }
        });
        return merger.createMergedOntology(createOWLOntologyManager(), IRI.create("reasoners:input-" + System.currentTimeMillis()));
    } catch (OWLOntologyCreationException e) {
        String message = "The network for scope/session cannot be retrieved";
        log.error(message + ":", e);
        throw new IllegalArgumentException(message);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) OWLOntologyMerger(org.semanticweb.owlapi.util.OWLOntologyMerger) IOException(java.io.IOException) OWLOntologySetProvider(org.semanticweb.owlapi.model.OWLOntologySetProvider) Scope(org.apache.stanbol.ontologymanager.servicesapi.scope.Scope) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) Session(org.apache.stanbol.ontologymanager.servicesapi.session.Session) HashSet(java.util.HashSet)

Example 2 with Session

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

the class SessionManagerResource method createSessionWithAutomaticId.

@POST
public Response createSessionWithAutomaticId(@Context UriInfo uriInfo, @Context HttpHeaders headers) {
    Session s;
    try {
        s = sessionManager.createSession();
    } catch (SessionLimitException e) {
        throw new WebApplicationException(e, FORBIDDEN);
    }
    String uri = uriInfo.getRequestUri().toString();
    while (uri.endsWith("/")) uri = uri.substring(0, uri.length() - 1);
    uri += "/" + s.getID();
    ResponseBuilder rb = Response.created(URI.create(uri));
    //        addCORSOrigin(servletContext, rb, headers);
    return rb.build();
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) SessionLimitException(org.apache.stanbol.ontologymanager.servicesapi.session.SessionLimitException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Session(org.apache.stanbol.ontologymanager.servicesapi.session.Session) POST(javax.ws.rs.POST)

Example 3 with Session

use of org.apache.stanbol.ontologymanager.servicesapi.session.Session 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);
    }
}
Also used : NonReferenceableSessionException(org.apache.stanbol.ontologymanager.servicesapi.session.NonReferenceableSessionException) SessionImpl(org.apache.stanbol.ontologymanager.multiplexer.clerezza.impl.SessionImpl) Session(org.apache.stanbol.ontologymanager.servicesapi.session.Session)

Example 4 with Session

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

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

Aggregations

Session (org.apache.stanbol.ontologymanager.servicesapi.session.Session)16 OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)5 Scope (org.apache.stanbol.ontologymanager.servicesapi.scope.Scope)4 Test (org.junit.Test)4 IOException (java.io.IOException)3 IRI (org.apache.clerezza.commons.rdf.IRI)3 Triple (org.apache.clerezza.commons.rdf.Triple)3 DuplicateSessionIDException (org.apache.stanbol.ontologymanager.servicesapi.session.DuplicateSessionIDException)3 NonReferenceableSessionException (org.apache.stanbol.ontologymanager.servicesapi.session.NonReferenceableSessionException)3 SessionLimitException (org.apache.stanbol.ontologymanager.servicesapi.session.SessionLimitException)3 HashSet (java.util.HashSet)2 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)2 TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)2 SessionImpl (org.apache.stanbol.ontologymanager.multiplexer.clerezza.impl.SessionImpl)2 OntologySpace (org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace)2 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)2 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)2 FileNotFoundException (java.io.FileNotFoundException)1 Set (java.util.Set)1 POST (javax.ws.rs.POST)1