fr.emn.reactiveinput
Class Configuration

java.lang.Object
  extended byfr.emn.reactiveinput.Configuration
All Implemented Interfaces:
java.awt.event.AWTEventListener, java.util.EventListener

public class Configuration
extends java.lang.Object
implements java.awt.event.AWTEventListener

The Configuration class contains all connection & mutation methods for one input configuration.

Using this class is forbidden during execution.

Warning: This class is not thread-safe.


Field Summary
protected  boolean autoMutation
           
static int COMPATIBLE_ALWAYS
          A type-compatible connection
static int COMPATIBLE_FOR_NOW
          A type-compatible connection, but which may become incompatible if one of the slots mutates
static int INCOMPATIBLE_ALWAYS
          A type-incompatible connection
static int INCOMPATIBLE_FOR_NOW
          A type-incompatible connection, but which may become compatible if one of the slots mutates
 int maxIterations
          The max. number of iterations when performing mutations.
protected  java.util.Vector mutationCache
           
protected  java.util.Hashtable mutationCounter
           
 
Constructor Summary
Configuration(OpenContext context)
          Creates a new empty configuration with default folders.
Configuration(OpenContext context, DeviceFolder rootFolder)
          Creates a new empty configuration with the given root folder. context may be null.
Configuration(OpenContext context, DeviceFolder rootFolder, java.io.File icFile)
          Creates a configuration from an .ic file.
Configuration(OpenContext context, DeviceFolder rootFolder, java.lang.String configurationScript)
          Creates a configuration from a String script.
 
Method Summary
 Device add(Device d)
          Adds a device to this Configuration.
 void addListener(ConfigurationListener c)
          Listener management
 MissingIn addMissingIn(java.lang.String fullInAlias)
          Creates and adds a MissingIn instance.
 MissingOut addMissingOut(java.lang.String fullOutAlias)
          Creates and adds a MissingOut instance.
 boolean canConnect(Slot slot1, Slot slot2)
          Returns true if a connection can be made between given slots, disregard the compatibility between them.
 boolean canConnect(Slot slot1, Slot slot2, Slot disconnect1, Slot disconnect2)
          Returns true if a connection can be made between given slots, after the given link has been disconnected.
 void clear()
          Clear all except root folder
 void close()
          Closes all the devices.
 boolean connect(Slot slot1, Slot slot2)
          Connects this input slot to an output slot.
 void disconnect(Device d)
           
 boolean disconnect(In in)
          Same as connect(in, null).
 boolean disconnect(Out out)
          Removes all connections from this slot.
 void eventDispatched(java.awt.AWTEvent event)
          Listen to Ctrl-C events
protected  void finalize()
          Closes all devices
 Device findDevice(DeviceDescriptor descriptor)
          Returns the first available device matching the given descriptor in the root folder.
 Device findDevice(java.lang.String descriptor)
          Returns the first available device matching the given descriptor in the root folder.
 Device[] findDeviceMatch(DeviceDescriptor[] descriptors)
          Find an array of devices matching the given array of descriptors, with distinct declared slots.
 Device[] findDeviceMatch(java.lang.String descriptors)
          Find an array of devices matching the given list of descriptors, with distinct declared slots.
 Device[] findDevices(DeviceDescriptor descriptor)
          Returns all available devices matching the given descriptor in the root folder.
 Device[] findDevices(java.lang.String descriptor)
          Returns all available devices matching the given descriptor in the root folder.
protected  void fireConfigurationStarted()
           
protected  void fireConfigurationStopped()
           
protected  void fireDeviceFailed(Device d)
           
protected  void fireDeviceOpened(Device d)
           
 java.lang.String getAlias(Device d)
          Returns the alias that has been assigned to the device, or null if the device has no alias.
 java.lang.String getAlias(Slot s)
          Returns the single alias of the slot, or null if the slot has no alias.
