public final class Broadcast extends Object
Represents a collection of ServerResponse
s to be sent from the
server to one or more client(s) as the result of a user registration or
deregistration, or in response to a command received from some client. The
methods in ServerModel
which correspond to these activities each
return an instance of this class. As outlined in the protocol specification, each one of these activities
results in at least one response being sent to a client.
We will test each of the aforementioned ServerModel
methods by
checking whether the Broadcast
s they return exactly match the
reference Broadcast
constructed in the test case, except for tests
that expect an error code, for which the error messages may be different.
See ClientConnectionTest
for examples.
You should not edit this file.
ServerModel
,
ServerResponse
,
ClientConnectionTest
Constructor and Description |
---|
Broadcast()
Constructs an empty
Broadcast . |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o) |
int |
hashCode() |
void |
send(int userId,
ServerResponse response)
Adds a
ServerResponse to the list of responses to be
broadcast to the user with specified user ID. |
void |
sendAll(Broadcast other)
Appends all responses in
other to this broadcast, excluding any
duplicates sent to the same user ID in both broadcasts. |
void |
sendError(int userId,
String senderNick,
ServerErrorCode errorCode,
String errorMessage)
A convenience method which constructs an
ERROR response and
sends it to the user with specified user ID, exactly as if using send(int, ServerResponse) . |
String |
toString() |
public void send(int userId, ServerResponse response)
Adds a ServerResponse
to the list of responses to be
broadcast to the user with specified user ID. Note that the prefix
of the command may be different from
the ID of the user receiving the command: it is often necessary to relay
commands sent by one client to another one. This method will not cause a
duplicate response to be sent to the client; if the given response
is already being sent to userId
in this broadcast,
this method has no effect.
userId
- the ID of the user to send toresponse
- the response to sendpublic void sendError(int userId, String senderNick, ServerErrorCode errorCode, String errorMessage)
ERROR
response and
sends it to the user with specified user ID, exactly as if using send(int, ServerResponse)
.userId
- the ID of the user to send tosenderNick
- the user's nickerrorCode
- the error code to senderrorMessage
- the (optional) error message to includepublic void sendAll(Broadcast other)
other
to this broadcast, excluding any
duplicates sent to the same user ID in both broadcasts. In short, merges
the two broadcasts together.other
- the broadcast to merge