CoCoME TestDriver for Reference Implementation

org.cocome.tradingsystem.testdriver
Class UpdateReceiver

java.lang.Object
  extended by org.cocome.tradingsystem.testdriver.UpdateReceiver
All Implemented Interfaces:
javax.jms.MessageListener, org.cocome.tradingsystem.systests.interfaces.IUpdateReceiver
Direct Known Subclasses:
CashBox, LightsDisplay, Printer, UserDisplay

public class UpdateReceiver
extends java.lang.Object
implements org.cocome.tradingsystem.systests.interfaces.IUpdateReceiver, javax.jms.MessageListener

This is the base for all classes implementing the IUpdateReceiver. The idea is to listen on a specified channel and keep only messages of certain types.

Version:
$Rev: 63 $
Author:
Benjamin Hummel, $Author: hummel $

Field Summary
private  boolean isNewMessage
          A flag indicating if this is a new message or if this has been read before.
private  java.io.Serializable lastRelevantMessage
          The last message (of those we are interested in) received.
private  java.lang.Class<?>[] relevantMessages
          The array of message types we are interested in.
 
Constructor Summary
UpdateReceiver(javax.jms.TopicSubscriber subscriber, java.lang.Class<?>... relevantMessageClasses)
          Creates a new update receiver.
 
Method Summary
protected  void expectMessage(java.lang.Class<? extends java.io.Serializable> messageType)
          Signals that the next expected message should be of the given type.
protected  java.io.Serializable getLastRelevantMessage()
          Returns the last relevant message received.
 void onMessage(javax.jms.Message message)
          
 void waitForUpdate(int maxMilliseconds)
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lastRelevantMessage

private java.io.Serializable lastRelevantMessage
The last message (of those we are interested in) received.


isNewMessage

private boolean isNewMessage
A flag indicating if this is a new message or if this has been read before.


relevantMessages

private final java.lang.Class<?>[] relevantMessages
The array of message types we are interested in.

Constructor Detail

UpdateReceiver

public UpdateReceiver(javax.jms.TopicSubscriber subscriber,
                      java.lang.Class<?>... relevantMessageClasses)
               throws javax.jms.JMSException
Creates a new update receiver.

Parameters:
subscriber - the subscriber to get the messages from.
relevantMessageClasses - the classes of messages we are interested in.
Throws:
javax.jms.JMSException
Method Detail

waitForUpdate

public void waitForUpdate(int maxMilliseconds)
                   throws java.util.concurrent.TimeoutException

Specified by:
waitForUpdate in interface org.cocome.tradingsystem.systests.interfaces.IUpdateReceiver
Throws:
java.util.concurrent.TimeoutException

expectMessage

protected void expectMessage(java.lang.Class<? extends java.io.Serializable> messageType)
Signals that the next expected message should be of the given type. This checks if such a message is available, and waits again for a short time to get the chance of receiving the missing message. This is mostly used to circumvent situations where two messages are sent at the (nearly) same time.

Parameters:
messageType - the type of the message expected.

getLastRelevantMessage

protected java.io.Serializable getLastRelevantMessage()
Returns the last relevant message received.


onMessage

public void onMessage(javax.jms.Message message)

Specified by:
onMessage in interface javax.jms.MessageListener

CoCoME TestDriver for Reference Implementation

CoCoME TestDriver for Reference Implementation - 0.1