public class Calculator extends Tester implements CallableClient
Modifier and Type | Class and Description |
---|---|
private class |
Calculator.CalcRequest
Represents a request which may be sent to a Calculator object.
|
static class |
Calculator.SendMode
Represents a delivery pattern.
|
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
ADD_MTYPE |
static Calculator.SendMode |
ASYNCH_MODE
Sends messages using the Synchronous Call/Response delivery pattern.
|
private java.util.Map |
callMap_ |
private HubConnection |
connection_ |
private static java.lang.String |
DIV_MTYPE |
private static java.lang.String |
iconUrl_ |
private static java.util.logging.Logger |
logger_ |
private static java.lang.String |
MUL_MTYPE |
private int |
nCalc_ |
private int |
nCall_ |
static Calculator.SendMode |
NOTIFY_MODE
Sends messages using the Notify delivery pattern.
|
private java.util.Random |
random_ |
static Calculator.SendMode |
RANDOM_MODE
Sends messages using a random choice of one of the other modes.
|
private static java.lang.String |
SUB_MTYPE |
static Calculator.SendMode |
SYNCH_MODE
Sends messages using the Asynchronous Call/Response delivery pattern.
|
Constructor and Description |
---|
Calculator(HubConnection connection,
java.util.Random random)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
private Calculator.CalcRequest |
createRandomRequest()
Generates a random calculation request.
|
void |
flush()
Waits until all the responses this client is expecting to get
have been safely received.
|
HubConnection |
getConnection()
Returns the hub connection used by this client.
|
private static java.lang.String |
getIconUrl() |
int |
getReceiveCount()
Returns the total number of messages received using any delivery pattern.
|
int |
getSendCount()
Returns the total number of messages sent using any delivery pattern.
|
private int |
nextCall()
Increments and then returns the number of calls so far made by this
object.
|
private java.util.Map |
processCall(java.lang.String senderId,
Message msg)
Does the work for both the receiveNotify and receiveCall methods.
|
void |
receiveCall(java.lang.String senderId,
java.lang.String msgId,
Message msg)
Receives a message for which a response is required.
|
void |
receiveNotification(java.lang.String senderId,
Message msg)
Receives a message for which no response is required.
|
void |
receiveResponse(java.lang.String senderId,
java.lang.String msgTag,
Response response)
Receives a response to a message previously sent by this client.
|
void |
sendMessage(java.lang.String receiverId,
Calculator.SendMode mode)
Sends a randomly generated message in a randomly generated way to
a given receiver.
|
assertEquals, assertEquals, assertTrue, fail
private final HubConnection connection_
private final java.util.Map callMap_
private final java.util.Random random_
private volatile int nCalc_
private volatile int nCall_
private static final java.lang.String ADD_MTYPE
private static final java.lang.String SUB_MTYPE
private static final java.lang.String MUL_MTYPE
private static final java.lang.String DIV_MTYPE
private static final java.util.logging.Logger logger_
private static java.lang.String iconUrl_
public static final Calculator.SendMode NOTIFY_MODE
public static final Calculator.SendMode ASYNCH_MODE
public static final Calculator.SendMode SYNCH_MODE
public static final Calculator.SendMode RANDOM_MODE
public Calculator(HubConnection connection, java.util.Random random) throws SampException
connection
- hub connectionrandom
- random number generatorSampException
public void sendMessage(java.lang.String receiverId, Calculator.SendMode mode) throws SampException
receiverId
- client ID of another Calculator client.SampException
public int getSendCount()
public int getReceiveCount()
public HubConnection getConnection()
public void flush()
public void receiveNotification(java.lang.String senderId, Message msg)
CallableClient
receiveNotification
in interface CallableClient
senderId
- public ID of sending clientmsg
- messagepublic void receiveCall(java.lang.String senderId, java.lang.String msgId, Message msg) throws SampException
CallableClient
reply
method at some future point.receiveCall
in interface CallableClient
senderId
- public ID of sending clientmsgId
- message identifier for later use with replymsg
- messageSampException
public void receiveResponse(java.lang.String senderId, java.lang.String msgTag, Response response)
CallableClient
receiveResponse
in interface CallableClient
senderId
- public ID of responding clientmsgTag
- client-defined tag labelling previously-sent messageresponse
- returned response objectprivate java.util.Map processCall(java.lang.String senderId, Message msg)
senderId
- sender public IDmsg
- message objectprivate int nextCall()
private Calculator.CalcRequest createRandomRequest()
private static java.lang.String getIconUrl()