Starting the Erudine Behaviour Engine

Note
Before you begin working through this article, please ensure you have:

Purpose

To start the Erudine Behaviour Engine using a method call from another Java application.

Theory

In this exercise, you will learn how to start the Erudine Behaviour Engine using a Java method call. Starting the Erudine Behaviour Engine in this way allows you to access the application's Behaviour Execution Engine. This Behaviour Execution Engine allows you to query the structure of your knowledge models programmatically. More importantly, the Behaviour Execution Engine allows you to process data by creating situations and running them through your knowledge models.

Actions

Writing code to start the Erudine Behaviour Engine

To create a method that will start the Erudine Behaviour Engine:

  1. Open Eclipse.
  2. Expand the src/java folder.
  3. Expand the exercise.startingEbe package
  4. Open the StartEbeCommand class.
    This class contains some utility methods so that this exercise can focus on the steps involved in starting the Erudine Behaviour Engine.
    The method getUrl takes a path and converts it to a URL, throwing exceptions if the file indicated by the path does not exist or there is some reason why a URL cannot be successfully generated.
    The method you will write to start the Erudine Behaviour Engine will take a list of logical names and knowledge model paths. Each pair consisting of a name and a path represents a knowledge model to be deployed into the Behaviour Execution Engine. The checkCorrectNumberOfModels method checks that at least one pair is supplied and that for every name there is a path (and vice versa).
  5. Delete the following lines from the startEbe method of the StartEbeCommand class:
    // TODO - Remove the line below when starting this exercise
    return null;

    These lines were included in the supplied code to avoid compiler errors.

  6. Collapse the src/java folder and expand the resources folder.
  7. Open the StartEbeCommand_StartEbe.java file.
  8. Copy the following line from the file into the startEbe method of the StartEbeCommand class:
    checkCorrectNumberOfModels( logicalNames, knowledgeModelPaths ); 

    This line validates uses the method described above to validate the parameters to the startEbe method.

  9. Copy the following line from the file into the startEbe method of the StartEbeCommand class:
    KnowledgeModelSet knowledgeModelSet 
    = new KnowledgeModelSet( configurationString );

    This line creates a new KnowledgeModelSet using the configuration supplied to the method. The configuration string is equivalent to the contents of an erudine.config file. This will be supplied by the method's caller and could be created on the fly or read from the file system. The KnowledgeModelSet is the set of knowledge models that will be deployed when the Behaviour Execution Engine is started.

  10. Copy the following text from the file into the startEbe method of the StartEbeCommand class:
    for ( int i = 0; i < logicalNames.size(); i++ ) {
    String logicalName = logicalNames.get( i );
    String knowledgeModelPath = knowledgeModelPaths.get( i );
    knowledgeModelSet.addKnowledgeModel( logicalName, 
    getUrl( knowledgeModelPath ) );
    }

    This code iterates through all of the logical name-knowledge model path pairs provided by the method's caller. For each pair, a knowledge model is created and added to the KnowledgeModelSet. The method getUrl is used to convert the given path into the required URL.

  11. Copy the following line from the file into the startEbe method of the StartEbeCommand class:
    return new BehaviourExecutionEngine( knowledgeModelSet );

    This line uses the KnowledgeModelSet that you have created to initialise the Behaviour Execution Engine. The Behaviour Engine is returned to the method's caller and they are now free to use it to query the knowledge models or process data.

  12. Press Ctrl + Shift + O to organise the imports.

Testing the code that starts the Erudine Behaviour Engine

Once the code has been created, it is necessary to test it.
To test the code that starts the Erudine Behaviour Engine:

  1. Collapse the resources folder and expand the src/unit folder.
  2. Expand the exercise.startingEbe package.
  3. Open the StartEbeCommandTest class to display its contents.
  4. Right click over the Java code and select Run As > JUnit Test from the context menu.
    This runs the tests contained in StartEbeCommandTest class against the StartEbeCommand class that has been created in this exercise.
    If the tests are successful, the JUnit bar in the top left corner of the screen will go green, confirming that your function has been correctly implemented.
  5. Examine the testStartEbe method.
    This method tests that when given the correct parameters, the StartEbeCommand class will create a Behaviour Execution Engine from which a knowledge model can be retrieved. In this instance, the startEbe method is passed an arbitrary logical name and the path to an example knowledge model file. The Behaviour Execution Engine is returned and a programmatic interface to the example knowledge model is obtained.
  6. Examine the testStartEbeFailsWithInconsistentParameters method.
    This method tests that when given inconsistent parameters the startEbe method does not deploy a knowledge model and no Behaviour Execution Engine is returned. In this instance, the startEbe method is passed two logical names and only a single knowledge model path. This is an invalid combination, as a logical name and a knowledge model path are needed to deploy a knowledge model.
  7. Examine the testStartEbeFailsWhenNoKnmSpecified method.
    This method tests that when given no logical names or knowledge model paths, the startEbe method does not deploy a knowledge model and no Behaviour Execution Engine is returned. It only makes sense to deploy an existing knowledge model.
  8. Examine the testStartEbeFailsInvalidKnmSpecified method.
    This method tests that when given a knowledge model path that refers to a non-existent file, the startEbe method does not deploy a knowledge model and no Behaviour Execution Engine is returned.
  9. Close Eclipse.

Platform: all
EBE Version: 2.4
Category: Development Training Guide
Author: Patrick Peisker


Browse Space

- Pages
- News
- Labels
- Attachments
- Bookmarks
- Mail
- Activity
- Advanced

Explore Confluence

- Popular Labels
- Notation Guide

Your Account

Log In

 

Other Features

Add Content