public abstract class PubSub extends Object
BulletConfig and use the information to wire up and return
Publishers and Subscribers.| Modifier and Type | Class and Description |
|---|---|
static class |
PubSub.Context
The context determines how the
Publisher and Subscriber returned by PubSub behave. |
| Modifier and Type | Field and Description |
|---|---|
protected BulletConfig |
config |
protected PubSub.Context |
context |
| Constructor and Description |
|---|
PubSub(BulletConfig config)
Instantiate a PubSub using parameters from
BulletConfig. |
| Modifier and Type | Method and Description |
|---|---|
static PubSub |
from(BulletConfig config)
Create a PubSub instance using the class specified in the config file.
|
abstract Publisher |
getPublisher()
|
abstract List<Publisher> |
getPublishers(int n)
|
<T> T |
getRequiredConfig(Class<T> clazz,
String name)
A method to get a required configuration of a particular type.
|
abstract Subscriber |
getSubscriber()
Get a
Subscriber instance wired to read from all allocated partitions in the appropriate queue (See
context). |
abstract List<Subscriber> |
getSubscribers(int n)
Get a list of n
Subscriber instances with allocated partitions from the appropriate queue
(See context) split as evenly as possible among them. |
void |
switchContext(PubSub.Context context,
BulletConfig config)
Use this method to switch the
PubSub.Context to another one. |
protected PubSub.Context context
protected BulletConfig config
public PubSub(BulletConfig config) throws PubSubException
BulletConfig.config - A non-null BulletConfig containing all required PubSub parameters.PubSubException - if the context name is not present or cannot be parsed.public void switchContext(PubSub.Context context, BulletConfig config) throws PubSubException
PubSub.Context to another one.context - A different context from the initial one.config - The BulletConfig containing any new required PubSub parameters. This will be merged
with the existing config. Can be null.PubSubException - if the context switch could not be done.public abstract Publisher getPublisher() throws PubSubException
Publisher instance wired to write to all allocated partitions in the appropriate queue (See
context).Publisher wired as required.PubSubException - if the Publisher could not be created.public abstract List<Publisher> getPublishers(int n) throws PubSubException
Publisher instances with the allocated partitions in the appropriate queue
(See context) split as evenly as possible among them.n - The number of Publishers requested.List of n Publishers wired as required.PubSubException - if Publishers could not be created.public abstract Subscriber getSubscriber() throws PubSubException
Subscriber instance wired to read from all allocated partitions in the appropriate queue (See
context).Subscriber wired as required.PubSubException - if the Subscriber could not be created.public abstract List<Subscriber> getSubscribers(int n) throws PubSubException
Subscriber instances with allocated partitions from the appropriate queue
(See context) split as evenly as possible among them.n - The number of Subscribers requested.List of n Subscribers wired as required.PubSubException - if Subscribers could not be created.public static PubSub from(BulletConfig config) throws PubSubException
config - The non-null BulletConfig containing the class name and PubSub settings.PubSubException - if PubSub creation fails.public <T> T getRequiredConfig(Class<T> clazz, String name) throws PubSubException
T - The type to cast the configuration to. Inferred from clazz.name - The name of the required configuration.clazz - The class of the required configuration.PubSubException - if the configuration is missing or cannot be cast to type T.Copyright © 2021. All rights reserved.