FourMS
Class Mechanism

java.lang.Object
  extended by java.util.TimerTask
      extended by FourMS.MechanismBase
          extended by FourMS.Mechanism
All Implemented Interfaces:
i4MSMessageListenerInterface, java.lang.Runnable

public class Mechanism
extends MechanismBase
implements i4MSMessageListenerInterface

This class models a mechanism in a 4MS. On initialisation the data relating to the messages that may be sent and received by the 4MS are read from the ICS database. This class must ensure that all units to be sent backwards and forwards between the 4MS module are converted between logical and engineering units. It is also responsible for setting up the CORBA interfaced subactions which can be used to control the mechanisms through which the 4MS is controlled.

Finally, the status information coming back for the mechanism will be written to a machine state monitor called the ParameterNoticeBoard from where it can be accessed by 3rd party applications.

Version:
$Id: Mechanism.java,v 1.9 2006/04/07 08:05:39 cb Exp $
Author:
Craige Bevil

Field Summary
private  java.util.Hashtable<java.lang.String,SubAction> AssociatedSubActions
          This is the valid list of subactions associated with this mechanism which may be executed upon the 4MS microprocessor currently attached to the port Server.
 iRawParameterTransformation EngineeringUnitConverter
          A converter which can be used to perform transformations on raw values before they are sent to the noticeboard.
private  FourMSMessageHandler ER412MessageHandler
          This will be used in order to send messages to the 4MS microprocessor (or the simulator)
private  org.omg.CosNaming.NamingContextExt MechanismNameServiceContext
          A reference to the context in the COS naming service which is to hold the details of the subactions
private static java.util.Timer MechanismTimer
          This is a timer object which will be used for scheduling action updates on the part of the simulation mechanisms
private  org.omg.CORBA.ORB Orb
          ORB used by the class
private  iParameterNoticeBoard.ParameterNoticeBoardSupplier ParameterNoticeBoard
          This is reference to the remote proxy CORBA object which will be used to access the parameter noticeboard so that we may store status information that comes back from the 4MS
private  org.omg.CosNaming.NamingContextExt RootNamingServiceContext
          The CORBA name service
 
Fields inherited from class FourMS.MechanismBase
AssociatedInstrumentName, CmdError, CommandErrorCodes, CurrentMechanismPosition, DatumPosition, DatumTimeInSecs, DBConnection, EncoderLowerLimit, EncoderPosition, EncoderUpperLimit, ER412ParameterConverter, FourMsMechMsgTypes, MechanismErrorCodes, MechanismState, MechError, MechLowerLimit, MechMovementRatePerSec, MechName, MechUpperLimit, NeedsInitialisation, RangeConversionLookups, SyslogMessageHandler, UsesEncoder
 
Constructor Summary
Mechanism(java.sql.Connection DBConnection, java.lang.String InstrumentName, java.lang.String MechanismName, MessageHandler SysLogMessageHandler, FourMSParameterConverter ER412ParameterConverter, org.omg.CORBA.ORB Orb, org.omg.PortableServer.POA Poa, org.omg.CosNaming.NamingContextExt ControllerNameServiceContext, FourMSMessageHandler ER412MessageHandler)
          This is the constructor for this class
 
Method Summary
private  boolean createParametersInNoticeBoard()
          Create parameters in the notice board which are associated with the status information which is returned by the 4MS controller for this mechanism.
 boolean createSubactions(org.omg.CORBA.ORB Orb, org.omg.PortableServer.POA Poa)
          Each mechanism has optionally associated one or more subactions.
 int getMessageParameterCount(java.lang.String MsgType)
          This method returns the number of expected parameters for this message type.
 void messageReceivedCB(java.lang.String IncomingMessage, FourMSMessage IncomingMessageStructure)
          This method is a callback and this classes contractual obligation of the i4MSMessageListenerInterface.
