Package org.astrogrid.samp.hub
Class WrapperHubConnection
- java.lang.Object
-
- org.astrogrid.samp.hub.WrapperHubConnection
-
- All Implemented Interfaces:
HubConnection
- Direct Known Subclasses:
FacadeHubService.FacadeHubConnection
class WrapperHubConnection extends java.lang.Object implements HubConnection
HubConnection implementation that delegates all calls to a base instance.- Since:
- 3 Feb 2011
- Author:
- Mark Taylor
-
-
Field Summary
Fields Modifier and Type Field Description private HubConnection
base_
-
Constructor Summary
Constructors Constructor Description WrapperHubConnection(HubConnection base)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.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.void
setCallable(CallableClient client)
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.
-
-
-
Field Detail
-
base_
private final HubConnection base_
-
-
Constructor Detail
-
WrapperHubConnection
public WrapperHubConnection(HubConnection base)
Constructor.- Parameters:
base
- hub connection to which all calls are delegated
-
-
Method Detail
-
getRegInfo
public RegInfo getRegInfo()
Description copied from interface:HubConnection
Returns the registration information associated with this connection.- Specified by:
getRegInfo
in interfaceHubConnection
- Returns:
- registration info
-
setCallable
public void setCallable(CallableClient client) throws SampException
Description copied from interface:HubConnection
Tells the hub how it can perform callbacks on the client by providing a CallableClient object. This is required before the client can declare subscriptions or make asynchronous calls.- Specified by:
setCallable
in interfaceHubConnection
- Parameters:
client
- callable client- Throws:
SampException
-
ping
public void ping() throws SampException
Description copied from interface:HubConnection
Tests whether the connection is currently open.- Specified by:
ping
in interfaceHubConnection
- Throws:
SampException
- if the hub has disappeared or communications are disrupted in some other way
-
unregister
public void unregister() throws SampException
Description copied from interface:HubConnection
Unregisters the client and terminates this connection.- Specified by:
unregister
in interfaceHubConnection
- Throws:
SampException
-
declareMetadata
public void declareMetadata(java.util.Map meta) throws SampException
Description copied from interface:HubConnection
Declares this registered client's metadata.- Specified by:
declareMetadata
in interfaceHubConnection
- Parameters:
meta
-Metadata
-like map- Throws:
SampException
-
getMetadata
public Metadata getMetadata(java.lang.String clientId) throws SampException
Description copied from interface:HubConnection
Returns the metadata for another registered client.- Specified by:
getMetadata
in interfaceHubConnection
- Parameters:
clientId
- public id for another registered client- Returns:
- metadata map
- Throws:
SampException
-
declareSubscriptions
public void declareSubscriptions(java.util.Map subs) throws SampException
Description copied from interface:HubConnection
Declares this registered client's MType subscriptions.Only permitted if this client is already callable.
- Specified by:
declareSubscriptions
in interfaceHubConnection
- Parameters:
subs
-Subscriptions
-like map- Throws:
SampException
-
getSubscriptions
public Subscriptions getSubscriptions(java.lang.String clientId) throws SampException
Description copied from interface:HubConnection
Returns the subscriptions for another registered client.- Specified by:
getSubscriptions
in interfaceHubConnection
- Parameters:
clientId
- public id for another registered client- Returns:
- subscriptions map
- Throws:
SampException
-
getRegisteredClients
public java.lang.String[] getRegisteredClients() throws SampException
Description copied from interface:HubConnection
Returns the list of client public IDs for those clients currently registered.- Specified by:
getRegisteredClients
in interfaceHubConnection
- Returns:
- array of client ids, excluding the one for this client
- Throws:
SampException
-
getSubscribedClients
public java.util.Map getSubscribedClients(java.lang.String mtype) throws SampException
Description copied from interface:HubConnection
Returns a map of subscriptions for a given MType.- Specified by:
getSubscribedClients
in interfaceHubConnection
- Parameters:
mtype
- MType- Returns:
- map in which the keys are the public IDs of clients subscribed
to
mtype
- Throws:
SampException
-
notify
public void notify(java.lang.String recipientId, java.util.Map msg) throws SampException
Description copied from interface:HubConnection
Sends a message to a given client without wanting a response.- Specified by:
notify
in interfaceHubConnection
- Parameters:
recipientId
- public-id of client to receive messagemsg
-Message
-like map- Throws:
SampException
-
notifyAll
public java.util.List notifyAll(java.util.Map msg) throws SampException
Description copied from interface:HubConnection
Sends a message to all subscribed clients without wanting a response.- Specified by:
notifyAll
in interfaceHubConnection
- Parameters:
msg
-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 recipientId, java.lang.String msgTag, java.util.Map msg) throws SampException
Description copied from interface:HubConnection
Sends a message to a given client expecting a response. ThereceiveResponse
method of this connection'sCallableClient
will be called with a response at some time in the future.Only permitted if this client is already callable.
- Specified by:
call
in interfaceHubConnection
- Parameters:
recipientId
- 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 msgTag, java.util.Map msg) throws SampException
Description copied from interface:HubConnection
Sends a message to all subscribed clients expecting responses. ThereceiveResponse
method of this connection'sCallableClient
will be called with responses at some time in the future.Only permitted if this client is already callable.
- Specified by:
callAll
in interfaceHubConnection
- Parameters:
msgTag
- 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 Response callAndWait(java.lang.String recipientId, java.util.Map msg, int timeout) throws SampException
Description copied from interface:HubConnection
Sends a message synchronously to a client, waiting for the response. If more seconds elapse than the value of thetimeout
parameter, an exception will result.- Specified by:
callAndWait
in interfaceHubConnection
- Parameters:
recipientId
- public-id of client to receive messagemsg
-Message
-like maptimeout
- timeout in seconds, or <0 for no timeout- Returns:
- response
- Throws:
SampException
-
reply
public void reply(java.lang.String msgId, java.util.Map response) throws SampException
Description copied from interface:HubConnection
Supplies a response to a previously received message.- Specified by:
reply
in interfaceHubConnection
- Parameters:
msgId
- ID associated with earlier sendresponse
-Response
-like map- Throws:
SampException
-
-