org.jlab.coda.et
Class SystemCreate

java.lang.Object
  extended byorg.jlab.coda.et.SystemCreate

public class SystemCreate
extends java.lang.Object

This class creates an ET system.


Field Summary
(package private)  java.util.HashMap attachments
          Table of all ET system attachments.
(package private)  SystemConfig config
          A copy of the ET system configuration.
(package private)  int dataLength
          Length of valid data in array storing system information.
(package private)  java.util.HashMap events
          Table of all ET system events.
(package private)  byte[] infoArray
          Array for storing system information for distribution.
(package private)  boolean killAllThreads
          Flag for killing all threads started by ET system.
(package private)  java.lang.String name
          The name of the ET system file name.
(package private)  java.net.InetAddress[] netAddresses
          All local IP addresses
(package private)  int stationCount
          The total number of idle and active stations.
(package private)  byte[] stationLock
          Mutex for station stuff.
(package private)  java.util.LinkedList stations
          A list of stations defining the flow of events.
(package private)  byte[] systemLock
          Mutex for system stuff.
 
Constructor Summary
SystemCreate(java.lang.String _name)
          Creates a new ET system using default parameters and starts it running.
SystemCreate(java.lang.String _name, SystemConfig _config)
          Creates a new ET system with specified parameters and starts it running.
 
Method Summary
(package private)  AttachmentLocal attach(int statId)
          Create an attachment to a station.
 StationLocal createStation(StationConfig stationConfig, java.lang.String name)
          Creates a new station placed at the end of the linked list of stations.
(package private)  StationLocal createStation(StationConfig stationConfig, java.lang.String name, int position, int parallelPosition)
          Creates a new station at a specified position in the linked list of stations.
(package private)  void detach(AttachmentLocal att)
          Remove an attachment from a station.
(package private)  void dumpEvents(AttachmentLocal att, Event[] eventArray)
          Dispose of unwanted events in an ET system.
(package private)  int gatherSystemData()
          Gather all ET system data for sending over the network and put it into a single byte array.
 SystemConfig getConfig()
          Gets the ET system configuration.
(package private)  Event[] getEvents(AttachmentLocal att, int mode, int microSec, int count)
          Get events from an ET system.
 java.lang.String getName()
          Gets the ET system file name.
(package private)  int getStationParallelPosition(int statId)
          Gets the position of a parallel station in its linked list of parallel stations.
(package private)  int getStationPosition(int statId)
          Gets the position of a station in the main linked list of stations.
(package private)  Event[] newEvents(AttachmentLocal att, int mode, int microSec, int count, int size)
          Get new or unused events from an ET system.
(package private)  void putEvents(AttachmentLocal att, Event[] eventArray)
          Put events into an ET system.
(package private)  void removeStation(int statId)
          Removes an existing station.
 boolean running()
          Tells if the ET system is running or not.
(package private)  void setStationPosition(int statId, int position, int parallelPosition)
          Changes the position of a station in the linked lists of stations.
 void shutdown()
          Stops the ET system if it is running.
 void startUp()
          Starts the ET system running.
(package private)  boolean stationAttached(int statId, int attId)
          Tells if an attachment is attached to a station.
(package private)  boolean stationExists(StationLocal station)
          Tells if a station exists.
(package private)  boolean stationExists(java.lang.String name)
          Tells if a station exists.
(package private)  StationLocal stationIdToObject(int statId)
          Given a station id number, this method gets the corresponding StationLocal object.
(package private)  StationLocal stationNameToObject(java.lang.String name)
          Gets a station's object representation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

config

SystemConfig config
A copy of the ET system configuration.


name

java.lang.String name
The name of the ET system file name.


stations

java.util.LinkedList stations
A list of stations defining the flow of events. Only the first station of a single group of parallel stations is included in this list. The other parallel stations are available in a list kept by the first parallel station.


stationCount

int stationCount
The total number of idle and active stations. This consists of the number of main stations given by the size of the "stations" linked list (stations.size()) and the number of additional parallel stations added together.


attachments

java.util.HashMap attachments
Table of all ET system attachments.


events

java.util.HashMap events
Table of all ET system events.


netAddresses