static int getCompatibility(Slot slot1, Slot slot2)
          Returns the type of compatibility between those 2 slots.
 java.lang.String getConfigurationScript()
          Creates the script for this configuration
 Device[] getConnectedDevices(Device d)
           
 OpenContext getContext()
           
 java.lang.String getCustomDescription(Device obj)
          Returns contextual description on object.
 java.lang.String getCustomDescription(Slot obj)
          Returns contextual description on object.
 java.lang.String getCustomHelp(Device obj)
          Returns contextual help on object.
 java.lang.String getCustomHelp(Slot obj)
          Returns contextual help on object.
 DeviceDescriptor getCustomSignature(Device d)
           
 DeviceDescriptor getDefaultSignature(Device d)
          Builds a default signature for the device d.
 Device getDevice(java.lang.String alias)
          Returns the device having the given alias.
 Device[] getDevices()
          Returns all devices used in this configuration.
 int getFrequency()
           
 java.lang.String getFullAlias(Slot s)
          Returns the full slot alias (devAlias.slotAlias).
 ConfigurationInfo getInfo()
           
protected  MissingIn getMissingIn(Device d, java.lang.String name)
          Retreive a missing slot by its parent device & slot name
 MissingIn[] getMissingIns(Device d)
           
protected  MissingOut getMissingOut(Device d, java.lang.String name)
          Retreive a missing slot by its parent device & slot name
 MissingOut[] getMissingOuts(Device d)
           
 java.lang.String getOriginalFileScript()
           
 java.lang.String getOriginalScript()
          Returns the whole script that was used to create this configuration.
 DeviceFolder getRootFolder()
          Returns the folder containing all devices ready to use in this configuration.
 Slot getSlot(java.lang.String fullSlotAlias, boolean inSlot, boolean outSlot)
          Returns the slot having the given full alias (devAlias.slotAlias).
 java.io.File getSourceFile()
          Returns the file this configuration is associated to, if this configuration was previously loaded from disk or saved to disk.
 Configuration[] getSubConfigurations()
          Returns subconfigurations from compound devices
static boolean isConnected(In in, Out out)
          Returns true if slots are connected.
 boolean isIndirectSuccessor(Device before, Device after)
          Returns true if "after" is dependent on "before".
 boolean isStarted()
           
 boolean isSuccessor(Device before, Device after)
          Returns true if there exists a direct connection between a "before" output and an "after" input.
 boolean load(java.io.File icFile)
          Creates a configuration from an .ic file.
 void load(java.lang.String configurationScript)
          Fills the configuration from a String script.
 void mutate(MutableDevice d)
          Force a single device to mutate without propagating mutations.
 Device[][] open()
          Prepares the execution of reactive machine.
 Device[][] open(boolean createMachines)
           
 MutableDevice[] performMutations()
          Trigger all cached mutations.
 void remove(Device d)
          Removes a device from this Configuration.
 void removeListener(ConfigurationListener c)
           
 boolean save(java.io.File icfFile)
          Saves this configuration to an .icf file.
 boolean save(java.io.File icfFile, java.lang.String additionalScript)
          Saves this configuration to an .icf file.
 void setAlias(Device d, java.lang.String alias)
          Sets/replaces a device alias.
 void setAlias(Slot s, java.lang.String alias)
          Sets/replaces a slot alias.
 void setAutoMutation(boolean auto)
          Sets whether mutations must be performed automatically at each change on connections (connect/disconnect).
 void setContext(OpenContext context)
           
 void setCustomDescription(Device obj, java.lang.String value)
          Assigns a custom contextual description to the device.
 void setCustomDescription(Slot obj, java.lang.String value)
          Assigns a custom contextual description to the slot.
 void setCustomHelp(Device obj, java.lang.String value)
          Assigns a custom contextual help to the device.
 void setCustomHelp(Slot obj, java.lang.String value)
          Assigns a custom contextual help to the slot.
 void setCustomSignature(Device d, DeviceDescriptor signature)
          Assigns a signature to the device, to override the getDefaultSignature() method.
 void setCustomSignature(Device d, java.lang.String signature)
          Assigns a signature to the device, to override the getDefaultSignature() method.
 void setFrequency(int freq)
           
 void setInfo(ConfigurationInfo info)
           
 void setInfo(java.lang.String description, java.lang.String help)
           
 void setRootFolder(DeviceFolder rootFolder)
           
 void setSourceFile(java.io.File sourceFile)
          Sets the sourceFile.
 void start()
          Starts running the configuration.
 void start(boolean withAnalysis)
          Starts running the configuration.
 double startBenchmark(int loops)
           
 void stop()
          Stops running the configuration.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INCOMPATIBLE_ALWAYS

