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. The more sophisticated version of the constructor allows to specify a java.lang.String containing a set of arguments and a boolean value which determines the startup behaviour of the cells.
   import dmg.cells.nucleus.* ;
   
   public class FooCell extends CellAdapter {
   
       public FooCell( String name , String arguments ){
       
          super( name , arguments  , false )
          
          ...
          
          start() ;
       }
   }
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".
The second argument is forwarded to the helper class dmg.util.Args. Args tokenizes the argument string. The tokendelimiter is one or more blank characters. Some arguments may have specific meanings for the CellAdapter. See Arguments for the CellAdapter for more information. The residual arguments are available throu :
import dmg.utils.* ;
//
// get the arguments
//
Args args = getArgs() ;
//
// print the standard arguments
//
for( int i = 0 ; i < args.argc() ; i++ ){
   say( "Argument "+i+" : "+args.argv(i) ) ;
}
//
// print the options (whatever start with a '-' )
//
for( int i = 0 ; i < args.optc() ; i++ ){
   say( "Option "+i+" : "+args.optv(i) ) ;
}
The say method is part of the CellAdapter. It tries to send the message to the standard output if possible. It may be configured differently.
The third argument of the CellAdapter constructor is a boolean value which determines if the intrinsic cell services should start immediately or after the start() method has been issued. Sometimes it might be necessary to delay the startup of the cell services because some variables are not yet initialized while the CellAdapter constructor is executing.

NOTE : Caused by a BUG in the current implementation, leaving the cell constructor with an exception needs some special attention if the startup is delayed ( third argument is false). In this case the cell must be started first and then stopped before the exception can be thrown or forwarded.

  import dmg.cells.nucleus.* ;
  
  public class FooCell extends CellAdapter {
  
     public FooCell( String name ) throws Exception {
     
        super( name , "" , false ) ;
        
        try{
            
            ...

        }catch( Exception e ){
            
            start() ;
            stop() ;
            
            throw e ;
        }
        
        start() ;
        
     }   
  }