Class Seti

java.lang.Object
org.eclipse.jetty.util.component.AbstractLifeCycle
org.cometd.oort.Seti
All Implemented Interfaces:
org.eclipse.jetty.util.component.Dumpable, org.eclipse.jetty.util.component.LifeCycle

@ManagedObject("CometD cloud peer discovery component")
public class Seti
extends org.eclipse.jetty.util.component.AbstractLifeCycle
implements org.eclipse.jetty.util.component.Dumpable

The component that Searches for Extra Terrestrial Intelligence or, in this case, just searches for a user logged onto a comet in an Oort cloud.

Seti allows an application to maintain a mapping from userId (any application identifier such as user names or database IDs that represent users) to server sessions using the associate(String, ServerSession) and disassociate(String, ServerSession) methods.

A typical example of usage of associate(String, ServerSession) is in a SecurityPolicy after a successful handshake (where authentication information can be linked with the server session), or in CometD services where the association is established upon receiving a message on a particular channel processed by the service itself.

Each comet in the cluster keeps its own mapping for clients connected to it.

The sendMessage(Collection, String, Object) and sendMessage(String, String, Object) methods may be used to send messages to user(s) anywhere in the Oort cluster and Seti organizes the search in order to locate the user(s).

See Also:
SetiServlet
  • Nested Class Summary

    Nested Classes
    Modifier and Type Class Description
    protected class  Seti.LocalLocation
    A Location that represent a user connected to a local comet.
    protected static interface  Seti.Location
    The representation of where a user is.
    static interface  Seti.PresenceListener
    Listener interface that gets notified of remote Seti presence events.
    protected class  Seti.SetiLocation
    A Location that represent a user connected to a remote comet.

    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.eclipse.jetty.util.component.Dumpable

    org.eclipse.jetty.util.component.Dumpable.DumpableContainer

    Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle

    org.eclipse.jetty.util.component.LifeCycle.Listener
  • Field Summary

    Fields
    Modifier and Type Field Description
    static java.lang.String SETI_ATTRIBUTE  

    Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

    FAILED, STARTED, STARTING, STOPPED, STOPPING

    Fields inherited from interface org.eclipse.jetty.util.component.Dumpable

    KEY
  • Constructor Summary

    Constructors
    Constructor Description
    Seti​(Oort oort)  
  • Method Summary

    Modifier and Type Method Description
    void addPresenceListener​(Seti.PresenceListener listener)  
    boolean associate​(java.lang.String userId, ServerSession session)
    Associates the given userId to the given session.
    protected boolean associate​(java.lang.String userId, Seti.Location location)  
    java.util.Set<ServerSession> disassociate​(java.lang.String userId)
    Disassociates the given userId from all sessions.
    boolean disassociate​(java.lang.String userId, ServerSession session)
    Disassociates the given userId from the given session.
    protected boolean disassociate​(java.lang.String userId, Seti.Location location)  
    protected void doStart()  
    protected void doStop()  
    void dump​(java.lang.Appendable out, java.lang.String indent)  
    protected java.lang.String generateSetiChannel​(java.lang.String setiId)  
    protected java.lang.String generateSetiId​(java.lang.String oortURL)  
    java.util.Set<java.lang.String> getAssociatedUserIds()  
    int getAssociationCount​(java.lang.String userId)  
    java.lang.String getId()  
    Oort getOort()  
    int getPresenceCount​(java.lang.String userId)  
    java.util.Set<java.lang.String> getUserIds()  
    boolean isAssociated​(java.lang.String userId)  
    boolean isPresent​(java.lang.String userId)  
    protected void receiveBroadcast​(Message message)
    Receives messages broadcast by other Setis in the cloud.
    protected void receiveDirect​(Message message)
    Receives messages directly from other Setis in the cloud, containing messages to be delivered to sessions connected to this comet.
    protected void receiveLocalPresence​(java.util.Map<java.lang.String,​java.lang.Object> presence)  
    protected void receiveMessage​(java.util.Map<java.lang.String,​java.lang.Object> message)
    Receives a seti message.
    protected void receivePresence​(java.util.Map<java.lang.String,​java.lang.Object> presence)
    Receives a presence message.
    protected void receiveRemotePresence​(java.util.Map<java.lang.String,​java.lang.Object> presence)  
    protected void removeAssociationsAndPresences()  
    void removePresenceListener​(Seti.PresenceListener listener)  
    void removePresenceListeners()  
    protected void removePresences​(java.lang.String oortURL)  
    void sendMessage​(java.lang.String toUserId, java.lang.String toChannel, java.lang.Object data)
    Sends a message to the given userId in the Oort cloud.
    void sendMessage​(java.util.Collection<java.lang.String> toUserIds, java.lang.String toChannel, java.lang.Object data)
    Sends a message to multiple userIds in the Oort cloud.
    java.lang.String 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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.eclipse.jetty.util.component.Dumpable

    dump, dumpSelf
  • Field Details

    • SETI_ATTRIBUTE

      public static final java.lang.String SETI_ATTRIBUTE
  • Constructor Details

    • Seti

      public Seti​(Oort oort)
  • Method Details

    • getOort

      @ManagedAttribute(value="The Oort of this Seti", readonly=true) public Oort getOort()
    • getId

      @ManagedAttribute(value="The unique ID of this Seti", readonly=true) public java.lang.String getId()
    • doStart

      protected void doStart()
      Overrides:
      doStart in class org.eclipse.jetty.util.component.AbstractLifeCycle
    • doStop

      protected void doStop()
      Overrides:
      doStop in class org.eclipse.jetty.util.component.AbstractLifeCycle
    • generateSetiId

      protected java.lang.String generateSetiId​(java.lang.String oortURL)
    • generateSetiChannel

      protected java.lang.String generateSetiChannel​(java.lang.String setiId)
    • associate

      public boolean associate​(java.lang.String userId, ServerSession session)

      Associates the given userId to the given session.

      If it is the first association for this userId, broadcasts this information on the Oort cloud, so that other comets will know that the given userId is on this comet.

      Parameters:
      userId - the user identifier to associate
      session - the session to map the userId to
      Returns:
      true if the session has been associated, false if it was already associated
      See Also:
      isAssociated(String), disassociate(String, ServerSession)
    • associate

      protected boolean associate​(java.lang.String userId, Seti.Location location)
    • isAssociated

      @ManagedOperation(value="Whether the given userId is associated locally", impact="INFO") public boolean isAssociated​(@Name(value="userId",description="The userId to test for local association") java.lang.String userId)
      Parameters:
      userId - the user identifier to test for association
      Returns:
      whether the given userId has been associated via associate(String, ServerSession)
      See Also:
      associate(String, ServerSession), isPresent(String), getAssociationCount(String)
    • getAssociationCount

      @ManagedOperation(value="The number of local associations for the given userId", impact="INFO") public int getAssociationCount​(@Name(value="userId",description="The userId to test for local association count") java.lang.String userId)
      Parameters:
      userId - the user identifier to test for association count
      Returns:
      the number of local associations
      See Also:
      isAssociated(String), getPresenceCount(String)
    • isPresent

      @ManagedOperation(value="Whether the given userId is present in the cloud", impact="INFO") public boolean isPresent​(@Name(value="userId",description="The userId to test for presence in the cloud") java.lang.String userId)
      Parameters:
      userId - the user identifier to test for presence
      Returns:
      whether the given userId is present on the cloud (and therefore has been associated either locally or remotely)
      See Also:
      isAssociated(String), getPresenceCount(String)
    • getPresenceCount

      @ManagedOperation(value="The number of local and remote associations for the given userId", impact="INFO") public int getPresenceCount​(@Name(value="userId",description="The userId to test for presence count") java.lang.String userId)
      Parameters:
      userId - the user identifier to test for presence count
      Returns:
      the number of associations (local or remote) on the cloud
      See Also:
      isPresent(String), getAssociationCount(String)
    • disassociate

      public boolean disassociate​(java.lang.String userId, ServerSession session)

      Disassociates the given userId from the given session.

      If this is the last disassociation for this userId, broadcasts this information on the Oort cloud, so that other comets will know that the given userId no longer is on this comet.

      Parameters:
      userId - the user identifier to disassociate
      session - the session mapped to the userId
      Returns:
      true if the session has been disassociated, false if it was not associated
      See Also:
      associate(String, ServerSession)
    • disassociate

      public java.util.Set<ServerSession> disassociate​(java.lang.String userId)

      Disassociates the given userId from all sessions.

      If this user had sessions on this comet, broadcast this information on the Oort cloud, so that other comets will know that the given userId no longer is on this comet.

      Parameters:
      userId - the user identifier to disassociate
      Returns:
      set of sessions that were disassociated
      See Also:
      associate(String, ServerSession)
    • disassociate

      protected boolean disassociate​(java.lang.String userId, Seti.Location location)
    • removeAssociationsAndPresences

      protected void removeAssociationsAndPresences()
    • removePresences

      protected void removePresences​(java.lang.String oortURL)
    • getUserIds

      @ManagedAttribute(value="The set of userIds known to this Seti", readonly=true) public java.util.Set<java.lang.String> getUserIds()
      Returns:
      the set of userIds known to this Seti, both local and remote
    • getAssociatedUserIds

      public java.util.Set<java.lang.String> getAssociatedUserIds()
      Returns:
      the set of userIds associated via associate(String, ServerSession)
    • sendMessage

      public void sendMessage​(java.lang.String toUserId, java.lang.String toChannel, java.lang.Object data)

      Sends a message to the given userId in the Oort cloud.

      Parameters:
      toUserId - the userId to send the message to
      toChannel - the channel to send the message to
      data - the content of the message
      See Also:
      sendMessage(Collection, String, Object)
    • sendMessage

      public void sendMessage​(java.util.Collection<java.lang.String> toUserIds, java.lang.String toChannel, java.lang.Object data)

      Sends a message to multiple userIds in the Oort cloud.

      Parameters:
      toUserIds - the userIds to send the message to
      toChannel - the channel to send the message to
      data - the content of the message
    • receiveDirect

      protected void receiveDirect​(Message message)

      Receives messages directly from other Setis in the cloud, containing messages to be delivered to sessions connected to this comet.

      Parameters:
      message - the message to deliver to a session connected to this comet
    • receiveBroadcast

      protected void receiveBroadcast​(Message message)

      Receives messages broadcast by other Setis in the cloud.

      Broadcast messages may be presence messages, where another Seti advertises an association, or fallback messages. Fallback messages are messages that were sent to a particular Seti because the sender thought the target userId was there, but the receiving Seti does not know that userId anymore (for example, it just disconnected); in this case, the receiving Seti broadcasts the message to the whole cloud, in the hope that the user can be found in some other comet of the cloud.

      Parameters:
      message - the message to possibly deliver to a session connected to this comet
    • receivePresence

      protected void receivePresence​(java.util.Map<java.lang.String,​java.lang.Object> presence)

      Receives a presence message.

      Parameters:
      presence - the presence message received
    • receiveLocalPresence

      protected void receiveLocalPresence​(java.util.Map<java.lang.String,​java.lang.Object> presence)
    • receiveRemotePresence

      protected void receiveRemotePresence​(java.util.Map<java.lang.String,​java.lang.Object> presence)
    • addPresenceListener

      public void addPresenceListener​(Seti.PresenceListener listener)
    • removePresenceListener

      public void removePresenceListener​(Seti.PresenceListener listener)
    • removePresenceListeners

      public void removePresenceListeners()
    • receiveMessage

      protected void receiveMessage​(java.util.Map<java.lang.String,​java.lang.Object> message)

      Receives a seti message.

      Parameters:
      message - the seti message received
    • dump

      public void dump​(java.lang.Appendable out, java.lang.String indent) throws java.io.IOException
      Specified by:
      dump in interface org.eclipse.jetty.util.component.Dumpable
      Throws:
      java.io.IOException
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class org.eclipse.jetty.util.component.AbstractLifeCycle