Interface IEventService
- All Known Implementing Classes:
EventServiceImpl
IJobQueueencapsulates a queue that beans can be submitted to, and a consumer thread that removes items from the head of the queue and creates and runs a process for them. It also published bean updates to a status topic and can be controlled via a command topic;ISubmitterto submit to a JMS queue.IJmsQueueReaderto read a JMS queue and submit any items found immediately to theIJobQueue.IPublishercan be used to publish to a JMS topic. For example theIJobQueueimplementation uses one to pubilsh bean update to the status topic;ISubscribercan be used to subscribe to a JMS topic. For example this can be used to listen to bean updates from anIJobQueueas the process for a job is run;IRequesterto post a request to a topic and listen for a response.IResponderto listen for requests on a topic and post a response. This
Note that ISubmitter and IJmsQueueReader are legacy interface and should not be used
by new code. IJobQueue replaced IConsumer, which used to consume beans from the head of a JMS queue,
it did not have its own submit method. An ISubmitter was required to submit beans to the tail of the
queue. This is no longer necessary as IJobQueue contains a queue in memory and does have its own
IJobQueue.submit(Object) method - on the client an proxy should be used by calling
createJobQueueProxy(URI, String). Due to existing code still using submitters,
or other mechanisms to submit a bean to a JMS queue to run a job, IJmsQueueReader was developed
as a temporary measure. This works by running a loop consuming items from a JMS queue and immediately
submitting them to the IJobQueue with the same submission queue name.
IEventService service = ... // OSGi
final IEventSubscriber subscriber = service.createSubscriber(...);
IScanListener listener = new IScanListener() { // Listen to any scan
void scanEventPerformed(ScanEvent evt) {
ScanBean scan = evt.getBean();
System.out.println(scan.getName()+" @ "+scan.getPercentComplete());
}
};
subscriber.addScanListener(listener);
// Subscribe to anything
IEventService service = ... // OSGi
final IPublisher publisher = service.createPublisher(...);
final ScanBean scan = new ScanBean(...);
publisher.broadcast(scan);
// An event comes internally that the scan has changed state, so we notify like this:
scan.setPercentComplete(3.14);
publisher.broadcast(scan);
-
Method Summary
Modifier and TypeMethodDescription<T extends EventListener>
ISubscriber<T> createAMQPSubscriber(URI uri, String routingKey) Creates an ISubscriber for an AMQP topic with a given routingKey.<U extends StatusBean>
IJmsQueueReader<U> createJmsQueueReader(URI uri, String submissionQueueName) Create a Jms queue reader.<U extends StatusBean>
IJobQueue<U> createJobQueue(URI uri) Create anIJobQueuewith the default submission queue, status topic and command topic names<U extends StatusBean>
IJobQueue<U> createJobQueue(URI uri, String submissionQueueName, String statusTopicName) Create a consumer with the given submission queue, and status topic names.<U extends StatusBean>
IJobQueue<U> createJobQueue(URI uri, String submissionQueueName, String statusTopicName, String consumerStatusTopicName, String commandTopicName, String commandAckTopicName) Create a job queue with the given submission queue, status queue, status topic, consumer status topic, command topic and command acknowledgement topic names.<U extends StatusBean>
IJobQueue<U> createJobQueueProxy(URI uri, String submissionQueueName) Create a proxy for theIJobQueuefor the given submission queue name, using the default command and command acknowledgement topics.<U extends StatusBean>
IJobQueue<U> createJobQueueProxy(URI uri, String submissionQueueName, String commandTopicName, String commandAckTopicName) Create a proxy for theIJobQueuefor the given submission queue.<U> IPublisher<U> createPublisher(URI uri, String topicName) Creates an IEventPublisher for the topic with the given name.<T> TcreateRemoteService(URI uri, Class<T> serviceClass) Use this call to create a remote service.<T extends IdBean>
IRequester<T> createRequestor(URI uri, String requestTopic, String responseTopic) A poster encapsulates sending and receiving a reply.<T extends IdBean>
IResponder<T> createResponder(URI uri, String requestTopic, String responseTopic) Creates a responder on a given topic.<U extends StatusBean>
ISubmitter<U> createSubmitter(URI uri, String queueName) Create a submitter for adding a bean of type U onto the queue.<T extends EventListener>
ISubscriber<T> createSubscriber(URI uri, String topicName) Creates an ISubscriber for the topic with the given name.voidDisconnect all JMS resources used by allIJobQueues and unregisters them from this service.voiddisposeJobQueue(String submissionQueueName) Disconnect the JMS resources used by theIJobQueuefor the given submission queue name and unregisters it from this service.The current event connector service that this event service is using to talk to messaging and to marshall objects.IJobQueue<? extends StatusBean> getJobQueue(String submissionQueueName) Returns the job queue for the given submission queue name.
-
Method Details
-
createSubscriber
Creates an ISubscriber for the topic with the given name. Useful on the client for adding event listeners to be notified. Scan events have a unique id with which to ascertain if a given scan event came from given scan.- Parameters:
uri- - the location of the JMS broker- Returns:
- IEventManager
-
createAMQPSubscriber
Creates an ISubscriber for an AMQP topic with a given routingKey.- Parameters:
uri- - the location of the JMS broker- Returns:
- IEventManager
-
createPublisher
Creates an IEventPublisher for the topic with the given name.- Parameters:
uri- - the location of the JMS broker- Returns:
- IEventManager
-
createSubmitter
Create a submitter for adding a bean of type U onto the queue.- Parameters:
uri-queueName-- Returns:
- the new submitter
-
createJobQueue
Create anIJobQueuewith the default submission queue, status topic and command topic names- Parameters:
uri-- Returns:
- the new job queue
- Throws:
EventException
-
createJobQueue
<U extends StatusBean> IJobQueue<U> createJobQueue(URI uri, String submissionQueueName, String statusTopicName) throws EventException Create a consumer with the given submission queue, and status topic names.- Parameters:
uri-submissionQueueName- name of the submission queuestatusTopicName-- Returns:
- the new job queue
- Throws:
EventException
-
createJobQueue
<U extends StatusBean> IJobQueue<U> createJobQueue(URI uri, String submissionQueueName, String statusTopicName, String consumerStatusTopicName, String commandTopicName, String commandAckTopicName) throws EventException Create a job queue with the given submission queue, status queue, status topic, consumer status topic, command topic and command acknowledgement topic names.- Parameters:
uri- the uri of the messagesubmissionQueueName-statusTopicName-commandTopicName-commandAckTopicName-- Returns:
- the new job queue
- Throws:
EventException
-
createJmsQueueReader
<U extends StatusBean> IJmsQueueReader<U> createJmsQueueReader(URI uri, String submissionQueueName) throws EventException Create a Jms queue reader. This will read messages from the JMS (ActiveMq) queue with the given name and add it to the submission queue of theIJobQueuewith the same name.- Parameters:
uri-submissionQueueName-- Returns:
- the JMS queue reader
- Throws:
EventException
-
getJobQueue
Returns the job queue for the given submission queue name. For server-side code only! Client-side code should usecreateJobQueueProxy(URI, String).- Parameters:
submissionQueueName-- Returns:
- the consumer for the given queue name
- Throws:
EventException- thrown if no job queue exists for the given queue name.
-
createJobQueueProxy
<U extends StatusBean> IJobQueue<U> createJobQueueProxy(URI uri, String submissionQueueName) throws EventException Create a proxy for theIJobQueuefor the given submission queue name, using the default command and command acknowledgement topics.- Parameters:
uri-submissionQueueName-- Returns:
- a proxy to the job queue for the given queue name
- Throws:
EventException
-
createJobQueueProxy
<U extends StatusBean> IJobQueue<U> createJobQueueProxy(URI uri, String submissionQueueName, String commandTopicName, String commandAckTopicName) throws EventException Create a proxy for theIJobQueuefor the given submission queue. The given command topic and command acknowledgement topic names are used to communicate with the job queue.- Parameters:
uri-submissionQueueName-commandTopicName-commandAckTopicName-- Returns:
- a proxy to the job queue for the given queue name
- Throws:
EventException
-
disposeJobQueue
Disconnect the JMS resources used by theIJobQueuefor the given submission queue name and unregisters it from this service.- Parameters:
submissionQueueName-- Throws:
EventException
-
disposeAllJobQueues
Disconnect all JMS resources used by allIJobQueues and unregisters them from this service.- Throws:
EventException
-
createRequestor
<T extends IdBean> IRequester<T> createRequestor(URI uri, String requestTopic, String responseTopic) throws EventException A poster encapsulates sending and receiving a reply. For instance request a list of detectors on the server. This is the same as creating a broadcaster, sending an object then subscribing to the reply.- Parameters:
uri-requestTopic-responseTopic-- Returns:
- Throws:
EventException
-
createResponder
<T extends IdBean> IResponder<T> createResponder(URI uri, String requestTopic, String responseTopic) throws EventException Creates a responder on a given topic.- Parameters:
uri-requestTopic-responseTopic-- Returns:
- Throws:
EventException
-
getEventConnectorService
IEventConnectorService getEventConnectorService()The current event connector service that this event service is using to talk to messaging and to marshall objects.- Returns:
-
createRemoteService
Use this call to create a remote service. A wrapper will be created around the service such that methods called on the client will cause an event to trigger which has a response generated by the server. The event service caches remote services assuming that each service should exist once.- Parameters:
uri-serviceClass-- Returns:
- Throws:
EventException
-