Interface ChannelLifecycleListener


  • public interface ChannelLifecycleListener
    Interface that will be implemented by a chain manager to get callbacks on channel creation and destroy.

    The chain manager will need to register listeners for channel prefixes of interest using its ChainManagerHost (see AbstractChainManager.host.

    Thread-safety: the callback methods can be called from multiple threads so the caller must take care to access any mutable state in thread-safe manner.

    If using correlator persistence, the required channel lifecycle notifications for channels in use by any persistent monitors will be replayed to listeners during recovery, so there is no need for chain managers to persist any state across restarts to support correct operation of persistence.

    See Also:
    AbstractChainManager, ChainManagerHost
    • Method Detail

      • onChannelCreated

        void onChannelCreated​(java.lang.String channel,
                              Direction direction)
                       throws java.lang.Exception
        Called by the host when a channel is created.

        This method might be called multiple times for the same channel and direction, to give the manager a chance to re-evaluate whether a chain is required for the given channel if the channel cache is flushed. When this method is called the manager must first decide whether it currently needs to have a chain for the specified channel, as some managers may only wish to take action if a channel with the specified name exists on the external system they are connected to. The manager must also check if it already has a chain for this channel in the specified direction, since in some situations the listener will notify about creation of the same channel more than once. If the manager has established that a chain is needed for this channel and none already exists it should create one, if a chain already exists for this channel but is no longer needed it should destroy it, and otherwise it should do nothing.

        In the case that a channel is created just after the last subscription has been removed it might be possible that onChannelCreated is called without onChannelDestroyed ever being called, so do not rely on the onChannelCreated and onChannelDestroyed invocations being paired.

        If a chain needs to be created for this channel this must be done before this method returns, which is required to ensure that any messages sent on the channel while the channel creation is being processed are delivered and not lost.

        Thread-safety: Any chain started from onChannelCreated must not send messages to the host in the start() method of the transport, as this can cause deadlock because this method may be called from the receiving thread. The transport can instead send the message from the hostReady() method which is always called from a background thread. This method can be called from multiple threads so plug-in should take care of accessing any mutable state in a thread-safe manner.

        Parameters:
        channel - the name of the channel created
        direction - Direction.TOWARDS_HOST indicates the channel was created because of a monitor.subscribe()/monitor.unsubscribe() call in EPL, whereas Direction.TOWARDS_TRANSPORT indicates some EPL tries to send an event to the channel for the first time.
        Throws:
        java.lang.Exception - any exception thrown by this method will be logged and then ignored.
      • onChannelDestroyed

        void onChannelDestroyed​(java.lang.String channel,
                                Direction direction)
                         throws java.lang.Exception
        Called by the host when a channel is destroyed.

        The method can be called from multiple threads so plug-in should take care of accessing any mutable state in thread-safe manner.

        At present, channel destroy notifications are only sent for the TOWARDS_HOST direction (monitor.subscribe()) since in the TOWARDS_TRANSPORT direction (send ... to ...) there is no unambiguous way of determining when a channel is no longer needed.

        Parameters:
        channel - the name of channel destroyed
        direction - the direction for which the channel is being destroyed
        Throws:
        java.lang.Exception - any exception thrown by this method will be logged and then ignored.