Interface ISubscriber<T extends EventListener>
- All Superinterfaces:
AutoCloseable,IConnection,IPropertyFilter,ITopicConnection,IURIConnection
- All Known Implementing Classes:
AMQPSubscriberImpl
This interface is designed to make it easy to listen to all events and easy to listen to a specific scan.
Listen to all events:
IEventService service = ...
IScanSubscriber sub = service.createSubscriber(...)
IScanListener listener = new IScanListener() {
{@literal @}Override
public void scanEventPerformed(ScanEvent evt) {
// Everything that happens ...
}
};
sub.addListener(listener);
Listen to specific events for a given scan:
IScanListener listener2 = new IScanListener() {
{@literal @}Override
public void scanEventPerformed(ScanEvent evt) {
// Everything that happens ...
}
sub.addListener(<b>id</b>, listener2);
}
NOTE: If a listener is registered it will then be associated with the scan it
is registered with only. It should be unregistered and readded. So for
instance:
sub.addListener(id, listener); // registers for id but removes it as general listener.
Removes the Object listener from the general listeners and defines it as a
listener of the id. This listener would have to be readded using
addListener(listener) to use it again as a general listener.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.eclipse.scanning.api.event.core.IPropertyFilter
IPropertyFilter.FilterAction -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(String id, T listener) Register events for a given id to be reported.voidaddListener(T listener) Adds a listener which is notified when events are broadcast.booleanvoidRemoves all listeners without disconnecting from events or stopping the JMS threads.voidremoveListener(String id, T listener) Unregister events for a given id to be reported.voidremoveListener(T listener) Removes a listener such that events are no longer sent to it.voidUnregister all listeners with this id.voidsetSynchronous(boolean sync) Call to set if the events should be ordered and BLOCKING.Methods inherited from interface org.eclipse.scanning.api.event.core.IConnection
close, disconnect, isConnectedMethods inherited from interface org.eclipse.scanning.api.event.core.IPropertyFilter
addProperty, getProperties, removePropertyMethods inherited from interface org.eclipse.scanning.api.event.core.ITopicConnection
getTopicNameMethods inherited from interface org.eclipse.scanning.api.event.core.IURIConnection
getConnectorService, getUri
-
Method Details
-
addListener
Adds a listener which is notified when events are broadcast. The listener works event if the manager is running on a client and the broadcast is happening from a server because through JMS or similar messaging system which this service and manager are hiding.- Parameters:
listener-
-
removeListener
Removes a listener such that events are no longer sent to it.- Parameters:
listener-
-
addListener
Register events for a given id to be reported.- Parameters:
id-listener-
-
removeListener
Unregister events for a given id to be reported.- Parameters:
id-listener-
-
removeListeners
Unregister all listeners with this id.- Parameters:
id-listener-
-
removeAllListeners
void removeAllListeners()Removes all listeners without disconnecting from events or stopping the JMS threads. -
setSynchronous
void setSynchronous(boolean sync) Call to set if the events should be ordered and BLOCKING. The default is true. When synchronous is true events are despatched in order and the event listener method is waited for until it returns before processing more events. If it is false the messaging thread is used to directly depatch the event meaning that more events may occur and be called the last listener has returned. Note: this method must be called before adding any listeners by callingaddListener(EventListener)oraddListener(String, EventListener).- Parameters:
sync-
-
isSynchronous
boolean isSynchronous()- Returns:
- true by default.
-