public class DefaultLoaderService extends Object implements LoaderService
UpdatePolicy
loads/updates the resources from arbitrary locations and stores it to the
internal file cache. Default loading tasks can be configured within the javamoney.properties
file, @see org.javamoney.moneta.loader.internal.LoaderConfigurator .
LoaderService.LoaderListener, LoaderService.UpdatePolicy| Constructor and Description |
|---|
DefaultLoaderService()
Constructor, initializing from config.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addLoaderListener(LoaderService.LoaderListener l,
String... dataIds)
Add a
LoaderService.LoaderListener callback that is informed when a data
resource was update from remote, or resetToFallback. |
InputStream |
getData(String resourceId)
Access the input stream of the given data resource.
|
Set<String> |
getResourceIds()
Get a
Set of all registered data resource identifiers. |
Map<String,String> |
getUpdateConfiguration(String resourceId)
Get the update configuration for the given dataId.
|
LoaderService.UpdatePolicy |
getUpdatePolicy(String resourceId)
Get the
LoaderService.UpdatePolicy in place for the given dataId. |
protected void |
initialize()
This method reads initial loads from the javamoney.properties and installs the according timers.
|
boolean |
isResourceRegistered(String dataId)
Allows to check if a data resource with the given dataId is registered.
|
boolean |
loadData(String resourceId)
Explicitly triggers the remote loading of the registered data, regardless
of its current
LoaderService.UpdatePolicy configured. |
Future<Boolean> |
loadDataAsync(String resourceId)
Explicitly asynchronously triggers the remote loading of the registered
data, regardless of its current
LoaderService.UpdatePolicy configured. |
boolean |
loadDataLocal(String resourceId)
Explicitly triggers the loading of the registered data, regardless of its
current
LoaderService.UpdatePolicy configured, from the fallback/local
resource. |
protected long |
parseDuration(String value)
Parse a duration of the form HH:mm:ss:nnn, whereas only hours are non
optional.
|
void |
registerAndLoadData(String resourceId,
LoaderService.UpdatePolicy updatePolicy,
Map<String,String> properties,
LoaderService.LoaderListener loaderListener,
URI backupResource,
URI... resourceLocations)
Programmatically registers a remote resource
resourceLocation,
backed up by a classpath resource backupResource, reachable as
dataId and (synchronously) loads the data. |
void |
registerData(String resourceId,
LoaderService.UpdatePolicy updatePolicy,
Map<String,String> properties,
LoaderService.LoaderListener loaderListener,
URI backupResource,
URI... resourceLocations)
Programmatically registers a remote resource
resourceLocation,
backed up by a classpath resource backupResource, reachable as
dataId. |
void |
removeLoaderListener(LoaderService.LoaderListener l,
String... dataIds)
Remove a registered
LoaderService.LoaderListener callback. |
void |
resetData(String dataId)
Explicitly triggers the resetToFallback (loading of the registered data from the
classpath backup resource).
|
String |
toString() |
void |
unload(String resourceId)
Removes a resource managed.
|
public DefaultLoaderService()
protected void initialize()
public void unload(String resourceId)
resourceId - the resource id.public void registerData(String resourceId, LoaderService.UpdatePolicy updatePolicy, Map<String,String> properties, LoaderService.LoaderListener loaderListener, URI backupResource, URI... resourceLocations)
LoaderServiceresourceLocation,
backed up by a classpath resource backupResource, reachable as
dataId.registerData in interface LoaderServiceresourceId - The unique identifier of the resource that must also be used
for accessing the resource, not null.loaderListener - An (optional) LoaderListener to be registered.backupResource - The backup resource location in the classpath, not
null.resourceLocations - The remote resource locations, not null.public void registerAndLoadData(String resourceId, LoaderService.UpdatePolicy updatePolicy, Map<String,String> properties, LoaderService.LoaderListener loaderListener, URI backupResource, URI... resourceLocations)
LoaderServiceresourceLocation,
backed up by a classpath resource backupResource, reachable as
dataId and (synchronously) loads the data.registerAndLoadData in interface LoaderServiceresourceId - The unique identifier of the resource that must also be used
for accessing the resource, not null.loaderListener - An (optional) LoaderListener to be registered.backupResource - The backup resource location in the classpath, not
null.resourceLocations - The remote resource locations, not null.public Map<String,String> getUpdateConfiguration(String resourceId)
LoaderServicegetUpdateConfiguration in interface LoaderServiceresourceId - the dataId, not nullnullpublic boolean isResourceRegistered(String dataId)
LoaderServiceisResourceRegistered in interface LoaderServicedataId - The unique identifier of the resource, not null.true, if such a data resource is registered.public Set<String> getResourceIds()
LoaderServiceSet of all registered data resource identifiers.getResourceIds in interface LoaderServiceSet of all registered data resource identifiers, never
null.public InputStream getData(String resourceId) throws IOException
LoaderServiceThis method is called by the modules that depend on the given data item. The method always returns the most current data, either from the classpath or the local cache, depending which flavors are available and recently updated.
The method must be thread safe and can be accessed in parallel. Hereby it is possible that, when an intermediate update of the data by update occurs, that different input stream content is returned.
getData in interface LoaderServiceresourceId - The unique identifier of the resource, not null.InputStream for reading the data.IOException - if a problem occurred.public boolean loadData(String resourceId)
LoaderServiceLoaderService.UpdatePolicy configured.loadData in interface LoaderServiceresourceId - The unique identifier of the resource, not null.public Future<Boolean> loadDataAsync(String resourceId)
LoaderServiceLoaderService.UpdatePolicy configured.loadDataAsync in interface LoaderServiceresourceId - The unique identifier of the resource, not null.public boolean loadDataLocal(String resourceId)
LoaderServiceLoaderService.UpdatePolicy configured, from the fallback/local
resource.loadDataLocal in interface LoaderServiceresourceId - The unique identifier of the resource, not null.public void resetData(String dataId) throws IOException
LoaderServiceresetData in interface LoaderServicedataId - The unique identifier of the resource, not null.IOException - if a problem occurred.public void addLoaderListener(LoaderService.LoaderListener l, String... dataIds)
LoaderServiceLoaderService.LoaderListener callback that is informed when a data
resource was update from remote, or resetToFallback. Passing an empty String or
null sa dataId allows to register a listener for all data
resources registered. LoaderService.loadData(String)
LoaderService.resetData(String)addLoaderListener in interface LoaderServicel - The listener to be addeddataIds - The unique identifiers of the resource, not null.LoaderService.removeLoaderListener(LoaderListener, String...)public void removeLoaderListener(LoaderService.LoaderListener l, String... dataIds)
LoaderServiceLoaderService.LoaderListener callback.removeLoaderListener in interface LoaderServicel - The listener to be removeddataIds - The unique identifier of the resource, not null.LoaderService.addLoaderListener(LoaderListener, String...)public LoaderService.UpdatePolicy getUpdatePolicy(String resourceId)
LoaderServiceLoaderService.UpdatePolicy in place for the given dataId.getUpdatePolicy in interface LoaderServiceresourceId - the resource's id, not nullLoaderService.UpdatePolicy, not nullprotected long parseDuration(String value)
value - the input valueCopyright © 2012-2015 JavaMoney. All Rights Reserved.