ist.palcom.device
Class AbstractDevice

java.lang.Object
  extended by ist.palcom.device.AbstractDevice
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
AbstractSwingDisplayUDPDevice, AbstractUDPDevice, BioBeltDevice, PalOverviewBrowserDevice, PoetryDisplayerDevice, PoetryGeneratorDevice, RespiratorDevice, SaturimeterDevice, Tile, TimerDevice

public abstract class AbstractDevice
extends java.lang.Object
implements java.lang.Runnable

The base class of a PalCom device. This abstract class creates no specific managers. Subclasses implement the createDeviceContext method for creating a DeviceContext with the right set of managers.


Field Summary
protected  DeviceContext context
           
protected  PalcomScheduler scheduler
           
 
Constructor Summary
protected AbstractDevice(java.lang.String name)
          WARNING!
protected AbstractDevice(java.lang.String name, DeviceID deviceID)
          This constructor can be used by simulated devices that uses their own DeviceID and not the one stored in the file system.
 
Method Summary
protected abstract  DeviceContext createDeviceContext(DeviceID deviceID, PalcomScheduler scheduler)
          Creates the DeviceContext of the device.
 DeviceContext getDeviceContext()
           
 PRDDevice getDeviceInfo()
           
 java.lang.String getName()
           
 java.lang.String getRootPath()
           
protected  void initDevice()
          Initialize the device.
 void run()
          Run the scheduler of the device until completion.
 void safePutEvent(Event event, PalcomThread target)
          Put an event in the mailbox of a PalcomThread in a way that does not interfere with this device's PalcomScheduler.
 void setHeartBeatPeriod(long period)
          Set the time interval between heartbeats.
 void stop()
          Stop the device.
protected  void stopDevice()
          Stop the device.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

scheduler

protected PalcomScheduler scheduler

context

protected DeviceContext context
Constructor Detail

AbstractDevice

protected AbstractDevice(java.lang.String name)
                  throws java.io.IOException
WARNING! This constructor should only be used by devices that run alone on the "real" device (computer). It uses a stored DeviceID from the file system. If two or more devices runs at the same time with this constructor there will be a DeviceID collision and strange things will happen in discovery.

Throws:
java.io.IOException - if a file read/write error occurred when trying to read/write DeviceID

AbstractDevice

protected AbstractDevice(java.lang.String name,
                         DeviceID deviceID)
This constructor can be used by simulated devices that uses their own DeviceID and not the one stored in the file system.

Method Detail

getDeviceContext

public DeviceContext getDeviceContext()

createDeviceContext

protected abstract DeviceContext createDeviceContext(DeviceID deviceID,
                                                     PalcomScheduler scheduler)
Creates the DeviceContext of the device. This method has to be implemented in a concrete subclass.

Parameters:
deviceID - The device ID.
scheduler - The scheduler.
Returns:
The DeviceContext

getDeviceInfo

public PRDDevice getDeviceInfo()

setHeartBeatPeriod

public void setHeartBeatPeriod(long period)
Set the time interval between heartbeats. This method has to be called in order for the device to send out heartbeats requesting answers, otherwise it will only send out heartbeats in reply to other devices.


getName

public java.lang.String getName()

getRootPath

public java.lang.String getRootPath()
Returns:
The path to this device own file system folder

run

public final void run()
Run the scheduler of the device until completion. This method is blocking. May be called by a Java thread.

Specified by:
run in interface java.lang.Runnable

stop

public void stop()
Stop the device. May be called by Java threads. The actual cleanup is done by a PalcomThread in the method stopDevice.


safePutEvent

public void safePutEvent(Event event,
                         PalcomThread target)
Put an event in the mailbox of a PalcomThread in a way that does not interfere with this device's PalcomScheduler.


initDevice

protected void initDevice()
                   throws java.io.IOException
Initialize the device. Called from a PalcomThread. Here the actual setup is done. Subclasses override this method, and call super.initDevice from there.

Throws:
java.io.IOException

stopDevice

protected void stopDevice()
                   throws java.io.IOException
Stop the device. Called from a PalcomThread. Here the actual cleanup is done. Subclasses override this method, and call super.stopDevice from there.

Throws:
java.io.IOException