Class OortList<E>
- Type Parameters:
E
- the element type
- All Implemented Interfaces:
Iterable<OortObject.Info<List<E>>>
,EventListener
,ConfigurableServerChannel.Initializer
,Oort.CometListener
,org.eclipse.jetty.util.component.LifeCycle
public class OortList<E> extends OortContainer<List<E>>
A specialized oort object whose entity is a List
.
OortList
specializes OortObject
and allows optimized replication of elements
across the cluster: instead of replicating the whole list, that may be contain a lot of elements,
only elements that are added or removed are replicated.
Applications can use addAndShare(Result, Object[])
and removeAndShare(Result, Object[])
to broadcast changes related to elements, as well as OortObject.setAndShare(Object, Result)
to
change the whole list.
When one or more elements are changed, OortList.ElementListener
s are notified.
OortList.DeltaListener
converts whole list updates triggered by OortObject.setAndShare(Object, Result)
into events for OortList.ElementListener
s, giving applications a single listener type to implement
their business logic.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
OortList.DeltaListener<E>
An implementation ofOortObject.Listener
that converts whole list events intoOortList.ElementListener
events.static interface
OortList.ElementListener<E>
Listener for element events that update the entity list, either locally or remotely.Nested classes/interfaces inherited from class org.cometd.oort.OortObject
OortObject.Data<T>, OortObject.Factory<T>, OortObject.Info<T>, OortObject.Listener<T>, OortObject.Merger<T,R>, OortObject.Result<R>
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener
Nested classes/interfaces inherited from interface org.cometd.bayeux.server.ConfigurableServerChannel.Initializer
ConfigurableServerChannel.Initializer.Persistent
Nested classes/interfaces inherited from interface org.cometd.oort.Oort.CometListener
Oort.CometListener.Adapter, Oort.CometListener.Event
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description boolean
addAndShare(E... elements)
Deprecated.useaddAndShare(Result, Object[])
insteadvoid
addAndShare(OortObject.Result<Boolean> callback, E... elements)
Adds the givenelements
to the local entity list, and then broadcasts the addition to all nodes in the cluster.void
addElementListener(OortList.ElementListener<E> listener)
boolean
contains(E element)
Returns whether the givenelement
is present in the local entity list of this node.protected boolean
isItemUpdate(Map<String,Object> data)
boolean
isPresent(E element)
Returns whether the givenelement
is present in one of the entity lists of all nodes.protected void
onItem(OortObject.Info<List<E>> info, Map<String,Object> data)
boolean
removeAndShare(E... elements)
Deprecated.useremoveAndShare(Result, Object[])
insteadvoid
removeAndShare(OortObject.Result<Boolean> callback, E... elements)
Removes the givenelements
to the local entity list, and then broadcasts the removal to all nodes in the cluster.void
removeElementListener(OortList.ElementListener<E> listener)
void
removeElementListeners()
Methods inherited from class org.cometd.oort.OortObject
addListener, cometJoined, configureChannel, deserialize, doStart, getChannelName, getFactory, getInfo, getInfoByObject, getInfos, getLocalSession, getName, getOort, iterator, merge, newInfo, notifyRemoved, notifyUpdated, pullInfo, pushInfo, removeListener, removeListeners, serialize, setAndShare, setAndShare, toString
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, setStopTimeout, start, stop
-
Constructor Details
-
Method Details
-
addElementListener
-
removeElementListener
-
removeElementListeners
public void removeElementListeners() -
contains
Returns whether the givenelement
is present in the local entity list of this node. Differently fromisPresent(Object)
, only the local entity list is scanned.- Parameters:
element
- the element to test for presence- Returns:
- true if the
element
is contained in the local entity list, false otherwise
-
isPresent
Returns whether the givenelement
is present in one of the entity lists of all nodes. Differently fromcontains(Object)
entity lists of all nodes are scanned.- Parameters:
element
- the element to test for presence- Returns:
- true if the
element
is contained in one of the entity lists of all nodes, false otherwise
-
addAndShare
Deprecated.useaddAndShare(Result, Object[])
insteadBlocking version of
addAndShare(Result, Object[])
, but deprecated.This method will be removed in a future release.
- Parameters:
elements
- the elements to add- Returns:
- whether at least one of the elements was added to the local entity list
-
addAndShare
Adds the given
elements
to the local entity list, and then broadcasts the addition to all nodes in the cluster.Calling this method triggers notifications
OortList.ElementListener
s, both on this node and on remote nodes.The element is guaranteed to be added not when this method returns, but when the
OortObject.Result
parameter is notified.- Parameters:
callback
- the callback invoked with whether at least one of the elements was added to the local entity list ornull
if there is no interest in knowing whether elements were addedelements
- the elements to add
-
removeAndShare
Deprecated.useremoveAndShare(Result, Object[])
insteadBlocking version of
removeAndShare(Result, Object[])
, but deprecated.This method will be removed in a future release.
- Parameters:
elements
- the elements to remove- Returns:
- whether at least one of the elements was removed from the local entity list
-
removeAndShare
Removes the given
elements
to the local entity list, and then broadcasts the removal to all nodes in the cluster.Calling this method triggers notifications
OortList.ElementListener
s, both on this node and on remote nodes.The element is guaranteed to be removed not when this method returns, but when the
OortObject.Result
parameter is notified.- Parameters:
callback
- the callback invoked with whether at least one of the elements was removed to the local entity list ornull
if there is no interest in knowing whether elements were removedelements
- the elements to remove
-
isItemUpdate
- Specified by:
isItemUpdate
in classOortContainer<List<E>>
-
onItem
- Specified by:
onItem
in classOortContainer<List<E>>
-