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

pack-priv Class LoadableURLResource

extends Object
implements DataStreamFactory
Class Inheritance
All Implemented Interfaces
org.javamoney.moneta.spi.loader.DataStreamFactory
Imports
org.javamoney.moneta.spi.loader.*, java.io.ByteArrayInputStream, .ByteArrayOutputStream, .IOException, .InputStream, java.lang.ref.SoftReference, java.net.*, java.util.ArrayList, .Arrays, .Collections, .List, .Map, .Objects, java.util.concurrent.atomic.AtomicInteger, java.util.logging.Level, .Logger

This class represent a resource that automatically is reloaded, if needed. To create this instance use: LoadableURLResourceBuilder
Author
Anatole Tresch

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
LoadableURLResource.WrappedInputStream

InputStream , that helps managing the load count.

Field Summary

Modifier and TypeField and Description
private final AtomicInteger
accessCount

How many times this resource was accessed.

private final ResourceCache
cache

The cache used.

private long
cacheTTLMillis

The time to live (TTL) of cache entries in milliseconds, by default 24 h.

private volatile SoftReference<byte[]>
data

The current data array.

private final URI
fallbackLocation

The fallback location (classpath).

private long
lastLoaded

THe timestamp of the last successful load.

private final AtomicInteger
loadCount

How many times this resource was successfully loaded.

private final Object
lock

Lock for this instance.

private static final Logger
LOG

The logger used.

private final Map<String, String>
properties

The resource configuration.

private final List<URI>
remoteResources

The remote URLs to be looked up (first wins).

private final String
resourceId

resource id.

private final LoaderService.UpdatePolicy
updatePolicy

The required update policy for this resource.

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected void
clearCache()

This method is called when the cached data should be removed, e.g. after an explicit fallback reload, or a clear operation.

public final int

Returns:

the number of successful accesses.
getAccessCount
()

Get the number of successful accesses.

public final byte[]

Returns:

the data to load.
getData
()

Get the resource data.

public InputStream

Returns:

the input stream.
getDataStream
()

Implements org.javamoney.moneta.spi.loader.DataStreamFactory.getDataStream.

Get the resource data as input stream.

public final URI

Returns:

the fallback location, or null.
getFallbackResource
()

Return the fallback location.

public final long

Returns:

the lastLoaded
getLastLoaded
()

Get the timestamp of the last succesful load.

public final int

Returns:

the number of successful loads.
getLoadCount
()

Get the number of active loads of this resource (InputStream).

public Map<String, String>

Returns:

the configuration properties of this resource, never null.
getProperties
()

Get the configuration properties of this resource.

public final List<URI>

Returns:

the remote locations, maybe empty.
getRemoteResources
()

Get the remote locations.

public final String

Returns:

the resourceId
getResourceId
()

Get the resourceId.

public LoaderService.UpdatePolicy

Returns:

the UpdatePolicy of this resource, never null.
getUpdatePolicy
()

Get the UpdatePolicy of this resource.

public boolean

Returns:

true, if load succeeded.
load
()

Loads the resource, first from the remote resources, if that fails from the fallback location.

protected boolean
load(URI
the target URL
itemToLoad
,
boolean
true, for a fallback URL.
fallbackLoad
)

Tries to load the data from the given location.

public boolean

Returns:

true, on success.
loadFallback
()

Try to load the resource from the fallback resources.

public boolean

Returns:

true, on success.
loadRemote
()

Try to load the resource from the remote locations.

public boolean

Returns:

true, if data could be read and applied from the cache sucdcessfully.
readCache
()

This method is called when the data should be loaded from the cache.

public boolean

Returns:

true on success.
resetToFallback
()

Explicitly override the resource wih the fallback context and resets the load counter.

protected final void
setData(byte[] bytes)

private boolean
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public void
protected void
writeCache()

This method is called after data could be successfully loaded from a non fallback resource.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

accessCountback to summary
private final AtomicInteger accessCount

How many times this resource was accessed.

cacheback to summary
private final ResourceCache cache

The cache used.

cacheTTLMillisback to summary
private long cacheTTLMillis

The time to live (TTL) of cache entries in milliseconds, by default 24 h.

databack to summary
private volatile SoftReference<byte[]> data

The current data array.

fallbackLocationback to summary
private final URI fallbackLocation

The fallback location (classpath).

lastLoadedback to summary
private long lastLoaded

THe timestamp of the last successful load.

loadCountback to summary
private final AtomicInteger loadCount

How many times this resource was successfully loaded.

lockback to summary
private final Object lock

Lock for this instance.

LOGback to summary
private static final Logger LOG

The logger used.

propertiesback to summary
private final Map<String, String> properties

The resource configuration.

remoteResourcesback to summary
private final List<URI> remoteResources

