public class BasicHubService extends Object implements HubService
| Modifier and Type | Field and Description |
|---|---|
static int |
MAX_TIMEOUT
The maximum timeout for a synchronous call permitted in seconds.
|
static int |
MAX_WAITERS
The maximum number of concurrently pending synchronous calls.
|
| Constructor and Description |
|---|
BasicHubService(Random random)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected String |
call(HubClient caller,
String recipientId,
String msgTag,
Map message)
Does the work for the
call method of connections
registered with this service. |
protected Map |
callAll(HubClient caller,
String msgTag,
Map message)
Does the work for the
call method of connections
registered with this service. |
protected Response |
callAndWait(HubClient caller,
String recipientId,
Map message,
int timeout)
Does the work for the
callAndWait method of connections
registered with this service. |
protected HubClient |
createClient(String publicId,
ProfileToken ptoken)
Factory method used to create all the client objects which will
be used by this hub service.
|
protected ClientSet |
createClientSet()
Factory method used to create the client set used by this hub service.
|
protected HubConnection |
createConnection(HubClient caller)
Returns a new HubConnection for use by a given hub client.
|
protected AbstractMessageHandler[] |
createHubMessageHandlers()
Constructs a list of MessageHandlers to use for the client
provided by the Hub.
|
protected void |
declareMetadata(HubClient caller,
Map meta)
Does the work for the
declareMetadata method of connections
registered with this service. |
protected void |
declareSubscriptions(HubClient caller,
Map subscriptions)
Does the work for the
declareSubscriptions method of
connections registered with this service. |
void |
disconnect(String clientId,
String reason)
Forcibly disconnects a given client.
|
void |
disconnectAll(ProfileToken profileToken)
Forcibly terminates any connections created by a previous call of
HubService.register(org.astrogrid.samp.hub.ProfileToken)
with a particular profileToken. |
ClientSet |
getClientSet()
Returns the structure which keeps track of registered clients.
|
Comparator |
getIdComparator()
Returns a comparator which will order client IDs.
|
protected Metadata |
getMetadata(HubClient caller,
String clientId)
Does the work for the
getMetadata method of connections
registered with this service. |
protected String[] |
getRegisteredClients(HubClient caller)
Does the work for the
getRegisteredClients method of
connections registered with this service. |
HubConnection |
getServiceConnection()
Returns the HubConnection object used by the hub itself to send
and receive messages.
|
protected Map |
getSubscribedClients(HubClient caller,
String mtype)
Does the work for the
getSubscribedClients method of
connections registered with this service. |
protected Subscriptions |
getSubscriptions(HubClient caller,
String clientId)
Does the work for the
getSubscriptions method of connections
registered with this service. |
boolean |
isHubRunning()
Indicates whether this hub service is currently open for operations.
|
protected void |
notify(HubClient caller,
String recipientId,
Map message)
Does the work for the
notify method of connections
registered with this service. |
protected List |
notifyAll(HubClient caller,
Map message)
Does the work for the
notifyAll method of connections
registered with this service. |
HubConnection |
register(ProfileToken ptoken)
Creates a new connection to this hub service, thereby initiating
a new registered client.
|
protected void |
reply(HubClient caller,
String msgIdStr,
Map resp)
Does the work for the
reply method of connections
registered with this service. |
protected void |
setCallable(HubClient caller,
CallableClient callable)
Does the work for the
setCallable method of connections
registered with this service. |
void |
shutdown()
Tidies up any resources owned by this object.
|
void |
start()
Begin operation.
|
protected void |
unregister(HubClient caller)
Does the work for the
unregister method of conections
registered with this service. |
public static int MAX_TIMEOUT
public static int MAX_WAITERS
public BasicHubService(Random random)
random - random number generator used for message tags etcpublic void start()
HubServiceHubService.register(org.astrogrid.samp.hub.ProfileToken) method should not be
called until the hub has been started.start in interface HubServiceprotected ClientSet createClientSet()
protected HubClient createClient(String publicId, ProfileToken ptoken)
publicId - client public IDptoken - connection sourceprotected AbstractMessageHandler[] createHubMessageHandlers()
public Comparator getIdComparator()
public ClientSet getClientSet()
public HubConnection register(ProfileToken ptoken) throws SampException
HubServiceIt is the responsibility of the returned connection, not the
user of that connection, to broadcast the various
samp.hub.event.* notifications at the appropriate times.
Most of the HubConnection methods are declared to
throw SampException, however, implementations may
throw unchecked exceptions if that is more convenient;
users of the connection should be prepared to catch these if
they occur.
register in interface HubServiceptoken - identifier for the profile acting as gatekeeper
for this connectionSampExceptionpublic void disconnectAll(ProfileToken profileToken)
HubServiceHubService.register(org.astrogrid.samp.hub.ProfileToken)
with a particular profileToken.
Any necessary hub events will be sent.disconnectAll in interface HubServiceprofileToken - previous argument to registerprotected HubConnection createConnection(HubClient caller)
caller - client requiring a connectioncallerprotected void unregister(HubClient caller) throws SampException
unregister method of conections
registered with this service.caller - client to unregisterSampExceptionHubConnection.unregister()protected void setCallable(HubClient caller, CallableClient callable) throws SampException
setCallable method of connections
registered with this service.caller - clientcallable - callable objectSampExceptionHubConnection.setCallable(org.astrogrid.samp.client.CallableClient)protected void declareMetadata(HubClient caller, Map meta) throws SampException
declareMetadata method of connections
registered with this service.caller - clientmeta - new metadata for clientSampExceptionHubConnection.declareMetadata(java.util.Map)protected Metadata getMetadata(HubClient caller, String clientId) throws SampException
getMetadata method of connections
registered with this service.caller - calling clientclientId - id of client being queriedSampExceptionHubConnection.getMetadata(java.lang.String)protected void declareSubscriptions(HubClient caller, Map subscriptions) throws SampException
declareSubscriptions method of
connections registered with this service.caller - clientsubscriptions - new subscriptions for clientSampExceptionHubConnection.declareSubscriptions(java.util.Map)protected Subscriptions getSubscriptions(HubClient caller, String clientId) throws SampException
getSubscriptions method of connections
registered with this service.caller - calling clientclientId - id of client being queriedSampExceptionHubConnection.getSubscriptions(java.lang.String)protected String[] getRegisteredClients(HubClient caller) throws SampException
getRegisteredClients method of
connections registered with this service.caller - calling clientcaller'sSampExceptionHubConnection.getRegisteredClients()protected Map getSubscribedClients(HubClient caller, String mtype) throws SampException
getSubscribedClients method of
connections registered with this service.caller - calling clientmtype - message typemtypeSampExceptionHubConnection.getSubscribedClients(java.lang.String)protected void notify(HubClient caller, String recipientId, Map message) throws SampException
notify method of connections
registered with this service.caller - calling clientrecipientId - public ID of client to receive messagemessage - messageSampExceptionHubConnection.notify(java.lang.String, java.util.Map)protected String call(HubClient caller, String recipientId, String msgTag, Map message) throws SampException
call method of connections
registered with this service.caller - calling clientrecipientId - client ID of recipientmsgTag - message tagmessage - messageSampExceptionHubConnection.call(java.lang.String, java.lang.String, java.util.Map)protected List notifyAll(HubClient caller, Map message) throws SampException
notifyAll method of connections
registered with this service.caller - calling clientmessage - messageSampExceptionHubConnection.notifyAll(java.util.Map)protected Map callAll(HubClient caller, String msgTag, Map message) throws SampException
call method of connections
registered with this service.caller - calling clientmsgTag - message tagmessage - messageSampExceptionHubConnection.callAll(java.lang.String, java.util.Map)protected void reply(HubClient caller, String msgIdStr, Map resp) throws SampException
reply method of connections
registered with this service.caller - calling clientmsgIdStr - message IDresp - response to forwardSampExceptionHubConnection.reply(java.lang.String, java.util.Map)protected Response callAndWait(HubClient caller, String recipientId, Map message, int timeout) throws SampException
callAndWait method of connections
registered with this service.caller - calling clientrecipientId - client ID of recipientmessage - messagetimeout - timeout in secondsSampExceptionHubConnection.callAndWait(java.lang.String, java.util.Map, int)public HubConnection getServiceConnection()
public void disconnect(String clientId, String reason)
samp.hub.disconnect message to the
client which is about to be ejected, if the client is
subscribed to that MTypesamp.hub.unregister message to all
remaining clients indicating that the client has disappearedclientId - public-id of client to ejectreason - short text string indicating reason for ejectionpublic boolean isHubRunning()
HubServiceisHubRunning in interface HubServiceHubService.start() and HubService.shutdown()public void shutdown()
HubServiceshutdown in interface HubServiceCopyright © 2008–2024. All rights reserved.