stella.io
Class CastingRS485Server

java.lang.Object
  extended by util.PropertyContainer
      extended by util.PropertyResources
          extended by util.PropertyBundles
              extended by io.AbstractDriver
                  extended by io.AbstractSerialDriver
                      extended by stella.io.RS485Server
                          extended by stella.io.CastingRS485Server
All Implemented Interfaces:
Driver, Cloneable, Remote, RmiSerialCaster, ExitCleaning, Initializable, LocalizedSupplying, PropertySupplying, ResourceSupplying, RmiCaster
Direct Known Subclasses:
WatchdogRS485Server

public class CastingRS485Server
extends RS485Server
implements RmiSerialCaster

A class that acts as a serial caster, additionally to its RS485 server capabilities. On init(), this caster binds itself to a running registry if the KEY_BIND property is true. RmiSerialListeners can subscribe to the caster services using the methods defined in RmiSerialCaster.

To allow subclasses to specify which commands sent to the serial line should actually invoke a serial event, the writeCommand(java.lang.String) method is splitted into a normal method (directly passed to the superclass), and a method adding a serial flag that sparks the generation of a serial event if true.


Nested Class Summary
 
Nested classes/interfaces inherited from class stella.io.RS485Server
RS485Server.Checksum, RS485Server.Command, RS485Server.Info, RS485Server.Scan
 
Nested classes/interfaces inherited from class io.AbstractSerialDriver
AbstractSerialDriver.Available
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
private static boolean DEFBIND
          The default binding behavior.
static String KEY_BIND
          The key specifying the binding behavior of this caster.
private  List listeners
          The list of serial listeners.
 
Fields inherited from class stella.io.RS485Server
KEY_CHECKCHAR, KEY_CHECKSUM, KEY_CLOSE, KEY_CR, KEY_ECHO, KEY_FAILTIME, KEY_FAILURES, KEY_INVALID, KEY_MAXBUFFER, KEY_MAXBUSY, KEY_QUERYTIME, KEY_REINIT, KEY_RESPONDTIME, KEY_STARTUP, KEY_TIMEBUSY, lock
 
Fields inherited from class io.AbstractSerialDriver
inport, KEY_BAUDRATE, KEY_CLOSETIMEOUT, KEY_DATABIT, KEY_FLOWCONTROL, KEY_INBUFFER, KEY_NOTIFYCOOLDOWN, KEY_OUTBUFFER, KEY_PARITYBIT, KEY_PORTNAME, KEY_RECEIVEFRAMING, KEY_RECEIVETHRESHOLD, KEY_RECEIVETIMEOUT, KEY_STOPBIT, KEY_TIMEOUT, outport, staticlock
 
Fields inherited from class io.AbstractDriver
KEY_DRIVERNAME
 
Fields inherited from class util.PropertyBundles
KEY_LOCALECOUNTRY, KEY_LOCALELANGUAGE, KEY_RESOURCEBUNDLES
 
Fields inherited from class util.PropertyResources
KEY_NOINITONCREATE, localurl, locate, POSTFIX_DIR, POSTFIX_EXT, POSTFIX_FILE, POSTFIX_LIST, POSTFIX_URL, urlset
 
Fields inherited from class util.PropertyContainer
KEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATOR
 
Fields inherited from interface stella.rmi.RmiSerialCaster
NAMING_EXTENSION
 
Fields inherited from interface util.ResourceSupplying
KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Fields inherited from interface util.PropertySupplying
CONFIG, KEY_CLASS
 
Constructor Summary
CastingRS485Server(Map prop)
          Constructs a new casting RS485 server.
 
Method Summary
 void addRmiSerialListener(RmiSerialListener ear)
          Adds an rmi-enabled serial listener to this class's listeners list.
 boolean bindToRegistry()
          Binds myself to a running registry using the static binding method in AbstractRmiCaster.
 void exit()
          Unbind from registry, if bound after closing serial port.
 void init()
          The init method specialises initialization for a Driver object necessary prior to use.
 boolean isValid()
          The method for listeners to check if the remote reference is still valid.
protected  void notifyListeners(SerialEvent se)
          Notifies all registerd listeners of an upcoming serial event.
 void removeRmiSerialListener(RmiSerialListener ear)
          Removes an rmi-enabled serial listener from this class's listeners.
 boolean unbindFromRegistry()
          Uninds myself to a running registry using the static binding method in AbstractRmiCaster.
 String writeCommand(String cmd)
          Writes a command to the serial line.
 String writeCommand(String cmd, boolean flag)
          Writes a command to the serial line.
 String writeString(String mess, boolean flag)
          Writes the string to the port.
 
