To use an event that you have defined in the mini-bundle in your data processing code, you must generate a Java enums file from the mini-bundle and then add the event to a trail with the relevant enum.

The Ant task for generating the enums file is generate-bundle-enums, and the relevant Java class is provided in the client/lib/rhino-extensions-ant.jar Rhino TAS library.

In Rhino TAS, if you check client/etc/rhino-extensions.xml, you will find the task defined as follows:

<taskdef name="generate-bundle-enums" classname="com.opencloud.ant.sas.GenerateBundleEnumsTask">
    <classpath refid="rhino-extensions-ant.classpath"/>
</taskdef>

You can add this task to your build script so that when the application is built, the enums files are automatically generated from the latest mini-bundle files.

To use the task in your build script, import rhino-extensions.xml first. For example, you can import the file like this:

<import file="${client.home}/etc/rhino-extensions.xml"/>

After that, you can define a build target that calls the task, as illustrated below:

<target name="generate-sas-enums" depends="initiation">
    <generate-bundle-enums destDir="${src}" dir="${basedir}/resources/sas-bundles" includes="*.yaml"/>
</target>

The attributes that you can set for the task are:

  • dir: The base directory to search for the mini-bundle files. The default value is resources/sas-bundles.

  • destDir: The output base directory where the task will save the generated enums files. The default value is src.

  • eventsClassName: The class name for the generated enum. The default value is SasEvent. This attribute is optional.

Note The Java class for the task extends the Ant class MatchingTask, which makes attributes such as includes available.

By convention, the script reads the mini-bundle files from the resources/sas-bundles base directory and saves the generated enums files to the src base directory. The name of the Java package determines the actual subdirectory paths. For example, for a package named com.abc.feature.xyz, the path of the mini-bundle should be resources/sas-bundles/com/abc/feature/xyz/sas-bundle.yaml, and the path of the generated enums file should be src/com/abc/feature/xyz/SasEvent.java.

The following example shows a generated enum class:

public enum SasEvent implements SasEventEnum {

    ANNOUNCE ( 0 ),
    DIVERT ( 1 ),
    ERROR ( 2 ),
    ;

    SasEvent(int id) {
        this.id = id;
    }

    @Override
    public int id() {
        return id;
    }

    private int id;
}

Once this file is generated, you can add relevant events to a trail in your code. For example, you can use the following code to add the ANNOUNCE event:

EventMessage event = trail.event(SasEvent.ANNOUNCE);

For more information, see Create and send an API message.

Warning Don’t edit the generated enums file. If you need an updated version of the file after changing the relevant mini-bundle, use the Ant task to generate it again.
Previous page Next page