Class ManagerBase

java.lang.Object
com.github.eventmanager.internal.ManagerBase
Direct Known Subclasses:
EventManager, InternalEventManager

public abstract class ManagerBase extends Object
Abstract base class providing foundational functionality for event management, including event queuing, processing, and logging.
  • Field Details

    • logHandler

      protected LogHandler logHandler
      Handles log file writing and log configuration.
    • processorHelper

      protected ProcessorHelper processorHelper
      Processes and enriches log events.
    • outputHelper

      protected OutputHelper outputHelper
      Helper class for output operations.
    • eventQueue

      protected final BlockingQueue<String> eventQueue
      Queue that holds events ready to be written to the log file.
    • processingQueue

      protected final BlockingQueue<String> processingQueue
      Queue that holds events pending processing by processors.
  • Constructor Details

    • ManagerBase

      public ManagerBase(LogHandler logHandler)
      Initializes ManagerBase with a provided LogHandler instance.
      Parameters:
      logHandler - The LogHandler responsible for managing logging operations.
    • ManagerBase

      public ManagerBase(String configPath)
      Initializes ManagerBase using a configuration file path.
      Parameters:
      configPath - Path to the logging configuration file.
  • Method Details

    • initiateThreads

      protected void initiateThreads()
      Starts event processing and logging threads.
    • initiateThreads

      protected void initiateThreads(InternalEventManager internalEventManager)
      Starts event processing and logging threads.
    • stopAllThreads

      protected void stopAllThreads(InternalEventManager internalEventManager)
      Stops all threads gracefully and processes remaining events, using InternalEventManager for structured logging of shutdown status.
      Parameters:
      internalEventManager - The event manager used for logging shutdown information.
    • stopAllThreads

      protected void stopAllThreads()
      Stops all threads gracefully without structured logging. Logs status information directly to the standard output.
    • logMessage

      protected void logMessage(String level, Object message)
      Formats and queues a log message for processing and eventual writing to log file.
      Parameters:
      level - Log level (e.g., INFO, ERROR).
      message - Message content to log, which can be an Exception or String.
    • logMessage

      protected void logMessage(String level, KeyValueWrapper... messages)
      Logs a message to the destination file.
      Parameters:
      level - the log level of the message.
      messages - an object array to be appended to the message.
    • writeEventToQueue

      protected void writeEventToQueue(String event)
      Adds processed event to the event queue.
      Parameters:
      event - The event string after processing.
    • writeEventToProcessingQueue

      protected void writeEventToProcessingQueue(String event)
      Adds raw event to the processing queue.
      Parameters:
      event - The event string before processing.
    • outputEvent

      protected void outputEvent(String event)
      Passes the event to the output or outputs specified in the runtime or config specification.
    • outputEvent

      protected void outputEvent(InternalEventManager internalEventManager, String event)
      Passes the event to the output or outputs specified in the runtime or config specification.
    • addOutput

      public boolean addOutput(OutputEntry output)
      Adds a new output destination.
      Parameters:
      output - The output entry to add.
      Returns:
      true if the output was added successfully, false otherwise.
    • removeOutput

      public boolean removeOutput(OutputEntry outputEntry)
      Removes an output destination.
      Parameters:
      outputEntry - The output entry to remove.
      Returns:
      true if the output was removed successfully, false otherwise.
    • removeOutput

      public boolean removeOutput(String outputName)
      Removes an output destination by class name.
      Parameters:
      outputName - The class name of the output to remove.
      Returns:
      true if the output was removed successfully, false otherwise.
    • addProcessor

      public boolean addProcessor(ProcessorEntry processorName)
      Adds a new processor to the list of processors.
      Parameters:
      processorName - The processor entry to add.
      Returns:
      true if the processor was added successfully, false otherwise.
    • removeProcessor

      public boolean removeProcessor(String processorName)
      Removes a processor from the list of processors.
      Parameters:
      processorName - The class name of the processor to remove.
      Returns:
      true if the processor was removed successfully, false otherwise.
    • removeProcessor

      protected boolean removeProcessor(ProcessorEntry processorEntry)
      Removes a processor from the list of processors.
      Parameters:
      processorEntry - The processor entry to remove.
      Returns:
      true if the processor was removed successfully, false otherwise.
    • castExceptionStackTraceToString

      protected static String castExceptionStackTraceToString(Exception e)