Top Description Inners Methods
org.javamoney.moneta.spi.loader

public Interface LoaderService

Known Direct Implementers
org.javamoney.moneta.spi.loader.urlconnection.URLConnectionLoaderService, org.javamoney.moneta.spi.loader.okhttp.OkHttpLoaderService
Imports
java.io.IOException, .InputStream, java.net.URI, java.util.Map, .Set, java.util.concurrent.Future

This interface defines an updatable/reloadable data cache for providing data sources that are updatable by any remote URIs. Initial version are loaded from the classpath, or other fallback URL.

This class is used for managing/updating/reloading of data sources, e.g. data streams for exchange rates, additional currency data, historical currency data and so on.

Note

this class is implementation specific and not part of the official JSR's API.

Authors
Anatole Tresch, Werner Keil

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
LoaderService.Listener

Callback that can be registered to be informed, when a data item was loaded/updated or resetToFallback.

public static enum
LoaderService.UpdatePolicy

Platform RI: The update policy defines how and when the LoaderService tries to update the local cache with newest version of the registered data resources, accessing the configured remote URIs.

Method Summary

Modifier and TypeMethod and Description
public void
addLoaderListener(LoaderService.Listener
The listener to be added
l
,
String...
The unique identifiers of the resource, not null.
resourceIds
)

Add a Listener callback that is informed when a data resource was update from remote, or resetToFallback.

public InputStream

Returns:

The InputStream for reading the data.
getData
(String
The unique identifier of the resource, not null.
resourceId
)

Access the input stream of the given data resource.

public Set<String>

Returns:

a Set of all registered data resource identifiers, never null.
getResourceIds
()

Get a Set of all registered data resource identifiers.

public Map<String, String>

Returns:

the update configuration properties, not null
getUpdateConfiguration
(String
the dataId, not null
resourceId
)

Get the update configuration for the given dataId.

public LoaderService.UpdatePolicy

Returns:

the UpdatePolicy, not null
getUpdatePolicy
(String
the resource's id, not null
resourceId
)

Get the UpdatePolicy in place for the given dataId.

public boolean

Returns:

true, if such a data resource is registered.
isResourceRegistered
(String
The unique identifier of the resource, not null.
resourceId
)

Allows to check if a data resource with the given dataId is registered.

public boolean

Returns:

true if load was successful.
loadData
(String
The unique identifier of the resource, not null.
resourceId
)

Explicitly triggers the remote loading of the registered data, regardless of its current UpdatePolicy configured.

public Future<Boolean>

Returns:

the Future of the load task started, returns Boolean.TRUE if the load was successful (either from remote or from the fallback resource).
loadDataAsync
(String
The unique identifier of the resource, not null.
resourceId
)

Explicitly asynchronously triggers the remote loading of the registered data, regardless of its current UpdatePolicy configured.

public boolean

Returns:

true if load was successful.
loadDataLocal
(String
The unique identifier of the resource, not null.
resourceId
)

Explicitly triggers the loading of the registered data, regardless of its current UpdatePolicy configured, from the fallback/local resource.

public 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.

public void
registerAndLoadData(String resourceId, LoaderService.UpdatePolicy updatePolicy, Map<String, String> properties, LoaderService.Listener listener, URI backupResource, URI... resourceLocations)
Deprecated

public void
registerData(LoadDataInformation loadDataInformation)

Programmatically registers a remote resource resourceLocation, backed up by a classpath resource backupResource, reachable as dataId.

public void
registerData(String resourceId, LoaderService.UpdatePolicy updatePolicy, Map<String, String> properties, LoaderService.Listener listener, URI backupResource, URI... resourceLocations)
Deprecated

public void
removeLoaderListener(LoaderService.Listener
The listener to be removed
l
,
String...
The unique identifier of the resource, not null.
resourceIds
)

Remove a registered Listener callback.

public void
resetData(String
The unique identifier of the resource, not null.
resourceId
)

Explicitly triggers the resetToFallback (loading of the registered data from the classpath backup resource).

Method Detail

addLoaderListenerback to summary
public void addLoaderListener(LoaderService.Listener l, String... resourceIds)

Add a Listener 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. loadData(String) resetData(String)

Parameters
l:LoaderService.Listener

The listener to be added

resourceIds:String[]

The unique identifiers of the resource, not null.

See Also
removeLoaderListener(Listener, String...)
getDataback to summary
public InputStream getData(String resourceId) throws IOException

Access the input stream of the given data resource.

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.

Parameters
resourceId:String

The unique identifier of the resource, not null.

Returns:InputStream

The InputStream for reading the data.

Exceptions
IOException:
if a problem occurred.
getResourceIdsback to summary
public Set<String> getResourceIds()

Get a Set of all registered data resource identifiers.

Returns:Set<String>

a Set of all registered data resource identifiers, never null.

getUpdateConfigurationback to summary
public Map<String, String> getUpdateConfiguration(String resourceId)

Get the update configuration for the given dataId.

Parameters
resourceId:String

the dataId, not null

Returns:Map<String, String>

the update configuration properties, not null

Exceptions
IllegalArgumentException:
if no such dataId is available.
getUpdatePolicyback to summary
public LoaderService.UpdatePolicy getUpdatePolicy(String resourceId)

Get the UpdatePolicy in place for the given dataId.

Parameters
resourceId:String

the resource's id, not null

