org.topbraid.spin.arq
Class SPINThreadFunctionRegistry
java.lang.Object
FunctionRegistry
org.topbraid.spin.arq.SPINThreadFunctionRegistry
public class SPINThreadFunctionRegistry
- extends FunctionRegistry
An ARQ FunctionRegistry that can be used to associate functions
with Threads, so that additional functions from a given Model can
be made visible depending on the SPARQL query thread.
Note that this concept only works if ARQ has been set to single
threading, which is done by the static block below.
The contract of this class is very strict to prevent memory leaks:
Users always need to make sure that unregister is called as soon
as a query (block) ends, and to restore any old SPINThreadFunctions
object that was registered before. So a typical block would be:
Model model = ... a Model with extra SPIN functions
SPINThreadFunctions old = SPINThreadFunctionRegistry.register(model);
try {
// run SPARQL queries here
}
finally {
SPINThreadFunctionRegistry.unregister(old);
}
In preparation of the above, the application should start up with code such as
FunctionRegistry oldFR = FunctionRegistry.get();
SPINThreadFunctionRegistry threadFR = new SPINThreadFunctionRegistry(oldFR);
FunctionRegistry.set(ARQ.getContext(), threadFR);
and do the same for the SPINThreadPropertyFunctionRegistry.
- Author:
- Holger Knublauch
|
Method Summary |
FunctionFactory |
get(java.lang.String uri)
|
boolean |
isRegistered(java.lang.String uri)
|
java.util.Iterator<java.lang.String> |
keys()
|
void |
put(java.lang.String uri,
java.lang.Class<?> funcClass)
|
void |
put(java.lang.String uri,
FunctionFactory f)
|
static SPINThreadFunctions |
register(Model model)
Registers a set of extra SPIN functions from a given Model for the current
Thread. |
FunctionFactory |
remove(java.lang.String uri)
|
static void |
unregister(SPINThreadFunctions old)
Unregisters the current Model for the current Thread. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SPINThreadFunctionRegistry
public SPINThreadFunctionRegistry(FunctionRegistry base)
register
public static SPINThreadFunctions register(Model model)
- Registers a set of extra SPIN functions from a given Model for the current
Thread.
- Parameters:
model - the Model containing the SPIN functions
- Returns:
- any old object that was registered for the current Thread, so that
the old value can be restored when done.
unregister
public static void unregister(SPINThreadFunctions old)
- Unregisters the current Model for the current Thread.
- Parameters:
old - the old functions that shall be restored or null
get
public FunctionFactory get(java.lang.String uri)
isRegistered
public boolean isRegistered(java.lang.String uri)
keys
public java.util.Iterator<java.lang.String> keys()
put
public void put(java.lang.String uri,
java.lang.Class<?> funcClass)
put
public void put(java.lang.String uri,
FunctionFactory f)
remove
public FunctionFactory remove(java.lang.String uri)