Class OortList<E>

java.lang.Object
org.eclipse.jetty.util.component.AbstractLifeCycle
Type Parameters:
E - the element type
All Implemented Interfaces:
Iterable<OortObject.Info<List<E>>>, EventListener, ConfigurableServerChannel.Initializer, Oort.CometListener, org.eclipse.jetty.util.component.Dumpable, 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.ElementListeners are notified. OortList.DeltaListener converts whole list updates triggered by OortObject.setAndShare(Object, Result) into events for OortList.ElementListeners, giving applications a single listener type to implement their business logic.

  • Constructor Details

  • Method Details

    • 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 given element is present in the local entity list of this node. Differently from isPresent(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

      public boolean isPresent(E element)
      Returns whether the given element is present in one of the entity lists of all nodes. Differently from contains(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

      public void addAndShare(OortObject.Result<Boolean> callback, E... elements)

      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.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.Result parameter is notified.

      Parameters:
      callback - the callback invoked with whether at least one of the elements was added to the local entity list or null if there is no interest in knowing whether elements were added
      elements - the elements to add
    • removeAndShare

      public void removeAndShare(OortObject.Result<Boolean> callback, E... elements)

      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.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.Result parameter is notified.

      Parameters:
      callback - the callback invoked with whether at least one of the elements was removed to the local entity list or null if there is no interest in knowing whether elements were removed
      elements - the elements to remove
    • isItemUpdate

      protected boolean isItemUpdate(Map<String,Object> data)
      Specified by:
      isItemUpdate in class OortContainer<List<E>>
    • onItem

      protected void onItem(OortObject.Info<List<E>> info, Map<String,Object> data)
      Specified by:
      onItem in class OortContainer<List<E>>