stella.rmi
Class DailyDump

java.lang.Object
  extended by util.PropertyContainer
      extended by util.PropertyResources
          extended by util.PropertyBundles
              extended by util.rmi.RmiPropertyContainer
                  extended by util.rmi.AbstractRmiListener
                      extended by stella.rmi.DailyDump
All Implemented Interfaces:
Cloneable, Remote, EventListener, RmiDataListener, ExitCleaning, Initializable, LocalizedSupplying, PropertySupplying, ResourceSupplying, RmiEventListener, RmiListener, RmiPropertyBearing

public class DailyDump
extends AbstractRmiListener
implements RmiDataListener

A rmi-based data listener. The data received is dumped into a ascii-file. In the basic version, the only properties used are the KEY_FILE and the KEY_BIND. The latter one points to the binding name of the remote caster. If the file key is not present it is constructed from the binding name by stripping the host information from the binding name and adding the DEFEXTENSION to it.

This class listens to a single sensor and dumps only its raw data. If the data event received is a subclass of DataEvent and the main value of the data event links to a weather indicator, the current status of the weather as defined by this single sensor is added after the raw data using the KEY_GOOD and KEY_BAD keys. Note that it may not be a good idea to set one of these two strings to a whitespace string because some plot-programs may have difficulties reading varying number of columns.


Nested Class Summary
private  class DailyDump.WriterCloseThread
          A shutdown hook that closes the argumental writer.
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
private static String DEFBAD
          The default good-weather indicator.
private static String DEFEXTENSION
          The default dump file name.
private static String DEFGOOD
          The default good-weather indicator.
private  BufferedWriter dump
          The stream the data is writtn to.
private  DailyDump.WriterCloseThread hook
          A thread devoted to closing the actually open file on interupts.
static String KEY_BAD
          The key pointing to the string added for good weather.
static String KEY_BIND
          The key pointing to the binding name of the rmi-data caster.
static String KEY_FILE
          The key pointing to the output file.
static String KEY_GOOD
          The key pointing to the string added for good weather.
static String KEY_PATH
          The key pointing to the output dir.
private  int lastmjd
          A flag indicating the last dump mjd.
 
Fields inherited from class util.rmi.AbstractRmiListener
KEY_ALIVE, KEY_EXPORTPORT, KEY_INIT, KEY_LISTENERNAME, KEY_RETRY, KEY_RETRYSLEEP, KEY_SHUTDOWNDELAY
 
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 util.ResourceSupplying
KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Fields inherited from interface util.PropertySupplying
CONFIG, KEY_CLASS
 
Constructor Summary
DailyDump(Map prop)
          Constructs a new file dump instance.
 
Method Summary
protected  boolean deregisterAtCaster(RmiCaster caster, Class ignored)
          Deregisters at the appropriate caster.
static void main(String[] arg)
          Adds the first command line argument as the binding name.
private  void openStream(int mjd)
          Opens the file as a stream for writing.
protected  boolean registerAtCaster(RmiCaster caster, Class ignored)
          Registers at the appropriate caster.
 void rmiDataAvailable(DataEvent de)
          The data receiving edge.
private  void writeHead()
          Writes some header information.
 
Methods inherited from class util.rmi.AbstractRmiListener
allBound, blockBinding, blockBinding, disconnect, exit, getIP, getListenerName, isConnected, listenerName, releaseBinding, releaseBinding, rescanned, startBinding, startBinding
 
Methods inherited from class util.rmi.RmiPropertyContainer
containsRemoteProperty, getRemoteProperties, getRemoteProperty, setRemoteProperty
 
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, init, 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, setObject, setProperties, setProperty, stringProperties, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface util.rmi.RmiEventListener
getListenerName
 
Methods inherited from interface util.rmi.RmiListener
disconnect, isConnected
 
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
 
Methods inherited from interface util.Initializable
init
 

Field Detail

KEY_PATH

public static final String KEY_PATH
The key pointing to the output dir.

See Also:
Constant Field Values

KEY_FILE

public static final String KEY_FILE
The key pointing to the output file.

See Also:
Constant Field Values

KEY_BIND

public static final String KEY_BIND
The key pointing to the binding name of the rmi-data caster.

See Also:
Constant Field Values

KEY_GOOD

public static final String KEY_GOOD
The key pointing to the string added for good weather.

See Also:
Constant Field Values

KEY_BAD

public static final String KEY_BAD
The key pointing to the string added for good weather.

See Also:
Constant Field Values

DEFGOOD

private static final String DEFGOOD
The default good-weather indicator.

See Also:
Constant Field Values

DEFBAD

private static final String DEFBAD
The default good-weather indicator.

See Also:
Constant Field Values

DEFEXTENSION

private static final String DEFEXTENSION
The default dump file name.

See Also:
Constant Field Values

dump

private BufferedWriter dump
The stream the data is writtn to.


lastmjd

private int lastmjd
A flag indicating the last dump mjd.


hook

private DailyDump.WriterCloseThread hook
A thread devoted to closing the actually open file on interupts.

Constructor Detail

DailyDump

public DailyDump(Map prop)
          throws IOException
Constructs a new file dump instance. If the file name is not set the default name, constructed with DEFEXTENSION is asumed.

Throws:
IllegalArgumentException - If no binding-to property is given.
IOException
Method Detail

rmiDataAvailable

public void rmiDataAvailable(DataEvent de)
                      throws RemoteException
The data receiving edge. This method should return fast, which is hopefully acieved by writing to a buffered stream.

Specified by:
rmiDataAvailable in interface RmiDataListener
Throws:
RemoteException

registerAtCaster

protected boolean registerAtCaster(RmiCaster caster,
                                   Class ignored)
Registers at the appropriate caster.

Specified by:
registerAtCaster in class AbstractRmiListener
Returns:
True, if this listener can register at the specified caster

deregisterAtCaster

protected boolean deregisterAtCaster(RmiCaster caster,
                                     Class ignored)
Deregisters at the appropriate caster.

Specified by:
deregisterAtCaster in class AbstractRmiListener
Returns:
True, if this listener can deregister at the specified caster

openStream

private void openStream(int mjd)
                 throws IOException
Opens the file as a stream for writing. If the file exists it is opened in append mode. For newly created dump files the method writeHead() is called.

To ensure proper closing of the file, a shutdown-hook is added to the system.

Throws:
IOException

writeHead

private void writeHead()
                throws IOException
Writes some header information.

Throws:
IOException - If the stream could not be writtn.

main

public static void main(String[] arg)
                 throws IOException
Adds the first command line argument as the binding name.

Throws:
IOException