Package org.astrogrid.samp.test

# Class Calculator

java.lang.Object
org.astrogrid.samp.test.Tester
org.astrogrid.samp.test.Calculator

All Implemented Interfaces:
  `CallableClient`

public class Calculator extends Tester implements CallableClient
Test client. Performs simple integer arithmetic.

Since:
  21 Jul 2008
Author:
  Mark Taylor

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static class`
`Calculator.SendMode`
Represents a delivery pattern.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final Calculator.SendMode`
`ASYNCH_MODE`
Sends messages using the Synchronous Call/Response delivery pattern.
`static final Calculator.SendMode`
`NOTIFY_MODE`
Sends messages using the Notify delivery pattern.
`static final Calculator.SendMode`
`RANDOM_MODE`
Sends messages using a random choice of one of the other modes.
`static final Calculator.SendMode`
`SYNCH_MODE`
Sends messages using the Asynchronous Call/Response delivery pattern.

## Constructor Summary

Constructors
Constructor
Description
`Calculator(HubConnection connection, Random random)`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`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.
`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.
`void`
`receiveCall(String senderId, String msgId, Message msg)`
Receives a message for which a response is required.
`void`
`receiveNotification(String senderId, Message msg)`
Receives a message for which no response is required.
`void`
`receiveResponse(String senderId, String msgTag, Response response)`
Receives a response to a message previously sent by this client.
`void`
`sendMessage(String receiverId, Calculator.SendMode mode)`
Sends a randomly generated message in a randomly generated way to a given receiver.

### Methods inherited from class org.astrogrid.samp.test.Tester

`assertEquals, assertEquals, assertTrue, fail`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### NOTIFY_MODE

public static final Calculator.SendMode NOTIFY_MODE
Sends messages using the Notify delivery pattern.

### ASYNCH_MODE

public static final Calculator.SendMode ASYNCH_MODE
Sends messages using the Synchronous Call/Response delivery pattern.

### SYNCH_MODE

public static final Calculator.SendMode SYNCH_MODE
Sends messages using the Asynchronous Call/Response delivery pattern.

### RANDOM_MODE

public static final Calculator.SendMode RANDOM_MODE
Sends messages using a random choice of one of the other modes.

## Constructor Details

### Calculator

public Calculator(HubConnection connection, Random random) throws SampException
Constructor.

Parameters:
  `connection` - hub connection
  `random` - random number generator
Throws:
  `SampException`

## Method Details

### sendMessage

public void sendMessage(String receiverId, Calculator.SendMode mode) throws SampException
Sends a randomly generated message in a randomly generated way to a given receiver. The receiver should be another calculator client, like this one. If the message is sent according to one of the call/response delivery patterns the response will be checked to ensure that it has the correct value.

Parameters:
  `receiverId` - client ID of another Calculator client.
Throws:
  `SampException`

### getSendCount

public int getSendCount()
Returns the total number of messages sent using any delivery pattern.

Returns:
  number of sends

### getReceiveCount

public int getReceiveCount()
Returns the total number of messages received using any delivery pattern.

Returns:
  number of receives

### getConnection

public HubConnection getConnection()
Returns the hub connection used by this client.

Returns:
  connection

### flush

public void flush()
Waits until all the responses this client is expecting to get have been safely received.

### receiveNotification

public void receiveNotification(String senderId, Message msg)
Description copied from interface: `CallableClient`
Receives a message for which no response is required.

Specified by:
  `receiveNotification` in interface `CallableClient`
Parameters:
  `senderId` - public ID of sending client
  `msg` - message

### receiveCall

public void receiveCall(String senderId, String msgId, Message msg) throws SampException
Description copied from interface: `CallableClient`
Receives a message for which a response is required. The implementation must take care to call the hub's `reply` method at some future point.

Specified by:
  `receiveCall` in interface `CallableClient`
Parameters:
  `senderId` - public ID of sending client
  `msgId` - message identifier for later use with reply
  `msg` - message
Throws:
  `SampException`

### receiveResponse

public void receiveResponse(String senderId, String msgTag, Response response)
Description copied from interface: `CallableClient`
Receives a response to a message previously sent by this client.

Specified by:
  `receiveResponse` in interface `CallableClient`
Parameters:
  `senderId` - public ID of responding client
  `msgTag` - client-defined tag labelling previously-sent message
  `response` - returned response object