Class ChannelTracker<K,C extends org.jgrapes.core.Channel,A>

java.lang.Object
org.jdrupes.vmoperator.manager.events.ChannelTracker<K,C,A>
Type Parameters:
K - the key type
C - the channel type
A - the type of the associated data
All Implemented Interfaces:
ChannelDictionary<K,C,A>

public class ChannelTracker<K,C extends org.jgrapes.core.Channel,A> extends Object implements ChannelDictionary<K,C,A>
Used to track mapping from a key to a channel.

Entries must be maintained by handlers for “add/remove” (or “open/close”) events delivered on the channels that are to be made available by the tracker.

The channels are stored in the dictionary using WeakReferences. Removing entries is therefore best practice but not an absolute necessity as entries for cleared references are removed when one of the methods values(), ChannelDictionary.channels() or ChannelDictionary.associated() is called.

  • Constructor Details

  • Method Details

    • keys

      public Set<K> keys()
      Description copied from interface: ChannelDictionary
      Returns all known keys.
      Specified by:
      keys in interface ChannelDictionary<K,C extends org.jgrapes.core.Channel,A>
      Returns:
      the keys
    • values

      Description copied from interface: ChannelDictionary
      Return all known values.
      Specified by:
      values in interface ChannelDictionary<K,C extends org.jgrapes.core.Channel,A>
      Returns:
      the collection
    • value

      Returns the channel and associates data registered for the key or an empty optional if no mapping exists.
      Specified by:
      value in interface ChannelDictionary<K,C extends org.jgrapes.core.Channel,A>
      Parameters:
      key - the key
      Returns:
      the result
    • put

      public ChannelTracker<K,C,A> put(K key, C channel, A associated)
      Store the given data.
      Parameters:
      key - the key
      channel - the channel
      associated - the associated
      Returns:
      the channel manager
    • put

      public ChannelTracker<K,C,A> put(K key, C channel)
      Store the given data.
      Parameters:
      key - the key
      channel - the channel
      Returns:
      the channel manager
    • associate

      public ChannelTracker<K,C,A> associate(K key, A data)
      Associate the entry for the channel with the given data.

      The entry for the channel must already exist.

      Parameters:
      key - the key
      data - the data
      Returns:
      the channel manager
    • remove

      public void remove(String name)
      Removes the channel with the given name.
      Parameters:
      name - the name