public class ConfigSubscriber extends Object
ConfigSource
for the configs
that will be used when subscribe(Class, String)
is called.
subscribe(Class, String)
on the configs needed, call nextConfig(long)
and get the config from the
ConfigHandle
which subscribe(Class, String)
returned.Modifier and Type | Class and Description |
---|---|
static interface |
ConfigSubscriber.SingleSubscriber<T extends com.yahoo.config.ConfigInstance>
Convenience interface for clients who only subscribe to one config.
|
protected static class |
ConfigSubscriber.State
The states of the subscriber.
|
Modifier and Type | Field and Description |
---|---|
private long |
generation |
private Logger |
log |
protected Map<ConfigSourceSet,com.yahoo.config.subscription.impl.JRTConfigRequester> |
requesters
Reuse requesters for equal source sets, limit number if many subscriptions.
|
private ConfigSource |
source |
private ConfigSubscriber.State |
state |
protected List<ConfigHandle<? extends com.yahoo.config.ConfigInstance>> |
subscriptionHandles |
Constructor and Description |
---|
ConfigSubscriber()
Constructs a new subscriber.
|
ConfigSubscriber(ConfigSource source)
Constructs a new subscriber with the given source.
|
Modifier and Type | Method and Description |
---|---|
private boolean |
acquireSnapshot(long timeoutInMillis,
boolean requireChange)
Acquire a snapshot of all configs with the same generation within a timeout.
|
protected void |
checkStateBeforeSubscribe() |
void |
close()
Closes all open
ConfigSubscription s |
protected void |
closeRequesters()
Closes all open requesters
|
protected void |
finalize()
Finalizer to ensure that we do not leak resources on reconfig.
|
long |
getGeneration()
The current generation of configs known by this subscriber.
|
ConfigSource |
getSource()
The source used by this subscriber.
|
boolean |
isClosed() |
private void |
markSubsChangedSeen() |
boolean |
nextConfig()
Use this for waiting for a new config that has changed.
|
boolean |
nextConfig(long timeoutMillis)
Use this for waiting for a new config that has changed, with the given timeout.
|
boolean |
nextGeneration()
Use this for waiting for a new config generation.
|
boolean |
nextGeneration(long timeoutMillis)
Use this for waiting for a new config generation, with the given timeout
Returns true if:
It is the first time nextGeneration() is called on this subscriber, and the framework has fetched config for all subscriptions.
|
void |
reload(long generation)
Sets all subscriptions under this subscriber to have the given generation.
|
Map<ConfigSourceSet,com.yahoo.config.subscription.impl.JRTConfigRequester> |
requesters()
Implementation detail, do not use.
|
private void |
sleep() |
Thread |
startConfigThread(Runnable runnable)
Convenience method to start a daemon thread called "Vespa config thread" with the given runnable.
|
protected ConfigSubscriber.State |
state() |
<T extends com.yahoo.config.ConfigInstance> |
subscribe(Class<T> configClass,
String configId)
Subscribes on the given type of
ConfigInstance with the given config id. |
(package private) <T extends com.yahoo.config.ConfigInstance> |
subscribe(Class<T> configClass,
String configId,
ConfigSource source,
com.yahoo.vespa.config.TimingValues timingValues) |
<T extends com.yahoo.config.ConfigInstance> |
subscribe(Class<T> configClass,
String configId,
long timeoutMillis)
Subscribes on the given type of
ConfigInstance with the given config id and subscribe timeout. |
<T extends com.yahoo.config.ConfigInstance> |
subscribe(ConfigSubscriber.SingleSubscriber<T> singleSubscriber,
Class<T> configClass,
String configId)
Use this convenience method if you only want to subscribe on one config, and want generic error handling.
|
protected void |
subscribeAndHandleErrors(com.yahoo.config.subscription.impl.ConfigSubscription<?> sub,
com.yahoo.vespa.config.ConfigKey<?> configKey,
ConfigHandle<?> handle,
com.yahoo.vespa.config.TimingValues timingValues) |
protected void |
throwIfExceptionSet(com.yahoo.config.subscription.impl.ConfigSubscription<? extends com.yahoo.config.ConfigInstance> sub)
If a
ConfigSubscription has its exception set, reset that field and throw it |
String |
toString() |
private Logger log
private ConfigSubscriber.State state
protected List<ConfigHandle<? extends com.yahoo.config.ConfigInstance>> subscriptionHandles
private final ConfigSource source
private long generation
protected Map<ConfigSourceSet,com.yahoo.config.subscription.impl.JRTConfigRequester> requesters
public ConfigSubscriber()
public ConfigSubscriber(ConfigSource source)
source
- a ConfigSource
that will be used when subscribe(Class, String)
is called.public <T extends com.yahoo.config.ConfigInstance> ConfigHandle<T> subscribe(Class<T> configClass, String configId)
ConfigInstance
with the given config id.
The method blocks until the first config is ready to be fetched with nextConfig()
.configClass
- The class, typically generated from a def-file using config-class-pluginconfigId
- Identifies the service in vespa-services.xml, or null if you are using a local ConfigSource
which does not use config id.
Also supported: raw:, file:, dir: or jar: config id which addresses config locally in the same way.public <T extends com.yahoo.config.ConfigInstance> ConfigHandle<T> subscribe(Class<T> configClass, String configId, long timeoutMillis)
ConfigInstance
with the given config id and subscribe timeout.
The method blocks until the first config is ready to be fetched with nextConfig()
.configClass
- The class, typically generated from a def-file using config-class-pluginconfigId
- Identifies the service in vespa-services.xml, or possibly raw:, file:, dir: or jar: type config which addresses config locally.timeoutMillis
- The time to wait for a config to become available, in milliseconds<T extends com.yahoo.config.ConfigInstance> ConfigHandle<T> subscribe(Class<T> configClass, String configId, ConfigSource source, com.yahoo.vespa.config.TimingValues timingValues)
protected void checkStateBeforeSubscribe()
protected void subscribeAndHandleErrors(com.yahoo.config.subscription.impl.ConfigSubscription<?> sub, com.yahoo.vespa.config.ConfigKey<?> configKey, ConfigHandle<?> handle, com.yahoo.vespa.config.TimingValues timingValues)
public boolean nextConfig()
ConfigHandle.isChanged()
on the handle you got from subscribe(Class, String)
.
If the call times out (timeout 1000 ms), no handle will have the changed flag set. You should not configure anything then.ConfigInterruptedException
- if thread performing this call interrupted.public boolean nextConfig(long timeoutMillis)
ConfigHandle.isChanged()
on the handle you got from subscribe(Class, String)
.
If the call times out, no handle will have the changed flag set. You should not configure anything then.timeoutMillis
- timeout in millisecondsConfigInterruptedException
- if thread performing this call interrupted.public boolean nextGeneration()
ConfigHandle.isChanged()
on the handle you got from subscribe(Class, String)
.
If the call times out (timeout 1000 ms), no handle will have the changed flag set. You should not configure anything then.ConfigInterruptedException
- if thread performing this call interrupted.public boolean nextGeneration(long timeoutMillis)
ConfigHandle.isChanged()
on the handle you got from subscribe(Class, String)
.
If the call times out (timeout 1000 ms), no handle will have the changed flag set. You should not configure anything then.timeoutMillis
- timeout in millisecondsConfigInterruptedException
- if thread performing this call interrupted.private boolean acquireSnapshot(long timeoutInMillis, boolean requireChange)
timeoutInMillis
- timeout to wait in millisecondsrequireChange
- if set, at least one config have to changerequireChange
is true), false otherwiseprivate void sleep()
protected void throwIfExceptionSet(com.yahoo.config.subscription.impl.ConfigSubscription<? extends com.yahoo.config.ConfigInstance> sub)
ConfigSubscription
has its exception set, reset that field and throw itsub
- ConfigSubscription
private void markSubsChangedSeen()
public void close()
ConfigSubscription
sprotected void closeRequesters()
public Thread startConfigThread(Runnable runnable)
ConfigSubscriber
or ConfigHandle
you have declared locally outside, declare them as final to make it work.runnable
- a class implementing Runnable
protected ConfigSubscriber.State state()
public void reload(long generation)
generation
- a generation numberpublic ConfigSource getSource()
ConfigSource
used by this subscriberpublic Map<ConfigSourceSet,com.yahoo.config.subscription.impl.JRTConfigRequester> requesters()
public boolean isClosed()
public <T extends com.yahoo.config.ConfigInstance> ConfigHandle<T> subscribe(ConfigSubscriber.SingleSubscriber<T> singleSubscriber, Class<T> configClass, String configId)
ConfigSubscriber.SingleSubscriber
and pass to this method.
You will get initial config, and a config thread will be started. The method will throw in your thread if initial
configuration fails, and the config thread will print a generic error message (but continue) if it fails thereafter. The config
thread will stop if you close()
this ConfigSubscriber
.T
- ConfigInstance typesingleSubscriber
- The object to receive configconfigClass
- The class, typically generated from a def-file using config-class-pluginconfigId
- Identifies the service in vespa-services.xmlstartConfigThread(Runnable)
public long getGeneration()
Copyright © 2018. All rights reserved.