Jumpi v1.2.0

org.jumpi.impl.connector.udp
Class UdpTransceiver

java.lang.Object
  |
  +--org.jumpi.impl.connector.udp.UdpTransceiver
All Implemented Interfaces:
Component, Configurable, Manageable, java.lang.Runnable, Task

public class UdpTransceiver
extends java.lang.Object
implements Task, Component

A connectionless UdpTransceiver establishes a DatagramSocket on a configured port and continuously reads packets from that port. Read packets are delivered to the UdpConnector via the callback onReceive().

A send is provided which sends from the DatagramSocket to any Udp address.


Constructor Summary
UdpTransceiver()
          Creates a new UdpTransceiver.
 
Method Summary
 void configure(java.lang.String name, Properties props)
          Configure the UdpTransceiver.
 java.net.InetAddress getInetAddress()
          Return the InetAddress.
 java.lang.String getName()
          Get the fully qualified name of the instance.
 int getPort()
          Return the port.
 java.lang.String getTaskId()
          A unique name for the task in the VM.
 boolean isLongRunning()
          Returns true since the Udp reading thread may block for at most readtimeout - which should be relatively long in terms of thread processing time.
 boolean isSchedulable()
          The instance is schedulable as long as the component is not shutdown.
 void manage(Component root, Component parent, java.lang.String operation, java.util.Hashtable parameters)
          Perform a recursive management operation through the Jumpi component tree, using the parameters provided.
 void run()
          The UdpTransceiver task continuously reads packets from the DatagramSocket and delivers to the UdpConnector's onReceive method.
 void send(java.net.DatagramPacket pack)
          Send a DatagramPacket via the DatagramSocket.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UdpTransceiver

public UdpTransceiver()
Creates a new UdpTransceiver.

Method Detail

configure

public void configure(java.lang.String name,
                      Properties props)
               throws java.lang.Exception
Configure the UdpTransceiver.

The following configuration attributes are defined:

Specified by:
configure in interface Configurable
Parameters:
name - the fully qualified instance name.
props - the read-only properties to configure the instance with.
Throws:
java.lang.Exception - when configuration is unsuccessful.
java.lang.IllegalArgumentException - if name or properties are missing.

manage

public void manage(Component root,
                   Component parent,
                   java.lang.String operation,
                   java.util.Hashtable parameters)
            throws java.lang.Exception
Perform a recursive management operation through the Jumpi component tree, using the parameters provided.

The following management actions are handled:

Specified by:
manage in interface Manageable
Parameters:
root - the Jumpi instance at the root of the component tree.
parent - the immediate parent of the component.
operation - the operation.
parameters - the operation parameters.
Throws:
java.lang.Exception - if any failure to perform management occurs.
java.lang.IllegalArgumentException - when parameters are missing.

getName

public java.lang.String getName()
Get the fully qualified name of the instance. Identical to the name used in configure.

Specified by:
getName in interface Configurable
Returns:
the fully qualified name of the instance.
See Also:
configure(java.lang.String, org.jumpi.spi.Properties)

getTaskId

public java.lang.String getTaskId()
A unique name for the task in the VM.

Specified by:
getTaskId in interface Task
Returns:
a unique name for the task in the VM.

isSchedulable

public boolean isSchedulable()
The instance is schedulable as long as the component is not shutdown.

Specified by:
isSchedulable in interface Task
Returns:
true as long as the component is not shutdown.

isLongRunning

public boolean isLongRunning()
Returns true since the Udp reading thread may block for at most readtimeout - which should be relatively long in terms of thread processing time.

Specified by:
isLongRunning in interface Task
Returns:
true always.

run

public void run()
The UdpTransceiver task continuously reads packets from the DatagramSocket and delivers to the UdpConnector's onReceive method. A component shutdown can take place while the Task's thread is blocked in the DatagramSocket's read call. The Task thread will timeout in the read and then not be scheduled again to read if the shutdown has taken place. Otherwise the Task thread is rescheduled and reads again. Therefore the readtimeout should not be chosen to be too small.

Specified by:
run in interface java.lang.Runnable
See Also:
UdpConnector.onReceive(java.net.DatagramPacket)

send

public void send(java.net.DatagramPacket pack)
          throws java.lang.Exception
Send a DatagramPacket via the DatagramSocket.

Parameters:
pack - the DatagramPacket containing the data to send.
Throws:
java.lang.Exception - if any failure condition occurs during send.

getPort

public int getPort()
Return the port.

Returns:
the port.

getInetAddress

public java.net.InetAddress getInetAddress()
Return the InetAddress.

Returns:
the InetAddress.

Jumpi v1.2.0

Copyright © 2003, Peter Jonathan Klauser.