Class ConfigSubscription<T extends com.yahoo.config.ConfigInstance>
- java.lang.Object
-
- com.yahoo.config.subscription.impl.ConfigSubscription<T>
-
- Direct Known Subclasses:
ConfigSetSubscription
,FileConfigSubscription
,JarConfigSubscription
,JRTConfigSubscription
,RawConfigSubscription
public abstract class ConfigSubscription<T extends com.yahoo.config.ConfigInstance> extends java.lang.Object
Represents one active subscription to one config- Author:
- Vegard Havdal
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ConfigSubscription.ConfigState<T extends com.yahoo.config.ConfigInstance>
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.Class<T>
configClass
protected ConfigKey<T>
key
protected static java.util.logging.Logger
log
protected ConfigSubscriber
subscriber
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected boolean
checkReloaded()
True if someone has set thereloadedGeneration
number by callingreload(long)
and hence wants to force a given generation programmatically.void
close()
boolean
equals(java.lang.Object o)
static <T extends com.yahoo.config.ConfigInstance>
ConfigSubscription<T>get(ConfigKey<T> key, ConfigSubscriber subscriber, ConfigSource source, TimingValues timingValues)
Correct type of ConfigSubscription instance based on type of source or form of config idjava.lang.Class<T>
getConfigClass()
The class of the subscription's desiredConfigInstance
ConfigSubscription.ConfigState<T>
getConfigState()
The config state object of this subscriptionDefContent
getDefContent()
The config definition schemajava.lang.RuntimeException
getException()
Gets an exception set by for example a network thread.ConfigKey<T>
getKey()
The config key which this subscription uses to identify its configboolean
isConfigChangedAndReset(java.lang.Long requiredGen)
Called fromConfigSubscriber
when the changed status of this config is propagated to the clientsabstract boolean
nextConfig(long timeout)
Polls this subscription for a change.void
reload(long generation)
Force this into the given generation, used in testingprotected void
setConfigIfChanged(T config)
protected void
setConfigIncGen(T config)
Used byFileConfigSubscription
andConfigSetSubscription
void
setException(java.lang.RuntimeException e)
Called by for example network threads to signal that the user thread should throw this exception immediatelyabstract boolean
subscribe(long timeout)
Will block until the nextnextConfig(long)
is guaranteed to return an answer (or throw) immediately (i.e.java.lang.String
toString()
-
-
-
Field Detail
-
log
protected static java.util.logging.Logger log
-
subscriber
protected final ConfigSubscriber subscriber
-
configClass
protected final java.lang.Class<T extends com.yahoo.config.ConfigInstance> configClass
-
-
Method Detail
-
get
public static <T extends com.yahoo.config.ConfigInstance> ConfigSubscription<T> get(ConfigKey<T> key, ConfigSubscriber subscriber, ConfigSource source, TimingValues timingValues)
Correct type of ConfigSubscription instance based on type of source or form of config id- Parameters:
key
- aConfigKey
subscriber
- the subscriber for this subscription- Returns:
- a subclass of a ConfigsSubscription
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
isConfigChangedAndReset
public boolean isConfigChangedAndReset(java.lang.Long requiredGen)
Called fromConfigSubscriber
when the changed status of this config is propagated to the clients
-
setConfigIncGen
protected void setConfigIncGen(T config)
Used byFileConfigSubscription
andConfigSetSubscription
-
setConfigIfChanged
protected void setConfigIfChanged(T config)
-
getConfigState
public ConfigSubscription.ConfigState<T> getConfigState()
The config state object of this subscription- Returns:
- the ConfigInstance (the config) of this subscription
-
getConfigClass
public java.lang.Class<T> getConfigClass()
The class of the subscription's desiredConfigInstance
- Returns:
- the config class
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getKey
public ConfigKey<T> getKey()
The config key which this subscription uses to identify its config- Returns:
- the ConfigKey for this subscription
-
nextConfig
public abstract boolean nextConfig(long timeout)
Polls this subscription for a change. The method is guaranteed to use all of the given timeout before returning false. It will also take into account a user-set generation, that can be set byConfigSubscriber.reload(long)
.
-
subscribe
public abstract boolean subscribe(long timeout)
Will block until the nextnextConfig(long)
is guaranteed to return an answer (or throw) immediately (i.e. not block)- Parameters:
timeout
- in milliseconds- Returns:
- false if timed out
-
setException
public void setException(java.lang.RuntimeException e)
Called by for example network threads to signal that the user thread should throw this exception immediately- Parameters:
e
- a RuntimeException
-
getException
public java.lang.RuntimeException getException()
Gets an exception set by for example a network thread. If not null, it indicates that it should be thrown in the user's thread immediately.- Returns:
- a RuntimeException if there exists one
-
close
public void close()
-
reload
public void reload(long generation)
Force this into the given generation, used in testing- Parameters:
generation
- a config generation
-
checkReloaded
protected boolean checkReloaded()
True if someone has set thereloadedGeneration
number by callingreload(long)
and hence wants to force a given generation programmatically. If that is the case, sets the generation and flags it as changed accordingly.- Returns:
- true if
reload(long)
has been called, false otherwise
-
getDefContent
public DefContent getDefContent()
The config definition schema- Returns:
- the config definition for this subscription
-
-