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