Jumpi v1.2.0

org.jumpi.impl.connector.udp
Class UdpConnector

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

public class UdpConnector
extends AbstractConnector
implements Task

The UdpConnector sends and receives packets over unicast UDP. A UdpTransceiver instance continuously receives packets from a local configured port. Receive operations define a Destination filter through which packets must match before being dispatched to the Controller layer. If packets are received where no receive Destination is defined, then the packet is simply discarded. Wildcard destinations are used to match any host, any port or the combination of both. Sending can take place to any UdpDestination.

<protocolname>://[<ipaddress>|*]:[<port>|*]


Field Summary
 
Fields inherited from class org.jumpi.impl.AbstractConnector
cancelledRecvs_, cancelledSends_, controller_, joinFailInterval_, joinTestInterval_, jumpi_, maxRecvBacklog_, maxSendBacklog_, name_, protocol_, recvQueue_, recvTransformer_, sendQueue_, sendTransformer_, started_, stopping_, taskId_, url_format_, url_prefix_
 
Constructor Summary
UdpConnector()
           
 
Method Summary
 void cancelRecv(Envelope env)
          Remove the receive Destination from the specific or wildcard receive filters, such receive matching cannot take place for the Destination.
protected  boolean checkJoinCondition()
          The clean shutdown condition is reached when there are no pending send operations and both wildcard and specific receive Destination filters are empty.
 void configure(java.lang.String name, Properties props)
          Configure the UdpConnector.
 Destination getDestination(java.lang.String url, java.util.Hashtable clientProps)
          Return a Destination corresponding to the Url if the Url matches the UdpDestination syntax.
 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 onReceive(java.net.DatagramPacket pack)
          Callback used by the UdpTransceiver to deliver received DatagramPackets to the UdpConnector.
protected  boolean onRecv(Envelope env)
          Does nothing since there is no synchronous receiving.
protected  boolean onSend(Envelope env)
           Send a message to a UdpDestination.
 void recv(Envelope env)
           Receive a message from a UdpDestination.
protected  void shutdownState()
          Clears the pending send operation queue and receive filters.
 
Methods inherited from class org.jumpi.impl.AbstractConnector
cancelSend, getName, getTaskId, isLongRunning, isSchedulable, run, send
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jumpi.spi.component.Task
getTaskId, isLongRunning, isSchedulable
 
Methods inherited from interface java.lang.Runnable
run
 

Constructor Detail

UdpConnector

public UdpConnector()
Method Detail

configure

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

The following configuration attributes are defined in addition to those of the superclass:

Specified by:
configure in interface Configurable
Overrides:
configure in class AbstractConnector
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.

checkJoinCondition

protected boolean checkJoinCondition()
The clean shutdown condition is reached when there are no pending send operations and both wildcard and specific receive Destination filters are empty.

Specified by:
checkJoinCondition in class AbstractConnector
Returns:
true if there are no pending sends or receives.

shutdownState

protected void shutdownState()
Clears the pending send operation queue and receive filters.

Specified by:
shutdownState in class AbstractConnector

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 operations are managed explicitly in addition to those of the instance abstract superclass.

Specified by:
manage in interface Manageable
Overrides:
manage in class AbstractConnector
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.

getDestination

public Destination getDestination(java.lang.String url,
                                  java.util.Hashtable clientProps)
Return a Destination corresponding to the Url if the Url matches the UdpDestination syntax. The empty Uri, i.e. <protocol>:// represents the UdpConnector's UdpTransceiver.

Specified by:
getDestination in interface Connector
Overrides:
getDestination in class AbstractConnector
Parameters:
url - specific or wildcard UdpDestination Url.
clientProps - not used.
Returns:
a Destination if the url matches the UdpDestination syntax, else null.
Throws:
java.lang.IllegalArgumentException - when url is null.

recv

public void recv(Envelope env)
          throws java.lang.Exception

Receive a message from a UdpDestination. The UdpDestination of the receive is placed in a UdpDestination filter. When the UdpTransceiver receives a DatagramPacket which matches the UdpDestination, this will be passed up as the response to the receive operation. For best performance, use specific UdpDestinations without wildcards, or few wildcard Destinations.

The format of the data provided by the UdpTransceiver is a byte[]. This is given directly as the received data to the Controller in absence of a receive transformer. If a receive transformer is configured, then this is given the byte[] and it gives the transformed message to the Controller layer.

Allows multiple concurrent receive operations to different Destinations but not the same Destination. There is no limit to the number of different Destinations which can simultaneously be received from.

Non blocking always.

Specified by:
recv in interface Connector
Overrides:
recv in class AbstractConnector
Parameters:
env - the Envelope containing the Destination to receive from.
Throws:
java.lang.Exception - if a failure condition occurs.
java.lang.IllegalArgumentException - if env is null.
java.lang.IllegalStateException - if not started or stopping.
See Also:
Controller.callbackRecv(org.jumpi.spi.Envelope, boolean, java.lang.String)

onRecv

protected boolean onRecv(Envelope env)
                  throws java.lang.Exception
Does nothing since there is no synchronous receiving.

Specified by:
onRecv in class AbstractConnector
Parameters:
env - not used.
Returns:
true if successful, otherwise false on a managed failure.
Throws:
java.lang.Exception - never.

cancelRecv

public void cancelRecv(Envelope env)
Remove the receive Destination from the specific or wildcard receive filters, such receive matching cannot take place for the Destination. It may happen that the UdpTransceiver has just matched a receive on the Destination for a different Envelope. In this case the operation is not cancelled. The operation never blocks.

Specified by:
cancelRecv in interface Connector
Overrides:
cancelRecv in class AbstractConnector
Parameters:
env - the operation to cancel.
Throws:
java.lang.IllegalArgumentException - when env is null.

onSend

protected boolean onSend(Envelope env)
                  throws java.lang.Exception

Send a message to a UdpDestination.

The message format required for sending via the UdpTransceiver is a byte[]. If a send transformer is configured then this must map the input data to a byte[], otherwise the byte[] must be supplied by the Controller. The UdpTransceiver does not modify the data for sending via Udp at all. The operation may fail or truncate data if the length of the data is greater than that which can be sent by the operating system.

Allows multiple concurrent send operations to any Destinations. The sends are processes sequentially by the instance's task working off the buffered send queue.

Non blocking until the buffered send queue has filled, at which time send flow control prohibits further sending until there is space in the queue.

Specified by:
onSend in class AbstractConnector
Parameters:
env - the Envelope containing the Destination to send to and the message.
Returns:
true if successful, otherwise false on a managed failure.
Throws:
java.lang.Exception - if a failure condition occurs.

onReceive

public void onReceive(java.net.DatagramPacket pack)
Callback used by the UdpTransceiver to deliver received DatagramPackets to the UdpConnector.

Parameters:
pack - a DatagramPacket received from the UdpTransceiver.
See Also:
UdpTransceiver.run()

Jumpi v1.2.0

Copyright 2003, Peter Jonathan Klauser.