The remote URLs to be looked up (first wins).

resourceIdback to summary
private final String resourceId

resource id.

updatePolicyback to summary
private final LoaderService.UpdatePolicy updatePolicy

The required update policy for this resource.

Constructor Detail

LoadableURLResourceback to summary
pack-priv LoadableURLResource(ResourceCache cache, LoadDataInformation loadDataInformation)

Method Detail

clearCacheback to summary
protected void clearCache()

This method is called when the cached data should be removed, e.g. after an explicit fallback reload, or a clear operation.

getAccessCountback to summary
public final int getAccessCount()

Get the number of successful accesses.

Returns:int

the number of successful accesses.

getDataback to summary
public final byte[] getData()

Get the resource data. This will trigger a full load, if the resource is not loaded, e.g. for LAZY resources.

Returns:byte[]

the data to load.

getDataStreamback to summary
public InputStream getDataStream()

Implements org.javamoney.moneta.spi.loader.DataStreamFactory.getDataStream.

Get the resource data as input stream.

Returns:InputStream

the input stream.

getFallbackResourceback to summary
public final URI getFallbackResource()

Return the fallback location.

Returns:URI

the fallback location, or null.

getLastLoadedback to summary
public final long getLastLoaded()

Get the timestamp of the last succesful load.

Returns:long

the lastLoaded

getLoadCountback to summary
public final int getLoadCount()

Get the number of active loads of this resource (InputStream).

Returns:int

the number of successful loads.

getPropertiesback to summary
public Map<String, String> getProperties()

Get the configuration properties of this resource.

Returns:Map<String, String>

the configuration properties of this resource, never null.

getRemoteResourcesback to summary
public final List<URI> getRemoteResources()

Get the remote locations.

Returns:List<URI>

the remote locations, maybe empty.

getResourceIdback to summary
public final String getResourceId()

Get the resourceId.

Returns:String

the resourceId

getUpdatePolicyback to summary
public LoaderService.UpdatePolicy getUpdatePolicy()

Get the UpdatePolicy of this resource.

Returns:LoaderService.UpdatePolicy

the UpdatePolicy of this resource, never null.

loadback to summary
public boolean load()

Loads the resource, first from the remote resources, if that fails from the fallback location.

Returns:boolean

true, if load succeeded.

loadback to summary
protected boolean load(URI itemToLoad, boolean fallbackLoad)

Tries to load the data from the given location. The location hereby can be a remote location or a local location. Also it can be an URL pointing to a current dataset, or an url directing to fallback resources, e.g. within the current classpath.

Parameters
itemToLoad:URI

the target URL

fallbackLoad:boolean

true, for a fallback URL.

loadFallbackback to summary
public boolean loadFallback()

Try to load the resource from the fallback resources. This will override any remote data already loaded, and also will clear the cached data.

Returns:boolean

true, on success.

loadRemoteback to summary
public boolean loadRemote()

Try to load the resource from the remote locations.

Returns:boolean

true, on success.

readCacheback to summary
public boolean readCache()

This method is called when the data should be loaded from the cache. This method abstracts the effective caching mechanism implemented. By default it tries to read a file from the current user's home directory. If the data could be read, #setData(byte[]) should be called to apply the data read.

Returns:boolean

true, if data could be read and applied from the cache sucdcessfully.

resetToFallbackback to summary
public boolean resetToFallback()

Explicitly override the resource wih the fallback context and resets the load counter.

Returns:boolean

true on success.

setDataback to summary
protected final void setData(byte[] bytes)
shouldReadDataFromFallbackback to summary
private boolean shouldReadDataFromFallback()
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()
writeCacheback to summary
protected void writeCache() throws IOException

This method is called after data could be successfully loaded from a non fallback resource. This method by default writes an file containing the data into the user's local home directory, so subsequent or later calls, even after a VM restart, should be able to recover this information.

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

private final Class LoadableURLResource.WrappedInputStream

extends InputStream
Class Inheritance

InputStream , that helps managing the load count.
Author
Anatole

Field Summary

Modifier and TypeField and Description
private final InputStream

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Closes this input stream and releases any system resources associated with the stream.

public int
read()

Implements abstract java.io.InputStream.read.

Reads the next byte of data from the input stream.

Inherited from java.io.InputStream:
availablemarkmarkSupportednullInputStreamreadreadreadAllBytesreadNBytesreadNBytesresetskipskipNBytestransferTo

Field Detail

wrappedback to summary
private final InputStream wrapped

Constructor Detail

WrappedInputStreamback to summary
pack-priv WrappedInputStream(InputStream wrapped)

Method Detail

closeback to summary
public void close() throws IOException

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.InputStream.close.

Closes this input stream and releases any system resources associated with the stream.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
readback to summary
public int read() throws IOException

Implements abstract java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.