stella.parameter
Class SwitchRelay

java.lang.Object
  extended by java.rmi.server.RemoteObject
      extended by java.rmi.server.RemoteServer
          extended by java.rmi.server.UnicastRemoteObject
              extended by stella.parameter.SwitchRelay
All Implemented Interfaces:
Serializable, Remote, RemoteParameter, RemoteSwitch, RemoteTrigger, RmiCaster, RmiListener

public class SwitchRelay
extends UnicastRemoteObject
implements RemoteSwitch, RmiListener

Relay the parameter given at the first command line argument to the local registry.

See Also:
Serialized Form

Field Summary
private  String bind
           
private  String naming
           
private  RemoteSwitch relay
           
private  List<RmiListener> stubs
          A list of registered rmi listners.
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Fields inherited from interface stella.rmi.RemoteTrigger
NAMING_EXTENSION
 
Constructor Summary
SwitchRelay(String rmi, String local)
           
 
Method Summary
 void addRmiListener(RmiListener ear)
          Adds a listener for notification on exit.
 boolean bindToRegistry()
          Iniates binding of this caster to the registry.
 void disconnect(RmiCaster from)
          Signals that the caster will get invalid.
 boolean isConnected()
          A method for the caster to check connection.
 boolean isValid()
          A handle for the listener to test if the reference to the caster it is listening to is still valid.
static void main(String[] arg)
           
 Object remoteGet()
          The remote edge of this trigger.
 Boolean remoteGetTrigger()
          Retrieves the trigger value as a boolean.
 boolean remoteIsTrue()
          Retrieves the trigger value as a primitive boolean.
 Date remoteToggleTime()
          Retrieves the trigger toggle time using RMI.
 void removeRmiListener(RmiListener ear)
          Removes a listener.
private  boolean startRelay()
           
 boolean switchOff()
          The remote switching is diverted to the servers switchOn(long).
 boolean switchOn(long maxtime)
          The remote switching is diverted to the servers switchOn(long).
 boolean unbindFromRegistry()
          Unbinds the caster from the registry.
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toString, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

relay

private RemoteSwitch relay

naming

private String naming

bind

private String bind

stubs

private List<RmiListener> stubs
A list of registered rmi listners.

Constructor Detail

SwitchRelay

public SwitchRelay(String rmi,
                   String local)
            throws RemoteException
Throws:
RemoteException
Method Detail

startRelay

private boolean startRelay()
                    throws RemoteException
Throws:
RemoteException

bindToRegistry

public boolean bindToRegistry()
                       throws RemoteException
Description copied from interface: RmiCaster
Iniates binding of this caster to the registry. The cater always knows its binding name.

Specified by:
bindToRegistry in interface RmiCaster
Returns:
True if successful.
Throws:
RemoteException

unbindFromRegistry

public boolean unbindFromRegistry()
                           throws RemoteException
Description copied from interface: RmiCaster
Unbinds the caster from the registry. Normally called during clean-up process, i.e. if the caster is also ExitCleaning

Specified by:
unbindFromRegistry in interface RmiCaster
Returns:
True if successful.
Throws:
RemoteException

addRmiListener

public void addRmiListener(RmiListener ear)
                    throws RemoteException
Adds a listener for notification on exit.

Specified by:
addRmiListener in interface RemoteParameter
Throws:
RemoteException

removeRmiListener

public void removeRmiListener(RmiListener ear)
                       throws RemoteException
Removes a listener.

Specified by:
removeRmiListener in interface RemoteParameter
Throws:
RemoteException

remoteGet

public Object remoteGet()
                 throws RemoteException
The remote edge of this trigger.

Specified by:
remoteGet in interface RemoteParameter
Throws:
RemoteException

remoteGetTrigger

public Boolean remoteGetTrigger()
                         throws RemoteException
Description copied from interface: RemoteTrigger
Retrieves the trigger value as a boolean.

Specified by:
remoteGetTrigger in interface RemoteTrigger
Throws:
RemoteException

remoteIsTrue

public boolean remoteIsTrue()
                     throws RemoteException
Description copied from interface: RemoteTrigger
Retrieves the trigger value as a primitive boolean.

Specified by:
remoteIsTrue in interface RemoteTrigger
Throws:
RemoteException

remoteToggleTime

public Date remoteToggleTime()
                      throws RemoteException
Description copied from interface: RemoteTrigger
Retrieves the trigger toggle time using RMI.

Specified by:
remoteToggleTime in interface RemoteTrigger
Throws:
RemoteException

switchOn

public boolean switchOn(long maxtime)
                 throws RemoteException
The remote switching is diverted to the servers switchOn(long).

Specified by:
switchOn in interface RemoteSwitch
Parameters:
maxtime - The maximum illumination time, in ms. Zero for unlimitied.
Returns:
True, if turning on of the switch was successful.
Throws:
RemoteException

switchOff

public boolean switchOff()
                  throws RemoteException
The remote switching is diverted to the servers switchOn(long).

Specified by:
switchOff in interface RemoteSwitch
Returns:
True, if turning off of the light was successful.
Throws:
RemoteException

isValid

public boolean isValid()
                throws RemoteException
Description copied from interface: RmiCaster
A handle for the listener to test if the reference to the caster it is listening to is still valid. During its entrie lifetime, a listener should regularly call this method to test if the caster it is listening to is still connected. If the caster has ceased existance a call to this method will cause a remote exception to be thrown. The listener catches this exception and re-tries to register to the caster.

Specified by:
isValid in interface RmiCaster
Throws:
RemoteException

isConnected

public boolean isConnected()
                    throws RemoteException
Description copied from interface: RmiListener
A method for the caster to check connection. Should immedeately return true. If the connection is lost a remote exception will be thrown. The caster catches this exception and though realizes that the connection is lost.

Specified by:
isConnected in interface RmiListener
Throws:
RemoteException

disconnect

public void disconnect(RmiCaster from)
                throws RemoteException
Description copied from interface: RmiListener
Signals that the caster will get invalid. Listeners should remove from the caster using the appropriate remove method. The method should return as soon as the listener has removed itself.

Specified by:
disconnect in interface RmiListener
Throws:
RemoteException

main

public static void main(String[] arg)
                 throws RemoteException
Throws:
RemoteException