#Process Class Example
The following code shows an example of a complete (but small) process class.
/* Process class that sends one message. */ process class Sender ports /* This is the only port; it is used for outgoing messages. */ Out messages /* Outgoing message */ Out!Message(String) variables init Send()() methods /* Send one message */ Send()() Out!Message("Hello World")
The first line
process class Sender starts the process class definition and declares the name of the class as
Sender. This process class does not inherit from another class. This would have been indicated with the construct
extends SomeClass following the first line.
extends is a keyword and
SomeClass is the nae of a process class from which it will inherit. This class needs to be defined in the same poosl file, or in a file that is being included.
ports Out declares that instances of this class have one communication port called
Out. More ports can be defined using a comma-separated list.
The message interface is defined by the part.
messages /* Outgoing message */ Out!Message(String)
It defines in this case, a single message. It is a message send (
!) on port
Out with the message name
Message and it includes a single parameter, which will be a data object of type
variables declares the instance variables of the process class. This class has none.
init section defines which of the methods of the process class will be called immediately after the process is instantiated. In this case
Send()(). It follows the syntax of any other method call, but return parameters are not allowed here. The second pair of parentheses is always empty. In this example no parameters are passed to the method either.
methods /* Send one message */ Send()() Out!Message("Hello World")
The last section defines the methods of the process class. It starts with the keyword
methods, followed by a list of method definitions. In this case only one method, called
Send is defined.
This simple method has only one statement, a send statement. Note that it conforms to the declared message interface.
Note that there is no explicit termination symbol or keyword to delineate the end of the process class definition. It can be immediately followed by another class definition, or other elements of the model syntax.