|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--objectivehtml.oms.OMSObject
This abstract class is the base class of all objects that are capable of participating in the Objective Html Messaging System (OMS).
There are 2 major components to OMS, the signal and the slot. A signal is emitted by objects that wish to inform other objects (the slots) of an interesting event. The signal can carry additional information in the form of object parameters, the slot can also receives these object parameters. A signal can be connected to many slots and a slot can be connected to many signals.
A signal is simply a Java instance method. Once a signal is emitted all slots that are connected to it will receive the signal regardless of whether the other slots successfully process the signal. The connected slot methods will receive the signal in the same order they were connected to the signal method. The only syntatical requirement of a signal method is that it public and returns a Signal object. However the signal will not work unless the signal method is correctly implemented.
A slot is simply a Java instance method. When a signal is received by a listening slot object, the slot method will execute. Generally its desirable for a slot method not to throw any exceptions and have itself handle any exceptions that it might encounter. If you wish a slot method to throw an exception, then you can provide an ErrorHandler object. A ErrorHandler object is simply a class that implements the ErrorHandler interface. If this is provided then the handleError(SlotId, Signal, Throwable) will be called when an exception is thrown by the slot method. If no error handler object is provided then any exceptions thrown by the slots simple have their stack-traces printed to the standard out. Any public method can be a slot. Even a signal method can act as a slot.
A signal and a slot signature's must match for them to be connected. i.e. The parameter types of the signal must match the slot and in the correct order too. A slot can accept less parameters that the signal can give, in this case the extra parameters are lost. The opposite is not true however, a slot method cannot have more arguments that a signal method it is connecting to.
SignalId
,
SlotId
,
Signal
,
ErrorHandler
Constructor Summary | |
OMSObject()
Constructs an instance of OMSObject. |
Method Summary | |
protected static boolean |
compareClasses(java.lang.Class objSubClass,
java.lang.Class objSuperClass)
This method compares two classes. |
static void |
connect(SlotId objSlotId,
SignalId objSignalId)
This is used to connect a slot to a signal. |
static void |
disconnect(SlotId objSlotId,
SignalId objSignalId)
This is used to disconnect a slot to a signal. |
static void |
emit(Signal objSignal)
Emits the signal to all the connected slots. |
boolean |
isAlive()
Returns whether the object is alive or not. |
protected void |
setAlive(boolean bAlive)
Sets the object to be alive or dead. |
SignalId |
signal(java.lang.String sSignalSignature)
Returns the signal for the given signal signature. |
SlotId |
slot(java.lang.String sSlotSignature)
Returns the slot for the given slot signature. |
SlotId |
slot(java.lang.String sSlotSignature,
ErrorHandler objErrorHandler)
Returns the slot for the given slot signature. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public OMSObject()
Method Detail |
public static void disconnect(SlotId objSlotId, SignalId objSignalId)
objSlotId
- the slot idobjSignalId
- the signal idpublic static void connect(SlotId objSlotId, SignalId objSignalId) throws InvalidSlotException
objSlotId
- the slot idobjSignalId
- the signal idInvalidSlotException
- if the slot does not match the signalpublic static void emit(Signal objSignal)
Emits the signal to all the connected slots. The connected slot methods will be called in the same order they were connected to the signal (i.e. the first connected slot will be executed first, the second connected slot is next, and so on). The parameter values given by the Signal method are passed to each slot method. If the slot method has less arguments than the signal method then the extra arguments are lost. If the slot method throws an exception and has an ErrorHandler object set for it then the handleError method will be called. If no ErrorHandler object is for the slot then the exception will have its stack-trace printed to standard out and the exception is simply eaten up.
If the slot method is also a signal method, then this signal is then emitted.
objSignal
- the signal to emitpublic SlotId slot(java.lang.String sSlotSignature, ErrorHandler objErrorHandler) throws InvalidSlotException
Returns the slot for the given slot signature. The error handler object objErrorHandler is added to the slot.
A method signature has the following pattern (this applies to slots and signals):
method-name(argtype1, argtype2, ...)
Some points:
sSlotSignature
- the slot signatureobjErrorHandler
- the error handler for the slotInvalidSlotException
- if the slot cannot be foundslot(String)
public SlotId slot(java.lang.String sSlotSignature) throws InvalidSlotException
sSlotSignature
- the slot signatureInvalidSlotException
- if the slot cannot be foundslot(String, ErrorHandler)
public SignalId signal(java.lang.String sSignalSignature) throws InvalidSignalException
sSignalSignature
- the signal signatureInvalidSignalException
- if the signal cannot be foundslot(String, ErrorHandler)
protected static boolean compareClasses(java.lang.Class objSubClass, java.lang.Class objSuperClass)
objSubClass
- the sub-classobjSuperClass
- the super-classprotected void setAlive(boolean bAlive)
bAlive
- true if active, false otherwiseisAlive()
public boolean isAlive()
setAlive(boolean)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |