Package org.nuxeo.runtime.pubsub
Class PubSubServiceImpl
- java.lang.Object
-
- org.nuxeo.runtime.model.DefaultComponent
-
- org.nuxeo.runtime.pubsub.PubSubServiceImpl
-
- All Implemented Interfaces:
Adaptable
,Component
,Extensible
,PubSubService
,TimestampedService
public class PubSubServiceImpl extends DefaultComponent implements PubSubService
Implementation for the Publish/Subscribe Service.- Since:
- 9.1
-
-
Field Summary
Fields Modifier and Type Field Description static String
GLOBAL_PUBLISH_COUNTER
protected io.dropwizard.metrics5.Counter
globalPublishCount
protected Map<String,String>
options
protected PubSubProvider
provider
The currently-configured provider.protected Map<String,List<BiConsumer<String,byte[]>>>
subscribers
List of subscribers for each topic.static String
XP_CONFIG
-
Fields inherited from class org.nuxeo.runtime.model.DefaultComponent
lastModified, name
-
-
Constructor Summary
Constructors Constructor Description PubSubServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
deactivate(ComponentContext context)
Deactivates the component.int
getApplicationStartedOrder()
The component notification order forComponent.applicationStarted(org.nuxeo.runtime.model.ComponentContext)
.void
publish(String topic, byte[] message)
Publishes a message to the given topic.void
registerSubscriber(String topic, BiConsumer<String,byte[]> subscriber)
Registers a subscriber for the given topic.void
start(ComponentContext context)
Start the component.void
stop(ComponentContext context)
Stop the component.void
unregisterSubscriber(String topic, BiConsumer<String,byte[]> subscriber)
Unregisters a subscriber for the given topic.-
Methods inherited from class org.nuxeo.runtime.model.DefaultComponent
activate, addRuntimeMessage, addRuntimeMessage, getAdapter, getDescriptor, getDescriptors, getLastModified, getRegistry, register, registerContribution, registerExtension, setLastModified, setModifiedNow, setName, unregister, unregisterContribution, unregisterExtension
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.nuxeo.runtime.model.Component
applicationStarted
-
-
-
-
Field Detail
-
XP_CONFIG
public static final String XP_CONFIG
- See Also:
- Constant Field Values
-
GLOBAL_PUBLISH_COUNTER
public static final String GLOBAL_PUBLISH_COUNTER
-
provider
protected PubSubProvider provider
The currently-configured provider.
-
subscribers
protected Map<String,List<BiConsumer<String,byte[]>>> subscribers
List of subscribers for each topic.
-
globalPublishCount
protected io.dropwizard.metrics5.Counter globalPublishCount
-
-
Method Detail
-
deactivate
public void deactivate(ComponentContext context)
Description copied from interface:Component
Deactivates the component.This method is called by the runtime when a component is deactivated.
- Specified by:
deactivate
in interfaceComponent
- Overrides:
deactivate
in classDefaultComponent
- Parameters:
context
- the runtime context
-
start
public void start(ComponentContext context)
Description copied from interface:Component
Start the component. This method is called after all the components were resolved and activated- Specified by:
start
in interfaceComponent
- Overrides:
start
in classDefaultComponent
-
stop
public void stop(ComponentContext context) throws InterruptedException
Description copied from interface:Component
Stop the component.- Specified by:
stop
in interfaceComponent
- Overrides:
stop
in classDefaultComponent
- Throws:
InterruptedException
-
getApplicationStartedOrder
public int getApplicationStartedOrder()
Description copied from interface:Component
The component notification order forComponent.applicationStarted(org.nuxeo.runtime.model.ComponentContext)
.Components are notified in increasing order. Order 1000 is the default order for components that don't care. Order 100 is the repository initialization.
- Specified by:
getApplicationStartedOrder
in interfaceComponent
- Returns:
- the order, 1000 by default
-
publish
public void publish(String topic, byte[] message)
Description copied from interface:PubSubService
Publishes a message to the given topic.- Specified by:
publish
in interfacePubSubService
- Parameters:
topic
- the topicmessage
- the message
-
registerSubscriber
public void registerSubscriber(String topic, BiConsumer<String,byte[]> subscriber)
Description copied from interface:PubSubService
Registers a subscriber for the given topic.The subscriber must deal with the message without delay and return immediately, usually by storing it in a thread-safe datastructure.
- Specified by:
registerSubscriber
in interfacePubSubService
- Parameters:
topic
- the topicsubscriber
- the subscriber, who will receive the topic and abyte[]
message
-
unregisterSubscriber
public void unregisterSubscriber(String topic, BiConsumer<String,byte[]> subscriber)
Description copied from interface:PubSubService
Unregisters a subscriber for the given topic.- Specified by:
unregisterSubscriber
in interfacePubSubService
- Parameters:
topic
- the topicsubscriber
- the subscriber
-
-