java.net.InetAddress[] netAddresses
All local IP addresses


systemLock

byte[] systemLock
Mutex for system stuff.


stationLock

byte[] stationLock
Mutex for station stuff.


killAllThreads

volatile boolean killAllThreads
Flag for killing all threads started by ET system.


dataLength

int dataLength
Length of valid data in array storing system information.


infoArray

byte[] infoArray
Array for storing system information for distribution.

Constructor Detail

SystemCreate

public SystemCreate(java.lang.String _name)
             throws EtException
Creates a new ET system using default parameters and starts it running. The default parameters are: number of events = Constants.defaultNumEvents, event size = Constants.defaultEventSize, max number of stations = Constants.defaultStationsMax, max number of attachments = Constants.defaultAttsMax, debug level = Constants.debugError, udp port = Constants.broadcastPort, server (tcp) port = Constants.serverPort, and multicasting port = Constants.multicastPort

Parameters:
_name - file name
Throws:
EtException - if the file already exists or cannot be created

SystemCreate

public SystemCreate(java.lang.String _name,
                    SystemConfig _config)
             throws EtException
Creates a new ET system with specified parameters and starts it running.

Parameters:
_name - file name
_config - ET system configuration
Throws:
EtException - if the file already exists or cannot be created
Method Detail

getName

public java.lang.String getName()
Gets the ET system file name.

Returns:
ET system file name

getConfig

public SystemConfig getConfig()
Gets the ET system configuration.

Returns:
ET system configuration

running

public boolean running()
Tells if the ET system is running or not.

Returns:
true if the system is running and false if it is not

startUp

public void startUp()
Starts the ET system running. If the system is already running, nothing is done.


shutdown

public void shutdown()
Stops the ET system if it is running. All threads are stopped. If the system is not running, nothing is done.


createStation

public StationLocal createStation(StationConfig stationConfig,
                                  java.lang.String name)
                           throws EtException,
                                  EtExistsException,
                                  EtTooManyException
Creates a new station placed at the end of the linked list of stations.

Parameters:
stationConfig - station configuration
name - station name
Returns:
the new station object
Throws:
EtException - if the select method's class cannot be loaded
EtExistsException - if the station already exists but with a different configuration
EtTooManyException - if the maximum number of stations has been created already

createStation

StationLocal createStation(StationConfig stationConfig,
                           java.lang.String name,
                           int position,
                           int parallelPosition)
                     throws EtException,
                            EtExistsException,
                            EtTooManyException
Creates a new station at a specified position in the linked list of stations. Cannot exceed the maximum number of stations allowed in a system.

Parameters:
stationConfig - station configuration
name - station name
position - position in the linked list to put the station.
Returns:
the new station object
Throws:
EtException - if the select method's class cannot be loaded
EtExistsException - if the station already exists but with a different configuration
EtTooManyException - if the maximum number of stations has been created already

removeStation

void removeStation(int statId)
             throws EtException
Removes an existing station.

Parameters:
statId - station id
Throws:
EtException - if attachments to the station still exist or the station does not exist

setStationPosition

void setStationPosition(int statId,
                        int position,
                        int parallelPosition)
                  throws EtException
Changes the position of a station in the linked lists of stations.

Parameters:
statId - station id
position - position in the main linked list of stations (starting at 0)
parallelPosition - position of a parallel station in a group of parallel stations (starting at 0)
Throws:
EtException - if the station does not exist, or if trying to move an incompatible parallel station to an existing group of parallel stations or to the head of an existing group of parallel stations.

getStationPosition

int getStationPosition(int statId)
                 throws EtException
Gets the position of a station in the main linked list of stations.

Parameters:
statId - station id
Returns:
the position of a station in the linked list of stations
Throws:
EtException - if the station does not exist

getStationParallelPosition

int getStationParallelPosition(int statId)
                         throws EtException
Gets the position of a parallel station in its linked list of parallel stations.

Parameters:
statId - station id
Returns:
the position of a parallel station in its linked list of parallel stations, or zero if station is serial
Throws:
EtException - if the station does not exist

stationAttached

boolean stationAttached(int statId,
                        int attId)
                  throws EtException
Tells if an attachment is attached to a station.

