com.vaadin.collaborationengine.
Interface CollaborationMap
All Superinterfaces:
A map that is shared between multiple users. Map instances can be retrieved
through a TopicConnection
. Changes performed by one user will be
delivered as events to subscribers defined by other users.
Since:
1.0
Author:
Vaadin Ltd
-
Method Summary
Modifier and TypeMethodDescription<T> T
Gets the map value for the given key as an instance corresponding to the given type reference.
<T> T
Gets the map value for the given key as an instance of the given class.
Gets the topic connection which is used to propagate changes to this map.
Gets the optional expiration timeout of this map.
getKeys()
Gets a stream of the currently available keys.
default CompletableFuture<Void>
Associates the given value with the given key.
put
(String key, Object value, EntryScope scope) Associates the given value with the given key and scope.
default CompletableFuture<Void>
Removes the value with the given key.
default CompletableFuture<Boolean>
Removes the value with the given key only if and only if the current value is as expected.
Atomically replaces the value for a key if and only if the current value is as expected.
void
setExpirationTimeout
(Duration expirationTimeout) Sets the expiration timeout of this map.
subscribe
(MapSubscriber subscriber) Subscribes to changes to this map.
-
Method Details
-
get
Gets the map value for the given key as an instance of the given class.
Parameters:
key
- the string key for which to get a value, notnull
type
- the expected typeReturns:
the value associated with the key, or
null
if no value is presentThrows:
JsonConversionException
- if the value in the map cannot be converted to an instance of the given classSince:
1.0
-
get
Gets the map value for the given key as an instance corresponding to the given type reference.
Parameters:
key
- the string key for which to get a value, notnull
type
- the type reference of the expected type to getReturns:
the value associated with the key, or
null
if no value is presentThrows:
JsonConversionException
- if the value in the map cannot be converted to an instance of the given type referenceSince:
1.0
-
put
Associates the given value with the given key. This method can also be used to remove an association by passing
null
as the value. Subscribers are notified if the new value isn'tequals()
with the old value.The given value must be JSON-serializable so it can be sent over the network when Collaboration Engine is hosted in a standalone server.
Parameters:
key
- the string key for which to make an association, notnull
value
- the value to set, ornull
to remove the associationReturns:
a completable future that is resolved when the data update is completed.
Throws:
JsonConversionException
- if the given value isn't serializable as JSON stringSince:
1.0
-
remove
Removes the value with the given key. Subscribers are notified if there exists a non-null value.
Parameters:
key
- the string key for which to make an association, notnull
Returns:
a completable future that is resolved when the data update is completed.
-
remove
Removes the value with the given key only if and only if the current value is as expected. Subscribers are notified if the current value is non-null.
Parameters:
key
- the string key for which to make an association, notnull
expectedValue
- the value to compare with the current value to determine whether to remove the value, ornull
to expect that no value is present.Returns:
a boolean completable future that is resolved when the removal is completed. The resolved value is
true
if the expected value was present so that the operation could proceed;false
if the expected value was not present -
put
Associates the given value with the given key and scope. This method can also be used to remove an association by passing
null
as the value. Subscribers are notified if the new value isn'tequals()
with the old value.The given value must be JSON-serializable so it can be sent over the network when Collaboration Engine is hosted in a standalone server.
The
scope
parameter specifies the scope of the entry, which is either one ofEntryScope.TOPIC
to keep the entry in the map until explicitly removed, orEntryScope.CONNECTION
to automatically remove the entry when the connection which put the entry is deactivated. Putting the same value will update the ownership and the scope of the entry, but listeners won't be invoked.Parameters:
key
- the string key for which to make an association, notnull
value
- the value to set, ornull
to remove the associationscope
- the scope of the entry, notnull
Returns:
a completable future that is resolved when the data update is completed.
Throws:
JsonConversionException
- if the given value isn't serializable as JSON stringSince:
4.0
-
replace
Atomically replaces the value for a key if and only if the current value is as expected. Subscribers are notified if the new value isn't
equals()
with the old value.equals()
is also used to compare the current value with the expected value.The given value must be JSON-serializable so it can be sent over the network when Collaboration Engine is hosted in a standalone server.
Parameters:
key
- the string key for which to make an association, notnull
expectedValue
- the value to compare with the current value to determine whether to make an update, ornull
to expect that no value is presentnewValue
- the new value to set, ornull
to remove the associationReturns:
a boolean completable future that is resolved when the data update is completed. The resolved value is
true
if the expected value was present so that the operation could proceed;false
if the expected value was not presentThrows:
JsonConversionException
- if the given value isn't serializable as JSON stringSince:
1.0
-
getKeys
Gets a stream of the currently available keys. The stream is backed by a current snapshot of the available keys and will thus not update even if keys are added or removed before the stream is processed.
Returns:
the stream of keys, not
null
Since:
1.0
-
subscribe
Subscribes to changes to this map. When subscribing, the subscriber will receive an event for each current value association.
Parameters:
subscriber
- the subscriber to use, notnull
Returns:
a handle that can be used for removing the subscription, not
null
Since:
1.0
-
getConnection
TopicConnection getConnection()Gets the topic connection which is used to propagate changes to this map.
Returns:
the topic connection used by this map, not
null
Since:
1.0
-
getExpirationTimeout
Gets the optional expiration timeout of this map. An empty
Optional
is returned if no timeout is set, which means the map is not cleared when there are no connected users to the related topic (this is the default).Specified by:
getExpirationTimeout
in interfaceHasExpirationTimeout
Returns:
the expiration timeout
-
setExpirationTimeout
Sets the expiration timeout of this map. If set, this map data is cleared when
expirationTimeout
has passed after the last connection to the topic this map belongs to is closed. If set tonull
, the timeout is cancelled.Specified by:
setExpirationTimeout
in interfaceHasExpirationTimeout
Parameters:
expirationTimeout
- the expiration timeout
-