Top Description Fields Constructors Methods
org.javamoney.moneta.spi.loader.urlconnection

public Class URLConnectionLoaderService

extends Object
implements LoaderService
Class Inheritance
All Implemented Interfaces
org.javamoney.moneta.spi.loader.LoaderService
Annotations
@SuppressWarnings:SynchronizationOnLocalVariableOrMethodParameter
Imports
org.javamoney.moneta.spi.loader.*, java.io.IOException, .InputStream, java.net.URI, java.util.List, .Map, .Objects, .Optional, .Set, .Timer, java.util.concurrent.ConcurrentHashMap, .ExecutorService, .Executors, .Future, java.util.logging.Level, .Logger, javax.money.spi.Bootstrap

Deprecated

Will be removed in favor of OkHttpLoaderService

This class provides a mechanism to register resources, that may be updated regularly. The implementation, based on the LoaderService.UpdatePolicy loads/updates the resources from arbitrary locations via java.net.URLConnection and stores them to the format file cache. Default loading tasks can be configured within the javamoney.properties file.
Authors
Anatole Tresch, Werner Keil
See Also
org.javamoney.moneta.spi.loader.LoaderConfigurator, java.net.URLConnection

Field Summary

Modifier and TypeField and Description
private static final ResourceCache
CACHE

The local resource cache, to allow keeping current data on the local system.

private URLConnectionLoaderServiceFacade
private final ExecutorService
executors

The thread pool used for loading of data, triggered by the timer.

private final LoaderListener
listener

The registered Listener instances.

private static final Logger
LOG

Logger used.

private final Map<String, LoadableURLResource>
resources

The data resources managed by this instance.

private volatile Timer
timer

The timer used for schedules.

Constructor Summary

AccessConstructor and Description
public
URLConnectionLoaderService()

Constructor, initializing from config.

Method Summary

Modifier and TypeMethod and Description
public void
addLoaderListener(LoaderService.Listener l, String... resourceIds)

Implements org.javamoney.moneta.spi.loader.LoaderService.addLoaderListener.

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

public InputStream
getData(String resourceId)

Implements org.javamoney.moneta.spi.loader.LoaderService.getData.

Access the input stream of the given data resource.

pack-priv static ResourceCache

Returns:

the resource cache, not null.
getResourceCache
()

Get the resource cache loaded.

public Set<String>
getResourceIds()

Implements org.javamoney.moneta.spi.loader.LoaderService.getResourceIds.

Get a Set of all registered data resource identifiers.

public Map<String, String>
getUpdateConfiguration(String resourceId)

Implements org.javamoney.moneta.spi.loader.LoaderService.getUpdateConfiguration.

Get the update configuration for the given dataId.

public LoaderService.UpdatePolicy
getUpdatePolicy(String resourceId)

Implements org.javamoney.moneta.spi.loader.LoaderService.getUpdatePolicy.

Get the UpdatePolicy in place for the given dataId.

pack-priv void
initialize()

This method reads initial loads from the javamoney.properties and installs the according timers.

public boolean
isResourceRegistered(String resourceId)

Implements org.javamoney.moneta.spi.loader.LoaderService.isResourceRegistered.

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

public boolean
loadData(String resourceId)

Implements org.javamoney.moneta.spi.loader.LoaderService.loadData.

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

public Future<Boolean>
loadDataAsync(final String resourceId)

Implements org.javamoney.moneta.spi.loader.LoaderService.loadDataAsync.

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

public boolean
loadDataLocal(String resourceId)

Implements org.javamoney.moneta.spi.loader.LoaderService.loadDataLocal.

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

private static ResourceCache

Returns:

the cache to be used, not null.
loadResourceCache
()

Loads the cache to be used.

public void
registerAndLoadData(LoadDataInformation loadDataInformation)

Implements org.javamoney.moneta.spi.loader.LoaderService.registerAndLoadData.

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)

Implements org.javamoney.moneta.spi.loader.LoaderService.registerAndLoadData.

public void
registerData(LoadDataInformation loadDataInformation)

Implements org.javamoney.moneta.spi.loader.LoaderService.registerData.

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)

Implements org.javamoney.moneta.spi.loader.LoaderService.registerData.

public void
public void
resetData(String resourceId)

Implements org.javamoney.moneta.spi.loader.LoaderService.resetData.

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

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public void
unload(String
the resource id.
resourceId
)

Removes a resource managed.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

CACHEback to summary
private static final ResourceCache CACHE

The local resource cache, to allow keeping current data on the local system.

defaultLoaderServiceFacadeback to summary
private URLConnectionLoaderServiceFacade defaultLoaderServiceFacade
executorsback to summary
private final ExecutorService executors

The thread pool used for loading of data, triggered by the timer.

