public abstract class AbstractNutDao extends PollingScheduler<NutDaoListener> implements NutDao
An abstract implementation of a NutDao
. As any implementation should provides it, this class defines a base
path when retrieved nuts, a set of proxies URIs and a polling feature.
The class is designed to be thread safe.
Modifier and Type | Class and Description |
---|---|
static class |
AbstractNutDao.VersionNumberStrategy
This class wraps all information required by the
AbstractNutDao regarding version number management. |
class |
AbstractNutDao.WithRootPathNutDao
This class represents a modification of the the enclosing class behavior when the
NutDao.create(String, ProcessContext)
method is called. |
PollingScheduler.Polling
NutDao.PathFormat
Constructor and Description |
---|
AbstractNutDao(String base,
Boolean basePathAsSysProp,
String[] proxies,
int pollingSeconds,
AbstractNutDao.VersionNumberStrategy vns)
Builds a new instance.
|
Modifier and Type | Method and Description |
---|---|
protected String |
absolutePathOf(String relativePath)
Computes the absolute path of the given path relative to the DAO's base path.
|
protected abstract Nut |
accessFor(String realPath,
NutType type,
ProcessContext processContext)
Creates an access for the given parameters through a
Nut implementation. |
List<String> |
computeRealPaths(String pathName,
NutDao.PathFormat format,
ProcessContext processContext)
Returns a list of paths depending of the behavior of the dao with the given path.
|
List<Nut> |
create(String pathName,
NutDao.PathFormat format,
ProcessContext processContext)
Creates a list of
nuts thanks to the given path. |
List<Nut> |
create(String path,
ProcessContext processContext)
Creates a list of
nuts thanks to the given path considered as represented in any format. |
String |
getBasePath()
Returns the base path prefixing all paths.
|
String[] |
getProxyUris()
Gets the proxy URIs.
|
protected Future<Long> |
getVersionNumber(String path,
ProcessContext processContext)
Gets the version number for the
Nut the given path. |
AbstractNutDao.VersionNumberStrategy |
getVersionNumberStrategy()
Gets the version management strategy.
|
protected abstract List<String> |
listNutsPaths(String pattern)
Lists all the nuts path matching the given pattern.
|
String |
proxyUriFor(Nut nut)
Returns an URI in a
String representation of a proxy serving the given nut. |
void |
run() |
void |
save(Nut nut)
Saves the give nut.
|
Boolean |
saveSupported()
Indicates if this DAO is able to save a nut, which depends on the underlying protocol.
|
void |
shutdown()
Shutdowns this DAO by releasing its resources.
|
String |
toString() |
NutDao |
withRootPath(String rootPath)
Returns an instance that prefixes any nut name to be created with the given root path.
|
getLastUpdateTimestampFor, getNutObservers, getPollingInterval, observe, setPollingInterval
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
exists, newInputStream, observe
public AbstractNutDao(String base, Boolean basePathAsSysProp, String[] proxies, int pollingSeconds, AbstractNutDao.VersionNumberStrategy vns)
Builds a new instance.
base
- prefix for all paths (an IllegalArgumentException
is thrown is null
basePathAsSysProp
- true
if the base path is a system propertyproxies
- proxy URIs serving the nutpollingSeconds
- interval in seconds for polling feature (-1 to disable)vns
- fixed version numberprotected Future<Long> getVersionNumber(String path, ProcessContext processContext) throws IOException
Gets the version number for the Nut
the given path.
If the AbstractNutDao#versionNumberStrategy#contentBasedVersionNumber
value related to
ApplicationConfig.CONTENT_BASED_VERSION_NUMBER
is true
, then the content is read
to compute the hash value. However, it uses the last modification timestamp.
processContext
- the process contextpath
- the nut's pathIOException
- if version number could not be computedprotected String absolutePathOf(String relativePath)
Computes the absolute path of the given path relative to the DAO's base path.
relativePath
- the relative pathpublic List<Nut> create(String path, ProcessContext processContext) throws IOException
Creates a list of nuts
thanks to the given path considered as represented in any format.
create
in interface NutDao
path
- the path representing the location of the nut(s)processContext
- the process context calling this methodIOException
- if an I/O error occurs when creating the nutNutDao.create(String, com.github.wuic.nut.dao.NutDao.PathFormat, com.github.wuic.ProcessContext)
public List<Nut> create(String pathName, NutDao.PathFormat format, ProcessContext processContext) throws IOException
Creates a list of nuts
thanks to the given path.
A NutDao.PathFormat
also gives information on the format used in the string representation of the given path.
create
in interface NutDao
pathName
- the path representing the location of the nut(s)format
- the path formatprocessContext
- the process context calling this methodIOException
- if an I/O error occurs when creating the nutpublic String proxyUriFor(Nut nut)
Returns an URI in a String
representation of a proxy serving the given nut.
If many proxies are defined, proxy URI is selected in a round-robin mode. Each time a proxy is used, it won't be reused until all other proxies have been used too.
proxyUriFor
in interface NutDao
nut
- the nutnull
if not proxy is setpublic void save(Nut nut)
Saves the give nut. An UnsupportedOperationException
will be thrown if the implementation supports
only nut access.
public Boolean saveSupported()
Indicates if this DAO is able to save a nut, which depends on the underlying protocol.
saveSupported
in interface NutDao
true
if NutDao.save(Nut)
is supported, false
otherwisepublic void shutdown()
Shutdowns this DAO by releasing its resources.
public NutDao withRootPath(String rootPath)
Returns an instance that prefixes any nut name to be created with the given root path.
withRootPath
in interface NutDao
rootPath
- the root pathpublic List<String> computeRealPaths(String pathName, NutDao.PathFormat format, ProcessContext processContext) throws IOException
Returns a list of paths depending of the behavior of the dao with the given path. In fact, the dao could consider the path as a regex, a directory, etc.
pathName
- the path accessformat
- the path formatprocessContext
- the process contextIOException
- if an I/O error occurs when creating the nutpublic String getBasePath()
Returns the base path prefixing all paths.
public String[] getProxyUris()
Gets the proxy URIs.
public AbstractNutDao.VersionNumberStrategy getVersionNumberStrategy()
Gets the version management strategy.
protected abstract List<String> listNutsPaths(String pattern) throws IOException
Lists all the nuts path matching the given pattern.
pattern
- the patternIOException
- if any I/O error occurs while reading nutsprotected abstract Nut accessFor(String realPath, NutType type, ProcessContext processContext) throws IOException
Creates an access for the given parameters through a Nut
implementation.
realPath
- the real path to use to access the nuttype
- the path's typeprocessContext
- the process contextNut
IOException
- if an I/O error occurs while creating accessCopyright © 2012-2015. All Rights Reserved.