public class DefaultLoaderService extends Object implements LoaderService
UpdatePolicy
loads/updates the resources from arbitrary locations and stores it to the
format file cache. Default loading tasks can be configured within the javamoney.properties
file, @see org.javamoney.moneta.loader.format.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... resourceIds)
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 resourceId)
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... resourceIds)
Remove a registered
LoaderService.LoaderListener callback. |
void |
resetData(String resourceId)
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)
LoaderService
resourceLocation
,
backed up by a classpath resource backupResource
, reachable as
dataId
.registerData
in interface LoaderService
resourceId
- 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)
LoaderService
resourceLocation
,
backed up by a classpath resource backupResource
, reachable as
dataId
and (synchronously) loads the data.registerAndLoadData
in interface LoaderService
resourceId
- 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)
LoaderService
getUpdateConfiguration
in interface LoaderService
resourceId
- the dataId, not null
null
public boolean isResourceRegistered(String resourceId)
LoaderService
isResourceRegistered
in interface LoaderService
resourceId
- The unique identifier of the resource, not null
.true
, if such a data resource is registered.public Set<String> getResourceIds()
LoaderService
Set
of all registered data resource identifiers.getResourceIds
in interface LoaderService
Set
of all registered data resource identifiers, never
null
.public InputStream getData(String resourceId) throws IOException
LoaderService
This 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 LoaderService
resourceId
- The unique identifier of the resource, not null
.InputStream
for reading the data.IOException
- if a problem occurred.public boolean loadData(String resourceId)
LoaderService
LoaderService.UpdatePolicy
configured.loadData
in interface LoaderService
resourceId
- The unique identifier of the resource, not null
.public Future<Boolean> loadDataAsync(String resourceId)
LoaderService
LoaderService.UpdatePolicy
configured.loadDataAsync
in interface LoaderService
resourceId
- The unique identifier of the resource, not null
.public boolean loadDataLocal(String resourceId)
LoaderService
LoaderService.UpdatePolicy
configured, from the fallback/local
resource.loadDataLocal
in interface LoaderService
resourceId
- The unique identifier of the resource, not null
.public void resetData(String resourceId) throws IOException
LoaderService
resetData
in interface LoaderService
resourceId
- The unique identifier of the resource, not null
.IOException
- if a problem occurred.public void addLoaderListener(LoaderService.LoaderListener l, String... resourceIds)
LoaderService
LoaderService.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 LoaderService
l
- The listener to be addedresourceIds
- The unique identifiers of the resource, not null
.LoaderService.removeLoaderListener(LoaderListener, String...)
public void removeLoaderListener(LoaderService.LoaderListener l, String... resourceIds)
LoaderService
LoaderService.LoaderListener
callback.removeLoaderListener
in interface LoaderService
l
- The listener to be removedresourceIds
- The unique identifier of the resource, not null
.LoaderService.addLoaderListener(LoaderListener, String...)
public LoaderService.UpdatePolicy getUpdatePolicy(String resourceId)
LoaderService
LoaderService.UpdatePolicy
in place for the given dataId.getUpdatePolicy
in interface LoaderService
resourceId
- the resource's id, not null
LoaderService.UpdatePolicy
, not null
protected long parseDuration(String value)
value
- the input valueCopyright © 2012-2015 JavaMoney. All Rights Reserved.