com.vaadin.collaborationengine.
Interface CollaborationMap
-
public interface CollaborationMap
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.Author:
Vaadin Ltd
-
-
Method Summary
All Methods Modifier and Type Method and Description <T> T
get(String key, Class<T> type)
Gets the map value for the given key as an instance of the given class.
<T> T
get(String key, com.fasterxml.jackson.core.type.TypeReference<T> type)
Gets the map value for the given key as an instance corresponding to the given type reference.
TopicConnection
getConnection()
Gets the topic connection which is used to propagate changes to this map.
Stream<String>
getKeys()
Gets a stream of the currently available keys.
CompletableFuture<Void>
put(String key, Object value)
Associates the given value with the given key.
CompletableFuture<Boolean>
replace(String key, Object expectedValue, Object newValue)
Atomically replaces the value for a key if and only if the current value is as expected.
Registration
subscribe(MapSubscriber subscriber)
Subscribes to changes to this map.
-
-
-
Method Detail
-
get
<T> T get(String key, Class<T> type)
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 class
-
get
<T> T get(String key, com.fasterxml.jackson.core.type.TypeReference<T> type)
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 reference
-
put
CompletableFuture<Void> put(String key, Object value)
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 string
-
replace
CompletableFuture<Boolean> replace(String key, Object expectedValue, Object newValue)
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 string
-
getKeys
Stream<String> 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
-
subscribe
Registration subscribe(MapSubscriber subscriber)
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
-
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
-
-