|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
public interface IPubSubService
IPubSubService is a centralized publish/subscribe message-dispatching component in IRIS. It is used for the instrumentation and automation of tasks. The IPubSubService facilitates publishing and subscribing to ontology-based message in IRIS. All messages are in relation to some task (also ontology-based) that will be or has been performed.
ITaskPojos) and messages (ITaskMessagePojos) can be conveniently
created using methods from IPubSubUtilities, available via the getUtilities()
method. To create a task instance, use the IPubSubUtilities.newTaskInstance(String)
method, passing in the URI of the task class that you'd like to create. To create a message
instance, use the IPubSubUtilities.newMessageInstance(String) method, passing in the
URI of the message class that you'd like to create.
IInstrumentationMessagePojo instance) that is attached to the specific
task instance (an ITaskPojo). More specifically, if an agent wants to instrument the
completion of a task, it creates an IExecutionSucceededMessagePojo, attaches the
task instance using ITaskMessagePojo.setTaskIs(ITaskPojo), and
publishes it using publish(String, IInstrumentationMessagePojo). Since task
completion instrumentation is common, a utility method
IPubSubUtilities.notifyInstrumentation(String, ITaskPojo)
has been created that does these steps for you.subscribe(String, String, IMessageListener) method, where the first parameter
is a messageSpec String, the second is a taskSpec String, and the third is a callback.
That is, subscriptions are keyed by a messageSpec paired with a taskSpec, where the
messageSpec is the URI of the root message class to which you'll be subscribed,
and taskSpec is the root task class to which you'll be subscribed. When any
instrumentation message is published that is a subtype of the messageSpec and whose
attached task is a subtype of the taskSpec, the subscription will fire and the message
will be routed to the specified IMessageListener callback.subscribe(String, String, String, IMessageListener)
method exists that accepts a filterSpec as the third argument. The filterSpec is a
SPARQL
ASK query where the variable
?MSG is pre-bound to the message URI being applied to the filter at the time
of filtering. If the ASK query succeeds, the subscription fires; otherwise, the
subscription fails.
IControlMessagePojo instance) that
is attached to a specific task instance. When a control message is published, a
"conversation" is started by the publisher and a callback must be provided for
the publisher to receive responses (IResponseMessagePojos) in that conversation.
One of two things can happen next: the executor can either accept or reject the control
message. If the control message is accepted by the executor, the executor will publish
an acceptance message for the specified task. If there is no executor or if the executor
finds the task instance unacceptable (incomplete inputs, invalid inputs, etc.), a
rejection message will be published. If the executor accepts the message, it will
invoke the task and eventually publish a success message or a failure message. A
conversation ends when either a reject, success, or failure message is sent.publish(String, IControlMessagePojo, IMessageListener)
method, passing a callback as the third argument that will fire when response messages
are published in the same conversation. The second way is to use the
publishAndWait(String, IControlMessagePojo, long, java.util.concurrent.TimeUnit)
method, which blocks until either the final message in the conversation is received or
until the specified timeout occurs.IPubSubUtilities.executeAndForget(String, ITaskPojo)
utility method was added. This method creates an IExecuteMessagePojo instance,
attaches the given task, and publishes it with a null callback.subscribe(String, String, IMessageListener), passing IExecuteMessagePojo.URI
for the messageSpec and the URI for the Foo task as the taskSpec.rejectionMessageIs property.failureMessageIs property.
| Nested Class Summary | |
|---|---|
static interface |
IPubSubService.IMessageReceipt
|
static interface |
IPubSubService.ISubscription
Describes subscription data for a message listener. |
| Method Summary | |
|---|---|
void |
addSubscriptionListener(ISubscriptionListener listener)
Adds a listener to receive a notification when subscriptions are made. |
Map<Pair<String,String>,List<String>> |
getAllSubscriptions()
Returns subscriptions to all message/task pairs. |
Map<Pair<String,String>,String> |
getControlSubscriptions()
Returns all subscriptions to control messages. |
Map<Pair<String,String>,List<String>> |
getInstrumentationSubscriptions()
Returns all subscriptions to instrumentation messages. |
IPubSubUtilities |
getUtilities()
Get a singleton utility instance, useful for creating messages and tasks. |
boolean |
hasSubscription(String messageSpec,
String taskSpec)
Determines if there are any subscribers to messages. |
IPubSubService.IMessageReceipt |
publish(String publisherURI,
IControlMessagePojo message,
IMessageListener responseCallback)
Publishes a control message to all known subscribers. |
IPubSubService.IMessageReceipt |
publish(String publisherURI,
IInstrumentationMessagePojo message)
Publishes an instrumentation message to all known subscribers. |
IPubSubService.IMessageReceipt |
publish(String publisherURI,
String messageSpec,
String serializationSpec,
byte[] message,
IExternalMessageListener responseCallback,
String responseSerialSpec,
Object responseContentSpec)
Publishes a message to all known subscribers. |
IResponseMessagePojo |
publishAndWait(String publisherURI,
IControlMessagePojo message,
long timeOut,
TimeUnit timeUnit)
Publish a control message and wait for a final response messages. |
void |
removeSubscriptionListener(ISubscriptionListener listener)
Removes a listener from receiving a notification when subscriptions are made. |
List<IPubSubService.ISubscription> |
subscribe(String messageSpec,
String taskSpec,
IMessageListener callback)
Equivalent to subscribe(messageSpec, taskSpec, null, callback). |
List<IPubSubService.ISubscription> |
subscribe(String messageSpec,
String taskSpec,
String filterSpec,
IMessageListener callback)
Subscribe to the given messageSpec/taskSpec pair (all applicable message/task classes), using the specified filterSpec to filter callbacks and the specified callback to receive subscription notifications. |
List<IPubSubService.ISubscription> |
subscribe(String messageSpec,
String taskSpec,
String filterSpec,
String serializationSpec,
Object contentSpec,
IExternalMessageListener callback)
Adds a subscriber for an message/task pair. |
void |
unsubscribe(String messageSpec,
String taskSpec,
IMessageListener callback)
|
void |
unsubscribe(String messageSpec,
String taskSpec,
String filterSpec,
IMessageListener callback)
|
void |
unsubscribe(String messageSpec,
String taskSpec,
String filterSpec,
String serializationSpec,
Object contentSpec,
IExternalMessageListener callback)
|
| Method Detail |
|---|
void addSubscriptionListener(ISubscriptionListener listener)
listener - the listener to notify when a subscription is madevoid removeSubscriptionListener(ISubscriptionListener listener)
listener - the listener to stop notifying when a subscription is madeMap<Pair<String,String>,String> getControlSubscriptions()
Map<Pair<String,String>,List<String>> getInstrumentationSubscriptions()
Map<Pair<String,String>,List<String>> getAllSubscriptions()
boolean hasSubscription(String messageSpec,
String taskSpec)
true if any subscribers exist for the input message/task pair
(regardless of any filter), and false if there are no subscribers.IPubSubUtilities getUtilities()
IPubSubService.IMessageReceipt publish(String publisherURI,
IInstrumentationMessagePojo message)
publisherURI - message - the message instance to send to applicable subscribers.
IPubSubService.IMessageReceipt publish(String publisherURI,
IControlMessagePojo message,
IMessageListener responseCallback)
responseCallback argument is used in such
auto-subscriptions and must be provided if responses are desired.
The filterSpec used for auto-subscriptions is as follows, where <TASK_ID> is replaced
with the URI of the task instance being controlled:
ASK {
?MSG <http://calo.sri.com/psMessages#taskIs> <TASK_ID>
}
publisherURI - message - the message instance to send to subscribersresponseCallback - the callback to use when autosubscribing for responses to this control message
IResponseMessagePojo publishAndWait(String publisherURI,
IControlMessagePojo message,
long timeOut,
TimeUnit timeUnit)
publisherURI - message - ControlMessage to publishtimeOut - timeout periodtimeUnit - TimeUnit for timeout periods
IPubSubService.IMessageReceipt publish(String publisherURI,
String messageSpec,
String serializationSpec,
byte[] message,
IExternalMessageListener responseCallback,
String responseSerialSpec,
Object responseContentSpec)
throws KBSerializationException
publish(String,IInstrumentationMessagePojo) or publish(String,IControlMessagePojo,IMessageListener),
except the message is read from a serialized format.
messageSpec - the message class URIserializationSpec - described the format of the serialized messagemessage - the message in serialized formresponseCallback - if the message is a control message and responses are desired,
the responses will be fed back over this callback.responseSerialSpec - if the message is a control message and responses are desired,
the responses will be serialized in this formatresponseContentSpec - if the message is a control message and responses are desired,
the responses will use this contentSpec
KBSerializationException - if an error occurs while deserializing the event
List<IPubSubService.ISubscription> subscribe(String messageSpec,
String taskSpec,
IMessageListener callback)
subscribe(messageSpec, taskSpec, null, callback).
This method is a convenience for apps who want to subscribe to a messageSpec/taskSpec
pair without any filtering (a common case).
List<IPubSubService.ISubscription> subscribe(String messageSpec,
String taskSpec,
String filterSpec,
IMessageListener callback)
messageSpec - the root message URI for subscription.taskSpec - the root task URI for subscription.filterSpec - the SPARQL ASK query used to filter messages for this subscription, where the var
?MSG is pre-bound to the message being filtered.callback - callback to call when the event is triggered. Note that the callback may also be an
instanceof IExternalMessageListener.
List<IPubSubService.ISubscription> subscribe(String messageSpec,
String taskSpec,
String filterSpec,
String serializationSpec,
Object contentSpec,
IExternalMessageListener callback)
messageSpec - the root message URI for subscription.taskSpec - the root task URI for subscription.filterSpec - the SPARQL ASK query used to filter messages for this subscription, where the var
?MSG is pre-bound to the message being filtered.serializationSpec - see the configuration bean for the knowledge base for supported serialization specscontentSpec - see the configuration bean for the knowledge base for supported content specscallback - callback to call when the event is triggered. Note that the callback may also be an
instanceof IExternalMessageListener.
subscribe(String,String,IMessageListener),
IExternalMessageListener
void unsubscribe(String messageSpec,
String taskSpec,
IMessageListener callback)
void unsubscribe(String messageSpec,
String taskSpec,
String filterSpec,
IMessageListener callback)
void unsubscribe(String messageSpec,
String taskSpec,
String filterSpec,
String serializationSpec,
Object contentSpec,
IExternalMessageListener callback)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||