Jumpi v1.2.0

org.jumpi.impl.connector.loopback
Class LoopbackConnector

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

public class LoopbackConnector
extends AbstractConnector
implements Task

The LoopbackConnector simulates a loopback network adapter where sends are passed straight back to receives without actually performing the operations on the network layer. This can be helpful for testing purposes. There is a configurable send delay for simulating network delays.


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
LoopbackConnector()
           
 
Method Summary
 void cancelRecv(Envelope env)
           Cancel a receive operation which is registered by removing it from the registered operations table.
protected  boolean checkJoinCondition()
          Return true if the buffered send queue is empty and there are no registered receive filters.
 void configure(java.lang.String name, Properties props)
          Configure the LoopbackConnector.
 Destination getDestination(java.lang.String url, java.util.Hashtable clientProps)
           Any Urls are managed which have the configured protocol prefix.
 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.
protected  boolean onRecv(Envelope env)
          Synchronous receive is not used.
protected  boolean onSend(Envelope env)
           Send a message asynchronously to a receiver on the Destination, providing configurable send delay.
 void recv(Envelope env)
           Receive a message asynchronously from a Destination.
protected  void shutdownState()
          Clear the buffered send queue and registered receives.
 
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

LoopbackConnector

public LoopbackConnector()
Method Detail

configure

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

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.

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)

Any Urls are managed which have the configured protocol prefix. The syntax of supported Urls is defined as:

<protocol>://<uri> where <protocol> is the configured protocol and <uri> is any string. The <uri> value * represents a wildcard, matching any other <uri;>

Specified by:
getDestination in interface Connector
Overrides:
getDestination in class AbstractConnector
Parameters:
url - the Destination Url.
clientProps - not used.
Returns:
a Destination if the Url prefix matches the configured protocol.
Throws:
java.lang.IllegalArgumentException - when url is null.

recv

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

Receive a message asynchronously from a Destination. The receive operations are registered in two tables. One table for specific Destinations, and the other for the wildcard Destination. A send operation matching a registered receive will be passed back to the receiver. A send operation matching no receive operation will fail.

The message format required on reception is determined by the receive transformer.

Allows concurrent receive operations to different Destinations, yet only a single receive operation to each Destination.

Non blocking always.

All manipulations of the receive filters are synchronized.

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 - when env is null.
java.lang.IllegalStateException - when 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
Synchronous receive is not used.

Specified by:
onRecv in class AbstractConnector
Parameters:
env - the Envelope containing the Destination to receive from.
Returns:
true if successful, otherwise false on a managed failure.
Throws:
java.lang.Exception - never.

cancelRecv

public void cancelRecv(Envelope env)

Cancel a receive operation which is registered by removing it from the registered operations table.

All manipulations of the receive filters are synchronized.

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

onSend

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

Send a message asynchronously to a receiver on the Destination, providing configurable send delay. If no receiver is registered on the Destination at the time of sending, then the send will fail. The message is not sent over any network. Illegal to send to the wildcard Destination, since this is not a real Destination.

The message format required on entry is determined by the send transformer. The transformed message is passed unchanged by value to the receiver.

Allows multiple concurrent send operations to the same Destination and different Destinations. The sends are however 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, or no receiver is registered.

checkJoinCondition

protected boolean checkJoinCondition()
Return true if the buffered send queue is empty and there are no registered receive filters.

Specified by:
checkJoinCondition in class AbstractConnector
Returns:
true if the buffered send queue is empty and there are no registered receive filters.

shutdownState

protected void shutdownState()
Clear the buffered send queue and registered receives.

Specified by:
shutdownState in class AbstractConnector

Jumpi v1.2.0

Copyright © 2003, Peter Jonathan Klauser.