private  boolean resolveParameterNoticeBoard()
          This method will be used to resolve a reference to the parameter notice board.
 void run()
          This is this classes obligation to implement the timer interface Any classes that want to inherit from this class and want to use timers should override this method
 void updateMechanismStateImage(java.util.List ConvertedMessageParameters, java.util.List UnconvertedMessageParameters, FourMSDBSchemaDerivedClasses.OM_FourMSMessage MessageStructureDetails)
          This method will be used to update the "noticeboard" so that the full status of the mechanisms are available to other systems in the WHT OCS.
 
Methods inherited from class FourMS.MechanismBase
buildFourMSMessage, getCurrentCommandError, getCurrentMechanismError, getMechanismError, getMechanismName, interpret4MSMessage, setEncoderPosition
 
Methods inherited from class java.util.TimerTask
cancel, scheduledExecutionTime
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EngineeringUnitConverter

public iRawParameterTransformation EngineeringUnitConverter
A converter which can be used to perform transformations on raw values before they are sent to the noticeboard. Note that this is not the same as the transformations which are performed when a raw parameter is converted to a logical unit. This is a after the fact solution for a problem which I encountered in the implementation of the A&G box as I needed to be able to convert the value of filter position before it goes into the noticeboard.


ParameterNoticeBoard

private iParameterNoticeBoard.ParameterNoticeBoardSupplier ParameterNoticeBoard
This is reference to the remote proxy CORBA object which will be used to access the parameter noticeboard so that we may store status information that comes back from the 4MS


Orb

private org.omg.CORBA.ORB Orb
ORB used by the class


RootNamingServiceContext

private org.omg.CosNaming.NamingContextExt RootNamingServiceContext
The CORBA name service


MechanismTimer

private static final java.util.Timer MechanismTimer
This is a timer object which will be used for scheduling action updates on the part of the simulation mechanisms


AssociatedSubActions

private java.util.Hashtable<java.lang.String,SubAction> AssociatedSubActions
This is the valid list of subactions associated with this mechanism which may be executed upon the 4MS microprocessor currently attached to the port Server. These will be initiated through the subaction's CORBA interface


ER412MessageHandler

private FourMSMessageHandler ER412MessageHandler
This will be used in order to send messages to the 4MS microprocessor (or the simulator)


MechanismNameServiceContext

private org.omg.CosNaming.NamingContextExt MechanismNameServiceContext
A reference to the context in the COS naming service which is to hold the details of the subactions

Constructor Detail

Mechanism

public Mechanism(java.sql.Connection DBConnection,
                 java.lang.String InstrumentName,
                 java.lang.String MechanismName,
                 MessageHandler SysLogMessageHandler,
                 FourMSParameterConverter ER412ParameterConverter,
                 org.omg.CORBA.ORB Orb,
                 org.omg.PortableServer.POA Poa,
                 org.omg.CosNaming.NamingContextExt ControllerNameServiceContext,
                 FourMSMessageHandler ER412MessageHandler)
This is the constructor for this class

Parameters:
DBConnection - This is a pre-establish connection to the WHTOCS database which will be used to extract the mechanism data from the WHT OCS
InstrumentName - This is the name of the instrument which this mechanism is associated with
MechanismName - This is the name of the mechanism
SysLogMessageHandler - This a syslog error reporting object which will be used for reporting errors and the like
ER412ParameterConverter - This will be used in the conversion of parameters between engineering and logical units
Orb - This is a reference to an ORB
Poa - This a reference to the root POA
ControllerNameServiceContext - This is a reference to the COS naming service so that the method can add a context for this mechanism within the controller context in the COS naming service
ER412MessageHandler -
Method Detail

updateMechanismStateImage

public void updateMechanismStateImage(java.util.List ConvertedMessageParameters,
                                      java.util.List UnconvertedMessageParameters,
                                      FourMSDBSchemaDerivedClasses.OM_FourMSMessage MessageStructureDetails)
This method will be used to update the "noticeboard" so that the full status of the mechanisms are available to other systems in the WHT OCS. The details of how the status information should be stored in the noticeboard shall be extracted from the database, there should be information linking the status information returned by the 4MS to the noticeboard items. If specified in the database configuration for this parameter, a reverse conversion will be done from micro units to logical units and this value will be stored in the noticeboard as well. If there is no logical unit counterpart associated with this parameter then no conversion will be subsequently performed and subsequently no logical value will be stored in the noticeboard. Subsequently redistribution of events will be taken care of by the notice board which will use the CORBA event channel to send on the events to interested parties.

