public class StandardRoot extends LifecycleMBeanBase implements WebResourceRoot
Provides the resources implementation for a web application. The
Lifecycle of this class should be aligned with
that of the associated Context.
This implementation assumes that the base attribute supplied to createWebResourceSet(
org.apache.catalina.WebResourceRoot.ResourceSetType, String, String, String,
String) represents the absolute path to a file.
WebResourceRoot.ResourceSetTypeLifecycle.SingleUse| Modifier and Type | Field and Description |
|---|---|
protected static StringManager |
sm |
mserverAFTER_DESTROY_EVENT, AFTER_INIT_EVENT, AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_DESTROY_EVENT, BEFORE_INIT_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, CONFIGURE_START_EVENT, CONFIGURE_STOP_EVENT, PERIODIC_EVENT, START_EVENT, STOP_EVENT| Constructor and Description |
|---|
StandardRoot()
Creates a new standard implementation of
WebResourceRoot. |
StandardRoot(Context context) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addClassResources(WebResourceSet webResourceSet) |
void |
addJarResources(WebResourceSet webResourceSet)
Adds the provided WebResourceSet to this web application as a 'Jar'
resource.
|
void |
addPostResources(WebResourceSet webResourceSet)
Adds the provided WebResourceSet to this web application as a 'Post'
resource.
|
void |
addPreResources(WebResourceSet webResourceSet)
Adds the provided WebResourceSet to this web application as a 'Pre'
resource.
|
void |
backgroundProcess()
This method will be invoked by the context on a periodic basis and allows
the implementation a method that executes periodic tasks, such as purging
expired cache entries.
|
protected WebResourceSet |
createMainResourceSet() |
void |
createWebResourceSet(WebResourceRoot.ResourceSetType type,
java.lang.String webAppMount,
java.lang.String base,
java.lang.String archivePath,
java.lang.String internalPath)
Creates a new
WebResourceSet for this WebResourceRoot
based on the provided parameters. |
void |
createWebResourceSet(WebResourceRoot.ResourceSetType type,
java.lang.String webAppMount,
java.net.URL url,
java.lang.String internalPath)
Creates a new
WebResourceSet for this WebResourceRoot
based on the provided parameters. |
void |
deregisterTrackedResource(TrackedWebResource trackedResource)
Stop tracking specified resource, once it no longer needs to free resources.
|
protected void |
destroyInternal()
Sub-classes wishing to perform additional clean-up should override this
method, ensuring that super.destroyInternal() is the last call in the
overriding method.
|
void |
gc()
Implementations may cache some information to improve performance.
|
boolean |
getAllowLinking()
Determine if this resources allow the use of symbolic links.
|
java.util.List<java.net.URL> |
getBaseUrls() |
long |
getCacheMaxSize()
Get the maximum permitted size for the cache.
|
int |
getCacheObjectMaxSize()
Get the maximum permitted size for a single object in the cache.
|
long |
getCacheTtl()
Get the Time-To-Live (TTL) for cache entries.
|
WebResource |
getClassLoaderResource(java.lang.String path)
Obtain the object that represents the class loader resource at the given
path.
|
WebResource[] |
getClassLoaderResources(java.lang.String path)
Obtain the objects that represent the class loader resource at the given
path.
|
protected WebResourceSet[] |
getClassResources() |
Context |
getContext() |
protected java.lang.String |
getDomainInternal()
Method implemented by sub-classes to identify the domain in which MBeans
should be registered.
|
WebResourceSet[] |
getJarResources() |
protected java.lang.String |
getObjectNameKeyProperties()
Allow sub-classes to specify the key properties component of the
ObjectName that will be used to register this component. |
WebResourceSet[] |
getPostResources() |
WebResourceSet[] |
getPreResources() |
WebResource |
getResource(java.lang.String path)
Obtain the object that represents the resource at the given path.
|
protected WebResource |
getResourceInternal(java.lang.String path,
boolean useClassLoaderResources) |
WebResource[] |
getResources(java.lang.String path)
Obtain the objects that represent the resource at the given path.
|
protected WebResource[] |
getResourcesInternal(java.lang.String path,
boolean useClassLoaderResources) |
java.util.List<java.lang.String> |
getTrackedResources() |
boolean |
getTrackLockedFiles()
Has the track locked files feature been enabled?
|
protected void |
initInternal()
Sub-classes wishing to perform additional initialization should override
this method, ensuring that super.initInternal() is the first call in the
overriding method.
|
boolean |
isCachingAllowed() |
protected boolean |
isPackedWarFile() |
java.lang.String[] |
list(java.lang.String path)
Obtain the list of the names of all of the files and directories located
in the specified directory.
|
WebResource[] |
listResources(java.lang.String path)
Obtain the list of all of the WebResources in the specified directory.
|
protected WebResource[] |
listResources(java.lang.String path,
boolean validate) |
java.util.Set<java.lang.String> |
listWebAppPaths(java.lang.String path)
Obtain the Set of the web applications pathnames of all of the files and
directories located in the specified directory.
|
boolean |
mkdir(java.lang.String path)
Create a new directory at the given path.
|
protected void |
processWebInfLib()
Class loader resources are handled by treating JARs in WEB-INF/lib as
resource JARs (without the internal META-INF/resources/ prefix) mounted
at WEB-INF/classes (rather than the web app root).
|
void |
registerTrackedResource(TrackedWebResource trackedResource)
Add a specified resource to track to be able to later release
resources on stop.
|
protected void |
registerURLStreamHandlerFactory() |
void |
setAllowLinking(boolean allowLinking)
Configure if this resources allow the use of symbolic links.
|
void |
setCacheMaxSize(long cacheMaxSize)
Set the maximum permitted size for the cache.
|
void |
setCacheObjectMaxSize(int cacheObjectMaxSize)
Set the maximum permitted size for a single object in the cache.
|
void |
setCacheTtl(long cacheTtl)
Set the Time-To-Live (TTL) for cache entries.
|
void |
setCachingAllowed(boolean cachingAllowed)
Set whether or not caching is permitted for this web application.
|
void |
setContext(Context context)
Set the web application this WebResourceRoot is associated with.
|
protected void |
setMainResources(WebResourceSet main)
For unit testing.
|
void |
setTrackLockedFiles(boolean trackLockedFiles)
Controls whether the track locked files feature is enabled.
|
protected void |
startInternal()
Sub-classes must ensure that the state is changed to
LifecycleState.STARTING during the execution of this method. |
protected void |
stopInternal()
Sub-classes must ensure that the state is changed to
LifecycleState.STOPPING during the execution of this method. |
boolean |
write(java.lang.String path,
java.io.InputStream is,
boolean overwrite)
Create a new resource at the requested path using the provided
InputStream.
|
getDomain, getObjectName, postDeregister, postRegister, preDeregister, preRegister, register, setDomain, unregister, unregisteraddLifecycleListener, destroy, findLifecycleListeners, fireLifecycleEvent, getState, getStateName, getThrowOnFailure, init, removeLifecycleListener, setState, setState, setThrowOnFailure, start, stopclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddLifecycleListener, destroy, findLifecycleListeners, getState, getStateName, init, removeLifecycleListener, start, stopprotected static final StringManager sm
public StandardRoot()
WebResourceRoot. A no
argument constructor is required for this to work with the digester.
setContext(Context) must be called before this component is
initialized.public StandardRoot(Context context)
public java.lang.String[] list(java.lang.String path)
WebResourceRootlist in interface WebResourceRootpath - The path for the resource of interest relative to the root
of the web application. It must start with '/'.public java.util.Set<java.lang.String> listWebAppPaths(java.lang.String path)
WebResourceRootlistWebAppPaths in interface WebResourceRootpath - The path for the resource of interest relative to the root
of the web application. It must start with '/'.public boolean mkdir(java.lang.String path)
WebResourceRootmkdir in interface WebResourceRootpath - The path for the new resource to create relative to the root
of the web application. It must start with '/'.true if the directory was created, otherwise
falsepublic boolean write(java.lang.String path,
java.io.InputStream is,
boolean overwrite)
WebResourceRootwrite in interface WebResourceRootpath - The path to be used for the new Resource. It is relative
to the root of the web application and must start with
'/'.is - The InputStream that will provide the content for the
new Resource.overwrite - If true and the resource already exists it
will be overwritten. If false and the
resource already exists the write will fail.true if and only if the new Resource is writtenpublic WebResource getResource(java.lang.String path)
WebResourceRootgetResource in interface WebResourceRootpath - The path for the resource of interest relative to the root
of the web application. It must start with '/'.public WebResource getClassLoaderResource(java.lang.String path)
WebResourceRootgetClassLoaderResource in interface WebResourceRootpath - The path of the class loader resource of interest relative
to the the root of class loader resources for this web
application.public WebResource[] getClassLoaderResources(java.lang.String path)
WebResourceRootgetClassLoaderResources in interface WebResourceRootpath - The path for the class loader resource of interest relative
to the root of the class loader resources for the web
application. It must start with '/'.protected final WebResource getResourceInternal(java.lang.String path, boolean useClassLoaderResources)
public WebResource[] getResources(java.lang.String path)
WebResourceRootgetResources in interface WebResourceRootpath - The path for the resource of interest relative to the root
of the web application. It must start with '/'.protected WebResource[] getResourcesInternal(java.lang.String path, boolean useClassLoaderResources)
public WebResource[] listResources(java.lang.String path)
WebResourceRootlistResources in interface WebResourceRootpath - The path for the resource of interest relative to the root
of the web application. It must start with '/'.protected WebResource[] listResources(java.lang.String path, boolean validate)
public void createWebResourceSet(WebResourceRoot.ResourceSetType type, java.lang.String webAppMount, java.net.URL url, java.lang.String internalPath)
WebResourceRootWebResourceSet for this WebResourceRoot
based on the provided parameters.createWebResourceSet in interface WebResourceRoottype - The type of WebResourceSet to createwebAppMount - The path within the web application that the
resources should be published at. It must start
with '/'.url - The URL of the resource (must locate a JAR, file or
directory)internalPath - The path within the resource where the content is to
be found. It must start with '/'.public void createWebResourceSet(WebResourceRoot.ResourceSetType type, java.lang.String webAppMount, java.lang.String base, java.lang.String archivePath, java.lang.String internalPath)
WebResourceRootWebResourceSet for this WebResourceRoot
based on the provided parameters.createWebResourceSet in interface WebResourceRoottype - The type of WebResourceSet to createwebAppMount - The path within the web application that the
resources should be published at. It must start
with '/'.base - The location of the resourcesarchivePath - The path within the resource to the archive where
the content is to be found. If there is no
archive then this should be null.internalPath - The path within the archive (or the resource if the
archivePath is null where the
content is to be found. It must start with '/'.public void addPreResources(WebResourceSet webResourceSet)
WebResourceRootaddPreResources in interface WebResourceRootwebResourceSet - the resource set to usepublic WebResourceSet[] getPreResources()
getPreResources in interface WebResourceRootpublic void addJarResources(WebResourceSet webResourceSet)
WebResourceRootaddJarResources in interface WebResourceRootwebResourceSet - the resource set to usepublic WebResourceSet[] getJarResources()
getJarResources in interface WebResourceRootpublic void addPostResources(WebResourceSet webResourceSet)
WebResourceRootaddPostResources in interface WebResourceRootwebResourceSet - the resource set to usepublic WebResourceSet[] getPostResources()
getPostResources in interface WebResourceRootprotected WebResourceSet[] getClassResources()
protected void addClassResources(WebResourceSet webResourceSet)
public void setAllowLinking(boolean allowLinking)
WebResourceRootsetAllowLinking in interface WebResourceRootallowLinking - true if symbolic links are allowed.public boolean getAllowLinking()
WebResourceRootgetAllowLinking in interface WebResourceRoottrue if symbolic links are allowedpublic void setCachingAllowed(boolean cachingAllowed)
WebResourceRootsetCachingAllowed in interface WebResourceRootcachingAllowed - true to enable caching, else
falsepublic boolean isCachingAllowed()
isCachingAllowed in interface WebResourceRoottrue if caching is permitted for this web application.public long getCacheTtl()
WebResourceRootgetCacheTtl in interface WebResourceRootpublic void setCacheTtl(long cacheTtl)
WebResourceRootsetCacheTtl in interface WebResourceRootcacheTtl - TTL in millisecondspublic long getCacheMaxSize()
WebResourceRootgetCacheMaxSize in interface WebResourceRootpublic void setCacheMaxSize(long cacheMaxSize)
WebResourceRootsetCacheMaxSize in interface WebResourceRootcacheMaxSize - Maximum cache size in kilobytespublic void setCacheObjectMaxSize(int cacheObjectMaxSize)
WebResourceRootInteger.MAX_VALUE.setCacheObjectMaxSize in interface WebResourceRootcacheObjectMaxSize - Maximum size for a single cached object in
kilobytespublic int getCacheObjectMaxSize()
WebResourceRootInteger.MAX_VALUE.getCacheObjectMaxSize in interface WebResourceRootpublic void setTrackLockedFiles(boolean trackLockedFiles)
WebResourceRootWebResource.getInputStream()
will perform a number of additional tasks.
setTrackLockedFiles in interface WebResourceRoottrackLockedFiles - true to enable it, false to
disable itpublic boolean getTrackLockedFiles()
WebResourceRootgetTrackLockedFiles in interface WebResourceRoottrue if it has been enabled, otherwise falsepublic java.util.List<java.lang.String> getTrackedResources()
public Context getContext()
getContext in interface WebResourceRootpublic void setContext(Context context)
WebResourceRootsetContext in interface WebResourceRootcontext - the associated contextprotected void processWebInfLib()
throws LifecycleException
LifecycleException - If an error occurs that should stop the web
application from startingprotected final void setMainResources(WebResourceSet main)
main - The main resourcespublic void backgroundProcess()
WebResourceRootbackgroundProcess in interface WebResourceRootpublic void gc()
WebResourceRootgc in interface WebResourceRootpublic void registerTrackedResource(TrackedWebResource trackedResource)
WebResourceRootregisterTrackedResource in interface WebResourceRoottrackedResource - the resource that will be trackedpublic void deregisterTrackedResource(TrackedWebResource trackedResource)
WebResourceRootderegisterTrackedResource in interface WebResourceRoottrackedResource - the resource that was trackedpublic java.util.List<java.net.URL> getBaseUrls()
getBaseUrls in interface WebResourceRootWebResourceSet.getBaseUrl() for all
WebResourceSets used by this root.protected boolean isPackedWarFile()
protected java.lang.String getDomainInternal()
LifecycleMBeanBasegetDomainInternal in class LifecycleMBeanBaseprotected java.lang.String getObjectNameKeyProperties()
LifecycleMBeanBaseObjectName that will be used to register this component.getObjectNameKeyProperties in class LifecycleMBeanBaseObjectNameprotected void initInternal()
throws LifecycleException
LifecycleMBeanBaseinitInternal in class LifecycleMBeanBaseLifecycleException - If the initialisation failsprotected void registerURLStreamHandlerFactory()
protected void startInternal()
throws LifecycleException
LifecycleBaseLifecycleState.STARTING during the execution of this method.
Changing state will trigger the Lifecycle.START_EVENT event.
If a component fails to start it may either throw a
LifecycleException which will cause it's parent to fail to start
or it can place itself in the error state in which case LifecycleBase.stop()
will be called on the failed component but the parent component will
continue to start normally.startInternal in class LifecycleBaseLifecycleException - Start error occurredprotected WebResourceSet createMainResourceSet()
protected void stopInternal()
throws LifecycleException
LifecycleBaseLifecycleState.STOPPING during the execution of this method.
Changing state will trigger the Lifecycle.STOP_EVENT event.stopInternal in class LifecycleBaseLifecycleException - Stop error occurredprotected void destroyInternal()
throws LifecycleException
LifecycleMBeanBasedestroyInternal in class LifecycleMBeanBaseLifecycleException - If the destruction failsCopyright © 2000-2019 Apache Software Foundation. All Rights Reserved.