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);
}
}
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();
}
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);
}
}
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;
}
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;
}
Aggregations