Class OortList<E>
- java.lang.Object
-
- org.eclipse.jetty.util.component.AbstractLifeCycle
-
- org.cometd.oort.OortObject<T>
-
- org.cometd.oort.OortContainer<java.util.List<E>>
-
- org.cometd.oort.OortList<E>
-
- Type Parameters:
E- the element type
- All Implemented Interfaces:
java.lang.Iterable<OortObject.Info<java.util.List<E>>>,java.util.EventListener,ConfigurableServerChannel.Initializer,Oort.CometListener,org.eclipse.jetty.util.component.Dumpable,org.eclipse.jetty.util.component.LifeCycle
public class OortList<E> extends OortContainer<java.util.List<E>>
A specialized oort object whose entity is a
List.OortListspecializesOortObjectand 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[])andremoveAndShare(Result, Object[])to broadcast changes related to elements, as well asOortObject.setAndShare(Object, Result)to change the whole list.When one or more elements are changed,
OortList.ElementListeners are notified.OortList.DeltaListenerconverts whole list updates triggered byOortObject.setAndShare(Object, Result)into events forOortList.ElementListeners, giving applications a single listener type to implement their business logic.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classOortList.DeltaListener<E>An implementation ofOortObject.Listenerthat converts whole list events intoOortList.ElementListenerevents.static interfaceOortList.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, org.eclipse.jetty.util.component.AbstractLifeCycle.StopException
-
Nested classes/interfaces inherited from interface org.cometd.bayeux.server.ConfigurableServerChannel.Initializer
ConfigurableServerChannel.Initializer.Persistent
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
org.eclipse.jetty.util.component.Dumpable.DumpableContainer
-
Nested classes/interfaces inherited from interface org.cometd.oort.Oort.CometListener
Oort.CometListener.Event
-
-
Field Summary
-
Fields inherited from class org.cometd.oort.OortObject
OORT_OBJECTS_CHANNEL
-
-
Constructor Summary
Constructors Constructor Description OortList(Oort oort, java.lang.String name, OortObject.Factory<java.util.List<E>> factory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAndShare(OortObject.Result<java.lang.Boolean> callback, E... elements)Adds the givenelementsto the local entity list, and then broadcasts the addition to all nodes in the cluster.voidaddElementListener(OortList.ElementListener<E> listener)booleancontains(E element)Returns whether the givenelementis present in the local entity list of this node.protected booleanisItemUpdate(java.util.Map<java.lang.String,java.lang.Object> data)booleanisPresent(E element)Returns whether the givenelementis present in one of the entity lists of all nodes.protected voidonItem(OortObject.Info<java.util.List<E>> info, java.util.Map<java.lang.String,java.lang.Object> data)voidremoveAndShare(OortObject.Result<java.lang.Boolean> callback, E... elements)Removes the givenelementsto the local entity list, and then broadcasts the removal to all nodes in the cluster.voidremoveElementListener(OortList.ElementListener<E> listener)voidremoveElementListeners()-
Methods inherited from class org.cometd.oort.OortContainer
cometLeft, doStop, onObject
-
Methods inherited from class org.cometd.oort.OortObject
addListener, cometJoined, configureChannel, deserialize, doStart, dump, getChannelName, getFactory, getInfo, getInfoByObject, getInfos, getLocalSession, getName, getOort, iterator, merge, newInfo, notifyRemoved, notifyUpdated, pullInfo, pushInfo, removeListener, removeListeners, serialize, setAndShare, toString
-
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addEventListener, getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeEventListener, setEventListeners, start, stop
-
-
-
-
Constructor Detail
-
OortList
public OortList(Oort oort, java.lang.String name, OortObject.Factory<java.util.List<E>> factory)
-
-
Method Detail
-
addElementListener
public void addElementListener(OortList.ElementListener<E> listener)
-
removeElementListener
public void removeElementListener(OortList.ElementListener<E> listener)
-
removeElementListeners
public void removeElementListeners()
-
contains
public boolean contains(E element)
Returns whether the givenelementis 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
elementis contained in the local entity list, false otherwise
-
isPresent
public boolean isPresent(E element)
Returns whether the givenelementis 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
elementis contained in one of the entity lists of all nodes, false otherwise
-
addAndShare
public void addAndShare(OortObject.Result<java.lang.Boolean> callback, E... elements)
Adds the given
elementsto the local entity list, and then broadcasts the addition to all nodes in the cluster.Calling this method triggers notifications
OortList.ElementListeners, both on this node and on remote nodes.The element is guaranteed to be added not when this method returns, but when the
OortObject.Resultparameter is notified.- Parameters:
callback- the callback invoked with whether at least one of the elements was added to the local entity list ornullif there is no interest in knowing whether elements were addedelements- the elements to add
-
removeAndShare
public void removeAndShare(OortObject.Result<java.lang.Boolean> callback, E... elements)
Removes the given
elementsto the local entity list, and then broadcasts the removal to all nodes in the cluster.Calling this method triggers notifications
OortList.ElementListeners, both on this node and on remote nodes.The element is guaranteed to be removed not when this method returns, but when the
OortObject.Resultparameter is notified.- Parameters:
callback- the callback invoked with whether at least one of the elements was removed to the local entity list ornullif there is no interest in knowing whether elements were removedelements- the elements to remove
-
isItemUpdate
protected boolean isItemUpdate(java.util.Map<java.lang.String,java.lang.Object> data)
- Specified by:
isItemUpdatein classOortContainer<java.util.List<E>>
-
onItem
protected void onItem(OortObject.Info<java.util.List<E>> info, java.util.Map<java.lang.String,java.lang.Object> data)
- Specified by:
onItemin classOortContainer<java.util.List<E>>
-
-