public static final int INCOMPATIBLE_ALWAYS
A type-incompatible connection

See Also:
Constant Field Values

INCOMPATIBLE_FOR_NOW

public static final int INCOMPATIBLE_FOR_NOW
A type-incompatible connection, but which may become compatible if one of the slots mutates

See Also:
Constant Field Values

COMPATIBLE_FOR_NOW

public static final int COMPATIBLE_FOR_NOW
A type-compatible connection, but which may become incompatible if one of the slots mutates

See Also:
Constant Field Values

COMPATIBLE_ALWAYS

public static final int COMPATIBLE_ALWAYS
A type-compatible connection

See Also:
Constant Field Values

mutationCache

protected final java.util.Vector mutationCache

mutationCounter

protected final java.util.Hashtable mutationCounter

maxIterations

public int maxIterations
The max. number of iterations when performing mutations. If a device has been mutated "maxIterations" times, it is considered to have an "unstabilized" mutation.


autoMutation

protected boolean autoMutation
Constructor Detail

Configuration

public Configuration(OpenContext context)
Creates a new empty configuration with default folders.

The OpenContext argument will be passed to the devices as the open context. This argument may be null, however some devices will really need a OpenContext argument to run.


Configuration

public Configuration(OpenContext context,
                     DeviceFolder rootFolder)
Creates a new empty configuration with the given root folder. context may be null.


Configuration

public Configuration(OpenContext context,
                     DeviceFolder rootFolder,
                     java.io.File icFile)
Creates a configuration from an .ic file.


Configuration

public Configuration(OpenContext context,
                     DeviceFolder rootFolder,
                     java.lang.String configurationScript)
Creates a configuration from a String script.

Method Detail

add

public Device add(Device d)
Adds a device to this Configuration.


addMissingIn

public MissingIn addMissingIn(java.lang.String fullInAlias)
Creates and adds a MissingIn instance. Also adds a MissingDevice instance if needed (i.e. if getDevice(fullInAlias) == null).

This method is automatically called by load() if slots are missing while performing connections. Call this method if you want to preserve connections even if devices or slots are missing. Missing devices/slots may appear in graphical editors, in order to be replaced by the user.

This method also displays a warning message in standard output.


addMissingOut

public MissingOut addMissingOut(java.lang.String fullOutAlias)
Creates and adds a MissingOut instance. Also adds a MissingDevice instance if needed (i.e. if getDevice(fullOutAlias) == null).

This method is automatically called by load() if slots are missing while performing connections. Call this method if you want to preserve connections even if devices or slots are missing. Missing devices/slots may appear in graphical editors, in order to be replaced by the user.

This method also displays a warning message in standard output.


getSourceFile

public java.io.File getSourceFile()
Returns the file this configuration is associated to, if this configuration was previously loaded from disk or saved to disk.


canConnect

public boolean canConnect(Slot slot1,
                          Slot slot2)
Returns true if a connection can be made between given slots, disregard the compatibility between them.

This method returns true only if: - One slot is In and the other is Out - We are in design mode (configuration is not started), - These slots belong to existing devices (have not been removed from device) - These devices do not already belong to another configuration, - The connection does not generate a cycle.

out can be equal to null (this means disconnecting a slot).


canConnect

public boolean canConnect(Slot slot1,
                          Slot slot2,
                          Slot disconnect1,
                          Slot disconnect2)
Returns true if a connection can be made between given slots, after the given link has been disconnected.


clear

public void clear()
Clear all except root folder


connect

public boolean connect(Slot slot1,
                       Slot slot2)
Connects this input slot to an output slot. Old output slot, if exists, will be disconnected.

Devices are automatically added to this configuration.

Call connect(in, null) to disconnect.

Returns:
true if connection has been done (canConnect()==true).

disconnect

public void disconnect(Device d)

disconnect

public boolean disconnect(In in)
Same as connect(in, null).


disconnect

public boolean disconnect(Out out)
Removes all connections from this slot.


finalize

protected void finalize()
Closes all devices


findDevice

public Device findDevice(DeviceDescriptor descriptor)
Returns the first available device matching the given descriptor in the root folder. Returns null if no match.

See Finder.findDevice(DeviceFolder, DeviceDescriptor).


findDevice

