class UrlTrackerHubConnection extends java.lang.Object implements HubConnection
| Modifier and Type | Class and Description |
|---|---|
private class |
UrlTrackerHubConnection.UrlTrackerCallableClient
CallableClient wrapper implementation which intercepts
communications, scans the payloads for URLs, and informs an
associated UrlTracker.
|
| Modifier and Type | Field and Description |
|---|---|
private HubConnection |
base_ |
private UrlTracker |
urlTracker_ |
| Constructor and Description |
|---|
UrlTrackerHubConnection(HubConnection base,
UrlTracker urlTracker)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
call(java.lang.String recipientId,
java.lang.String msgTag,
java.util.Map msg)
Sends a message to a given client expecting a response.
|
java.util.Map |
callAll(java.lang.String msgTag,
java.util.Map msg)
Sends a message to all subscribed clients expecting responses.
|
Response |
callAndWait(java.lang.String recipientId,
java.util.Map msg,
int timeout)
Sends a message synchronously to a client, waiting for the response.
|
void |
declareMetadata(java.util.Map meta)
Declares this registered client's metadata.
|
void |
declareSubscriptions(java.util.Map subs)
Declares this registered client's MType subscriptions.
|
Metadata |
getMetadata(java.lang.String clientId)
Returns the metadata for another registered client.
|
RegInfo |
getRegInfo()
Returns the registration information associated with this connection.
|
java.lang.String[] |
getRegisteredClients()
Returns the list of client public IDs for those clients currently
registered.
|
java.util.Map |
getSubscribedClients(java.lang.String mtype)
Returns a map of subscriptions for a given MType.
|
Subscriptions |
getSubscriptions(java.lang.String clientId)
Returns the subscriptions for another registered client.
|
private boolean |
isUrl(java.lang.String str)
Determines whether a given string is apparently a URL.
|
void |
notify(java.lang.String recipientId,
java.util.Map msg)
Sends a message to a given client without wanting a response.
|
java.util.List |
notifyAll(java.util.Map msg)
Sends a message to all subscribed clients without wanting a response.
|
void |
ping()
Tests whether the connection is currently open.
|
void |
reply(java.lang.String msgId,
java.util.Map response)
Supplies a response to a previously received message.
|
private java.net.URL[] |
scanForUrls(java.util.Map map)
Recursively scans a map for items that look like URLs and
returns them as an array.
|
private void |
scanForUrls(java.lang.Object item,
java.util.Collection urlSet)
Recursively scans a SAMP data item for items that look like URLs
and appends them into a supplied list.
|
private java.util.Map |
scanIncoming(java.util.Map map)
Recursively scans a SAMP map for items that look like URLs,
and notifies the tracker that they are incoming.
|
private java.util.Map |
scanOutgoing(java.util.Map map)
Recursively scans a SAMP map for items that look like URLs,
and notifies the tracker that they are outgoing.
|
void |
setCallable(CallableClient callable)
Tells the hub how it can perform callbacks on the client by providing
a CallableClient object.
|
void |
unregister()
Unregisters the client and terminates this connection.
|
private final HubConnection base_
private final UrlTracker urlTracker_
public UrlTrackerHubConnection(HubConnection base, UrlTracker urlTracker)
base - connection on which this one is basedurlTracker - tracker for URL usageprivate java.util.Map scanIncoming(java.util.Map map)
map - map to scanprivate java.util.Map scanOutgoing(java.util.Map map)
map - map to scanprivate java.net.URL[] scanForUrls(java.util.Map map)
map - map to scanmapprivate void scanForUrls(java.lang.Object item,
java.util.Collection urlSet)
item - SAMP data item (String, List or Map)urlSet - list of URL objects to which URLs can be addedprivate boolean isUrl(java.lang.String str)
str - string to teststr looks like a URLpublic void setCallable(CallableClient callable) throws SampException
HubConnectionsetCallable in interface HubConnectioncallable - callable clientSampExceptionpublic void notify(java.lang.String recipientId,
java.util.Map msg)
throws SampException
HubConnectionnotify in interface HubConnectionrecipientId - public-id of client to receive messagemsg - Message-like mapSampExceptionpublic java.util.List notifyAll(java.util.Map msg)
throws SampException
HubConnectionnotifyAll in interface HubConnectionmsg - Message-like mapSampExceptionpublic java.lang.String call(java.lang.String recipientId,
java.lang.String msgTag,
java.util.Map msg)
throws SampException
HubConnectionreceiveResponse method of this connection's
CallableClient will be called with a
response at some time in the future.
Only permitted if this client is already callable.
call in interface HubConnectionrecipientId - public-id of client to receive messagemsgTag - arbitrary string tagging this message for caller's
benefitmsg - Message-like mapSampExceptionpublic java.util.Map callAll(java.lang.String msgTag,
java.util.Map msg)
throws SampException
HubConnectionreceiveResponse method of this connection's
CallableClient will be called with responses at some
time in the future.
Only permitted if this client is already callable.
callAll in interface HubConnectionmsgTag - arbitrary string tagging this message for caller's
benefitmsg - Message-like mapSampExceptionpublic Response callAndWait(java.lang.String recipientId, java.util.Map msg, int timeout) throws SampException
HubConnectiontimeout
parameter, an exception will result.callAndWait in interface HubConnectionrecipientId - public-id of client to receive messagemsg - Message-like maptimeout - timeout in seconds, or <0 for no timeoutSampExceptionpublic void reply(java.lang.String msgId,
java.util.Map response)
throws SampException
HubConnectionreply in interface HubConnectionmsgId - ID associated with earlier sendresponse - Response-like mapSampExceptionpublic RegInfo getRegInfo()
HubConnectiongetRegInfo in interface HubConnectionpublic void ping()
throws SampException
HubConnectionping in interface HubConnectionSampException - if the hub has disappeared or communications
are disrupted in some other waypublic void unregister()
throws SampException
HubConnectionunregister in interface HubConnectionSampExceptionpublic void declareMetadata(java.util.Map meta)
throws SampException
HubConnectiondeclareMetadata in interface HubConnectionmeta - Metadata-like mapSampExceptionpublic Metadata getMetadata(java.lang.String clientId) throws SampException
HubConnectiongetMetadata in interface HubConnectionclientId - public id for another registered clientSampExceptionpublic void declareSubscriptions(java.util.Map subs)
throws SampException
HubConnectionOnly permitted if this client is already callable.
declareSubscriptions in interface HubConnectionsubs - Subscriptions-like mapSampExceptionpublic Subscriptions getSubscriptions(java.lang.String clientId) throws SampException
HubConnectiongetSubscriptions in interface HubConnectionclientId - public id for another registered clientSampExceptionpublic java.lang.String[] getRegisteredClients()
throws SampException
HubConnectiongetRegisteredClients in interface HubConnectionSampExceptionpublic java.util.Map getSubscribedClients(java.lang.String mtype)
throws SampException
HubConnectiongetSubscribedClients in interface HubConnectionmtype - MTypemtypeSampException