net.sourceforge.fluxion.utils
Class ReasonerSessionManager

java.lang.Object
  extended by net.sourceforge.fluxion.utils.ReasonerSessionManager

public class ReasonerSessionManager
extends java.lang.Object

A singleton class for acquiring ReasonerSessions, thereby providing access to a pre-classified ontology. To use this class, you should use

     OWLOntology ontology = ...
     ReasonerSessionManager.createManager().acquireReasonerSession(ontology);
 

Whenever you attempt to acquire a reasoner session, this manager compares the ontology you've requested a reasoner for to a backing collection, and then attempts to supply a ReasonerSession that can classify this ontology. If the ontology you're requesting has been previously classified, and a reasoner for it is available, a ReasonerSession that has pre-classified this ontology will be supplied. If not, a new ReasonerSession may be created and the ontology supplied classified up front.

Note that a ReasonerSession is considered to be available if it can be leased in

Version:
1.0
Author:
Tony Burdett

Method Summary
 ReasonerSession acquireReasonerSession(org.semanticweb.owl.model.OWLOntology ontology)
          Acquire any available reasoner session that supplies a reasoned-over version of the given ontology.
 ReasonerSession acquireReasonerSession(org.semanticweb.owl.model.OWLOntology ontology, int timeout)
          Acquire any available reasoner session that supplies a reasoned-over version of the given ontology.
static ReasonerSessionManager createManager()
           
 void destroy()
          Attempts to reclaim all resources this ReasonerSessionManager is currently using, removes all ontologies and reasoners from memory, and shuts down any threads being used to harvest stale results.
 int getDefaultTimeout()
          Gets the default period of time that this ReasonerSessionManager will wait before creating a new ReasonerSession, whenever acquireReasonerSession(org.semanticweb.owl.model.OWLOntology) is called.
 int getMaxNumberOfSessions()
          Gets the default maximum number of sessions that can be created.
 int getRecycleAfter()
          Gets the number of seconds ReasonerSessions are allowed to remain idle before getting recycled.
 void setDefaultTimeout(int defaultTimeout)
          Sets the default period of time that this ReasonerSessionManager will wait before creating a new ReasonerSession, whenever acquireReasonerSession(org.semanticweb.owl.model.OWLOntology) is called.
 void setMaxNumberOfSessions(int maxSessions)
          Sets the default maximum number of sessions that can be created.
 void setRecycleAfter(int recycleAfter)
          Sets the number of seconds ReasonerSessions are allowed to remain idle before getting recycled.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createManager

public static ReasonerSessionManager createManager()

getDefaultTimeout

public int getDefaultTimeout()
Gets the default period of time that this ReasonerSessionManager will wait before creating a new ReasonerSession, whenever acquireReasonerSession(org.semanticweb.owl.model.OWLOntology) is called.

Returns:
the default timeout period for this reasoner session manager

setDefaultTimeout

public void setDefaultTimeout(int defaultTimeout)
Sets the default period of time that this ReasonerSessionManager will wait before creating a new ReasonerSession, whenever acquireReasonerSession(org.semanticweb.owl.model.OWLOntology) is called.

Parameters:
defaultTimeout - the default timeout period for this reasoner session manager

getMaxNumberOfSessions

public int getMaxNumberOfSessions()
Gets the default maximum number of sessions that can be created. If the number of reasoner sessions per ontology is exceeded, an exception will be thrown.

Returns:
the maximum number of sessions allowed

getRecycleAfter

public int getRecycleAfter()
Gets the number of seconds ReasonerSessions are allowed to remain idle before getting recycled. -1 is the default, meaning ReasonerSessions managed by this manager never get recycled. Setting this value to a non-negative value will cause ReasonerSessions that were last leased more than this time period ago to be recycled, reclaiming any resources they were using.

Returns:
the number of seconds this manager will wait before reclaiming idle reasoner sessions.

setRecycleAfter

public void setRecycleAfter(int recycleAfter)
Sets the number of seconds ReasonerSessions are allowed to remain idle before getting recycled. -1 is the default, meaning ReasonerSessions managed by this manager never get recycled. Setting this value to a non-negative value will cause ReasonerSessions that were last leased more than this time period ago to be recycled, reclaiming any resources they were using.

Parameters:
recycleAfter - the number of seconds to wait before idle reasoner sessions are recycled and their resources reclaimed.

setMaxNumberOfSessions

public void setMaxNumberOfSessions(int maxSessions)
Sets the default maximum number of sessions that can be created. If the number of reasoner sessions per ontology is exceeded, an exception will be thrown.

Parameters:
maxSessions - the maximum number of sessions allowed

destroy

public void destroy()
Attempts to reclaim all resources this ReasonerSessionManager is currently using, removes all ontologies and reasoners from memory, and shuts down any threads being used to harvest stale results.


acquireReasonerSession

public ReasonerSession acquireReasonerSession(org.semanticweb.owl.model.OWLOntology ontology)
Acquire any available reasoner session that supplies a reasoned-over version of the given ontology. This is equivalent to called acquireReasonerSession(org.semanticweb.owl.model.OWLOntology, int), substituting a default timeoout period (normally five seconds).

Parameters:
ontology - the ontology to obtain a reasoner session for
Returns:
the reasoner session that provides access to a reasoner for the supplied ontology

acquireReasonerSession

public ReasonerSession acquireReasonerSession(org.semanticweb.owl.model.OWLOntology ontology,
                                              int timeout)
                                       throws java.lang.RuntimeException
Acquire any available reasoner session that supplies a reasoned-over version of the given ontology. If a ReasonerSession can be obtained within the timeout period specified, it will be returned, and if not a new ReasonerSession will be fetched and added to the collection of reasoner sessions for this ontology.

It is important to note that this class imposes no restrictions on modifications that may be made on the underlying ontology. If you're application allows scope for programmatically modifying the ontology, reusing pre-reasoned data may give unexpected or out-of-date results. If there is a possibility that this has occurred since classification, you should always re-classify data. If available, you can use incremental reasoner updates, but this is not managed for you by either this class or ReasonerSession.

Parameters:
ontology - the ontology to obtain a reasoner session for
timeout - the maximum amount of time to wait before creating a new reasoner session
Returns:
the reasoner session that provides access to a reasoner for the supplied ontology
Throws:
java.lang.RuntimeException - if the maximum number of reasoner sessiosn for this ontology is exceeded


Copyright © 2010. All Rights Reserved.