public Device findDevice(java.lang.String descriptor)
Returns the first available device matching the given descriptor in the root folder. Returns null if no match.

See Finder.findDevice(DeviceFolder, DeviceDescriptor).


findDeviceMatch

public Device[] findDeviceMatch(DeviceDescriptor[] descriptors)
Find an array of devices matching the given array of descriptors, with distinct declared slots.

See Finder.findDeviceMatch(DeviceFolder, DeviceDescriptor[]) and getDeclared... methods.


findDeviceMatch

public Device[] findDeviceMatch(java.lang.String descriptors)
Find an array of devices matching the given list of descriptors, with distinct declared slots.

See Finder.findDeviceMatch(DeviceFolder, DeviceDescriptor[]) and getDeclared... methods.


findDevices

public Device[] findDevices(DeviceDescriptor descriptor)
Returns all available devices matching the given descriptor in the root folder. Returns null if no match.

See Finder.findDevices(DeviceFolder, DeviceDescriptor).


findDevices

public Device[] findDevices(java.lang.String descriptor)
Returns all available devices matching the given descriptor in the root folder. Returns null if no match.

See Finder.findDevices(DeviceFolder, DeviceDescriptor).


getAlias

public java.lang.String getAlias(Device d)
Returns the alias that has been assigned to the device, or null if the device has no alias.


getAlias

public java.lang.String getAlias(Slot s)
Returns the single alias of the slot, or null if the slot has no alias.


getCompatibility

public static int getCompatibility(Slot slot1,
                                   Slot slot2)
Returns the type of compatibility between those 2 slots.


getConfigurationScript

public java.lang.String getConfigurationScript()
Creates the script for this configuration


getConnectedDevices

public Device[] getConnectedDevices(Device d)

getContext

public OpenContext getContext()

getCustomDescription

public java.lang.String getCustomDescription(Device obj)
Returns contextual description on object.


getCustomDescription

public java.lang.String getCustomDescription(Slot obj)
Returns contextual description on object.


getCustomHelp

public java.lang.String getCustomHelp(Device obj)
Returns contextual help on object.


getCustomHelp

public java.lang.String getCustomHelp(Slot obj)
Returns contextual help on object.


getCustomSignature

public DeviceDescriptor getCustomSignature(Device d)

getDefaultSignature

public DeviceDescriptor getDefaultSignature(Device d)
Builds a default signature for the device d.


getDevice

public Device getDevice(java.lang.String alias)
Returns the device having the given alias.


getDevices

public Device[] getDevices()
Returns all devices used in this configuration.


getFullAlias

public java.lang.String getFullAlias(Slot s)
Returns the full slot alias (devAlias.slotAlias).

The slot name is used if slot has no alias.


getInfo

public ConfigurationInfo getInfo()

getMissingIns

public MissingIn[] getMissingIns(Device d)

getMissingIn

protected MissingIn getMissingIn(Device d,
                                 java.lang.String name)
Retreive a missing slot by its parent device & slot name


getMissingOuts

public MissingOut[] getMissingOuts(Device d)

getMissingOut

protected MissingOut getMissingOut(Device d,
                                   java.lang.String name)
Retreive a missing slot by its parent device & slot name


getOriginalScript

public java.lang.String getOriginalScript()
Returns the whole script that was used to create this configuration.

A configuration only uses the 'Devices' and 'Connections' sections of the script. Applications such as graphical configuration editors may need to retreive their own section.

Returns null if this Configuration was not created from a script or a file.


getOriginalFileScript

public java.lang.String getOriginalFileScript()

getRootFolder

public DeviceFolder getRootFolder()
Returns the folder containing all devices ready to use in this configuration.


getSlot

public Slot getSlot(java.lang.String fullSlotAlias,
                    boolean inSlot,
                    boolean outSlot)
Returns the slot having the given full alias (devAlias.slotAlias).


isConnected

public static boolean isConnected(In in,
                                  Out out)
Returns true if slots are connected.


isIndirectSuccessor

public boolean isIndirectSuccessor(Device before,
                                   Device after)
Returns true if "after" is dependent on "before".


isStarted

public boolean isStarted()

isSuccessor

public boolean isSuccessor(Device before,
                           Device after)
Returns true if there exists a direct connection between a "before" output and an "after" input.


load

public boolean load(java.io.File icFile)
Creates a configuration from an .ic file.


