public interface CollaborationMap extends HasExpirationTimeout
TopicConnection
. Changes performed by one user will be
delivered as events to subscribers defined by other users.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.
|
Optional<Duration> |
getExpirationTimeout()
Gets the optional expiration timeout of this map.
|
Stream<String> |
getKeys()
Gets a stream of the currently available keys.
|
default CompletableFuture<Void> |
put(String key,
Object value)
Associates the given value with the given key.
|
CompletableFuture<Void> |
put(String key,
Object value,
EntryScope scope)
Associates the given value with the given key and scope.
|
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.
|
void |
setExpirationTimeout(Duration expirationTimeout)
Sets the expiration timeout of this map.
|
Registration |
subscribe(MapSubscriber subscriber)
Subscribes to changes to this map.
|
<T> T get(String key, Class<T> type)
key
- the string key for which to get a value, not null
type
- the expected typenull
if no
value is presentJsonConversionException
- if the value in the map cannot be converted to an instance of
the given class<T> T get(String key, com.fasterxml.jackson.core.type.TypeReference<T> type)
key
- the string key for which to get a value, not null
type
- the type reference of the expected type to getnull
if no
value is presentJsonConversionException
- if the value in the map cannot be converted to an instance of
the given type referencedefault CompletableFuture<Void> put(String key, Object value)
null
as the value.
Subscribers are notified if the new value isn't equals()
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.
key
- the string key for which to make an association, not
null
value
- the value to set, or null
to remove the
associationJsonConversionException
- if the given value isn't serializable as JSON stringCompletableFuture<Void> put(String key, Object value, EntryScope scope)
null
as the
value. Subscribers are notified if the new value isn't
equals()
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 of EntryScope.TOPIC
to keep the entry in the map
until explicitly removed, or EntryScope.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.
key
- the string key for which to make an association, not
null
value
- the value to set, or null
to remove the
associationscope
- the scope of the entry, not null
JsonConversionException
- if the given value isn't serializable as JSON stringCompletableFuture<Boolean> replace(String key, Object expectedValue, Object newValue)
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.
key
- the string key for which to make an association, not
null
expectedValue
- the value to compare with the current value to determine
whether to make an update, or null
to expect that
no value is presentnewValue
- the new value to set, or null
to remove the
associationtrue
if
the expected value was present so that the operation could
proceed; false
if the expected value was not presentJsonConversionException
- if the given value isn't serializable as JSON stringStream<String> getKeys()
null
Registration subscribe(MapSubscriber subscriber)
subscriber
- the subscriber to use, not null
null
TopicConnection getConnection()
null
Optional<Duration> getExpirationTimeout()
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).getExpirationTimeout
in interface HasExpirationTimeout
void setExpirationTimeout(Duration expirationTimeout)
expirationTimeout
has passed after the last connection to
the topic this map belongs to is closed. If set to null
, the
timeout is cancelled.setExpirationTimeout
in interface HasExpirationTimeout
expirationTimeout
- the expiration timeoutCopyright © 2022. All rights reserved.