MyFirstCell

Creating a cell class

The Constructor

The easiest way to create a cell class is to extend an arbitrary class by dmg.cells.nucleus.CellAdapter . The constructor of CellAdapter needs at least the name of the cell which you want to create.
      import dmg.cells.nucleus.* ;

      public class FooCell extends CellAdapter {
          
          public FooCell( String name ){

             super( name )

             ...
             
             say( "Cell "+getCellName()+" created." ) ;

          }
      }
   
The CellAdapter tries to create the cell with the specified name. If the name is already in use by another cell, the constructor throws an java.lang.IllegalArgumentException with the message "Name Mismatch". If the name of the cell is not significant, an '*' can be used as last character in the cells name. The CellAdapter will find a unique name then. The getCellName() method will return the chosen name. The say method typically will send its argument to System.out.println but may configured differently. So
       CellAdapter cell1 = new FooCell( "foo*" ) 
       CellAdapter cell2 = new FooCell( "foo*" ) 
   
may print
       Cell foo-0022 created.
       Cell foo-0023 created.
   

Activating a cell

Cell Objects can only be created ( new FooCell ) within a Domain Environment. A virtual machine creates a Domain Environment as soon as a dmg.cells.nucleus.SystemCell object has been created.
       SystemCell system = new SystemCell( "<domainName>" ) ;
   
<domainName> is the name of this Domain Environment. As long as no Domains are connect to each other, the name is not significant. The name of the SystemCell will always be System. Only on SystemCell can be created within a Domain.
       SystemCell system = new SystemCell( "MyFirstDomain" ) ;
       new FooCell( "myFirstCell" ) ;
       new FooCell( "foo*" ) ;
       new FooCell( "foo*" ) ;
   
The above codelet will create a Domain Environment with the name MyFirstDomain and four cells called System, myFirstCell, foo-001, foo-002.

Running a Domain

The dmg.cells.services contains the code of a standard Domain with is configurable by command line options. dmg.cells.services.Domain allows you to create and remove Cells dynamically and to inspect the Cell Environment by login into it with by telnet.
NOTE : To enable the dynamic creation of cells the constructor of the cell class has to have two String arguments.
       public FooCell( String name , String args ){
           super( name ) ;
       }
   
You may choose any name as your username. The password has to be elch. You will be prompted by
   tn-<yourUserName>-100 >
   
The shell your are logged into, provides a small set of commands to manipulate and inspect the Domain Environment. A simple help is available throu the help command.
For a list of all cells use the ps -a command.
    tn-patrick-100 > ps -a
      Cell List
    ------------------
    tlm            Active    0   TelnetLoginManager  P=22123;C=dmg.cells.services.StreamLoginCell
    System         Active    0   SystemCell          TestDomain:R=0;A=0;F=0;R=0;X=0
    tn-patrick-100 Active    0   StreamLoginCell     patrick@localhost/127.0.0.1
    tn-patrick-100 > 
   
The output list the name of the cell, the current status, the number of messages queued for this cell, the class name and a short discription of the cell itself. The description is the result of the toString method of the perticular cell object.
To get more information about a cell you may use
   tn-patrick-100 > ps <cellName>
   
This command executes the getInfo() method of a cell. The toString() and getInfo() methods need to be overwritten by the cell implementation to get object specific information.
To activate an instance of your FooCell run :
   tn-patrick-100 > create FooCell fooCellName
   created : fooCellName
   
Check the creation of the new FooCell instance with 'ps -a'.

To remove the cell from the cell list, use the

   tn-patrick-100 > kill <cellName>
   
command.

Killing the SystemCell will start the domain shutdown sequence. First all cells except the System cell are killed and finally the System.exit(0) is called.

The exit command leaves the shell and jumps into a kind of micro shell, the .. shell. Another exit command quits the telnet connection. The micro shell can connect the telnet session to an arbitrary cell.

   .. > set dest <cellName>
   <cellName> > 
   
After issuing this command, all lines, typed in, are send to <cellName> and the respond is displayed by the telnet session. exit will return to the .. shell and
   .. > set dest <cellName>
   <cellName> > 
   
   .. > set dest local
   
returns to the standard cell shell.

Killing cells

There are a set of possibilities to kill a cell. As soon as one of the kill commands is executed : Its up to the creator of the cell class to overwrite the cleanUp method to perform any necessary clean up activities.

Exiting the domain

When logged into the

Full First Cell Example

The first example summarizes everything discussed in this chapter. The java file has to be called 'FooCell.java'. You can run it exactly as described above with the standard Domain Environment. After starting the cell it will live for 20 seconds and then it will call kill itself. The cleanUp call will sleep for 2 seconds before it returns, to simulate a complicated cleanup sequence.