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. |
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. |
void |
registerAndLoadData(LoadDataInformation loadDataInformation)
Programmatically registers a remote resource
resourceLocation,
backed up by a classpath resource backupResource, reachable as
dataId and (synchronously) loads the data. |
void |
registerAndLoadData(String resourceId,
LoaderService.UpdatePolicy updatePolicy,
Map<String,String> properties,
LoaderService.LoaderListener loaderListener,
URI backupResource,
URI... resourceLocations) |
void |
registerData(LoadDataInformation loadDataInformation)
Programmatically registers a remote resource
resourceLocation,
backed up by a classpath resource backupResource, reachable as
dataId. |
void |
registerData(String resourceId,
LoaderService.UpdatePolicy updatePolicy,
Map<String,String> properties,
LoaderService.LoaderListener loaderListener,
URI backupResource,
URI... resourceLocations) |
void |
removeLoaderListener(LoaderService.LoaderListener loadListener,
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()
public void unload(String resourceId)
resourceId - the resource id.public void registerData(LoadDataInformation loadDataInformation)
LoaderServiceresourceLocation,
backed up by a classpath resource backupResource, reachable as
dataId.
resourceId The unique identifier of the resource that must also be used
for accessing the resource, not null.
resourceLocations The remote resource locations, not null.
backupResource The backup resource location in the classpath, not
null.
loaderListener An (optional) LoaderListener to be registered.registerData in interface LoaderServicepublic void registerAndLoadData(LoadDataInformation loadDataInformation)
LoaderServiceresourceLocation,
backed up by a classpath resource backupResource, reachable as
dataId and (synchronously) loads the data.
resourceId The unique identifier of the resource that must also be used
for accessing the resource, not null.
resourceLocations The remote resource locations, not null.
backupResource The backup resource location in the classpath, not
null.
loaderListener An (optional) LoaderListener to be registered.registerAndLoadData in interface LoaderServicepublic void registerAndLoadData(String resourceId, LoaderService.UpdatePolicy updatePolicy, Map<String,String> properties, LoaderService.LoaderListener loaderListener, URI backupResource, URI... resourceLocations)
registerAndLoadData in interface LoaderServicepublic void registerData(String resourceId, LoaderService.UpdatePolicy updatePolicy, Map<String,String> properties, LoaderService.LoaderListener loaderListener, URI backupResource, URI... resourceLocations)
registerData in interface LoaderServicepublic Map<String,String> getUpdateConfiguration(String resourceId)
LoaderServicegetUpdateConfiguration in interface LoaderServiceresourceId - the dataId, not nullnullpublic boolean isResourceRegistered(String resourceId)
LoaderServiceisResourceRegistered in interface LoaderServiceresourceId - 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 resourceId) throws IOException
LoaderServiceresetData in interface LoaderServiceresourceId - The unique identifier of the resource, not null.IOException - if a problem occurred.public void addLoaderListener(LoaderService.LoaderListener l, String... resourceIds)
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 addedresourceIds - The unique identifiers of the resource, not null.LoaderService.removeLoaderListener(LoaderListener, String...)public void removeLoaderListener(LoaderService.LoaderListener loadListener, String... resourceIds)
LoaderServiceLoaderService.LoaderListener callback.removeLoaderListener in interface LoaderServiceloadListener - The listener to be removedresourceIds - 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 nullCopyright © 2012-2016 JavaMoney. All Rights Reserved.