Class AlarmSource

Object
com.tailf.ncs.alarmman.consumer.AlarmSource
All Implemented Interfaces:
AutoCloseable

public class AlarmSource extends Object implements AutoCloseable
This class establishes a listener queue for emitted alarms. It requires the AlarmSourceCentral to be started, which will submit the alarms to the queue
  • Constructor Summary

    Constructors
    Constructor
    Description
    Use the AlarmSourceCentral from the thread local NcsMain object.
    Use a specific AlarmSourceCentral.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes this alarm source by stopping the listening process.
    boolean
    Checks if this alarm source is currently listening for alarms.
    pollAlarm(int time, TimeUnit unit)
    Retrieves an alarm, waiting if necessary until one becomes available within the specified timeout period.
    void
    Starts listening for alarms by initializing the queue if not already active.
    void
    Stops listening for alarms
    Retrieves or waiting if necessary until an Alarm becomes available.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AlarmSource

      public AlarmSource()
      Use the AlarmSourceCentral from the thread local NcsMain object.
    • AlarmSource

      public AlarmSource(AlarmSourceCentral sourceCentral)
      Use a specific AlarmSourceCentral.
      Parameters:
      sourceCentral - the alarm source central
  • Method Details

    • takeAlarm

      public Alarm takeAlarm() throws InterruptedException

      Retrieves or waiting if necessary until an Alarm becomes available.

      Blocks the current thread indefinitely until the operation can succeed.

      Returns:
      Alarm the next available alarm
      Throws:
      InterruptedException - if interrupted while waiting
    • pollAlarm

      public Alarm pollAlarm(int time, TimeUnit unit) throws InterruptedException
      Retrieves an alarm, waiting if necessary until one becomes available within the specified timeout period.
      Parameters:
      time - the maximum time to wait
      unit - the time unit of the timeout parameter
      Returns:
      an alarm, or null if the timeout elapsed or not listening
      Throws:
      InterruptedException - if interrupted while waiting
    • startListening

      public void startListening()
      Starts listening for alarms by initializing the queue if not already active.
    • stopListening

      public void stopListening()
      Stops listening for alarms
    • isListening

      public boolean isListening()
      Checks if this alarm source is currently listening for alarms.
      Returns:
      true if listening, false otherwise
    • close

      public void close()
      Closes this alarm source by stopping the listening process.
      Specified by:
      close in interface AutoCloseable