Parameters:
statId - station id
attId - attachment id
Returns:
true if an attachment is attached to a station and false otherwise
Throws:
EtException - if the station does not exist

stationExists

boolean stationExists(StationLocal station)
Tells if a station exists.

Parameters:
station - station object
Returns:
true if a station exists and false otherwise

stationExists

boolean stationExists(java.lang.String name)
Tells if a station exists.

Parameters:
name - station name
Returns:
true if a station exists and false otherwise

stationNameToObject

StationLocal stationNameToObject(java.lang.String name)
                           throws EtException
Gets a station's object representation.

Parameters:
name - station name
Returns:
a station's object
Throws:
EtException - if the station does not exist

stationIdToObject

StationLocal stationIdToObject(int statId)
                         throws EtException
Given a station id number, this method gets the corresponding StationLocal object.

Returns:
the station's object
Throws:
EtException - if the station does not exist

attach

AttachmentLocal attach(int statId)
                 throws EtException,
                        EtTooManyException
Create an attachment to a station.

Parameters:
statId - station id
Returns:
an attachment object
Throws:
EtException - if the station does not exist
EtTooManyException - if station does not exist, or if no more attachments are allowed to the station, or if no more attachments are allowed to ET system

detach

void detach(AttachmentLocal att)
Remove an attachment from a station.

Parameters:
att - attachment object

newEvents

Event[] newEvents(AttachmentLocal att,
                  int mode,
                  int microSec,
                  int count,
                  int size)
            throws EtEmptyException,
                   EtBusyException,
                   EtTimeoutException,
                   EtWakeUpException
Get new or unused events from an ET system.

Parameters:
att - attachment object
mode - if there are no events available, this parameter specifies whether to wait for some by sleeping, by waiting for a set time, or by returning immediately (asynchronous)
microSec - the number of microseconds to wait if a timed wait is specified
count - the number of events desired
size - the size of events in bytes
Returns:
an array of events
Throws:
EtEmptyException - if the mode is asynchronous and the station's input list is empty
EtBusyException - if the mode is asynchronous and the station's input list is being used (the mutex is locked)
EtTimeoutException - if the mode is timed wait and the time has expired
EtWakeUpException - if the attachment has been commanded to wakeup, EventList.wakeUp(org.jlab.coda.et.AttachmentLocal), EventList.wakeUpAll()

getEvents

Event[] getEvents(AttachmentLocal att,
                  int mode,
                  int microSec,
                  int count)
            throws EtEmptyException,
                   EtBusyException,
                   EtTimeoutException,
                   EtWakeUpException
Get events from an ET system.

Parameters:
att - attachment object
mode - if there are no events available, this parameter specifies whether to wait for some by sleeping, by waiting for a set time, or by returning immediately (asynchronous)
microSec - the number of microseconds to wait if a timed wait is specified
count - the number of events desired
Returns:
an array of events
Throws:
EtEmptyException - if the mode is asynchronous and the station's input list is empty
EtBusyException - if the mode is asynchronous and the station's input list is being used (the mutex is locked)
EtTimeoutException - if the mode is timed wait and the time has expired
EtWakeUpException - if the attachment has been commanded to wakeup, EventList.wakeUp(org.jlab.coda.et.AttachmentLocal), EventList.wakeUpAll()

putEvents

void putEvents(AttachmentLocal att,
               Event[] eventArray)
Put events into an ET system.

Parameters:
att - attachment object
eventArray - array of event objects

dumpEvents

void dumpEvents(AttachmentLocal att,
                Event[] eventArray)
Dispose of unwanted events in an ET system. The events are recycled and not made available to any other user.

Parameters:
att - attachment object
eventArray - array of event objects

gatherSystemData

int gatherSystemData()
Gather all ET system data for sending over the network and put it into a single byte array. Putting the data into a byte array is done so that its size is known beforehand and can be sent as the first int of data. It is also done so that this gathering of data is done no more than once a second and so that the data is shared by the many attachments that may want it. It is far more efficient to send an existing array of data to an attachment than it is to regather it for each request. The calling of this method is mutex protected so only 1 thread/attachment can modify or access the array at a time.

Returns:
Constants.ok if everything is fine and Constants.error otherwise