Class TNCCallbackHandler

java.lang.Object
com.nt.udc.testnodechain.callbacks.TNCEventSender
com.nt.udc.testnodechain.callbacks.TNCCallbackHandler
All Implemented Interfaces:
TNCEventReceiverIfc, TNCEventSenderIfc, Serializable, Remote
Direct Known Subclasses:
AdminTNCCallbackHandler

public class TNCCallbackHandler extends TNCEventSender implements TNCEventReceiverIfc
The TNCCallbackHandler class extends TNCEventSender and implements TNCEventReceiverIfc. This class is responsible for both receiving events and sending them to registered receivers. It supports event buffering, where events are stored locally upon reception and sent to new subscribers upon subscribing for events, ensuring they receive events they might have missed otherwise.
See Also:
  • Constructor Details

    • TNCCallbackHandler

      public TNCCallbackHandler(Logger logger, boolean useBuffer)
  • Method Details

    • onNodeStatisticsChange

      public void onNodeStatisticsChange(List<NodeUpdateEvent> nodeData) throws RemoteException
      The onNodeStatisticsChange method is called when there is a change in node statistics. It receives a list of NodeUpdateEvent objects containing the updated node data.
      Specified by:
      onNodeStatisticsChange in interface TNCEventReceiverIfc
      Parameters:
      nodeData - A list of NodeUpdateEvent objects representing the updated node statistics.
      Throws:
      RemoteException - If there is a communication-related exception while propogating the update to registered receivers
    • onNodeStatusChange

      public void onNodeStatusChange(NodeStatusUpdateEventIfc nodeStatus) throws RemoteException
      The onNodeStatusChange method is called when there is a change in the status of a node. It receives a NodeStatusUpdateEventIfc object representing the updated node status.
      Specified by:
      onNodeStatusChange in interface TNCEventReceiverIfc
      Parameters:
      nodeStatus - A NodeStatusUpdateEventIfc object containing the updated node status information.
      Throws:
      RemoteException - If there is a communication-related exception while propogating the update to registered receivers
    • onBulkEvents

      public void onBulkEvents(List<BaseEventIfc> events) throws RemoteException
      This method is triggered when the receiver subscribes to a test for the first time, and the sender has event buffering implemented. The goal is to populate the events into the local buffer ( as a receiver ), with the actual distribution ( as as sender ) to the respective receivers being postponed and managed by the 'newTestSubscriberAdded()' method.
      Specified by:
      onBulkEvents in interface TNCEventReceiverIfc
      Parameters:
      events -
      Throws:
      RemoteException - If there is a communication-related exception while propogating the update to registered receivers
    • onTestStatusChange

      public void onTestStatusChange(TestStatusChangeEventIfc testStatus) throws RemoteException
      Notifies the receivers about changes in the status of a test.
      Specified by:
      onTestStatusChange in interface TNCEventReceiverIfc
      Parameters:
      testStatus - The event interface representing the change in test status.
      Throws:
      RemoteException - If a communication-related exception occurs during the remote method invocation.
    • onNodeOutputFileAvailable

      public void onNodeOutputFileAvailable(NodeOutputFileAvailableEvent nodeOutputFileAvailable) throws RemoteException
      Notifies the observer when a node's output file becomes available.
      Specified by:
      onNodeOutputFileAvailable in interface TNCEventReceiverIfc
      Parameters:
      nodeOutputFileAvailable - The event representing the availability of the node's output file.
      Throws:
      RemoteException - If a communication-related exception occurs during the remote method invocation.
    • onTestAboutToTimeout

      public void onTestAboutToTimeout(TestTimeoutReminderEvent event) throws RemoteException
      Handles the event when a test is about to timeout.
      Specified by:
      onTestAboutToTimeout in interface TNCEventReceiverIfc
      Parameters:
      event - The TestTimeoutReminderEvent containing information about the test about to timeout.
      Throws:
      RemoteException - If a remote exception occurs during the handling of node status changes.
    • segregateEvents

      public Map<String,List<BaseEventIfc>> segregateEvents(List<? extends BaseEventIfc> events)
      Segregates events based on the associated test ID into a Map. This method takes a list of events and segregates them into a Map, where each entry in the map represents a test ID, and the corresponding value is a List of events associated with that test ID.
      Parameters:
      events - A List of objects implementing the BaseEventIfc interface.
      Returns:
      A Map where keys represent test IDs, and values are Lists of events for the respective test IDs.
    • newTestSubscriberAdded

      protected void newTestSubscriberAdded(String recieverID, String testID)
      This method is called when a new test subscriber is added, providing information about the receiver ID and the associated test ID.
      Overrides:
      newTestSubscriberAdded in class TNCEventSender
      Parameters:
      recieverID - The identifier of the new test subscriber.
      testID - The unique identifier of the test associated with the new subscriber.
      receiverID - The identifier of the new test subscriber.
    • addEventToBuffer

      protected void addEventToBuffer(String testID, BaseEventIfc event)
      Adds a single event to the buffer associated with a specific test ID. This method is responsible for appending a single event to the buffer corresponding to the provided test ID.
      Parameters:
      testID - The unique identifier for the test to which the event will be added.
      event - A BaseEventIfc object representing the event to be added to the buffer.
    • addEventToBuffer

      protected void addEventToBuffer(String testID, List<BaseEventIfc> events)
      Adds events to the buffer associated with a specific test ID. This method is responsible for appending a list of events to the buffer corresponding to the provided test ID.
      Parameters:
      testID - The unique identifier for the test to which the events will be added.
      events - A List of BaseEventIfc objects representing the events to be added to the buffer.
    • bufferingEnabled

      public boolean bufferingEnabled()
      This method returns a boolean indicating whether event buffering is enabled for this callback handler.
      Returns:
      true if event buffering is enabled, false otherwise.
    • hasHistoricEvents

      public boolean hasHistoricEvents(String testId)
      Description copied from interface: TNCEventSenderIfc
      Checks whether there are historic events associated with the specified test ID.
      Specified by:
      hasHistoricEvents in interface TNCEventSenderIfc
      Overrides:
      hasHistoricEvents in class TNCEventSender
      Parameters:
      testId - The unique identifier of the test to check for historic events.
      Returns:
      true if there are historic events for the given test ID; false otherwise.
    • freeUpTestResources

      public void freeUpTestResources(String testId, boolean removeTestListeners)
      Description copied from interface: TNCEventSenderIfc
      Frees up resources associated with a test identified by the given test ID.
      Specified by:
      freeUpTestResources in interface TNCEventSenderIfc
      Overrides:
      freeUpTestResources in class TNCEventSender
      Parameters:
      testId - The unique identifier of the test whose resources should be freed up.
      removeTestListeners - A boolean flag indicating whether to remove test listeners associated with the test. If set to true, the test listeners will be removed; otherwise, they will be retained.
    • onFreeUpTestResources

      public void onFreeUpTestResources(String testId) throws RemoteException
      Description copied from interface: TNCEventReceiverIfc
      Will be called when the sender is cleaning up the resources allocated for this test.
      Specified by:
      onFreeUpTestResources in interface TNCEventReceiverIfc
      Parameters:
      testId - The identifier of the test being cleaned up.
      Throws:
      RemoteException - If there is a communication-related exception.
    • onRemoveTestListener

      public void onRemoveTestListener(String testId) throws RemoteException
      Description copied from interface: TNCEventReceiverIfc
      Will be called when the sender is removing this listener from test mapping.
      Specified by:
      onRemoveTestListener in interface TNCEventReceiverIfc
      Parameters:
      testId - The identifier of the test being cleaned up.
      Throws:
      RemoteException - If there is a communication-related exception.
    • onRemoveReceiver

      public void onRemoveReceiver(String receiverId) throws RemoteException
      Description copied from interface: TNCEventReceiverIfc
      Will be called when the sender is removing this listener enttirely
      Specified by:
      onRemoveReceiver in interface TNCEventReceiverIfc
      Throws:
      RemoteException - If there is a communication-related exception.