Class Broadcast

java.lang.Object
Broadcast

public final class Broadcast
extends Object
A Broadcast stores a mapping from users to a list of responses. The server backend uses a broadcast to send messages to clients to inform them of relevant events in their channels. For instance, many chat services inform you when someone has been removed from a chat that you're in. You do not need to modify this file.
  • Method Details

    • okay

      public static Broadcast okay​(Command command, Collection<String> recipients)
      Creates a Broadcast for the general case where a client's Command is accepted by the server and should be relayed to the appropriate clients.
      Parameters:
      command - The Command whose effects to broadcast
      recipients - The set of user names of clients who should receive the broadcast from the server
      Returns:
      A Broadcast representing a set of responses to send
    • error

      public static Broadcast error​(Command command, ServerError error)
      Creates a Broadcast for the case where a client's Command is invalid, and the client should be informed.
      Parameters:
      command - The command which caused the error
      error - The ServerError that the command caused
      Returns:
      A Broadcast representing the response to send
      Throws:
      IllegalArgumentException - if error value is OKAY
    • connected

      public static Broadcast connected​(String recipient)
      Creates a Broadcast for the case when a user first connects to the server and should be informed of their new nickname
      Parameters:
      recipient - The automatically generated nickname for the client
      Returns:
      A Broadcast to the new client
    • disconnected

      public static Broadcast disconnected​(String user, Collection<String> recipients)
      Creates a Broadcast for the case when a user disconnects from the server and other clients should be informed of this fact.
      Parameters:
      user - The nickname of the disconnected user
      recipients - A set of nicknames of clients who should be informed of the user's disconnection. Should not include the user who disconnected.
      Returns:
      A Broadcast representing the response to send
    • names

      public static Broadcast names​(Command command, Collection<String> recipients, String owner)
      A specialized method for creating a Broadcast in the event that a user is added to a channel as the result of a JoinCommand or InviteCommand. The resulting Broadcast informs the relevant client of the nicknames of all other users in the channel.
      Parameters:
      command - The command issued by the client (Invite or Join)
      recipients - A set of nicknames of the other users in the channel which the user is joining, and to whom the command should be relayed.
      owner - The nickname of the channel's owner
      Returns:
      A Broadcast representing the responses to send
      Throws:
      IllegalArgumentException - if command is not an instanceof JoinCommand or InviteCommand
    • getResponses

      public Map<Integer,​List<String>> getResponses​(ServerModelApi model)
      You should not call this method yourself. Associates the stored responses with the user IDs of the recipients. This * function will be called by the ServerBackend before dispatching the Broadcast.
      Parameters:
      model - A class conforming to ServerModelApi which can be used to look up user IDs.
      Returns:
      a mapping from user ID to a list of response strings that should be delivered by the ServerBackend
    • equals

      public boolean equals​(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object