Package com.ibm.streams.function.model

Annotations to define SPL Java native functions.

See: Description

  • Annotation Types Summary 
    Annotation Type Description
    Function
    Declare an SPL Java native function.

Package com.ibm.streams.function.model Description

Annotations to define SPL Java native functions.

The typical steps to create an SPL Java native function in an SPL toolkit are:

  1. Annotate a method with the Function annotation.
  2. Optionally, annotate the containing class with the ToolkitLibraries annotation.
  3. Compile the Java class containing the method.
  4. Package the class and its nested classes in a jar file in lib or impl/lib within the toolkit.
  5. Index the toolkit.
Details of these steps are covered in the following paragraphs.

Methods annotated with @Function define SPL Java native functions in an SPL toolkit. The native functions are created when the toolkit is indexed, which occurs by running spl-make-toolkit. Toolkit indexing may be explicit, by executing spl-make-toolkit, or implicit through the SPL compiler sc or Streams Studio.

A Java method annotated with @Function defines one or more SPL native functions during toolkit indexing if its class file is in one of these locations relative to the root directory of the toolkit (the value passed as the -i argument to spl-make-toolkit):

  • Contained in a jar file within lib or impl/lib. The jar file must have the suffix .jar or .JAR.
  • The class directory impl/java/bin (in its correct package based sub-directory).

The class must have been compiled with annotation processing enabled using the annotation processors defined by the jar file com.ibm.streams.operator.jar. This annotation processing occurs automatically when using a Java compiler or Streams Studio.
The annotation processing creates a nested class for the class containing the annotated method, with the class name addition being $StreamsModel. When creating a jar file containing classes for annotated methods, these nested classes must be included. Toolkit indexing creates SPL native function definitions from these nested classes. This is similar to including nested classes created by anonymous inner classes. Typically creating a jar file includes all classes within a package and thus no special action is required.

Toolkit indexing creates SPL artifacts under the native.function directory of the directory for the SPL namespace of the native function. The namespace for a native function is defined according to the namespace() element or the package annotation Namespace. The generated artifacts include:

  • The model file javaFunction.xml for the SPL Java native functions in the namespace.
  • A C++ header file containing code to call the Java methods from SPL
These generated artifacts are read-only and must not be modified.
The native.function directory may also contain manually generated SPL C++ native functions, represented by the function model file function.xml.

A single ClassLoader is created for each toolkit. It contains:

  • Jar files in lib and impl/lib that contain a class with a method annotated with @Function.
  • The class directory impl/java/bin if it contains a class with a method annotated with @Function.
  • Jar files and class directories added with @ToolkitLibraries.
The order of jars and impl/java/bin within the class loader is not defined.
Classes containing SPL Java native functions are loaded using this class loader. If additional jars are required in the class search path, they can be specified by using one of the following methods:
  • Use the ToolkitLibraries annotation to annotate the class and specify the required paths.
  • Package the class in a jar file where the jar file has a Class-Path manifest entry that references the required jars.
The required jars would typically be contained within the toolkit. For example third-party jars may be under opt and a jar file in lib would reference them using a relative path starting with ../opt/.

The Java Operator API classes and the dependent jars are available to SPL Java native functions at runtime.
Methods may use the SPL logging facilities of the Java Operator API, using Java platform logging or Apache Log4j.
Methods do not have access to the processing element or operator context.

Since:
InfoSphere® Streams Version 3.2