Class ChannelManager<K,C extends Channel,A>

java.lang.Object
org.jdrupes.vmoperator.manager.events.ChannelManager<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 ChannelManager<K,C extends Channel,A> extends Object implements ChannelDictionary<K,C,A>
Provides an actively managed implementation of the ChannelDictionary.

The ChannelManager can be used for housekeeping by any component that creates channels. It can be shared between this component and some other component, preferably passing it as ChannelDictionary (the read-only view) to the second component. Alternatively, the other component can use a ChannelTracker to track the mappings using events.

  • Constructor Details

    • ChannelManager

      public ChannelManager(Function<K,C> supplier)
      Instantiates a new channel manager.
      Parameters:
      supplier - the supplier that creates new channels
    • ChannelManager

      public ChannelManager()
      Instantiates a new channel manager without a default supplier.
  • 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 Channel,A>
      Returns:
      the keys
    • values

      Return all known values.
      Specified by:
      values in interface ChannelDictionary<K,C extends 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 Channel,A>
      Parameters:
      key - the key
      Returns:
      the result
    • put

      public ChannelManager<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 ChannelManager<K,C,A> put(K key, C channel)
      Store the given data.
      Parameters:
      key - the key
      channel - the channel
      Returns:
      the channel manager
    • channelGet

      public C channelGet(K key)
      Returns the Channel for the given name, creating it using the supplier passed to the constructor if it doesn’t exist yet.
      Parameters:
      key - the key
      Returns:
      the channel
    • computeIfAbsent

      public C computeIfAbsent(K key, Function<K,C> supplier)
      Returns the Channel for the given name, creating it using the given supplier if it doesn’t exist yet.
      Parameters:
      key - the key
      supplier - the supplier
      Returns:
      the channel
    • associate

      public ChannelManager<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