Class Channel

java.lang.Object
nl.andrewl.concord_server.channel.Channel
All Implemented Interfaces:
Comparable<Channel>

public class Channel extends Object implements Comparable<Channel>
Represents a single communication area in which messages are sent by clients and received by all connected clients. A channel is a top-level communication medium, and usually this is a server channel or private message between two clients in a server.
  • Field Details

    • server

      private final ConcordServer server
    • id

      private final UUID id
    • name

      private String name
    • connectedClients

      private final Set<ClientThread> connectedClients
      The set of clients that are connected to this channel.
    • messageCollection

      private final org.dizitart.no2.NitriteCollection messageCollection
      A document collection which holds all messages created in this channel, indexed on id, timestamp, message, and sender's username.
  • Constructor Details

  • Method Details

    • addClient

      public void addClient(ClientThread clientThread)
      Adds a client to this channel.
      Parameters:
      clientThread - The client to add.
    • removeClient

      public void removeClient(ClientThread clientThread)
      Removes a client from this channel.
      Parameters:
      clientThread - The client to remove.
    • sendMessage

      public void sendMessage(nl.andrewl.concord_core.msg.Message msg) throws IOException
      Sends a message to all clients that are currently connected to this channel. Makes use of the server's serializer to preemptively serialize the data once, so that clients need only write a byte array to their respective output streams.
      Parameters:
      msg - The message to send.
      Throws:
      IOException - If an error occurs.
    • getUserData

      public List<nl.andrewl.concord_core.msg.types.UserData> getUserData()
      Gets a list of information about each user in this channel.
      Returns:
      A list of UserData objects.
    • getAsTag

      public String getAsTag()
    • 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
    • compareTo

      public int compareTo(Channel o)
      Specified by:
      compareTo in interface Comparable<Channel>