jcontrol.comm.nv
Interface NetworkVariable

All Known Implementing Classes:
Eia709NetworkVariable

public interface NetworkVariable

A network variable is a variable that is shared by different nodes in a communication network. A classic example could be a switch that contain a variable reflecting its state. The state can be changed locally (by physically handling the switch) or remotely over the network, for instance from a different switch that serves the same purpose.

Network variables provide a convenient application interface for distributed application. While some protocols (EIA-709) already provide their own network variable interface, any protocol specification can be abstracted to network variables, making distributed applications work almost independently of the communication protocol.

The JControl network variable implementation uses an event/listener system to keep applications updated on network variable changes.

See Also:
NetworkVariableEvent, NetworkVariableListener

Method Summary
 DataInputStream getDataInputStream()
          Returns a DataInputStream for reading from the network variable value.
 DataOutputStream getDataOutputStream()
          Returns a DataOutputStream for writing to the network variable value.
 byte[] getValue()
          Returns the current value.
 void notifyListeners(NetworkVariableEvent event)
          Notify all connected Listeners about an event.
 void poll()
          Polls the network variable.
 void propagate()
          Propagates the network variable.
 void setListener(NetworkVariableListener listener)
          Attaches a listener to this network variable.
 void setValue(byte[] value)
          Sets the value.
 

Method Detail

getDataOutputStream

DataOutputStream getDataOutputStream()

Returns a DataOutputStream for writing to the network variable value. The DataOutputStream can be used to write complex data structures to a network variable value. After the modification of the value it can be propagated by calling the propagate() method.

Example:

 DataOutputStream out = nv.getDataOutputStream();
 out.writeInt( 0x123456); // write a 4-byte integer value
 out.writeFloat( 1.2f);   // write a 4-byte floating point value
 nv.propagate();          // propagate value
 

Returns:
DataOutputStream
See Also:
getDataInputStream(), propagate()

getDataInputStream

DataInputStream getDataInputStream()

Returns a DataInputStream for reading from the network variable value. The DataInputStream can be used to read complex data structures from a network variable value.

Example:

 DataInputStream in = nv.getDataInputStream();
 int i = in.readInt();       // read a 4-byte integer value
 float f = in.readFloat();   // read a 4-byte floating point value
 

Returns:
DataInputStream
See Also:
getDataOutputStream()

getValue

byte[] getValue()
Returns the current value.

Returns:
value

poll

void poll()
          throws IOException
Polls the network variable.

Throws:
IOException - in case of I/O errors

propagate

void propagate()
               throws IOException
Propagates the network variable.

Throws:
IOException - in case of I/O errors

setValue

void setValue(byte[] value)
              throws IOException
Sets the value. If the variable is OUTGOING and possesses the "sync" modifier, the value is automatically propagated to the address.

Parameters:
value - new value
Throws:
IOException - in case of I/O errors

setListener

void setListener(NetworkVariableListener listener)
Attaches a listener to this network variable. The listener's networkVariableChanged() method will be invoked whenever the value of a network variable gets updated. As parameter it receives a NetworkVariableEvent.

Parameters:
listener - listener
See Also:
NetworkVariableEvent

notifyListeners

void notifyListeners(NetworkVariableEvent event)
Notify all connected Listeners about an event.

Parameters:
event - event to pass to listeners