| java.lang.Object | |
| ↳ | com.google.gdata.util.VersionRegistry |
The VersionRegistry class is used to manage and retrieve version information
about executing services. The registry supports the ability to configure
versions for a running thread (via the setThreadVersion(Version)
method) or global defaults that will apply to all threads (using the
addDefaultVersion(Version, boolean) method. Thread defaults will
have precedence over global defaults if present for the same service.
The class provides a singleton instance that is being used to manage version
information. This instance is initialized by the ensureRegistry()
method. The active VersionRegistry instance can be retrieved using the
get() method. This method will throw an
IllegalStateException if the version registry has not been
initialized to aid in the detection of when version-conditional code is being
executed in an environment where versions have net been configured.
The getVersion(Class) method can be used to request
the version information for a particular service.
A model for writing version conditional code based upon the registry is:
Version myServiceVersion =
VersionRegistry.get().getVersion(MyService.class);
if (myServiceVersion.isCompatible(MyService.VERSIONS.V1) {
... execute V1-specific handling ...
}
VersionRegistry access is thread-safe.
| Fields | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| defaultVersions | Maintains the global defaults. | ||||||||||
| threadVersions | Maintains the per-thread version information. | ||||||||||
| versionRegistry | Singleton registry instance. | ||||||||||
| Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Adds a default version to the version registry.
| |||||||||||
Returns the current VersionRegistry, creating it if necessary.
| |||||||||||
Returns the version registry being used to manage version information.
| |||||||||||
Returns the list of default versions for the registry.
| |||||||||||
Returns the list of versions associated with the current thread or
null if there are currently no thread versions. | |||||||||||
Returns the version of a service.
| |||||||||||
Constructs a new Version instance based upon the value of a Java system
property associated with a
Service class. | |||||||||||
Resets the VersionRegistry to a clean state with no thread local
configuration and the specified set of version defaults.
| |||||||||||
Resets the version information for the current thread back to the
default state.
| |||||||||||
Sets the desired version for the current thread to the provided values.
| |||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
Maintains the per-thread version information. The field may be
null if thread tracking is not enabled and the thread local value
may be null if no versions have been set for the current thread.
Singleton registry instance. The singleton is lazily initialized when the
ensureRegistry() method is called. The reason for this design is
to support the detect of version-conditional code running in unit tests.
Such tests need to be run in a version-aware test environment (that will
validate the behavior against all valid versions), so having a model so
that they will fail by default is helpful to guarantee this.
Adds a default version to the version registry. This will overwrite any existing default version for the same service.
| newDefault | Default version to add to the registry
(not null) |
|---|---|
| includeImplied | If true, indicates that all implied versions
associated with the new default should be set as defaults too.
|
Returns the current VersionRegistry, creating it if necessary. The
get() method is preferred for most registry usage, as it enables
the discovery of the execution of version-conditional code in an
environment (such as unit test cases) where versioning has not been
properly configured.
Returns the version registry being used to manage version information.
| IllegalStateException | if the registry has not been initialized. |
|---|
Returns the list of default versions for the registry. The default version is the version that will be used if no version is explicitly selected.
Returns the list of versions associated with the current thread or
null if there are currently no thread versions.
null
Returns the version of a service.
| serviceClass | Of the service to return. |
|---|
| IllegalStateException | if no version information could be found for the requested service. |
|---|
Constructs a new Version instance based upon the value of a Java system
property associated with a Service class. The system property name
is computed from the service class name with ".version" appended. The
syntax of the property value is "[service]<major>[.<minor>]". The
default value of the service is assumed to be the initiating or target
service and the minor revision will be assumed to be zero if not present.
If the associated system property is not set, the method will return
null.
| serviceClass | Service class to use in computing the version property name. |
|---|
Version computed from the property of null if
the property is not set.| IllegalStateException | if the property value does not contain valid revision information. |
|---|
Resets the VersionRegistry to a clean state with no thread local configuration and the specified set of version defaults.
| initialDefaults | The list of default versions that should be used to
initialize the version registry, or null for an empty
default list.
|
|---|
Resets the version information for the current thread back to the default state.
Sets the desired version for the current thread to the provided values.
This method will update any existing request version information set by
defaults or a previous call to this method. The specified version (and
any related implied versions} will be set for the current thread until the
resetThreadVersion() method is called to reset to the version
information back to the default state.
| version | The new active version for this request. |
|---|