net.sourceforge.fluxion.utils
Class ReasonerSession

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

public class ReasonerSession
extends java.lang.Object

A ReasonerSession encapsulates an OWLReasoner and exposes it according to semaphore leases given by a ReasonerSessionManager. This allows OWLReasoners to be made accessible as part of a connection pool.

Since:
28-Aug-2007
Version:
1.0
Author:
Tony Burdett, Rob Davey

Constructor Summary
ReasonerSession(java.util.Set<org.semanticweb.owl.model.OWLOntology> ontologies)
          Construct a new ReasonerSession given a set of ontologies.
 
Method Summary
 void expire()
          Empty the ReasonerSession of any previously loaded and classified ontologies.
 java.util.Set<org.semanticweb.owl.model.OWLOntology> forOntologies()
          Retrieve the set of loaded ontologies from the underlying reasoner instance
 int getQueueSize()
          Get the number of connections waiting for this ReasonerSession to become available.
 org.semanticweb.owl.inference.OWLReasoner getReasoner()
          Expose the underlying OWLReasoner instance employed by this ReasonerSession
 boolean hasExpired()
          Check whether this ReasonerSession has expired.
 boolean isLeased()
          Check if this ReasonerSession is leased
 long lastLeased()
          The time (in milliseconds) that this reasoner was last leased in the connection pool
 ReasonerSession leaseSession()
          Acquire a ReasonerSession.
 ReasonerSession leaseSession(int timeout)
          Acquire a ReasonerSession, if one becomes available within the given waiting time.
 void releaseSession()
          Release this ReasonerSession for use by another connection
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReasonerSession

public ReasonerSession(java.util.Set<org.semanticweb.owl.model.OWLOntology> ontologies)
Construct a new ReasonerSession given a set of ontologies. This class usually isn't instantiated directly, but rather through a session management mechanism like ReasonerSessionManager

Parameters:
ontologies - the set of ontologies to load into the underlying reasoner instance
Method Detail

forOntologies

public java.util.Set<org.semanticweb.owl.model.OWLOntology> forOntologies()
Retrieve the set of loaded ontologies from the underlying reasoner instance

Returns:
the set of loaded ontologies

lastLeased

public long lastLeased()
The time (in milliseconds) that this reasoner was last leased in the connection pool

Returns:
the last lease time

isLeased

public boolean isLeased()
Check if this ReasonerSession is leased

Returns:
true if this ReasonerSession is currently leased

leaseSession

public ReasonerSession leaseSession(int timeout)
                             throws java.lang.InterruptedException
Acquire a ReasonerSession, if one becomes available within the given waiting time. If no permits are made available within this time, i.e. this ReasonerSession is leased, return false

Parameters:
timeout - the length of time to wait, in SECONDS
Returns:
a reference to this reasoner session, if a lease could be acquired within the given timeout period
Throws:
java.lang.InterruptedException - if there was a problem leasing a session, or if this session has expired

leaseSession

public ReasonerSession leaseSession()
                             throws java.lang.InterruptedException
Acquire a ReasonerSession. If no permits are available, i.e. this ReasonerSession is leased, this will block until the ReasonerSession becomes available after a call to releaseSession()

Returns:
a reference to this reasoner session
Throws:
java.lang.InterruptedException - if there was a problem acquiring a permit from the lease semaphore

releaseSession

public void releaseSession()
Release this ReasonerSession for use by another connection


expire

public void expire()
Empty the ReasonerSession of any previously loaded and classified ontologies. Marking a ReasonerSession as expired will cause any subsequent attempts to lease it to fail.


hasExpired

public boolean hasExpired()
Check whether this ReasonerSession has expired.

Returns:
true if this ReasonerSession has expired

getQueueSize

public int getQueueSize()
Get the number of connections waiting for this ReasonerSession to become available.

Queue length should not be taken as a measure of time before a ReasonerSession becomes available as reasoning tasks are not a factor of simple ontology size, i.e. a queue length of 1 waiting for a more complex ontology to be processed will probably wait longer than a larger queue for a less complex ontology.

Returns:
the number of threads queued that are waiting for the leasing semaphore to unblock

getReasoner

public org.semanticweb.owl.inference.OWLReasoner getReasoner()
                                                      throws org.semanticweb.owl.inference.OWLReasonerException
Expose the underlying OWLReasoner instance employed by this ReasonerSession

Returns:
the current OWLReasoner instance employed by this ReasonerSession
Throws:
org.semanticweb.owl.inference.OWLReasonerException - if this ReasonerSession hasn't been made available to a ReasonerSessionManager by leaseSession(int), or if the current session has expired.


Copyright © 2010. All Rights Reserved.