Jumpi v1.2.0

org.jumpi.impl.connector.dummy
Class DummyAsyncConnector

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

public class DummyAsyncConnector
extends AbstractConnector

The DummyAsyncConnector simulates asynchronous send and receive operations without actually performing the operations on the network layer. This can be helpful for testing purposes. Send and receive operations handled sequentially by a separate thread from the caller. The caller returns immediately on send or receive unless flow control kicks in. There is a configurable delay to simulate real network transmission times. This delay can be modified on a per operation basis with the respective operation's client properties.

The UrlSyntax supported is general:

<protocolname>://[*]


Field Summary
static java.lang.String PROPERTY_DELAY
          Property key for the operation delay.
static java.lang.String PROPERTY_FAIL
          Property key for failure simulation.
static java.lang.String PROPERTY_RECV_MESSAGE
          Property key for the message to receive.
static java.lang.String PROPERTY_RECV_SENDER
          Property key for the sender's Destination.
static java.lang.String RECV_MESSAGE_DEFAULT
          Default message to receive in the absence of a receive message property.
static java.lang.String RECV_SENDER_URL_DEFAULT
          Default Sender Url in the absence of a message sender property.
 
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
DummyAsyncConnector()
           
 
Method Summary
protected  boolean checkJoinCondition()
          Return true if the buffered receive and send queues are both empty.
 void configure(java.lang.String name, Properties props)
          Configure the DummyAsyncConnector.
 Destination getDestination(java.lang.String url, java.util.Hashtable clientProps)
           Any Urls are managed which have the configured protocol prefix.
protected  boolean onRecv(Envelope env)
           Simulate receiving a message asynchronously from a Destination, providing configurable receive delay and failure opportunity.
protected  boolean onSend(Envelope env)
           Simulate sending a message asynchronously to a Destination, providing configurable send delay and failure opportunity.
protected  void shutdownState()
          Clear the buffered send and receive queues.
 
Methods inherited from class org.jumpi.impl.AbstractConnector
cancelRecv, cancelSend, getName, getTaskId, isLongRunning, isSchedulable, manage, recv, run, send
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTY_RECV_MESSAGE

public static final java.lang.String PROPERTY_RECV_MESSAGE
Property key for the message to receive. Value: recvmessage.

See Also:
Constant Field Values

RECV_MESSAGE_DEFAULT

public static final java.lang.String RECV_MESSAGE_DEFAULT
Default message to receive in the absence of a receive message property.

See Also:
Constant Field Values

PROPERTY_RECV_SENDER

public static final java.lang.String PROPERTY_RECV_SENDER
Property key for the sender's Destination. Value: recvsender.

See Also:
Constant Field Values

RECV_SENDER_URL_DEFAULT

public static final java.lang.String RECV_SENDER_URL_DEFAULT
Default Sender Url in the absence of a message sender property.

See Also:
Constant Field Values

PROPERTY_FAIL

public static final java.lang.String PROPERTY_FAIL
Property key for failure simulation. Value: fail.

See Also:
Constant Field Values

PROPERTY_DELAY

public static final java.lang.String PROPERTY_DELAY
Property key for the operation delay. Value: delay.

See Also:
Constant Field Values
Constructor Detail

DummyAsyncConnector

public DummyAsyncConnector()
Method Detail

configure

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

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.

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.

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.

onSend

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

Simulate sending a message asynchronously to a Destination, providing configurable send delay and failure opportunity.

The message format required on entry is determined by the send transformer. Since messages are not actually sent, the Connector does not require any specific message format.

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.

If the PROPERTY_FAIL is present, the operation will fail after the delay.

If the PROPERTY_DELAY is present, it overrides the time delay in milliseconds that has been configured to simulate network operations for the operation.

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 PROPERTY_FAIL exists.

onRecv

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

Simulate receiving a message asynchronously from a Destination, providing configurable receive delay and failure opportunity. Since no actual message is received from the network layer, the client application can provide a message to return and a sender. In the absence of the client application specifying these values, defaults are provided.

The message format required on reception is determined by the receive transformer. Since messages are not actually received, the receive transformer must handle the default message type, which is a String, or the type passed as the received message in the client properties.

Allows multiple concurrent receive operations to the same Destination and different Destinations. The receives are however processes sequentially by the instance's task working off the buffered receive queue.

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

If the PROPERTY_FAIL is present, the operation will fail after the operation delay.

If the PROPERTY_DELAY is present, it overrides the time delay in milliseconds that has been configured to simulate network operations for the operation.

If the PROPERTY_RECV_MESSAGE is present, it will be used as the message received. If it is not present, then a default String message is received.

If the PROPERTY_RECV_SENDER is present, it will be used as the Url of the sender. If it is not present, then a default String Url is used as the Sender Url.

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 - if a failure condition occurs whilst receiving or PROPERTY_FAIL set.

checkJoinCondition

protected boolean checkJoinCondition()
Return true if the buffered receive and send queues are both empty.

Specified by:
checkJoinCondition in class AbstractConnector
Returns:
true if the buffered receive and send queues are both empty, else false.

shutdownState

protected void shutdownState()
Clear the buffered send and receive queues.

Specified by:
shutdownState in class AbstractConnector

Jumpi v1.2.0

Copyright © 2003, Peter Jonathan Klauser.