public abstract class ServiceCaller extends Caller
ServiceCaller
must incorporate the
logic of handling service responses into the implementation of the abstract
method handleResponse(String, ServiceResponse)
.busResourceURI, owner, theBus
Modifier | Constructor and Description |
---|---|
protected |
ServiceCaller(ModuleContext context)
The default constructor for this class.
|
Modifier and Type | Method and Description |
---|---|
void |
addAvailabilitySubscription(AvailabilitySubscriber subscriber,
ServiceRequest request)
Adds an availability subscription, in other words a listener, to receive
events about the availability of a specified service.
|
void |
busDyingOut(AbstractBus b)
This method is called when the bus is stopped to announce this to the bus
members.
|
ServiceResponse |
call(ServiceRequest request)
The "normal" (synchronous) way of calling a service.
|
ServiceResponse |
call(String request)
This method is a way of calling a service using Turtle Strings as input.
|
abstract void |
communicationChannelBroken()
This abstract method is called for each member of the bus when the bus is
being stopped.
|
ServiceProfile[] |
getAllServices()
A method used to instantly retrieve all services available to this
caller.
|
ServiceProfile[] |
getMatchingService(Service s)
A method used to retrieve a specified service, available to this
ServiceCaller . |
ServiceProfile[] |
getMatchingService(String serviceClassURI)
A method used to retrieve a specified service, available to this
ServiceCaller . |
ServiceProfile[] |
getMatchingService(String[] keywords)
A method used to retrieve a service available to this caller, that
matches the specified keywords.
|
String |
getMyID() |
void |
handleReply(BusMessage m) |
abstract void |
handleResponse(String reqID,
ServiceResponse response)
Will be called automatically in a new thread whenever the response
corresponding to a previous call to
sendRequest(ServiceRequest)
is ready. |
ServiceResponse |
inject(ServiceCall call,
PeerCard receiver)
Can be used to inject a
ServiceCall to the bus. |
ServiceResponse |
inject(ServiceCall call,
String receiver)
Can be used to inject a
ServiceCall to the bus. |
void |
removeAvailabilitySubscription(AvailabilitySubscriber subscriber,
String requestURI)
Removes an availability subscription for this
Caller , which
was previously added using addAvailabilitySubscription
method. |
String |
sendCall(ServiceCall call,
PeerCard receiver) |
String |
sendCall(ServiceCall call,
String receiver) |
String |
sendRequest(ServiceRequest request)
To be used if the caller would like to handle the reply asynchronously
within the method
handleResponse(String, ServiceResponse) , which
will automatically be called in another thread when the response is
ready. |
close, getComment, getLabel, getType, getURI, setComment, setLabel
protected ServiceCaller(ModuleContext context)
context
- The module context where the ServiceBus
is registered.
Note that if no service bus is registered within the passed
ModuleContext
at the time of creation, this
object will not be operational.public final void busDyingOut(AbstractBus b)
BusMember
busDyingOut
in class BusMember
b
- bus on which this member has been registeredBusMember.busDyingOut(AbstractBus)
public ServiceResponse call(ServiceRequest request)
sendRequest(ServiceRequest)
, if you want to handle the response
asynchronously in another thread.NullPointerException
- if request is nullpublic ServiceResponse inject(ServiceCall call, String receiver)
ServiceCall
to the bus. Compared to the
method call(ServiceRequest)
there is no matchmaking; the call
will be sent directly to a given ServiceCallee
. Therefore, this
method should NOT be used directly by applications.call
- the ServiceCall
.receiver
- the PeerCard
of the node that hosts the callee.public ServiceResponse inject(ServiceCall call, PeerCard receiver)
ServiceCall
to the bus. Compared to the
method call(ServiceRequest)
there is no matchmaking; the call
will be sent directly to a given ServiceCallee
. Therefore, this
method should NOT be used directly by applications.call
- the ServiceCall
.receiver
- the URI of the bus member that has registered the matching
ServiceProfile
. Only the identifier of the node that
hosts the callee is used from the bus member URI.public final ServiceResponse call(String request)
request
- the Turtle String which will be converted into
ServiceRequest
public abstract void communicationChannelBroken()
public final void handleReply(BusMessage m)
public abstract void handleResponse(String reqID, ServiceResponse response)
sendRequest(ServiceRequest)
is ready.reqID
- the ID returned by the previous call to
sendRequest(ServiceRequest)
.response
- the expected response.public final String sendRequest(ServiceRequest request)
handleResponse(String, ServiceResponse)
, which
will automatically be called in another thread when the response is
ready.handleResponse(String, ServiceResponse)
for an
unambiguous mapping of responses to requests. Returns null, if
this caller does not have the permission for the given requestNullPointerException
- if the request is nullpublic final String sendCall(ServiceCall call, PeerCard receiver)
public final String sendCall(ServiceCall call, String receiver)
public ServiceProfile[] getAllServices()
public ServiceProfile[] getMatchingService(Service s)
ServiceCaller
.s
- the desired service.public ServiceProfile[] getMatchingService(String serviceClassURI)
ServiceCaller
.serviceClassURI
- the class URI of the desired service.public ServiceProfile[] getMatchingService(String[] keywords)
keywords
- the keywords that should be matched by the service.public void addAvailabilitySubscription(AvailabilitySubscriber subscriber, ServiceRequest request)
subscriber
- the object which will receive events when the appropriate
service registers or unregisters.request
- the request that describes the desired service.public void removeAvailabilitySubscription(AvailabilitySubscriber subscriber, String requestURI)
Caller
, which
was previously added using addAvailabilitySubscription
method.subscriber
- the object which used to receive the events.requestURI
- the service that was being monitored.public String getMyID()
Copyright © 2018 universAAL Consortium. All rights reserved.