Package it.fi.meucci

Class RequestListener

java.lang.Object
it.fi.meucci.RequestListener
All Implemented Interfaces:
Runnable

public class RequestListener extends Object implements Runnable
The class used to read from the socket's input stream. It handles received messages with proper Handler methods.
  • Field Details

    • allowedToRun

      public boolean allowedToRun
      Says whether this instance of Request Listener is allowed to run
  • Constructor Details

  • Method Details

    • changeName

      public void changeName(String usr) throws IOException
      Changes name if available
      Parameters:
      usr - the new username
      Throws:
      IOException - when it's unable to send errors to the socket's output stream
    • run

      public void run()
      Thread.run() implementation. Starts the communication with a List message and a Need Name Message Catches a bunch of exceptions
      Specified by:
      run in interface Runnable
    • handle

      public void handle(Message msg) throws IOException
      Handles the received message
      Parameters:
      msg - The message to be handled
      Throws:
      IOException - when it's impossible to write to the socket's output stream
    • sendList

      public void sendList() throws com.fasterxml.jackson.core.JsonProcessingException, IOException
      Sends to the client a list of connected users
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - When parsing fails
      IOException - When writing to the socket's output stream fails
    • write

      public void write(Message msg)
      Sends the message to the output stream
      Parameters:
      msg - The message to be sent
    • read

      public Message read() throws IOException
      Reads from the socket's input stream
      Returns:
      The just read message
      Throws:
      IOException - When it's impossible to read from the socket's input stream
    • getUsername

      public String getUsername()
      Returns:
      the client's username
    • toString

      public String toString()
      Overrides:
      toString in class Object