load

public void load(java.lang.String configurationScript)
Fills the configuration from a String script.


mutate

public void mutate(MutableDevice d)
Force a single device to mutate without propagating mutations.


performMutations

public MutableDevice[] performMutations()
Trigger all cached mutations.


remove

public void remove(Device d)
Removes a device from this Configuration.


save

public boolean save(java.io.File icfFile)
Saves this configuration to an .icf file.


save

public boolean save(java.io.File icfFile,
                    java.lang.String additionalScript)
Saves this configuration to an .icf file.


setAlias

public void setAlias(Device d,
                     java.lang.String alias)
Sets/replaces a device alias. Use alias=null to remove alias.

Device aliases are used in the 'Connections' part of the configuration script. Each declared device must have a unique alias. If you don't provide alias values, default aliases will be assigned to your devices when a script is generated from your configuration.

This method is automatically called in load() methods.


setAlias

public void setAlias(Slot s,
                     java.lang.String alias)
Sets/replaces a slot alias. Use alias=null to remove alias.

Slot aliases are used in the 'Connections' part of the configuration script. Slot aliases are optional in configuration scripts, because slot names are unique inside a device. When no alias is provided, the slot name is used for referencing the slot.

This method is automatically called in load() methods.


setAutoMutation

public void setAutoMutation(boolean auto)
Sets whether mutations must be performed automatically at each change on connections (connect/disconnect).

If auto mutation is set to false, you must call performMutations() each time it is necessary.

Auto mutation is set to true by default.


setContext

public void setContext(OpenContext context)

setCustomDescription

public void setCustomDescription(Device obj,
                                 java.lang.String value)
Assigns a custom contextual description to the device.


setCustomDescription

public void setCustomDescription(Slot obj,
                                 java.lang.String value)
Assigns a custom contextual description to the slot.


setCustomHelp

public void setCustomHelp(Device obj,
                          java.lang.String value)
Assigns a custom contextual help to the device.


setCustomHelp

public void setCustomHelp(Slot obj,
                          java.lang.String value)
Assigns a custom contextual help to the slot.


setCustomSignature

public void setCustomSignature(Device d,
                               DeviceDescriptor signature)
Assigns a signature to the device, to override the getDefaultSignature() method.


setCustomSignature

public void setCustomSignature(Device d,
                               java.lang.String signature)
Assigns a signature to the device, to override the getDefaultSignature() method.


setInfo

public void setInfo(ConfigurationInfo info)

setInfo

public void setInfo(java.lang.String description,
                    java.lang.String help)

setRootFolder

public void setRootFolder(DeviceFolder rootFolder)

getFrequency

public int getFrequency()

setFrequency

public void setFrequency(int freq)

getSubConfigurations

public Configuration[] getSubConfigurations()
Returns subconfigurations from compound devices


open

public Device[][] open()
Prepares the execution of reactive machine.

Opens all the devices in this configuration, and return successfully opened devices, or null if a cycle was found. Call this method just before start(). PENDING: Change state changing algorithm or reopen all


open

public Device[][] open(boolean createMachines)

close

public void close()
Closes all the devices. Call this method if you do not need running this configuration any more.


start

public void start()
Starts running the configuration. Returns false if there is a cycle.

IMPORTANT: You must call open() method just before calling start().


start

public void start(boolean withAnalysis)
Starts running the configuration. Returns false if there is a cycle.

IMPORTANT: You must call open() method just before calling start().


startBenchmark

public double startBenchmark(int loops)

stop

public void stop()
Stops running the configuration.


eventDispatched

public void eventDispatched(java.awt.AWTEvent event)
Listen to Ctrl-C events

Specified by:
eventDispatched in interface java.awt.event.AWTEventListener

setSourceFile

public void setSourceFile(java.io.File sourceFile)
Sets the sourceFile.

Parameters:
sourceFile - The sourceFile to set

addListener

public void addListener(ConfigurationListener c)
Listener management


removeListener

public void removeListener(ConfigurationListener c)

fireDeviceOpened

protected void fireDeviceOpened(Device d)

fireDeviceFailed

protected void fireDeviceFailed(Device d)

fireConfigurationStarted

protected void fireConfigurationStarted()

fireConfigurationStopped

protected void fireConfigurationStopped()