dk.opi.io
Class DefaultIOGroup

java.lang.Object
  extended bydk.opi.io.DefaultIOGroup
All Implemented Interfaces:
IOGroup
Direct Known Subclasses:
OpcGroup

public class DefaultIOGroup
extends Object
implements IOGroup

This class implements the IOGroup interface and implements a simple polling interface for IOItem values. Ie. if you set the group active this class will poll IOItems belonging to this group and report any changes in item values


Field Summary
protected  boolean active
           
protected  String description
           
protected  Vector ioListeners
           
protected  Vector items
           
protected  String name
           
protected  int updateRate
           
 
Constructor Summary
DefaultIOGroup(String name, boolean active, int updateRate)
          Create a new DefaultIOGroup object.
DefaultIOGroup(String name, boolean active, int updateRate, String descr)
          Create a new DefaultIOGroup object
 
Method Summary
 void addIOListener(IOListener l)
          Add a listener for IO events related to this group
 void addItem(IOItem ioi)
          Add an item to this group
protected  void finalize()
           
 void fireAllItems()
          Use this method to manually fire a onValueChanged() for all IOItems in this group.
 void fireAllItems(IOListener iol)
          Use this method to manually fire a onValueChanged() for all IOItems in this group.
 void fireAllItems(IOListener iol, boolean performRead, int dataSource)
          Use this method to manually fire a IOListener.onValueChanged(dk.opi.io.IOItem) notification to the specified IOListener.
 void fireIOListenerOnValueChanged(IOItem oi)
          Fire the onDataChanged event
 String getDescription()
          Get descriptive text for this group
 IOItem getItem(String actionCmdName)
          Return an IOItem from this group
 Vector getItems()
          Return Vector of all IOItems currently added to this group.
 String getName()
          Get the name of this group
 int getUpdateRate()
           
 boolean isActive()
           
 void readAllItems(int dataSource)
          Read the item value for all items in this group.
 void removeIOListener(IOListener l)
          Remove a listener for IO events related to this group
 void removeItem(IOItem ioi)
          Remove an item from this group
 void setActive(boolean b)
          Turn off/on automatical updating from the IOItems in this group depending on the value of b.
 void setDescription(String text)
          Set descriptive text for this group
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ioListeners

protected transient Vector ioListeners

items

protected transient Vector items

name

protected String name

active

protected boolean active

updateRate

protected int updateRate

description

protected String description
Constructor Detail

DefaultIOGroup

public DefaultIOGroup(String name,
                      boolean active,
                      int updateRate)
Create a new DefaultIOGroup object. The description String of the group is set to the group name value

Parameters:
name - name of the group. Must be unique within this server
active - if items in this group are going to be monitored
updateRate - requested update rate for items in this group in milli seconds

DefaultIOGroup

public DefaultIOGroup(String name,
                      boolean active,
                      int updateRate,
                      String descr)
Create a new DefaultIOGroup object

Parameters:
name - name of the group. Must be unique within this server
active - if items in this group are going to be monitored
updateRate - requested update rate for items in this group in milli seconds
descr - description of the group. Can be queried by a call to getDescription()
Method Detail

addItem

public void addItem(IOItem ioi)
Add an item to this group

Specified by:
addItem in interface IOGroup
Parameters:
ioi - The item to add

removeItem

public void removeItem(IOItem ioi)
                throws RbxIOException
Remove an item from this group

Specified by:
removeItem in interface IOGroup
Parameters:
ioi - The item to remove
Throws:
RbxIOException - thrown if it was not possible to remove the specified item, for instance if the specified item is not a member of this group.

getItem

public IOItem getItem(String actionCmdName)
Return an IOItem from this group

Specified by:
getItem in interface IOGroup
Parameters:
actionCmdName - Name of the item to return
Returns:
null if not item with specified name exists - otherwise an IOItem object is returned

fireIOListenerOnValueChanged

public void fireIOListenerOnValueChanged(IOItem oi)
Fire the onDataChanged event


addIOListener

public void addIOListener(IOListener l)
Add a listener for IO events related to this group

Specified by:
addIOListener in interface IOGroup

removeIOListener

public void removeIOListener(IOListener l)
Remove a listener for IO events related to this group

