device
Class Device

java.lang.Object
  extended by device.Device
All Implemented Interfaces:
IDevice, java.lang.Runnable
Direct Known Subclasses:
DeviceNode, Robot, RobotDevice

public class Device
extends java.lang.Object
implements IDevice, java.lang.Runnable

A Device represents an abstract entity, i.e. device node, that can have other devices in its internal list. It will start and shutdown these devices (if any) and itself in a dedicated thread per device.


Field Summary
(package private)  java.util.concurrent.ConcurrentLinkedQueue<Device> deviceList
          The internal device list can contain other devices.
(package private)  java.lang.String host
          The host string, i.e. network name.
(package private)  int id
          The numerical identifiers of this device.
(package private)  int index
          The numerical device number.
(package private)  boolean isRunning
          Indicating if this device is currently in an action cycle.
(package private)  boolean isThreaded
          Indicating if this device is started in its own thread.
(package private)  java.util.logging.Logger logger
          Logging support
(package private)  int port
          The port number, i.e. host port.
(package private)  long sleeptime
          The periodical idle time in ms this device sleeps between action cycles.
(package private)  java.lang.Thread thread
          Every class of this type has it's own thread
 
Fields inherited from interface device.external.IDevice
DEVICE_ACTARRAY_CODE, DEVICE_AIO_CODE, DEVICE_AUDIO_CODE, DEVICE_AUDIODSP_CODE, DEVICE_AUDIOMIXER_CODE, DEVICE_BLINKENLIGHT_CODE, DEVICE_BLOBFINDER_CODE, DEVICE_BUMPER_CODE, DEVICE_CAMERA_CODE, DEVICE_DEVICE_CODE, DEVICE_DIO_CODE, DEVICE_ENERGY_CODE, DEVICE_FIDUCIAL_CODE, DEVICE_GPS_CODE, DEVICE_GRAPHICS2D_CODE, DEVICE_GRAPHICS3D_CODE, DEVICE_GRIPPER_CODE, DEVICE_HEALTH_CODE, DEVICE_IMU_CODE, DEVICE_IR_CODE, DEVICE_JOYSTICK_CODE, DEVICE_LASER_CODE, DEVICE_LIMB_CODE, DEVICE_LOCALIZE_CODE, DEVICE_LOG_CODE, DEVICE_MAP_CODE, DEVICE_MCOM_CODE, DEVICE_NOMAD_CODE, DEVICE_NULL_CODE, DEVICE_OPAQUE_CODE, DEVICE_PLANNER_CODE, DEVICE_POINTCLOUD3D_CODE, DEVICE_POSITION1D_CODE, DEVICE_POSITION2D_CODE, DEVICE_POSITION3D_CODE, DEVICE_POWER_CODE, DEVICE_PTZ_CODE, DEVICE_RANGER_CODE, DEVICE_RFID_CODE, DEVICE_SERVICE_ADV_CODE, DEVICE_SIMULATION_CODE, DEVICE_SONAR_CODE, DEVICE_SOUND_CODE, DEVICE_SPEECH_CODE, DEVICE_SPEECH_RECOGNITION_CODE, DEVICE_TRUTH_CODE, DEVICE_WAVEFORM_CODE, DEVICE_WIFI_CODE, DEVICE_WSN_CODE
 
Constructor Summary
Device()
          Creates a Device and initializes the internal device list.
Device(Device device)
          Creates a device with the given properties.
Device(int id, java.lang.String host, int port, int index)
          This constructor is used to create a data device object and has no internal devicelist or thread
 
Method Summary
 boolean equals(Device aDevice)
          Compares a Device according to its properties to another one
 Device getDevice(Device dev)
          Searches the internal device list for the device with the properties given.
 java.util.Iterator<Device> getDeviceIterator()
           
 java.util.concurrent.ConcurrentLinkedQueue<Device> getDeviceList()
          Returns a list of devices that this robot client provides.
 Device[] getDeviceListArray()
           
 java.lang.String getHost()
           
 int getId()
           
 int getIndex()
           
 java.util.logging.Logger getLogger()
           
 int getPort()
           
 long getSleepTime()
           
 java.lang.String getThreadName()
           
 boolean isInList(Device[] aDevList)
          Checks if this device properties is in the given device list.
 boolean isRunning()
           
 boolean isSupported()
           
 boolean isThreaded()
           
 boolean matches(Device aDevice)
          Matches this device with the given one.
 boolean matchesList(Device[] aDevList)
          Checks if this device properties matches against any of the given device list.
 void run()
          Manages the periodical action cycles and idle times.
 void runThreaded()
          Starts this device (and its sub-devices) in a thread each.
