Home
Categories
Dictionary
Glossary
Download
Project Details
Changes Log
What Links Here
FAQ
License

Jena uaFunctions



Jena custom functions function elements specified to use in Jena SPARQL queries can only make calculations using data properties passed to the function in the query.

By constrast uaFunction elements can invoke and subscribe to services.

Defining the functions factory

Contrary to regular functions, your factory must implement the org.da.protoframework.jena.sparql.functions.UAFunctionFactory interface to be able to handle UA functions. This interface extends the FunctionFactory interface and has the following API:

public class org.da.protoframework.jena.sparql.functions.UAFunctionFactory
A FunctionFactory which handles UA functions.

Modifier and Type Method and Description
Function createFunction(String uri)
Create a function with the given URI (this method is the method provided by the FunctionFactory interface)
void invokeAndBlock(UAFunction function, long timeOut)
Invoke a function and block. You will need to call unlock() after you have computed the function results
boolean unlock()
To be called after you have computed the function results

The org.da.protoframework.jena.sparql.functions.AbstractUAFunctionFactory class handle almost all these methods. The only method you will have to implement if you implement this class is:

public class org.da.protoframework.jena.sparql.functions.AbstractUAFunctionFactory
A FunctionFactory which handles UA functions.

Modifier and Type Method and Description
Function createFunctionImpl(String uri)
Create a function (this method is called by the createFunction(String uri) method)

Note that a UAFunctionFactory is a valid FunctionFactory, so it is not limited to create UAFunctions but can also create regular functions as any FunctionFactory can.

Defining a UAFunction

A UAFunction has the following API:

public class org.da.protoframework.jena.sparql.functions.UAFunction
A Function which is able to invoke and subscribe to services.

Modifier and Type Method and Description
void init(Module module, UAFunctionFactory factory)
Initialize the function after its creation
void invoke()
Invoke the function
void subscribe(ServiceInstance service)
Subscribe to a Service

Invocation an notification of the function

The services with which the UAFunction will be able to interact are those which are defined in the Jena module instance, and which are not defined in the Jena module definition interfaces (see the Jena module definition).

For example, suppose that we use the Jena module as followed:
      <application name="jena">
         <deployment>
            <lib url="../JenaModule.jar" />
            <lib url="TestUAFunctions.jar" />
         </deployment>
         <modules>
            <module name="jena">
               <interfaces>
                  <requestReceived service="owlObjectRequest" uri="http://dassault-aviation.com/jena" />
                  <requestSend service="compute" />
               </interfaces>
            </module>
         </modules>
      </application>
In this case the compute service is not part of the Jena module definition interfaces, which means that:
  • The UAFunction is able to invoke a compute request
  • The UAFunction subscribe method will be called if a response from this request is received

Invoking a service

You can invoke any service for which the UAFunction is able to invoke in the corresponding exec(...) method.

However you will probably use a request-response Service to ask for parameters and use them in your computation. This means that you will need to block your execution until you receive the response (assuming that you did not reach the timeout). The UAFunctionFactory has two utility methods which will help you to do just that:

public class org.da.protoframework.jena.sparql.functions.UAFunctionFactory
A FunctionFactory which handles UA functions.

Modifier and Type Method and Description
void invokeAndBlock(UAFunction function, long timeOut)
Invoke a function and block. You will need to call unlock() after you have computed the function results
boolean unlock()
To be called after you have computed the function results

Calling invokeAndBlock and passing your UAFunction as argument (and a timeOut) will call the invoke() method of your UAFunction in a background Thread and block the execution of the calling Thread until the unlock() is called.

Note that to be sure that the services invocations performed in the UAFunction are not called in the blocked calling Thread, you will need to call invokeAndBlock() rather than invoke() in your function code (see Invoking a service for more information).

See also


Categories: builtin-applis

Copyright 2017-2020 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v3 licence