Parameters:
ConvertedMessageParameters - This contains the values associated with the fields in the incoming status message which needs to be put into the parameter noticeboard which have been converted from engineering units to logical units

UnconvertedMessageParameters - This contains the values associated with the fields in the incoming status message which needs to be put into the parameter noticeboard which are in the raw engineering format

MessageStructureDetails - This will contain the details of the status message(s) that have just been received for this mechanism and for which the values of the status should be put into the parameter noticeboard

messageReceivedCB

public void messageReceivedCB(java.lang.String IncomingMessage,
                              FourMSMessage IncomingMessageStructure)
This method is a callback and this classes contractual obligation of the i4MSMessageListenerInterface. It is called when there is an incoming message from a 4MS transceiver and will result in this method being called and the message being processed by the mechanism. After the incoming message has been parsed it will be sent to all outstanding subactions associated with the mechanism. It is for the subactions to decide whether or not the incoming message was due to a request that they sent.

Specified by:
messageReceivedCB in interface i4MSMessageListenerInterface
Parameters:
IncomingMessage - This is the string which contains the message incoming from the 4MS
IncomingMessageStructure - This is a structure which contains the components of the message

run

public void run()
Description copied from class: MechanismBase
This is this classes obligation to implement the timer interface Any classes that want to inherit from this class and want to use timers should override this method

Specified by:
run in interface java.lang.Runnable
Specified by:
run in class MechanismBase

getMessageParameterCount

public int getMessageParameterCount(java.lang.String MsgType)
                             throws MessageTypeNotFoundException
This method returns the number of expected parameters for this message type. The subaction class needs to know this in order to process the incoming request to move a mechanism for instance, it needs to know that the caller has provided the correct number of arguments to the script. For example, generally in the case of MOVE request, the number of expected parameters will be one.

Parameters:
MsgType - This is the message type for which we want to know the number of parameters associated.
Returns:
int Number of expected parameters for this message type.
Throws:
MessageTypeNotFoundException
MessageTypeNotFoundException

createSubactions

public boolean createSubactions(org.omg.CORBA.ORB Orb,
                                org.omg.PortableServer.POA Poa)
Each mechanism has optionally associated one or more subactions. These subactions are the gateway through which external applications can control the 4MS. These subactions have a CORBA interface through which 3rd party applications can affect changes on the 4MS. The details of the subactions are stored in the WHTOCS database. This method is responsible for creating the subactions through which the the mechanism will be controlled. CORBA references to these actions will be put into the name server in order that 3rd party applications will be able to find them and subsequently control the mechanism.

Parameters:
Orb - This is a reference to an ORB
Poa - This a reference to the root POA
Returns:
boolean

resolveParameterNoticeBoard

private boolean resolveParameterNoticeBoard()
This method will be used to resolve a reference to the parameter notice board. The reference will be subsequently used to update the parameter noticebaord once status changes arrive from the 4MS.

Returns:
boolean Returns true if a the noticeboard could be found a

createParametersInNoticeBoard

private boolean createParametersInNoticeBoard()
Create parameters in the notice board which are associated with the status information which is returned by the 4MS controller for this mechanism. We only create parameters associated with a mechanism when we have an incoming status messages from that mechanism. We assume that all status messages coming back for a particular mechanism are of the same format (for instance an 800 message has the same format as a 801 message). There can be two parameters written into the parameter noticeboard that are associated with a particular status value coming back from the 4MS. One being an engineering unit and the other the logical value. If a logical value is associated with a status value then this will be determined by the configuration which is held in the ICS database. An example of the conversion of a engineering unit to a logical unit will be mapping a filter position in filter mechanism for instance to the name of the filter which is in that filter position.

If the parameter is flagged as Unused then it will not be added to the parameter noticeboard