Class RegistryStrategy
In this strategy:
- Logging is done onto
System.out; - The translation routine assumes that keys are prefixed with
'%'/; - Caching is enabled and doesn't use state or time stamp validation;
- Standard Java class loading is used to create executable extensions.
This class can be used without OSGi running.
This class can be overridden and/or instantiated by clients.
- Since:
- org.eclipse.equinox.registry 3.2
-
Constructor Summary
ConstructorsConstructorDescriptionRegistryStrategy(File[] storageDirs, boolean[] cacheReadOnly) Constructor for this default registry strategy. -
Method Summary
Modifier and TypeMethodDescriptionbooleanSpecifies if lazy cache loading is used.booleancacheUse()Specifies if the extension registry should use cache to store registry data between invocations.createExecutableExtension(RegistryContributor contributor, String className, String overridenContributorName) Creates an executable extension.booleandebug()Override this method to specify debug requirements to the registry.booleanOverride this method to specify debug requirements for the registry event processing.longThis method is called as a part of the registry cache validation.longThis method is called as a part of the registry cache validation.Returns the current locale for the extension registry with enabled multi-language support.final intReturns the number of possible cache locations for this registry.final FilegetStorage(int index) Returns the possible registry cache location identified by the index.Returns the parser used by the registry to parse descriptions of extension points and extensions.final booleanisCacheReadOnly(int index) Returns the read-only status of the registry cache location.voidOverride this method to provide customized logging functionality to the registry.voidonStart(IExtensionRegistry registry) Deprecated.voidonStart(IExtensionRegistry registry, boolean loadedFromCache) Override this method to provide additional processing performed when the registry is created and started.voidonStop(IExtensionRegistry registry) Override this method to provide additional processing to be performed just before the registry is stopped.static final IStatusprocessChangeEvent(Object[] listeners, Map<String, ?> deltas, Object registry) This method performs actual processing of the registry change event.voidscheduleChangeEvent(Object[] listeners, Map<String, ?> deltas, Object registry) Override this method to customize scheduling of an extension registry event.String[]translate(String[] nonTranslated, IContributor contributor, String locale) Translates array of keys supplied by the contributor to the requested locale.translate(String key, ResourceBundle resources) Translates key using the supplied resource bundle.
-
Constructor Details
-
RegistryStrategy
Constructor for this default registry strategy.The strategy sequentially checks the array of storage directories to discover the location of the registry cache formed by previous invocations of the extension registry. Once found, the location is used to store registry cache. If this value is
nullthen caching of the registry content is disabled.The cache read-only array is an array the same length as the storage directory array. It contains boolean values indicating whether or not each storage directory is read-only. If the value at an index is
truethen the location at the corresponding index in the storage directories array is read-only; iffalsethen the cache location is read-write. The array can benullif thestorageDirsparameter isnull.- Parameters:
storageDirs- array of file system directories, ornullcacheReadOnly- array of read only attributes, ornull
-
-
Method Details
-
getLocationsLength
public final int getLocationsLength()Returns the number of possible cache locations for this registry.- Returns:
- number of possible cache locations for this registry
-
getStorage
Returns the possible registry cache location identified by the index.- Parameters:
index- index of the possible registry location- Returns:
- potential registry cache location
-
isCacheReadOnly
public final boolean isCacheReadOnly(int index) Returns the read-only status of the registry cache location.- Parameters:
index- the index of the possible registry location- Returns:
trueif the location is read only andfalseif the location is read/write
-
log
Override this method to provide customized logging functionality to the registry. The method adds a log entry based on the supplied status.This method writes a message to
System.outin the following format:[Error|Warning|Log]: Main error message [Error|Warning|Log]: Child error message 1 ... [Error|Warning|Log]: Child error message N- Parameters:
status- the status to log
-
translate
Translates key using the supplied resource bundle. The resource bundle is optional and might benull.The default translation routine assumes that keys are prefixed with '%'. If no resource bundle is present, the key itself (without leading '%') is returned. There is no decoding for the leading '%%'.
- Parameters:
key- message key to be translatedresources- resource bundle, ornull- Returns:
- the translated string, must not be
null
-
onStart
Deprecated.Override this method to provide additional processing performed when the registry is created and started. Overrides should callsuper.onStart()at the beginning of the processing.NOTE: Avoid placing duplicate functionality in this method and
onStart(IExtensionRegistry, boolean)as both methods will be called on the registry startup.- Parameters:
registry- the extension registry being started
-
onStart
Override this method to provide additional processing performed when the registry is created and started. Overrides should callsuper.onStart()at the beginning of the processing.- Parameters:
registry- the extension registry being startedloadedFromCache- true is registry contents was loaded from cache when the registry was created- Since:
- 3.4
-
onStop
Override this method to provide additional processing to be performed just before the registry is stopped. Overrides should callsuper.onStop()at the end of the processing.- Parameters:
registry- the extension registry being stopped
-
createExecutableExtension
public Object createExecutableExtension(RegistryContributor contributor, String className, String overridenContributorName) throws CoreException Creates an executable extension. Override this method to supply an alternative processing for the creation of executable extensions.This method receives the contributor of the executable extension and, possibly, an optional contributor name if specified by the executable extension. The overridden contributor name might be
null.In this implementation registry attempts to instantiate the class specified via the class name (must not be
null) using standard Java reflection mechanism. This method assumes that such class has a default constructor with no arguments.- Parameters:
contributor- the contributor of this executable extensionclassName- the name of the class to be instantiatedoverridenContributorName- the contributor to be used, ornullif not specified- Returns:
- the object created, or
null - Throws:
CoreException- if there was a problem creating the executable extension- See Also:
-
scheduleChangeEvent
Override this method to customize scheduling of an extension registry event. Note that this method must make the following call to actually process the event:RegistryStrategy.processChangeEvent(listeners, deltas, registry);In the default implementation, the method registry events are executed in a queue on a separate thread (i.e. asynchronously, sequentially).
- Parameters:
listeners- the list of active listeners (thread safe); may not benulldeltas- the registry deltas (thread safe); may not benullregistry- the extension registry (NOT thread safe); may not benull
-
processChangeEvent
public static final IStatus processChangeEvent(Object[] listeners, Map<String, ?> deltas, Object registry) This method performs actual processing of the registry change event. It should only be used by overrides of the RegistryStrategy.scheduleChangeEvent. It will returnnullif an unexpected registry type was encountered.- Parameters:
listeners- the list of active listeners; may not benulldeltas- the extension registry deltas; may not benullregistry- the extension registry; may not benull- Returns:
- status of the operation or
null
-
debug
public boolean debug()Override this method to specify debug requirements to the registry. In the default implementation this method returnsfalseindicating that debug functionality is turned off.Note that in a general case the extension registry plug-in doesn't depend on OSGI and therefore cannot use Eclipse .options files to discover debug options.
- Returns:
trueif debug logging and validation should be performed andfalseotherwise
-
debugRegistryEvents
public boolean debugRegistryEvents()Override this method to specify debug requirements for the registry event processing. In the default implementation this method returnsfalseindicating that debug of the registry events is turned off.Note that in a general case the extension registry plug-in doesn't depend on OSGI and therefore cannot use Eclipse .options files to discover debug options.
- Returns:
trueif debug logging and validation of the registry events should be performed andfalseotherwise
-
cacheUse
public boolean cacheUse()Specifies if the extension registry should use cache to store registry data between invocations.The default implementation enables caching returning
true.- Returns:
trueif the cache should be used andfalseotherwise
-
cacheLazyLoading
public boolean cacheLazyLoading()Specifies if lazy cache loading is used.The default implementation specifies that lazy cache loading is going to be used and therefore returns
true.- Returns:
trueif lazy cache loading is used andfalseotherwise
-
getContainerTimestamp
public long getContainerTimestamp()This method is called as a part of the registry cache validation. The cache is valid on the registry startup if the pair {container time stamp, contributors time stamp} supplied by the registry strategy is the same as the {container time stamp, contributors time stamp} stored in the registry cache. The goal of the validation is to be able to catch modifications made to the original data contributed into the registry and not reflected in the registry cache.The method produces a number that corresponds to the current state of the data stored by the container. Increment the stamp if the data stored in the container has been updated so that the data cached by the registry is no longer valid. For instance, in Eclipse addition or removal of a bundle results in the number returned by this method being incremented. As a result, if a bundle that contributed plugin.xml into the extension registry was modified, the state doesn't match the state stored in the registry cache. In this case the cache content becomes invalid and the registry needs to be re-created from the original data.
Generally, treat this number as a hash code for the data stored in the registry. It stays the same as long as the registry content is not changing. It becomes a different number as the registry content gets modified.
Return 0 to indicate that state verification is not required.
- Returns:
- number indicating state of the application data
-
getContributionsTimestamp
public long getContributionsTimestamp()This method is called as a part of the registry cache validation. The method calculates a number describing the time when the originating contributions (i.e., plugin.xml files in case of the Eclipse registry) were last modified.The value returned by the method is compared with the timestamp tracked by the registry. If contributions changed since they have been added to the registry (i.e., plugin.xml file was modified since the last run), the value of the
getContributionsTimestamp()will change and no longer will be the same as the value tracked by the registry. In this case the cache is considered to be invalid and the registry is going to be re-populated form scratch.(The word "timestamp" is used very loosely here. In this context, "timestamp" is more likely to be a hash value aggregating a number of actual timestamps from the contributions.)
This method may return 0 to indicate that no time stamp verification is required.
- Returns:
- a value corresponding to the last modification time of contributions contained in the registry
-
getXMLParser
Returns the parser used by the registry to parse descriptions of extension points and extensions. This method must not returnnull.- Returns:
- this strategy's parser
- See Also:
-
translate
Translates array of keys supplied by the contributor to the requested locale.This method is intended to be overridden by specialized registry strategies that know translation conventions for the contributors, for instance, the agreed upon locations of the translated keys for bundle contributors. The base implementation simply returns the array of non-translated keys.
This method is only used if multi-language support is enabled.
- Parameters:
nonTranslated- message keys to be translatedcontributor- the contributor of the keys to be translatedlocale- the requested locale for the keys- Returns:
- the arrays of translated strings
- Since:
- org.eclipse.equinox.registry 3.5
- See Also:
-
getLocale
Returns the current locale for the extension registry with enabled multi-language support.The default implementation assumes that there is a single system wide locale, equivalent to
Locale.getDefault().The result of this method should not be retained or passed to other threads. The current locale can change any time and may be different for each thread.
This method can be overridden by subclasses that wish to provide a way to change the default locale.
This method is only used if multi-language support is enabled.
- Returns:
- the default locale
- Since:
- org.eclipse.equinox.registry 3.5
- See Also:
-
onStart(IExtensionRegistry, boolean).