Specified by:
removeIOListener in interface IOGroup

getItems

public Vector getItems()
Return Vector of all IOItems currently added to this group. Don't screw around with this Vector since it is the same Vector used for polling of variables

Specified by:
getItems in interface IOGroup
Returns:
Vector object containing list of all IOItems added to this group

getUpdateRate

public int getUpdateRate()
Specified by:
getUpdateRate in interface IOGroup
Returns:
Update rate for monitored items in this group in milli secs

finalize

protected void finalize()
                 throws Throwable
Throws:
Throwable

setActive

public void setActive(boolean b)
Turn off/on automatical updating from the IOItems in this group depending on the value of b.

Specified by:
setActive in interface IOGroup
Parameters:
b - if true IOItems in this group will fire the onValueChanged() event everytime a value is changed

isActive

public boolean isActive()
Specified by:
isActive in interface IOGroup
Returns:
True if the monitoring of the group is active, otherwise false is returned

fireAllItems

public void fireAllItems()
Use this method to manually fire a onValueChanged() for all IOItems in this group. Notification is sent to all IOListener which has signed up for events from this group. This method is usefull right after items have been added to the group. A call to this method will initialize your application with the current values.

Specified by:
fireAllItems in interface IOGroup

fireAllItems

public void fireAllItems(IOListener iol)
Use this method to manually fire a onValueChanged() for all IOItems in this group. Notification is sent to the specified IOListener. This method is usefull right after items have been added to the group. A call to this method will initialize your application with the current values.

Specified by:
fireAllItems in interface IOGroup
Parameters:
iol - onValueChanged() is only fired for the specified IOListener

fireAllItems

public void fireAllItems(IOListener iol,
                         boolean performRead,
                         int dataSource)
                  throws RbxIOException
Use this method to manually fire a IOListener.onValueChanged(dk.opi.io.IOItem) notification to the specified IOListener. This method is usefull right after items have been added to the group. A call to this method will initialize your application with the current values.

Specified by:
fireAllItems in interface IOGroup
Parameters:
iol - the listener to notify
performRead - if true a read will be performed for all items in the group prior to firing of the event. In combination with a dataSource value of DEVICE_READ this will ensure that the onValueChanged() is fired with the most recent and up to date value. Note: ignored in this default implementation
dataSource - The source to read from, ie. CACHE_READ or DEVICE_READ. Also see IOItem.readValue(int). Note: ignored in this default implementation
Throws:
RbxIOException - Will only be thrown if performRead is true and the read operation for some reason fails

readAllItems

public void readAllItems(int dataSource)
                  throws RbxIOException
Read the item value for all items in this group. Item values may subsequently be obtained by a call to getOldValue() on each item. The intended use of this method is to update register values for items, in case the group is intentially set to inactive, in which case the dataSource parameter should always be set to IOItem.DEVICE_READ.
onValueChanged() on registered listeners for the group will be called for changed values.
This default implementation will do a readValue() on all items in the group, one by one. Specific sub-classes may override this method in order to make a more efficient read

Specified by:
readAllItems in interface IOGroup
Parameters:
dataSource - The source to read from, ie. IOItem.CACHE_READ or IOItem.DEVICE_READ. A CACHE read will obtain the current value for the item from the device server cache (eg. OPC server). This is fast but the value is only updated with the specified update rate, ie. a CACHE read is accurate to within the 'UpdateRate' of the group.
The data can be read from the DEVICE in which case an actual read of the physical device is to be performed. The exact implementation of CACHE and DEVICE reads may vary between devices and communication servers.
For CACHE reads the data is only valid if both the group and the item are active. DEVICE reads are not affected by the ACTIVE state of the group or item.
Throws:
RbxIOException - thrown if one or more read operations failed.

getName

public String getName()
Get the name of this group

Specified by:
getName in interface IOGroup
Returns:
group name

setDescription

public void setDescription(String text)
Set descriptive text for this group

Specified by:
setDescription in interface IOGroup
Parameters:
text - the description.
See Also:
getDescription()

getDescription

public String getDescription()
Get descriptive text for this group

Specified by:
getDescription in interface IOGroup
Returns:
the description.
See Also:
setDescription(java.lang.String)