Package org.astrogrid.samp.web
Class WebHubXmlRpcHandler.WebHubActorImpl
- java.lang.Object
-
- org.astrogrid.samp.web.WebHubXmlRpcHandler.WebHubActorImpl
-
- All Implemented Interfaces:
WebHubActor
- Enclosing class:
- WebHubXmlRpcHandler
private static class WebHubXmlRpcHandler.WebHubActorImpl extends java.lang.Object implements WebHubActor
WebHubActor implementation.
-
-
Field Summary
Fields Modifier and Type Field Description private ClientAuthorizer
auth_
private java.net.URL
baseUrl_
private KeyGenerator
keyGen_
private ClientProfile
profile_
private java.util.Map
regMap_
private UrlTracker
urlTracker_
private WebHubXmlRpcHandler.URLTranslationHandler
urlTranslator_
-
Constructor Summary
Constructors Constructor Description WebHubActorImpl(ClientProfile profile, ClientAuthorizer auth, KeyGenerator keyGen, java.net.URL baseUrl, UrlTracker urlTracker)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
allowReverseCallbacks(java.lang.String clientKey, java.lang.String allow)
Indicates that the client will or will not be callingWebHubActor.pullCallbacks(java.lang.String, java.lang.String)
to receive callable client-type callbacks until further notice.java.lang.String
call(java.lang.String clientKey, 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 clientKey, java.lang.String msgTag, java.util.Map msg)
Sends a message to all subscribed clients expecting responses.java.util.Map
callAndWait(java.lang.String clientKey, java.lang.String recipientId, java.util.Map msg, java.lang.String timeout)
Sends a message synchronously to a client.void
declareMetadata(java.lang.String clientKey, java.util.Map meta)
Declares metadata for the calling client.void
declareSubscriptions(java.lang.String clientKey, java.util.Map subs)
Declares subscription information for the calling client.private HubConnection
getConnection(java.lang.String privateKey)
Returns the connection object associated with a given private key.java.util.Map
getMetadata(java.lang.String clientKey, java.lang.String clientId)
Returns metadata for a given client.java.util.List
getRegisteredClients(java.lang.String clientKey)
Returns a list of the public-ids of all currently registered clients.private WebHubXmlRpcHandler.Registration
getRegistration(java.lang.String privateKey)
Returns the registration object associated with a given private key.java.util.Map
getSubscribedClients(java.lang.String clientKey, java.lang.String mtype)
Returns a map of the clients subscribed to a given MType.java.util.Map
getSubscriptions(java.lang.String clientKey, java.lang.String clientId)
Returns subscriptions for a given client.HttpServer.Handler
getUrlTranslationHandler()
Returns a handler suitable for performing URL translations on behalf of sandboxed clients as required by the Web Profile.void
notify(java.lang.String clientKey, java.lang.String recipientId, java.util.Map msg)
Sends a message to a given client without wanting a response.java.util.List
notifyAll(java.lang.String clientKey, java.util.Map msg)
Sends a message to all subscribed clients without wanting a response.void
ping()
Throws an exception if service is not operating.void
ping(java.lang.String clientKey)
Throws an exception if service is not operating.java.util.List
pullCallbacks(java.lang.String clientKey, java.lang.String timeout)
Waits for up to a certain length of time for any callbacks to be delivered.RegInfo
register(HttpServer.Request request, java.util.Map securityMap)
Attempt client registration.void
reply(java.lang.String clientKey, java.lang.String msgId, java.util.Map response)
Responds to a previously sent message.void
unregister(java.lang.String clientKey)
Unregisters a registered client.
-
-
-
Field Detail
-
profile_
private final ClientProfile profile_
-
auth_
private final ClientAuthorizer auth_
-
keyGen_
private final KeyGenerator keyGen_
-
regMap_
private final java.util.Map regMap_
-
urlTranslator_
private final WebHubXmlRpcHandler.URLTranslationHandler urlTranslator_
-
baseUrl_
private final java.net.URL baseUrl_
-
urlTracker_
private final UrlTracker urlTracker_
-
-
Constructor Detail
-
WebHubActorImpl
public WebHubActorImpl(ClientProfile profile, ClientAuthorizer auth, KeyGenerator keyGen, java.net.URL baseUrl, UrlTracker urlTracker)
Constructor.- Parameters:
profile
- hub connection factoryauth
- client authorizerkeyGen
- key generator for private keysbaseUrl
- HTTP server base URLurlTracker
- controls access to translated URLs, may be null for no control
-
-
Method Detail
-
getUrlTranslationHandler
public HttpServer.Handler getUrlTranslationHandler()
Returns a handler suitable for performing URL translations on behalf of sandboxed clients as required by the Web Profile.- Returns:
- url translation handler
-
register
public RegInfo register(HttpServer.Request request, java.util.Map securityMap) throws SampException
Attempt client registration. An exception is thrown if registration fails for any reason.- Parameters:
request
- HTTP request from applicantsecurityMap
- map of required security information supplied by applicant- Returns:
- registration information if registration is successful
- Throws:
SampException
-
unregister
public void unregister(java.lang.String clientKey) throws SampException
Description copied from interface:WebHubActor
Unregisters a registered client.- Specified by:
unregister
in interfaceWebHubActor
- Parameters:
clientKey
- calling client private key- Throws:
SampException
-
allowReverseCallbacks
public void allowReverseCallbacks(java.lang.String clientKey, java.lang.String allow) throws SampException
Description copied from interface:WebHubActor
Indicates that the client will or will not be callingWebHubActor.pullCallbacks(java.lang.String, java.lang.String)
to receive callable client-type callbacks until further notice.- Specified by:
allowReverseCallbacks
in interfaceWebHubActor
- Parameters:
clientKey
- calling client private keyallow
- flag indicating that the client will/will not be pulling callbacks, encoded as a SAMP boolean ("1"/"0")- Throws:
SampException
-
pullCallbacks
public java.util.List pullCallbacks(java.lang.String clientKey, java.lang.String timeout) throws SampException
Description copied from interface:WebHubActor
Waits for up to a certain length of time for any callbacks to be delivered.- Specified by:
pullCallbacks
in interfaceWebHubActor
- Parameters:
clientKey
- calling client private keytimeout
- timeout in seconds encoded as a SAMP int- Returns:
- list of
Callback
-like maps ready for processing by the client; may be empty if none are ready - Throws:
SampException
-
declareMetadata
public void declareMetadata(java.lang.String clientKey, java.util.Map meta) throws SampException
Description copied from interface:WebHubActor
Declares metadata for the calling client.- Specified by:
declareMetadata
in interfaceWebHubActor
- Parameters:
clientKey
- calling client private keymeta
-Metadata
-like map- Throws:
SampException
-
getMetadata
public java.util.Map getMetadata(java.lang.String clientKey, java.lang.String clientId) throws SampException
Description copied from interface:WebHubActor
Returns metadata for a given client.- Specified by:
getMetadata
in interfaceWebHubActor
- Parameters:
clientKey
- calling client private keyclientId
- public ID for client whose metadata is required- Returns:
Metadata
-like map- Throws:
SampException
-
declareSubscriptions
public void declareSubscriptions(java.lang.String clientKey, java.util.Map subs) throws SampException
Description copied from interface:WebHubActor
Declares subscription information for the calling client.- Specified by:
declareSubscriptions
in interfaceWebHubActor
- Parameters:
clientKey
- calling client private keysubs
-Subscriptions
-like map- Throws:
SampException
-
getSubscriptions
public java.util.Map getSubscriptions(java.lang.String clientKey, java.lang.String clientId) throws SampException
Description copied from interface:WebHubActor
Returns subscriptions for a given client.- Specified by:
getSubscriptions
in interfaceWebHubActor
- Parameters:
clientKey
- calling client private key- Returns:
Subscriptions
-like map- Throws:
SampException
-
getRegisteredClients
public java.util.List getRegisteredClients(java.lang.String clientKey) throws SampException
Description copied from interface:WebHubActor
Returns a list of the public-ids of all currently registered clients.- Specified by:
getRegisteredClients
in interfaceWebHubActor
- Parameters:
clientKey
- calling client private key- Returns:
- list of Strings
- Throws:
SampException
-
getSubscribedClients
public java.util.Map getSubscribedClients(java.lang.String clientKey, java.lang.String mtype) throws SampException
Description copied from interface:WebHubActor
Returns a map of the clients subscribed to a given MType.- Specified by:
getSubscribedClients
in interfaceWebHubActor
- Parameters:
clientKey
- calling client private keymtype
- MType of interest- Returns:
- map in which the keys are the public-ids of clients subscribed
to
mtype
- Throws:
SampException
-
notify
public void notify(java.lang.String clientKey, java.lang.String recipientId, java.util.Map msg) throws SampException
Description copied from interface:WebHubActor
Sends a message to a given client without wanting a response.- Specified by:
notify
in interfaceWebHubActor
- Parameters:
clientKey
- calling client private keyrecipientId
- public-id of client to receive messagemsg
-Message
-like map- Throws:
SampException
-
notifyAll
public java.util.List notifyAll(java.lang.String clientKey, java.util.Map msg) throws SampException
Description copied from interface:WebHubActor
Sends a message to all subscribed clients without wanting a response.- Specified by:
notifyAll
in interfaceWebHubActor
- Parameters:
clientKey
- calling client private keymsg
-Message
-like map- Returns:
- list of public-ids for clients to which the notify will be sent
- Throws:
SampException
-
call
public java.lang.String call(java.lang.String clientKey, java.lang.String recipientId, java.lang.String msgTag, java.util.Map msg) throws SampException
Description copied from interface:WebHubActor
Sends a message to a given client expecting a response.- Specified by:
call
in interfaceWebHubActor
- Parameters:
clientKey
- calling client private keyrecipientId
- public-id of client to receive messagemsgTag
- arbitrary string tagging this message for caller's benefitmsg
-Message
-like map- Returns:
- message ID
- Throws:
SampException
-
callAll
public java.util.Map callAll(java.lang.String clientKey, java.lang.String msgTag, java.util.Map msg) throws SampException
Description copied from interface:WebHubActor
Sends a message to all subscribed clients expecting responses.- Specified by:
callAll
in interfaceWebHubActor
- Parameters:
clientKey
- calling client private keymsgTag
- arbitrary string tagging this message for caller's benefitmsg
-Message
-like map- Returns:
- public-id->msg-id map for clients to which an attempt to send the call will be made
- Throws:
SampException
-
callAndWait
public java.util.Map callAndWait(java.lang.String clientKey, java.lang.String recipientId, java.util.Map msg, java.lang.String timeout) throws SampException
Description copied from interface:WebHubActor
Sends a message synchronously to a client.- Specified by:
callAndWait
in interfaceWebHubActor
- Parameters:
clientKey
- calling client private keyrecipientId
- public-id of client to receive messagemsg
-Message
-like maptimeout
- timeout in seconds encoded as a SAMP int- Returns:
Response
-like map- Throws:
SampException
-
reply
public void reply(java.lang.String clientKey, java.lang.String msgId, java.util.Map response) throws SampException
Description copied from interface:WebHubActor
Responds to a previously sent message.- Specified by:
reply
in interfaceWebHubActor
- Parameters:
clientKey
- calling client private keymsgId
- ID associated with earlier sendresponse
-Response
-like map- Throws:
SampException
-
ping
public void ping()
Description copied from interface:WebHubActor
Throws an exception if service is not operating.- Specified by:
ping
in interfaceWebHubActor
-
ping
public void ping(java.lang.String clientKey)
Description copied from interface:WebHubActor
Throws an exception if service is not operating.- Specified by:
ping
in interfaceWebHubActor
- Parameters:
clientKey
- ignored
-
getRegistration
private WebHubXmlRpcHandler.Registration getRegistration(java.lang.String privateKey) throws SampException
Returns the registration object associated with a given private key.- Parameters:
privateKey
- private key string known by client and hub to identify the connection- Returns:
- registration object for client with key
privateKey
- Throws:
SampException
- if no client is known with that private key
-
getConnection
private HubConnection getConnection(java.lang.String privateKey) throws SampException
Returns the connection object associated with a given private key.- Parameters:
privateKey
- private key string known by client and hub to identify the connection- Returns:
- connection object for client with key
privateKey
- Throws:
SampException
- if no client is known with that private key
-
-