Class SubscribeHandler

All Implemented Interfaces:
Runnable

public class SubscribeHandler extends BaseHandler
SubscribeHandler - A handler for processing incoming subscription messages using JeroMQ.

This class handles the reception of messages on a ZeroMQ socket, processes them, and stores the updates in a circular buffer. It also manages a separate consumer thread that handles the subscription consumers and invokes their functions for each new update. The handler supports both UPDATE and PUBLISH message categories.

Author: Kobe Lei Version: 1.0 Package: org.kobe.xbot.JClient

This is part of the XTABLES project and facilitates subscribing and handling incoming messages from the server.

  • Constructor Details

    • SubscribeHandler

      public SubscribeHandler(org.zeromq.ZMQ.Socket socket, XTablesClient instance)
      Constructor that initializes the handler with the provided socket and server instance.
      Parameters:
      socket - The ZeroMQ socket to receive messages on
      instance - The XTablesClient instance
  • Method Details

    • requestSubscribe

      public boolean requestSubscribe(byte[] topic)
      Requests a new subscription to a topic.
      Parameters:
      topic - The topic to subscribe to.
    • requestUnsubscription

      public boolean requestUnsubscription(byte[] topic)
      Requests unsubscription from a topic.
      Parameters:
      topic - The topic to unsubscribe from.
    • run

      public void run()
      The main method for handling incoming messages.

      It continuously receives messages from the JeroMQ socket, processes them by parsing the message into a protocol buffer, and stores the updates in the buffer. It also increments the count of subscription messages received.

      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • interrupt

      public void interrupt()
      Logs exceptions and handles cleanup when the thread is interrupted.

      This method interrupts the consumer handling thread and calls the parent class's interrupt method to clean up.

      Overrides:
      interrupt in class BaseHandler