Class CurrentThreadFunctionRegistry


  • public class CurrentThreadFunctionRegistry
    extends org.apache.jena.sparql.function.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.

    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 CurrentThreadFunctions object that was registered before. So a typical block would be:

    Model model = ... a Model with extra SHACL/SPIN functions CurrentThreadFunctions old = CurrentThreadFunctionRegistry.register(model); try { // run SPARQL queries here } finally { CurrentThreadFunctionRegistry.unregister(old); }

    In preparation of the above, the application should start up with code such as

    FunctionRegistry oldFR = FunctionRegistry.get(); CurrentThreadFunctionRegistry threadFR = new CurrentThreadFunctionRegistry(oldFR); FunctionRegistry.set(ARQ.getContext(), threadFR);

    and (for SPIN) do the same for the SPINThreadPropertyFunctionRegistry.

    Author:
    Holger Knublauch
    • Method Detail

      • register

        public static Runnable register​(org.apache.jena.rdf.model.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:
        a Runnable that must be called (in a finally block) when done to restore the previous state
      • get

        public org.apache.jena.sparql.function.FunctionFactory get​(String uri)
        Overrides:
        get in class org.apache.jena.sparql.function.FunctionRegistry
      • isRegistered

        public boolean isRegistered​(String uri)
        Overrides:
        isRegistered in class org.apache.jena.sparql.function.FunctionRegistry
      • keys

        public Iterator<String> keys()
        Overrides:
        keys in class org.apache.jena.sparql.function.FunctionRegistry
      • put

        public void put​(String uri,
                        Class<?> funcClass)
        Overrides:
        put in class org.apache.jena.sparql.function.FunctionRegistry
      • put

        public void put​(String uri,
                        org.apache.jena.sparql.function.FunctionFactory f)
        Overrides:
        put in class org.apache.jena.sparql.function.FunctionRegistry
      • remove

        public org.apache.jena.sparql.function.FunctionFactory remove​(String uri)
        Overrides:
        remove in class org.apache.jena.sparql.function.FunctionRegistry