Package com.yahoo.config.subscription
Class ConfigSubscriber
java.lang.Object
com.yahoo.config.subscription.ConfigSubscriber
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
GenericConfigSubscriber
@Deprecated(forRemoval=true,
since="7")
public class ConfigSubscriber
extends Object
implements AutoCloseable
Deprecated, for removal: This API element is subject to removal in a future version.
Will be removed in Vespa 8. Only for internal use.
Used for subscribing to one or more configs. Can optionally be given a
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.- Author:
- Vegard Havdal
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
ConfigSubscriber.SingleSubscriber<T extends com.yahoo.config.ConfigInstance>
Deprecated, for removal: This API element is subject to removal in a future version.Convenience interface for clients who only subscribe to one config.protected static enum
Deprecated, for removal: This API element is subject to removal in a future version.The states of the subscriber. -
Field Summary
Modifier and TypeFieldDescriptionprotected final List<ConfigHandle<? extends com.yahoo.config.ConfigInstance>>
Deprecated, for removal: This API element is subject to removal in a future version. -
Constructor Summary
ConstructorDescriptionDeprecated, for removal: This API element is subject to removal in a future version.Constructs a new subscriber.ConfigSubscriber
(ConfigSource source) Deprecated, for removal: This API element is subject to removal in a future version.Constructs a new subscriber with the given source. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Deprecated, for removal: This API element is subject to removal in a future version.void
close()
Deprecated, for removal: This API element is subject to removal in a future version.Closes all openConfigSubscription
sprotected void
finalize()
Deprecated, for removal: This API element is subject to removal in a future version.Finalizer to ensure that we do not leak resources on reconfig.long
Deprecated, for removal: This API element is subject to removal in a future version.The current generation of configs known by this subscriber.Deprecated, for removal: This API element is subject to removal in a future version.The source used by this subscriber.boolean
isClosed()
Deprecated, for removal: This API element is subject to removal in a future version.boolean
Deprecated.boolean
nextConfig
(boolean isInitializing) Deprecated, for removal: This API element is subject to removal in a future version.Use this for waiting for a new config that has changed.boolean
nextConfig
(long timeoutMillis) Deprecated.boolean
nextConfig
(long timeoutMillis, boolean isInitializing) Deprecated, for removal: This API element is subject to removal in a future version.Use this for waiting for a new config that has changed, with the given timeout.boolean
Deprecated.boolean
nextGeneration
(boolean isInitializing) Deprecated, for removal: This API element is subject to removal in a future version.Use this for waiting for a new config generation.boolean
nextGeneration
(long timeoutMillis) Deprecated.boolean
nextGeneration
(long timeoutMillis, boolean isInitializing) Deprecated, for removal: This API element is subject to removal in a future version.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) Deprecated, for removal: This API element is subject to removal in a future version.Sets all subscriptions under this subscriber to have the given generation.startConfigThread
(Runnable runnable) Deprecated, for removal: This API element is subject to removal in a future version.Convenience method to start a daemon thread called "Vespa config thread" with the given runnable.protected ConfigSubscriber.State
state()
Deprecated, for removal: This API element is subject to removal in a future version.<T extends com.yahoo.config.ConfigInstance>
ConfigHandle<T>subscribe
(ConfigSubscriber.SingleSubscriber<T> singleSubscriber, Class<T> configClass, String configId) Deprecated, for removal: This API element is subject to removal in a future version.Convenience method that can be used if you only want to subscribe to one config, and want generic error handling.<T extends com.yahoo.config.ConfigInstance>
ConfigHandle<T>Deprecated, for removal: This API element is subject to removal in a future version.Subscribes on the given type ofConfigInstance
with the given config id.<T extends com.yahoo.config.ConfigInstance>
ConfigHandle<T>Deprecated, for removal: This API element is subject to removal in a future version.Subscribes on the given type ofConfigInstance
with the given config id and subscribe timeout.protected void
subscribeAndHandleErrors
(ConfigSubscription<?> sub, ConfigKey<?> configKey, ConfigHandle<?> handle, TimingValues timingValues) Deprecated, for removal: This API element is subject to removal in a future version.protected void
throwIfExceptionSet
(ConfigSubscription<? extends com.yahoo.config.ConfigInstance> sub) Deprecated, for removal: This API element is subject to removal in a future version.If aConfigSubscription
has its exception set, reset that field and throw ittoString()
Deprecated, for removal: This API element is subject to removal in a future version.
-
Field Details
-
subscriptionHandles
Deprecated, for removal: This API element is subject to removal in a future version.
-
-
Constructor Details
-
ConfigSubscriber
public ConfigSubscriber()Deprecated, for removal: This API element is subject to removal in a future version.Constructs a new subscriber. The default Vespa network config source will be used, which is the address of a config proxy running locally. It can also be changed by setting VESPA_CONFIG_SOURCES. -
ConfigSubscriber
Deprecated, for removal: This API element is subject to removal in a future version.Constructs a new subscriber with the given source.- Parameters:
source
- aConfigSource
that will be used whensubscribe(Class, String)
is called.
-
-
Method Details
-
subscribe
public <T extends com.yahoo.config.ConfigInstance> ConfigHandle<T> subscribe(Class<T> configClass, String configId) Deprecated, for removal: This API element is subject to removal in a future version.Subscribes on the given type ofConfigInstance
with the given config id. The method blocks until the first config is ready to be fetched withnextConfig()
.- Parameters:
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 localConfigSource
which does not use config id. Also supported: raw:, file:, dir: or jar: config id which addresses config locally in the same way.- Returns:
- a ConfigHandle
-
subscribe
public <T extends com.yahoo.config.ConfigInstance> ConfigHandle<T> subscribe(Class<T> configClass, String configId, long timeoutMillis) Deprecated, for removal: This API element is subject to removal in a future version.Subscribes on the given type ofConfigInstance
with the given config id and subscribe timeout. The method blocks until the first config is ready to be fetched withnextConfig()
.- Parameters:
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- Returns:
- a ConfigHandle
-
checkStateBeforeSubscribe
protected void checkStateBeforeSubscribe()Deprecated, for removal: This API element is subject to removal in a future version. -
subscribeAndHandleErrors
protected void subscribeAndHandleErrors(ConfigSubscription<?> sub, ConfigKey<?> configKey, ConfigHandle<?> handle, TimingValues timingValues) Deprecated, for removal: This API element is subject to removal in a future version. -
nextConfig
public boolean nextConfig(boolean isInitializing) Deprecated, for removal: This API element is subject to removal in a future version.Use this for waiting for a new config that has changed. Returns true if: It is the first time nextConfig() is called on this subscriber, and the framework has fetched config for all subscriptions. (Typically a first time config.) or All configs for the subscriber have a new generation since the last time nextConfig() was called, AND they have the same generation AND there is a change in config for at least one of the configs. (Typically calls for a reconfig.) You can check which configs are changed by callingConfigHandle.isChanged()
on the handle you got fromsubscribe(Class, String)
. If the call times out (timeout 1000 ms), no handle will have the changed flag set. You should not configure anything then.- Parameters:
isInitializing
- true if this the config is needed to create the initial configuration for the caller, false if this is for reconfiguration- Returns:
- true if a config/reconfig of your system should happen
- Throws:
ConfigInterruptedException
- if thread performing this call interrupted.SubscriberClosedException
- if subscriber is closed
-
nextConfig
Deprecated. -
nextConfig
public boolean nextConfig(long timeoutMillis, boolean isInitializing) Deprecated, for removal: This API element is subject to removal in a future version.Use this for waiting for a new config that has changed, with the given timeout. Returns true if: It is the first time nextConfig() is called on this subscriber, and the framework has fetched config for all subscriptions. (Typically a first time config.) or All configs for the subscriber have a new generation since the last time nextConfig() was called, AND they have the same generation AND there is a change in config for at least one of the configs. (Typically calls for a reconfig.) You can check which configs are changed by callingConfigHandle.isChanged()
on the handle you got fromsubscribe(Class, String)
. If the call times out, no handle will have the changed flag set. You should not configure anything then.- Parameters:
timeoutMillis
- timeout in millisecondsisInitializing
- true if this the config is needed to create the initial configuration for the caller, false if this is for reconfiguration- Returns:
- true if a config/reconfig of your system should happen
- Throws:
ConfigInterruptedException
- if thread performing this call interrupted.SubscriberClosedException
- if subscriber is closed
-
nextConfig
Deprecated. -
nextGeneration
public boolean nextGeneration(boolean isInitializing) Deprecated, for removal: This API element is subject to removal in a future version.Use this for waiting for a new config generation. Returns true if: It is the first time nextGeneration() is called on this subscriber, and the framework has fetched config for all subscriptions. (Typically a first time config.) or All configs for the subscriber have a new generation since the last time nextGeneration() was called, AND they have the same generation. Note that none of the configs have to be changed, but they might be. You can check which configs are changed by callingConfigHandle.isChanged()
on the handle you got fromsubscribe(Class, String)
. If the call times out (timeout 1000 ms), no handle will have the changed flag set. You should not configure anything then.- Parameters:
isInitializing
- true if this the next generation is needed to create the initial configuration for the caller, false if this is for reconfiguration- Returns:
- true if generations for all configs have been updated.
- Throws:
ConfigInterruptedException
- if thread performing this call interrupted.SubscriberClosedException
- if subscriber is closed
-
nextGeneration
Deprecated. -
nextGeneration
public boolean nextGeneration(long timeoutMillis, boolean isInitializing) Deprecated, for removal: This API element is subject to removal in a future version.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. (Typically a first time config.) or All configs for the subscriber have a new generation since the last time nextGeneration() was called, AND they have the same generation. Note that none of the configs have to be changed, but they might be. You can check which configs are changed by callingConfigHandle.isChanged()
on the handle you got fromsubscribe(Class, String)
. If the call times out (timeout 1000 ms), no handle will have the changed flag set. You should not configure anything then.- Parameters:
timeoutMillis
- timeout in millisecondsisInitializing
- true if this the next generation is needed to create the initial configuration for the caller, false if this is for reconfiguration- Returns:
- true if generations for all configs have been updated.
- Throws:
ConfigInterruptedException
- if thread performing this call interrupted.SubscriberClosedException
- if subscriber is closed
-
nextGeneration
Deprecated. -
throwIfExceptionSet
protected void throwIfExceptionSet(ConfigSubscription<? extends com.yahoo.config.ConfigInstance> sub) Deprecated, for removal: This API element is subject to removal in a future version.If aConfigSubscription
has its exception set, reset that field and throw it- Parameters:
sub
-ConfigSubscription
-
close
public void close()Deprecated, for removal: This API element is subject to removal in a future version.Closes all openConfigSubscription
s- Specified by:
close
in interfaceAutoCloseable
-
toString
Deprecated, for removal: This API element is subject to removal in a future version. -
startConfigThread
Deprecated, for removal: This API element is subject to removal in a future version.Convenience method to start a daemon thread called "Vespa config thread" with the given runnable. If you want the runnable to handle aConfigSubscriber
orConfigHandle
you have declared locally outside, declare them as final to make it work.- Parameters:
runnable
- a class implementingRunnable
- Returns:
- the newly started thread
-
state
Deprecated, for removal: This API element is subject to removal in a future version. -
reload
public void reload(long generation) Deprecated, for removal: This API element is subject to removal in a future version.Sets all subscriptions under this subscriber to have the given generation. This is intended for testing, to emulate a reload-config operation.- Parameters:
generation
- a generation number
-
getSource
Deprecated, for removal: This API element is subject to removal in a future version.The source used by this subscriber.- Returns:
- the
ConfigSource
used by this subscriber
-
isClosed
public boolean isClosed()Deprecated, for removal: This API element is subject to removal in a future version. -
subscribe
public <T extends com.yahoo.config.ConfigInstance> ConfigHandle<T> subscribe(ConfigSubscriber.SingleSubscriber<T> singleSubscriber, Class<T> configClass, String configId) Deprecated, for removal: This API element is subject to removal in a future version.Convenience method that can be used if you only want to subscribe to one config, and want generic error handling. ImplementConfigSubscriber.SingleSubscriber
and pass it 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 youclose()
thisConfigSubscriber
.- Type Parameters:
T
- ConfigInstance type- Parameters:
singleSubscriber
- The object to receive configconfigClass
- The class, typically generated from a def-file using config-class-pluginconfigId
- Identifies the service in vespa-services.xml- Returns:
- The handle of the config
- See Also:
-
getGeneration
public long getGeneration()Deprecated, for removal: This API element is subject to removal in a future version.The current generation of configs known by this subscriber.- Returns:
- the current generation of configs known by this subscriber
-
finalize
Deprecated, for removal: This API element is subject to removal in a future version.Finalizer to ensure that we do not leak resources on reconfig. Though finalizers are bad, this is not a performance critical object as it will be deconstructed typically container reconfig.
-