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

public class ChannelManager<K,C extends Channel,A> extends Object
A channel manager that maintains mappings from a key to a channel.

As a convenience, it is possible to additionally associate arbitrary data with the entry (and thus with the channel).

The manager should be used by a component that defines channels for housekeeping. It can be shared between this component and another component, preferably using the fixed() view for the second component. Alternatively, the second component can use a ChannelCache 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

    • both

      Returns the channel and associates data registered for the key or an empty optional if no mapping exists.
      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
    • channel

      public Optional<C> channel(K key)
      Returns the channel registered for the key or an empty optional if no mapping exists.
      Parameters:
      key - the key
      Returns:
      the optional
    • getChannel

      public Optional<C> getChannel(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
    • getChannel

      public Optional<C> getChannel(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
    • associated

      public Optional<A> associated(K key)
      Return the data associated with the entry for the channel.
      Parameters:
      key - the key
      Returns:
      the data
    • associated

      public Collection<A> associated()
      Returns all associated data.
      Returns:
      the collection
    • remove

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

      public Set<K> keys()
      Returns all known keys.
      Returns:
      the sets the
    • fixed

      public ChannelManager<K,C,A> fixed()
      Returns a read only view of this channel manager.

      The methods that usually create a new entry refrain from doing so. The methods that change the value of channel and remove(String) do nothing. The associated data, however, can still be changed.

      Returns:
      the channel manager