Skip to content

Creating a Greta Module in Java

Philippe Gauthier edited this page Feb 17, 2021 · 4 revisions

The easiest way is to copy the folder "auxiliary/SampleModule" into a new folder (for exemple "auxiliary/MyModule").

It contains two dummy modules that take input data from other module to forward it to the connected ones. They could for instance dynamically add data before forwarding it, or log it somwhere.

image

To interact with other pre-existing modules, you have to think at what kind of data they give you or what kind of data you want to send. A lot of pre-existing data format exist, and it's better to re-use them. The last option can be to create you own interfaces and replicate this approach. For each of data, you usually have an "Emitter" module that send the data to all connected "Performer" modules.

For exemple the Intention interface is defined in the Intentions.jar library and this two interfaces define the communication :

In this exemple the IntentionForwarder module will forwarder data, so it implements both interfaces.

The connections are also defined in the Modular.xml file in the "connectors" section to allow the UI to make the arrow connection.

<connector id="IntentionEmitterToIntentionPerformer">
    <input class="greta.core.intentions.IntentionEmitter" lib_id="greta_intentions"/>
    <output class="greta.core.intentions.IntentionPerformer" lib_id="greta_intentions"/>
    <connect from="input" method="addIntentionPerformer" to="output"/>    <!-- it will call input.addIntentionPerformer(output) on arrow connection -->
    <disconnect from="input" method="removeIntentionPerformer" to="output"/>    <!-- it will call input.removeIntentionPerformer(output) on arrow disconnection  -->
</connector>

You'll need to tell Modular how to load the new Module in the Modular.xml file.

You'll need a menu in the "menus" node :

<menu name="Sample">
	<item module="Signal Forwarder" name="Signal Forwarder"/>
	<item module="Intention Forwarder" name="Intention Forwarder"/>
</menu>

Corresponding Modules in the "modules" node :

<module name="Signal Forwarder" style="Signals">
	<object class="greta.auxiliary.sampleModule.SignalForwarder" lib_id="greta_sampleModule"/>            
</module>
<module name="Intention Forwarder" style="Intentions">
	<object class="greta.auxiliary.sampleModule.IntentionForwarder" lib_id="greta_sampleModule"/>            
</module>

And tell where to find the library :

<lib id="greta_sampleModule" path="./Common/Lib/Internal/SampleModule.jar">
	<depends lib_id="greta_util"/>
	<depends lib_id="greta_signals"/>
	<depends lib_id="greta_intentions"/>			
</lib>

Getting started with Greta

Greta Architecture

Quick start

Advanced

Functionalities

Core functionality

Auxiliary functionalities

Preview functionality

Nothing to show here

Previous functionality (possibly it still works, but not supported anymore)

Clone this wiki locally