@ManagedObject(value="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).
SetiServlet
Modifier and Type | Class and 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.
|
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener
Modifier and Type | Field and Description |
---|---|
static String |
SETI_ATTRIBUTE |
Modifier and Type | Method and Description |
---|---|
void |
addPresenceListener(Seti.PresenceListener listener) |
boolean |
associate(String userId,
ServerSession session)
Associates the given userId to the given session.
|
protected boolean |
associate(String userId,
Seti.Location location) |
Set<ServerSession> |
disassociate(String userId)
Disassociates the given userId from all sessions.
|
boolean |
disassociate(String userId,
ServerSession session)
Disassociates the given userId from the given session.
|
protected boolean |
disassociate(String userId,
Seti.Location location) |
protected void |
doStart() |
protected void |
doStop() |
void |
dump(Appendable out,
String indent) |
protected String |
generateSetiChannel(String setiId) |
protected String |
generateSetiId(String oortURL) |
Set<String> |
getAssociatedUserIds() |
int |
getAssociationCount(String userId) |
String |
getId() |
Oort |
getOort() |
int |
getPresenceCount(String userId) |
Set<String> |
getUserIds() |
boolean |
isAssociated(String userId) |
boolean |
isPresent(String userId) |
protected void |
protectSetiChannels(BayeuxServer bayeux) |
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(Map<String,Object> presence) |
protected void |
receiveMessage(Map<String,Object> message)
Receives a seti message.
|
protected void |
receivePresence(Map<String,Object> presence)
Receives a presence message.
|
protected void |
receiveRemotePresence(Map<String,Object> presence) |
protected void |
removeAssociationsAndPresences() |
void |
removePresenceListener(Seti.PresenceListener listener) |
void |
removePresenceListeners() |
protected void |
removePresences(String oortURL) |
void |
sendMessage(Collection<String> toUserIds,
String toChannel,
Object data)
Sends a message to multiple userIds in the Oort cloud.
|
void |
sendMessage(String toUserId,
String toChannel,
Object data)
Sends a message to the given userId in the Oort cloud.
|
String |
toString() |
protected void |
unprotectSetiChannels(BayeuxServer bayeux) |
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, setStopTimeout, start, stop
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public static final String SETI_ATTRIBUTE
public Seti(Oort oort)
@ManagedAttribute(value="The Oort of this Seti", readonly=true) public Oort getOort()
@ManagedAttribute(value="The unique ID of this Seti", readonly=true) public String getId()
protected void doStart()
doStart
in class org.eclipse.jetty.util.component.AbstractLifeCycle
protected void doStop()
doStop
in class org.eclipse.jetty.util.component.AbstractLifeCycle
protected void protectSetiChannels(BayeuxServer bayeux)
protected void unprotectSetiChannels(BayeuxServer bayeux)
public boolean associate(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.
userId
- the user identifier to associatesession
- the session to map the userId toisAssociated(String)
,
disassociate(String, ServerSession)
protected boolean associate(String userId, Seti.Location location)
@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") String userId)
userId
- the user identifier to test for associationassociate(String, ServerSession)
associate(String, ServerSession)
,
isPresent(String)
,
getAssociationCount(String)
@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") String userId)
userId
- the user identifier to test for association countisAssociated(String)
,
getPresenceCount(String)
@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") String userId)
userId
- the user identifier to test for presenceisAssociated(String)
,
getPresenceCount(String)
@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") String userId)
userId
- the user identifier to test for presence countisPresent(String)
,
getAssociationCount(String)
public boolean disassociate(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.
userId
- the user identifier to disassociatesession
- the session mapped to the userIdassociate(String, ServerSession)
public Set<ServerSession> disassociate(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.
userId
- the user identifier to disassociateassociate(String, ServerSession)
protected boolean disassociate(String userId, Seti.Location location)
protected void removeAssociationsAndPresences()
protected void removePresences(String oortURL)
@ManagedAttribute(value="The set of userIds known to this Seti", readonly=true) public Set<String> getUserIds()
userId
s known to this Seti, both local and remotepublic Set<String> getAssociatedUserIds()
userId
s associated via associate(String, ServerSession)
public void sendMessage(String toUserId, String toChannel, Object data)
Sends a message to the given userId in the Oort cloud.
toUserId
- the userId to send the message totoChannel
- the channel to send the message todata
- the content of the messagesendMessage(Collection, String, Object)
public void sendMessage(Collection<String> toUserIds, String toChannel, Object data)
Sends a message to multiple userIds in the Oort cloud.
toUserIds
- the userIds to send the message totoChannel
- the channel to send the message todata
- the content of the messageprotected void receiveDirect(Message message)
Receives messages directly from other Setis in the cloud, containing messages to be delivered to sessions connected to this comet.
message
- the message to deliver to a session connected to this cometprotected 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.
message
- the message to possibly deliver to a session connected to this cometprotected void receivePresence(Map<String,Object> presence)
Receives a presence message.
presence
- the presence message receivedpublic void addPresenceListener(Seti.PresenceListener listener)
public void removePresenceListener(Seti.PresenceListener listener)
public void removePresenceListeners()
protected void receiveMessage(Map<String,Object> message)
Receives a seti message.
message
- the seti message receivedpublic void dump(Appendable out, String indent) throws IOException
dump
in interface org.eclipse.jetty.util.component.Dumpable
IOException
public String toString()
toString
in class org.eclipse.jetty.util.component.AbstractLifeCycle
Copyright © 2008–2024 The CometD Project. All rights reserved.