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 ClientAuthorizerauth_private java.net.URLbaseUrl_private KeyGeneratorkeyGen_private ClientProfileprofile_private java.util.MapregMap_private UrlTrackerurlTracker_private WebHubXmlRpcHandler.URLTranslationHandlerurlTranslator_
-
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 voidallowReverseCallbacks(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.Stringcall(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.MapcallAll(java.lang.String clientKey, java.lang.String msgTag, java.util.Map msg)Sends a message to all subscribed clients expecting responses.java.util.MapcallAndWait(java.lang.String clientKey, java.lang.String recipientId, java.util.Map msg, java.lang.String timeout)Sends a message synchronously to a client.voiddeclareMetadata(java.lang.String clientKey, java.util.Map meta)Declares metadata for the calling client.voiddeclareSubscriptions(java.lang.String clientKey, java.util.Map subs)Declares subscription information for the calling client.private HubConnectiongetConnection(java.lang.String privateKey)Returns the connection object associated with a given private key.java.util.MapgetMetadata(java.lang.String clientKey, java.lang.String clientId)Returns metadata for a given client.java.util.ListgetRegisteredClients(java.lang.String clientKey)Returns a list of the public-ids of all currently registered clients.private WebHubXmlRpcHandler.RegistrationgetRegistration(java.lang.String privateKey)Returns the registration object associated with a given private key.java.util.MapgetSubscribedClients(java.lang.String clientKey, java.lang.String mtype)Returns a map of the clients subscribed to a given MType.java.util.MapgetSubscriptions(java.lang.String clientKey, java.lang.String clientId)Returns subscriptions for a given client.HttpServer.HandlergetUrlTranslationHandler()Returns a handler suitable for performing URL translations on behalf of sandboxed clients as required by the Web Profile.voidnotify(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.ListnotifyAll(java.lang.String clientKey, java.util.Map msg)Sends a message to all subscribed clients without wanting a response.voidping()Throws an exception if service is not operating.voidping(java.lang.String clientKey)Throws an exception if service is not operating.java.util.ListpullCallbacks(java.lang.String clientKey, java.lang.String timeout)Waits for up to a certain length of time for any callbacks to be delivered.RegInforegister(HttpServer.Request request, java.util.Map securityMap)Attempt client registration.voidreply(java.lang.String clientKey, java.lang.String msgId, java.util.Map response)Responds to a previously sent message.voidunregister(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 SampExceptionDescription copied from interface:WebHubActorUnregisters a registered client.- Specified by:
unregisterin interfaceWebHubActor- Parameters:
clientKey- calling client private key- Throws:
SampException
-
allowReverseCallbacks
public void allowReverseCallbacks(java.lang.String clientKey, java.lang.String allow) throws SampExceptionDescription copied from interface:WebHubActorIndicates 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:
allowReverseCallbacksin 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 SampExceptionDescription copied from interface:WebHubActorWaits for up to a certain length of time for any callbacks to be delivered.- Specified by:
pullCallbacksin 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 SampExceptionDescription copied from interface:WebHubActorDeclares metadata for the calling client.- Specified by:
declareMetadatain 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 SampExceptionDescription copied from interface:WebHubActorReturns metadata for a given client.- Specified by:
getMetadatain 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 SampExceptionDescription copied from interface:WebHubActorDeclares subscription information for the calling client.- Specified by:
declareSubscriptionsin 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 SampExceptionDescription copied from interface:WebHubActorReturns subscriptions for a given client.- Specified by:
getSubscriptionsin interfaceWebHubActor- Parameters:
clientKey- calling client private key- Returns:
Subscriptions-like map- Throws:
SampException
-
getRegisteredClients
public java.util.List getRegisteredClients(java.lang.String clientKey) throws SampExceptionDescription copied from interface:WebHubActorReturns a list of the public-ids of all currently registered clients.- Specified by:
getRegisteredClientsin 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 SampExceptionDescription copied from interface:WebHubActorReturns a map of the clients subscribed to a given MType.- Specified by:
getSubscribedClientsin 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 SampExceptionDescription copied from interface:WebHubActorSends a message to a given client without wanting a response.- Specified by:
notifyin 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 SampExceptionDescription copied from interface:WebHubActorSends a message to all subscribed clients without wanting a response.- Specified by:
notifyAllin 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 SampExceptionDescription copied from interface:WebHubActorSends a message to a given client expecting a response.- Specified by:
callin 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 SampExceptionDescription copied from interface:WebHubActorSends a message to all subscribed clients expecting responses.- Specified by:
callAllin 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 SampExceptionDescription copied from interface:WebHubActorSends a message synchronously to a client.- Specified by:
callAndWaitin 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 SampExceptionDescription copied from interface:WebHubActorResponds to a previously sent message.- Specified by:
replyin 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:WebHubActorThrows an exception if service is not operating.- Specified by:
pingin interfaceWebHubActor
-
ping
public void ping(java.lang.String clientKey)
Description copied from interface:WebHubActorThrows an exception if service is not operating.- Specified by:
pingin 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
-
-