Class ChannelManager<K,C extends Channel,A>
java.lang.Object
org.jdrupes.vmoperator.manager.events.ChannelManager<K,C,A>
- Type Parameters:
K
- the key typeC
- the channel typeA
- the type of the associated data
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
ChannelManager.Both<C extends Channel,
A> Combines the channel and the associated data. -
Constructor Summary
ConstructorDescriptionInstantiates a new channel manager without a default supplier.ChannelManager
(Function<K, C> supplier) Instantiates a new channel manager. -
Method Summary
Modifier and TypeMethodDescriptionAssociate the entry for the channel with the given data.Returns all associated data.associated
(K key) Return the data associated with the entry for the channel.Returns the channel and associates data registered for the key or an empty optional if no mapping exists.Returns the channel registered for the key or an empty optional if no mapping exists.fixed()
Returns a read only view of this channel manager.getChannel
(K key) Returns theChannel
for the given name, creating it using the supplier passed to the constructor if it doesn’t exist yet.getChannel
(K key, Function<K, C> supplier) Returns theChannel
for the given name, creating it using the given supplier if it doesn’t exist yet.keys()
Returns all known keys.Store the given data.Store the given data.void
Removes the channel with the given name.
-
Constructor Details
-
ChannelManager
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
Store the given data.- Parameters:
key
- the keychannel
- the channelassociated
- the associated- Returns:
- the channel manager
-
put
Store the given data.- Parameters:
key
- the keychannel
- the channel- Returns:
- the channel manager
-
channel
Returns the channel registered for the key or an empty optional if no mapping exists.- Parameters:
key
- the key- Returns:
- the optional
-
getChannel
Returns theChannel
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
Returns theChannel
for the given name, creating it using the given supplier if it doesn’t exist yet.- Parameters:
key
- the keysupplier
- the supplier- Returns:
- the channel
-
associate
Associate the entry for the channel with the given data.The entry for the channel must already exist.
- Parameters:
key
- the keydata
- the data- Returns:
- the channel manager
-
associated
Return the data associated with the entry for the channel.- Parameters:
key
- the key- Returns:
- the data
-
associated
Returns all associated data.- Returns:
- the collection
-
remove
Removes the channel with the given name.- Parameters:
name
- the name
-
keys
Returns all known keys.- Returns:
- the sets the
-
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
-