protected  void setDeviceList(java.util.concurrent.ConcurrentLinkedQueue<Device> deviceList)
           
 void setHost(java.lang.String host)
          Sets this device' host string.
 void setName(int name)
          Sets this device' numerical identifier.
 void setPort(int port)
          Sets this device' host port.
 void setSleepTime(long time)
           
 void shutdown()
          Shuts down this (and any sub-) device.
 java.lang.String toString()
           
protected  void update()
          Might be to be implemented by subclass to do something
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

java.util.logging.Logger logger
Logging support


deviceList

java.util.concurrent.ConcurrentLinkedQueue<Device> deviceList
The internal device list can contain other devices. For example if there is a device hierarchy.


id

int id
The numerical identifiers of this device.


host

java.lang.String host
The host string, i.e. network name.


port

int port
The port number, i.e. host port.


index

int index
The numerical device number.


thread

java.lang.Thread thread
Every class of this type has it's own thread


sleeptime

long sleeptime
The periodical idle time in ms this device sleeps between action cycles.


isRunning

boolean isRunning
Indicating if this device is currently in an action cycle.


isThreaded

boolean isThreaded
Indicating if this device is started in its own thread.

Constructor Detail

Device

public Device()
Creates a Device and initializes the internal device list.


Device

public Device(int id,
              java.lang.String host,
              int port,
              int index)
This constructor is used to create a data device object and has no internal devicelist or thread

Parameters:
id - The Device id.
host - The host to which this Device is connected.
port - The port to which this Device is connected.
index - The Device number (aka index) of the Device.

Device

public Device(Device device)
Creates a device with the given properties.

Parameters:
device - A device template to create a new device
Method Detail

update

protected void update()
Might be to be implemented by subclass to do something


runThreaded

public void runThreaded()
Starts this device (and its sub-devices) in a thread each.

Specified by:
runThreaded in interface IDevice

run

public void run()
         throws java.lang.IllegalStateException
Manages the periodical action cycles and idle times.

Specified by:
run in interface java.lang.Runnable
Throws:
java.lang.IllegalStateException - When updating the device fails.

shutdown

public void shutdown()
Shuts down this (and any sub-) device.

Specified by:
shutdown in interface IDevice

getDeviceList

public final java.util.concurrent.ConcurrentLinkedQueue<Device> getDeviceList()
Returns a list of devices that this robot client provides.

Returns:
The device list.

setDeviceList

protected final void setDeviceList(java.util.concurrent.ConcurrentLinkedQueue<Device> deviceList)
Parameters:
deviceList - the deviceList to set

getDeviceListArray

public final Device[] getDeviceListArray()
Returns:
A Device array list of the internal devices (if any)

getDeviceIterator

public final java.util.Iterator<Device> getDeviceIterator()
Returns:
An iterator of the internal device list.

getDevice

public final Device getDevice(Device dev)
Searches the internal device list for the device with the properties given.

Parameters:
dev - Device template (0 or null for args not to take care of).
Returns:
A device matching the given template when found in list, null otherwise.

getHost

public java.lang.String getHost()
Returns:
This device' host string, can be null.

setHost

public void setHost(java.lang.String host)
Sets this device' host string.

Parameters:
host - The host string.

getPort

public int getPort()
Returns:
This device' host port.

setPort

public void setPort(int port)
Sets this device' host port.

Parameters:
port -

getId

public int getId()
Returns:
This device' numerical identifier.

setName

public void setName(int name)
Sets this device' numerical identifier.

Parameters:
name - The identifier.

getIndex

public int getIndex()
Returns:
The device number.

getThreadName

public java.lang.String getThreadName()
Returns:
This device' thread name.

setSleepTime

public void setSleepTime(long time)
Parameters:
time - The idle time of this device.

getSleepTime

public long getSleepTime()
Returns:
This device' idle time.

isRunning

public boolean isRunning()
Returns:
true if this device is currently doing something (action cycle).

isThreaded

public boolean isThreaded()
Returns:
true if this device is threaded, false else.

getLogger

public java.util.logging.Logger getLogger()
Returns:
The logger.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

equals

public boolean equals(Device aDevice)
Compares a Device according to its properties to another one

Parameters:
aDevice - The device to compare to.
Returns:
true if they equal, false else.

matches

public boolean matches(Device aDevice)
Matches this device with the given one. It compares the explicitly set device properties only. Disabled properties will be ignored.

Parameters:
aDevice - The device to match against.
Returns:
true if the device matches, false else.

matchesList

public boolean matchesList(Device[] aDevList)
Checks if this device properties matches against any of the given device list.

Parameters:
aDevList - The list to search in.
Returns:
true if any device of the list matches, false else.

isInList

public boolean isInList(Device[] aDevList)
Checks if this device properties is in the given device list.

Parameters:
aDevList - The list to search in.
Returns:
true if any device of the list equals, false else.

isSupported

public boolean isSupported()