Returns:LoaderService.UpdatePolicy

the UpdatePolicy, not null

Exceptions
IllegalArgumentException:
if no such dataId is available.
isResourceRegisteredback to summary
public boolean isResourceRegistered(String resourceId)

Allows to check if a data resource with the given dataId is registered.

Parameters
resourceId:String

The unique identifier of the resource, not null.

Returns:boolean

true, if such a data resource is registered.

loadDataback to summary
public boolean loadData(String resourceId) throws IOException

Explicitly triggers the remote loading of the registered data, regardless of its current UpdatePolicy configured.

Parameters
resourceId:String

The unique identifier of the resource, not null.

Returns:boolean

true if load was successful.

Exceptions
IOException:
if a problem occurred.
loadDataAsyncback to summary
public Future<Boolean> loadDataAsync(String resourceId)

Explicitly asynchronously triggers the remote loading of the registered data, regardless of its current UpdatePolicy configured.

Parameters
resourceId:String

The unique identifier of the resource, not null.

Returns:Future<Boolean>

the Future of the load task started, returns Boolean.TRUE if the load was successful (either from remote or from the fallback resource).

loadDataLocalback to summary
public boolean loadDataLocal(String resourceId)

Explicitly triggers the loading of the registered data, regardless of its current UpdatePolicy configured, from the fallback/local resource.

Parameters
resourceId:String

The unique identifier of the resource, not null.

Returns:boolean

true if load was successful.

registerAndLoadDataback to summary
public 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. 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) Listener to be registered.

registerAndLoadDataback to summary
public void registerAndLoadData(String resourceId, LoaderService.UpdatePolicy updatePolicy, Map<String, String> properties, LoaderService.Listener listener, URI backupResource, URI... resourceLocations)

Deprecated

Annotations
@Deprecated
registerDataback to summary
public void registerData(LoadDataInformation loadDataInformation)

Programmatically registers a remote resource resourceLocation, 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) Listener to be registered.

registerDataback to summary
public void registerData(String resourceId, LoaderService.UpdatePolicy updatePolicy, Map<String, String> properties, LoaderService.Listener listener, URI backupResource, URI... resourceLocations)

Deprecated

Annotations
@Deprecated
removeLoaderListenerback to summary
public void removeLoaderListener(LoaderService.Listener l, String... resourceIds)

Remove a registered Listener callback.

Parameters
l:LoaderService.Listener

The listener to be removed

resourceIds:String[]

The unique identifier of the resource, not null.

See Also
addLoaderListener(Listener, String...)
resetDataback to summary
public void resetData(String resourceId) throws IOException

Explicitly triggers the resetToFallback (loading of the registered data from the classpath backup resource).

Parameters
resourceId:String

The unique identifier of the resource, not null.

Exceptions
IOException:
if a problem occurred.
org.javamoney.moneta.spi.loader back to summary

public Interface LoaderService.Listener


Callback that can be registered to be informed, when a data item was loaded/updated or resetToFallback.
Author
Anatole Tresch
See Also
resetData(String), loadData(String)

Method Summary

Modifier and TypeMethod and Description
public void
newDataLoaded(String
the resource id
resourceId
,
InputStream
the input stream for accessing the data
is
)

Callback called from the LoaderService, when new data was read for a given data item.

Method Detail

newDataLoadedback to summary
public void newDataLoaded(String resourceId, InputStream is)

Callback called from the LoaderService, when new data was read for a given data item.

Parameters
resourceId:String

the resource id

is:InputStream

the input stream for accessing the data

org.javamoney.moneta.spi.loader back to summary

public final Enum LoaderService.UpdatePolicy

extends Enum<LoaderService.UpdatePolicy>
Class Inheritance

Platform RI: The update policy defines how and when the LoaderService tries to update the local cache with newest version of the registered data resources, accessing the configured remote URIs. By default no remote connections are done ( UpdatePolicy#NEVER ).
Author
Anatole Tresch

Field Summary

Modifier and TypeField and Description
public static final LoaderService.UpdatePolicy
LAZY

The resource will be loaded automatically from remote only once, when accessed the first time.

public static final LoaderService.UpdatePolicy
NEVER

The resource will never be updated from remote, only the fallback URL will be evaluated.

public static final LoaderService.UpdatePolicy
ONSTARTUP

The resource will be loaded automatically from remote only once on startup.

public static final LoaderService.UpdatePolicy
SCHEDULED

The resource should be regularly reloaded based on a schedule.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static LoaderService.UpdatePolicy
public static LoaderService.UpdatePolicy[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

LAZYback to summary
public static final LoaderService.UpdatePolicy LAZY

The resource will be loaded automatically from remote only once, when accessed the first time.

NEVERback to summary
public static final LoaderService.UpdatePolicy NEVER

The resource will never be updated from remote, only the fallback URL will be evaluated.

ONSTARTUPback to summary
public static final LoaderService.UpdatePolicy ONSTARTUP

The resource will be loaded automatically from remote only once on startup.

SCHEDULEDback to summary
public static final LoaderService.UpdatePolicy SCHEDULED

The resource should be regularly reloaded based on a schedule.

Constructor Detail

UpdatePolicyback to summary
private UpdatePolicy()

Method Detail

valueOfback to summary
public static LoaderService.UpdatePolicy valueOf(String name)
valuesback to summary
public static LoaderService.UpdatePolicy[] values()