listenerback to summary
private final LoaderListener listener

The registered Listener instances.

LOGback to summary
private static final Logger LOG

Logger used.

resourcesback to summary
private final Map<String, LoadableURLResource> resources

The data resources managed by this instance.

timerback to summary
private volatile Timer timer

The timer used for schedules.

Constructor Detail

URLConnectionLoaderServiceback to summary
public URLConnectionLoaderService()

Constructor, initializing from config.

Method Detail

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

Implements org.javamoney.moneta.spi.loader.LoaderService.addLoaderListener.

Doc from org.javamoney.moneta.spi.loader.LoaderService.addLoaderListener.

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)

Annotations
@Override
getDataback to summary
public InputStream getData(String resourceId) throws IOException

Implements org.javamoney.moneta.spi.loader.LoaderService.getData.

Doc from org.javamoney.moneta.spi.loader.LoaderService.getData.

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.

Annotations
@Override
Exceptions
IOException:
if a problem occurred.
getResourceCacheback to summary
pack-priv static ResourceCache getResourceCache()

Get the resource cache loaded.

Returns:ResourceCache

the resource cache, not null.

getResourceIdsback to summary
public Set<String> getResourceIds()

Implements org.javamoney.moneta.spi.loader.LoaderService.getResourceIds.

Doc from org.javamoney.moneta.spi.loader.LoaderService.getResourceIds.

Get a Set of all registered data resource identifiers.

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

Implements org.javamoney.moneta.spi.loader.LoaderService.getUpdateConfiguration.

Doc from org.javamoney.moneta.spi.loader.LoaderService.getUpdateConfiguration.

Get the update configuration for the given dataId.

Annotations
@Override
getUpdatePolicyback to summary
public LoaderService.UpdatePolicy getUpdatePolicy(String resourceId)

Implements org.javamoney.moneta.spi.loader.LoaderService.getUpdatePolicy.

Doc from org.javamoney.moneta.spi.loader.LoaderService.getUpdatePolicy.

Get the UpdatePolicy in place for the given dataId.

Annotations
@Override
initializeback to summary
pack-priv void initialize()

This method reads initial loads from the javamoney.properties and installs the according timers.

isResourceRegisteredback to summary
public boolean isResourceRegistered(String resourceId)

Implements org.javamoney.moneta.spi.loader.LoaderService.isResourceRegistered.

Doc from org.javamoney.moneta.spi.loader.LoaderService.isResourceRegistered.

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

Annotations
@Override
loadDataback to summary
public boolean loadData(String resourceId)

Implements org.javamoney.moneta.spi.loader.LoaderService.loadData.

Doc from org.javamoney.moneta.spi.loader.LoaderService.loadData.

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

Annotations
@Override
loadDataAsyncback to summary
public Future<Boolean> loadDataAsync(final String resourceId)

Implements org.javamoney.moneta.spi.loader.LoaderService.loadDataAsync.

Doc from org.javamoney.moneta.spi.loader.LoaderService.loadDataAsync.

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

Annotations
@Override
loadDataLocalback to summary
public boolean loadDataLocal(String resourceId)

Implements org.javamoney.moneta.spi.loader.LoaderService.loadDataLocal.

Doc from org.javamoney.moneta.spi.loader.LoaderService.loadDataLocal.

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

Annotations
@Override
loadResourceCacheback to summary
private static ResourceCache loadResourceCache()

Loads the cache to be used.

Returns:ResourceCache

the cache to be used, not null.

registerAndLoadDataback to summary
public void registerAndLoadData(LoadDataInformation loadDataInformation)

Implements org.javamoney.moneta.spi.loader.LoaderService.registerAndLoadData.

Doc from org.javamoney.moneta.spi.loader.LoaderService.registerAndLoadData.

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.

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

Implements org.javamoney.moneta.spi.loader.LoaderService.registerAndLoadData.

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

Implements org.javamoney.moneta.spi.loader.LoaderService.registerData.

Doc from org.javamoney.moneta.spi.loader.LoaderService.registerData.

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.

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

Implements org.javamoney.moneta.spi.loader.LoaderService.registerData.

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

Implements org.javamoney.moneta.spi.loader.LoaderService.removeLoaderListener.

Doc from org.javamoney.moneta.spi.loader.LoaderService.removeLoaderListener.

Remove a registered Listener callback.

Annotations
@Override
resetDataback to summary
public void resetData(String resourceId) throws IOException

Implements org.javamoney.moneta.spi.loader.LoaderService.resetData.

Doc from org.javamoney.moneta.spi.loader.LoaderService.resetData.

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

Annotations
@Override
Exceptions
IOException:
if a problem occurred.
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
unloadback to summary
public void unload(String resourceId)

Removes a resource managed.

Parameters
resourceId:String

the resource id.