Class BaseListener

java.lang.Object
java.lang.Thread
com.example.common.listener.BaseListener
All Implemented Interfaces:
Listener, Runnable
Direct Known Subclasses:
BaseClientListener, BaseServerListener

public abstract class BaseListener extends Thread implements Listener
BaseListener class implements a basic listener functionality for receiving and sending messages. It extends Thread class and implements the Listener interface.
  • Field Details

  • Constructor Details

    • BaseListener

      public BaseListener(int portIn, StreamIO streamIO, TransportFactory transportFactory)
      Constructor for BaseListener class.
      Parameters:
      portIn - the input port number to listen for incoming connections
      streamIO - the StreamIO object for handling input and output streams
      transportFactory - the TransportFactory object for creating a listener
  • Method Details

    • run

      public void run()
      Continuously waits for incoming messages and processes them using the worker method.
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • worker

      protected abstract void worker() throws IOException
      Abstract method that must be implemented by subclasses to define the processing of incoming messages.
      Throws:
      IOException - if an error occurs while receiving or processing the message