![]() | Developing Modules
![]() Using Default Ports
| ![]() Creating Ports
| ![]() Adding Modules
| |
![]() | initialize() |
![]() | run() |
![]() | stop() |
![]() | destroy() |
The webflow module must implement all three methods. An adder module is used as an example below. It consists of three ports (two input and one output). The following are the steps in making an adder module.
import webflow.*;
MetaModule mm = new MetaModule("mm");
All ports are given a certain portID by the ConnectionManager. This portID is returned by the port using the getPortID method. All the port ID's are stored in the MetaModule object as shown below:
port1 = new InputPort();
mm.putPortID(port1.getPortID());
The last step in the initialize method is to return the MetaModule object:
return(mm);
num1=port1.recieve().intValue(); // read value from first port num2=port1.recieve().intValue(); //read value from second port
num3=num1 + num2; //add the two numbers
port2.send(new Integer(num3));//dispatch the value through the output port
port1.destroy();
In order to make the module developement easier, two default Port implementations are provided with the Webflow distribution. An InputPort class which
receives data and an OutputPort class which sends data. Both these classes
takes any Serializable data as arguments to their send and receive methods.
Thus module developers can make use of these two ports for sending any
serializable data between modules. For eg., the image filter demo modules
use a data type, ImgData, which implements serializable interface. The
InputPort and OutputPort classes are then used as follows :
outport = new OutputPort("ImgData"); // in module's initialize method
mm.putPortID(outport.getPortID());
inport = new InputPort("ImgData");
mm.putPortID(inport.getPortID()):
ImgData imgdat = (ImgData) inport.receive(); // In run method
outport.send(imgdat);// inside run method
Note : Here imgdat is a serializable data type which implements the Serializable interface.
If a developer needs to implement a special or custom port class follow these directions. All ports are derived from Port class . The main methods in the Port class are:
![]() | getPortID() |
![]() | send() |
![]() | recieve() |
![]() | getSocket() |
![]() | destroy() |
A simple integer port has been used for the adder class . The basic integer port sends and recieves an Integer object since the send and receive functions of the Port class deal with the Object class . When the IntPort object is created, the constructor of the Port class is called which registers the port with the ConnectionManager and gives a unique portID to the port. This id is retrieved using the getPortID() method in the initialize method of the module . This portID is what is stored in the MetaModule and it is what is used for making connections between modules.
The destroy method is used when the module terminates and is used to deregister the port.
The send and recieve methods are implemented in the following way in the IntPort class 1.
The send method as defined by the Port class takes an Object as its parameter:
In the IntPort class this Object is an Integer object which contains the integer data to be transmitted through the port. To get the Socket of the port the getSocket method is called . A new output stream is created through which the data is sent:
It returns an object of class Object:
In the IntPort class this Object is an Integer object which contains integer data recieved . As usual the getSocket method retrieves the Socket and a new input stream is created through which data is read:
data= new Integer(is.readInt());// data is an Integer object
return(data);// data object being returned
Once you have compiled the new module succesfully, put your module into some directory present in the server's CLASSPATH environment variable. (For eg. $WEBFLOW_HOME/webflow/modules ). Make sure you have the proper package name depending on where your module class is and put this fully qualified name of your module into the modules.txt file present in the $WEBFLOW_HOME directory.
The first entry in the modules.txt file is the fully qualified name of your module, next is the hostname of the machine where your module is going to be run, the port number of your webflow server is next, and finally the module representation class.(The module representation class is the icon(image) that you will see on the webflow editor window. You can use your own or use one of the representation classes used in the demo. (For eg: webflow.frontend.SinglePortRep class can be used and this class displays the name of your class on the representation icon with a single port, DualPortRep takes can be used for modules with an input and output port) So, for eg: if your module's fully qualified name is webflow.modules.myTest.myModule and if you are using the module representation class webflow.frontend.SinglePortRep and your webflow server is running on the host myhost.edu on port 8888, then you would have an entry in the modules.txt file as follows
webflow.modules.myTest.myModule myhost.edu 8888 webflow.frontend.SinglePortRep |
---|
Now start the webflow demo and the new entry in the modules.txt file should show up in the webflow modules tree pallete. Click and run the module as you do in the demo programs.