Methods inherited from class stella.io.RS485Server
deferCommand, ensureCommand, getCheckSum, getCheckSumming, isReading, open, readString, setCheckSumming, toString, writeString
 
Methods inherited from class io.AbstractSerialDriver
close, createPortEventListener, createPortEventListener, deregisterSoleEventListener, disableEvent, enableEvent, getDriverName, isOpen, registerSoleEventListener, resetOriginalParameters
 
Methods inherited from class io.AbstractDriver
createDriver, equals, hashCode
 
Methods inherited from class util.PropertyBundles
clone, getLocalized, getLocalized, getLocalizedString, getLocalizedString, loadResource
 
Methods inherited from class util.PropertyResources
createFrom, createFrom, createFrom, getApplet, getAsResources, getLocalClassLoader, getPropertiesToKey, getPropertiesToKey, getResource, getResourceAsStream, getResourceFromKey, getResources, keyCreate, keyCreate, reload, setApplet
 
Methods inherited from class util.PropertyContainer
augment, augment, augment, defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsEnums, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, isNew, parseObject, reload, removeProperty, rescanned, setObject, setProperties, setProperty, stringProperties
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface util.ResourceSupplying
getResource, getResourceAsStream, getResources
 
Methods inherited from interface util.PropertySupplying
defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, parseObject, removeProperty, setObject, setProperty, stringProperties
 

Field Detail

KEY_BIND

public static final String KEY_BIND
The key specifying the binding behavior of this caster.

See Also:
Constant Field Values

DEFBIND

private static final boolean DEFBIND
The default binding behavior.

See Also:
Constant Field Values

listeners

private List listeners
The list of serial listeners.

Constructor Detail

CastingRS485Server

public CastingRS485Server(Map prop)
Constructs a new casting RS485 server. Binding of the services is delayed until the init() method is called.

Method Detail

init

public void init()
The init method specialises initialization for a Driver object necessary prior to use. The casting RS485 server registers itself at a running registry after calling the parental method. Regisering only takes place if the parental init method returned true. If registering fails, but the serial line could be opened successfully, this method still returns true.

Specified by:
init in interface Initializable
Overrides:
init in class PropertyResources

bindToRegistry

public boolean bindToRegistry()
                       throws RemoteException
Binds myself to a running registry using the static binding method in AbstractRmiCaster.

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

unbindFromRegistry

public boolean unbindFromRegistry()
                           throws RemoteException
Uninds myself to a running registry using the static binding method in AbstractRmiCaster.

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

isValid

public boolean isValid()
                throws RemoteException
The method for listeners to check if the remote reference is still valid. Needed for rmi error-caster abilities. Returns true.

Specified by:
isValid in interface RmiCaster
Throws:
RemoteException

exit

public void exit()
Unbind from registry, if bound after closing serial port.

Specified by:
exit in interface ExitCleaning
Overrides:
exit in class RS485Server

writeString

public String writeString(String mess,
                          boolean flag)
                   throws IOException
Writes the string to the port. If the cast-flag is true, the listeners are notified.

Throws:
IOException

writeCommand

public String writeCommand(String cmd)
                    throws IOException
Writes a command to the serial line. Defaults to the event-generating version.

Overrides:
writeCommand in class RS485Server
Parameters:
cmd - The command to write
count - The number of bytes to read as a command reply. Zero for unspecified numbers.
Throws:
IOException

writeCommand

public String writeCommand(String cmd,
                           boolean flag)
                    throws IOException
Writes a command to the serial line. Defaults to the event-generating version.

Parameters:
cmd - The command to write
count - The number of bytes to read as a command reply. Zero for unspecified numbers.
flag - True, if serial events should be generated.
Throws:
IOException

addRmiSerialListener

public void addRmiSerialListener(RmiSerialListener ear)
                          throws RemoteException
Adds an rmi-enabled serial listener to this class's listeners list.

Specified by:
addRmiSerialListener in interface RmiSerialCaster
Throws:
RemoteException

removeRmiSerialListener

public void removeRmiSerialListener(RmiSerialListener ear)
                             throws RemoteException
Removes an rmi-enabled serial listener from this class's listeners.

Specified by:
removeRmiSerialListener in interface RmiSerialCaster
Throws:
RemoteException

notifyListeners

protected void notifyListeners(SerialEvent se)
Notifies all registerd listeners of an upcoming serial event.