Class InitDelayingTopologyEventListener

  • All Implemented Interfaces:
    TopologyEventListener

    public class InitDelayingTopologyEventListener
    extends java.lang.Object
    implements TopologyEventListener
    This listener facade applies a 'startup delay' to a topology event handler, that is, it allows to specify a startup time during which any topology events will be queued and processing only starts after this time.

    What happens aFter the startup time depends on what was received during the delay:

    • if no events were received then this is a no-op
    • if the last event received was a CHANGING then this facade waits until it receives the next non-CHANGING event (which should be the very next), to then simulate an INIT event (as the discovery API says the first event received is an INIT event).
    • if the last event received was not a CHANGING event (ie it was an INIT, CHANGED or PROPERTIES), then as soon as the startup time passes this facade will simulate an INIT event (again, as the discovery API says the first event received is an INIT event)
    Note that users of this facade must call dispose to avoid any async calls to the delegate after startup, in case they themselves are deactivated!
    Since:
    1.1.0
    • Constructor Detail

      • InitDelayingTopologyEventListener

        public InitDelayingTopologyEventListener​(long startupDelay,
                                                 TopologyEventListener delegate)
        Creates a new init-delaying listener with the given delay, delegate and scheduler.

        For properly disposing the caller should use the dispose method!

        Parameters:
        startupDelay - The startup delay in seconds
        delegate - The topology event listener
        See Also:
        dispose()
      • InitDelayingTopologyEventListener

        public InitDelayingTopologyEventListener​(long startupDelay,
                                                 TopologyEventListener delegate,
                                                 Logger loggerOrNull)
        Creates a new init-delaying listener with the given delay, delegate, scheduler and optinoal logger.

        For properly disposing the caller should use the dispose method!

        Parameters:
        startupDelay - The startup delay in seconds
        delegate - The topology event listener
        loggerOrNull - Optional logger instance
        See Also:
        dispose()
      • InitDelayingTopologyEventListener

        @Deprecated
        public InitDelayingTopologyEventListener​(long startupDelay,
                                                 TopologyEventListener delegate,
                                                 Scheduler scheduler)
        Creates a new init-delaying listener with the given delay, delegate and scheduler.

        For properly disposing the caller should use the dispose method!

        Parameters:
        startupDelay - The startup delay in seconds
        delegate - The topology event listener
        scheduler - Scheduler to schedule the delay (not used)
        See Also:
        dispose()
      • InitDelayingTopologyEventListener

        @Deprecated
        public InitDelayingTopologyEventListener​(long startupDelay,
                                                 TopologyEventListener delegate,
                                                 Scheduler scheduler,
                                                 Logger loggerOrNull)
        Creates a new init-delaying listener with the given delay, delegate, scheduler and optinoal logger.

        For properly disposing the caller should use the dispose method!

        Parameters:
        startupDelay - The startup delay in seconds
        delegate - The topology event listener
        scheduler - Scheduler to schedule the delay (not used)
        loggerOrNull - Optional logger instance
        See Also:
        dispose()
    • Method Detail

      • handleTopologyEvent

        public void handleTopologyEvent​(TopologyEvent event)
        Description copied from interface: TopologyEventListener
        Inform the service about an event in the topology - or in the discovery of the topology.

        Implementors of this method must ensure that this method returns quickly and that no locks are being acquired that could cause deadlocks (ie the framework might call this method holding locks).

        The TopologyEvent contains details about what changed. The supported event types are:

        • TOPOLOGY_INIT sent when the TopologyEventListener was first bound to the discovery service - represents the initial state of the topology at that time.
        • TOPOLOGY_CHANGING sent when the discovery service discovered a change in the topology and has started to settle the change. This event is sent before TOPOLOGY_CHANGED but is optional
        • TOPOLOGY_CHANGED sent when the discovery service discovered a change in the topology and has settled it.
        • PROPERTIES_CHANGED sent when the one or many properties have changed in an instance in the current topology
        A note on instance restarts: it is currently not a requirement on the discovery service to send a TopologyEvent should an instance restart occur rapidly (ie within the change detection timeout). A TopologyEvent is only sent if the number of instances or any property changes. Should there be a requirement to detect a restart in a guaranteed fashion, it is always possible to set a particular property (using the PropertyProvider) to the instance start time and have others detect a change in that property.
        Specified by:
        handleTopologyEvent in interface TopologyEventListener
        Parameters:
        event - The topology event
      • dispose

        public void dispose()
        Marks this listener as no longer active - ensures that it doesn't call the delegate via any potentially pending scheduler callback.

        Note that after dispose you can *still* call handleTopologyEvent and the events are passed to the delegate - but those are expected to be 'late' events and not really part of the normal game. Hence, the caller must also ensure that the handleTopologyEvent method isn't called anymore (which typically is automatically guaranteed since the caller is typically an osgi service that gets unregistered anyway)