inria.meije.rc.sugarcubes
Interface Machine


public interface Machine

This interface allows the programmer to handle a reactive machine.
A reactive machine is instantiated using dedicated methods of the class SC.

Note: A SugarCubes programmer should never implements that interface in any of its own object, as it is definitely not sufficient to implement a reactive machine. A developer API exists (not documented yet) in SugarCubes for people interested in extending SugarCubes with new Instructions and new Configurations or creating its own implementation of a reactive machine (see inria.meije.rc.sugarcubes.implementation package of the SugarCubes). The purpose of this interface is only to give a minimal type to handle reactive machines.


Method Summary
 void addProgram(Program aComponent)
          This method allows one to dynamically add copies of programs into the reactive machine.
 void addTask(Task t, boolean beforeReaction)
          This method allows the addition of inter-instant tasks.
 Identifier cubeDestructionIdentifier(java.lang.String aCubeName)
          This method returns an Identifier referencing the destruction event of a Cube whose the name is given as argument, using the appropriate type of identifiers internally used in the machine.
 void generateEvent(Identifier eventName, Argument[] args)
          This method generates an event in the machine.
 Program getFrozenProgram(java.lang.String programName)
          This method retrieves the residual of a frozen program according to its name.
 Program getProgramCopy()
          This method returns a copy of the program executed by the machine.
 Identifier identifierFromString(java.lang.String aString)
          This method returns an Identifier corresponding to the string parameter, using the appropriate type of identifiers internally used by the machine.
 boolean react()
          This method makes the machine react, executing one instant of its program.
 void removeTask(Task t)
          This method removes inter-instant tasks.
 void setMinimumTimeOfReactions(long timeInMillisecond)
          This method allows the user to specify a minimum duration for an instant in milliseconds.
 

Method Detail

addProgram

public void addProgram(Program aComponent)
This method allows one to dynamically add copies of programs into the reactive machine.
Programs are actually added at the next instant of execution if a reaction is being processed. This method makes a copy of the program to add before adding it in the machine.

addTask

public void addTask(Task t,
                    boolean beforeReaction)
This method allows the addition of inter-instant tasks.
Tasks can be either added to be processed before or after (depending on the booelan value: beforeReaction) the execution of an instant of the system.

cubeDestructionIdentifier

public Identifier cubeDestructionIdentifier(java.lang.String aCubeName)
This method returns an Identifier referencing the destruction event of a Cube whose the name is given as argument, using the appropriate type of identifiers internally used in the machine.
See Also:
SC.destroy(java.lang.String)

generateEvent

public void generateEvent(Identifier eventName,
                          Argument[] args)
This method generates an event in the machine.
The actual generation only occurs at the next instant of execution if its called concurently during the execution of an instant.
See Also:
react()

getFrozenProgram

public Program getFrozenProgram(java.lang.String programName)
This method retrieves the residual of a frozen program according to its name.
A frozen program can only be extracted one time after the instant when the freeze occurs. After having retrieved the frozen instruction once, this method returns Nothing for the subsequent invocation, until a new program with the same name is frozen.

getProgramCopy

public Program getProgramCopy()
This method returns a copy of the program executed by the machine.

identifierFromString

public Identifier identifierFromString(java.lang.String aString)
This method returns an Identifier corresponding to the string parameter, using the appropriate type of identifiers internally used by the machine.

react

public boolean react()
This method makes the machine react, executing one instant of its program.
If the whole system terminates, this method returns true else it returns false. This method can be executed many times in parallel: only one reaction can occur at a time.
If multiple different threads try to call the react method on the same reactive machine at the same time, as this method is synchronized, only one react can occur. Non-immediately satisfied calls are waiting for the termination of the current instant to be able to make the machine react again.
If the call to the react occurs in an atomic operation (which is strongly not recommended), then, the call to react method is recursive in the same thread so the protection with the synchronized keyword does not work. In this case the behavior is different: the react method immediately returns displaying a warning message in the standard error stream.
During a reaction of a machine no immediate transformation on the program or the event environment can occur. If calls to generateEvent or addProgram occur during a react, their actual effects are processed for the next reaction.

removeTask

public void removeTask(Task t)
This method removes inter-instant tasks.

setMinimumTimeOfReactions

public void setMinimumTimeOfReactions(long timeInMillisecond)

This method allows the user to specify a minimum duration for an instant in milliseconds.

Note: This specify only a minimal duration for an instant. No guaranty is provided about the maximum duration of the instant.