public abstract class ContainerBase extends Object implements Container, Lifecycle, Pipeline
getInfo()
, and may implement
a replacement for invoke()
.
All subclasses of this abstract base class will include support for a
Pipeline object that defines the processing to be performed for each request
received by the invoke()
method of this class, utilizing the
"Chain of Responsibility" design pattern. A subclass should encapsulate its
own processing functionality as a Valve
, and configure this
Valve into the pipeline by calling setBasic()
.
This implementation fires property change events, per the JavaBeans design
pattern, for changes in singleton properties. In addition, it fires the
following ContainerEvent
events to listeners who register
themselves with addContainerListener()
:
Type | Data | Description |
---|---|---|
addChild |
Container |
Child container added to this Container. |
addValve |
Valve |
Valve added to this Container. |
removeChild |
Container |
Child container removed from this Container. |
removeValve |
Valve |
Valve removed from this Container. |
start |
null |
Container was started. |
stop |
null |
Container was stopped. |
Modifier and Type | Class and Description |
---|---|
protected class |
ContainerBase.ContainerBackgroundProcessor
Private thread class to invoke the backgroundProcess method
of this container and its children after a fixed delay.
|
protected class |
ContainerBase.PrivilegedAddChild
Perform addChild with the permissions of this class.
|
Modifier and Type | Field and Description |
---|---|
protected int |
backgroundProcessorDelay
The processor delay for this component.
|
protected boolean |
checkIfRequestIsSecure
Flag indicating whether a check to see if the request is secure is
required before adding Pragma and Cache-Control headers when proxy
caching has been disabled
|
protected Map<String,Container> |
children
The child Containers belonging to this Container, keyed by name.
|
protected ObjectName |
controller |
protected int |
debug
The debugging detail level for this component.
|
protected String |
domain |
protected boolean |
hasCustomPipeline |
protected boolean |
initialized |
protected LifecycleSupport |
lifecycle
The lifecycle event support for this component.
|
protected ArrayList<ContainerListener> |
listeners
The container event listeners for this Container.
|
protected Loader |
loader
The Loader implementation with which this Container is associated.
|
protected static Logger |
log |
protected Logger |
logger
The Logger implementation with which this Container is associated.
|
protected Manager |
manager
The Manager implementation with which this Container is associated.
|
protected String |
name
The human-readable name of this Container.
|
protected boolean |
notifyContainerListeners
Indicates whether ContainerListener instances need to be notified
of a particular configuration event.
|
protected ObjectName |
oname |
protected Container |
parent
The parent Container to which this Container is a child.
|
protected ClassLoader |
parentClassLoader
The parent class loader to be configured when we install a Loader.
|
protected Pipeline |
pipeline
The Pipeline object with which this Container is associated.
|
protected static ResourceBundle |
rb |
protected Lock |
readLock |
protected Realm |
realm
The Realm with which this Container is associated.
|
protected DirContext |
resources
The resources DirContext object with which this Container is associated.
|
protected boolean |
started
Has this component been started?
|
protected PropertyChangeSupport |
support
The property change support for this component.
|
protected Lock |
writeLock |
ADD_CHILD_EVENT, ADD_MAPPER_EVENT, ADD_VALVE_EVENT, REMOVE_CHILD_EVENT, REMOVE_MAPPER_EVENT, REMOVE_VALVE_EVENT
AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, INIT_EVENT, START_EVENT, STOP_EVENT
Constructor and Description |
---|
ContainerBase() |
Modifier and Type | Method and Description |
---|---|
void |
addChild(Container child)
Add a new child Container to those associated with this Container,
if supported.
|
void |
addContainerListener(ContainerListener listener)
Add a container event listener to this component.
|
void |
addLifecycleListener(LifecycleListener listener)
Add a lifecycle event listener to this component.
|
void |
addPropertyChangeListener(PropertyChangeListener listener)
Add a property change listener to this component.
|
void |
addValve(GlassFishValve valve)
Add a new Valve to the end of the pipeline associated with this
Container.
|
void |
addValve(Valve valve)
Add Tomcat-style valve.
|
void |
backgroundProcess()
Execute a periodic task, such as reloading, etc.
|
ObjectName |
createObjectName(String domain,
ObjectName parent) |
void |
destroy()
Stops the component and any children and removes all listeners
|
Container |
findChild(String name)
Return the child Container, associated with this Container, with
the specified name (if any); otherwise, return
null |
Container[] |
findChildren()
Return the set of children Containers associated with this Container.
|
ContainerListener[] |
findContainerListeners()
Return the set of container listeners associated with this Container.
|
List<LifecycleListener> |
findLifecycleListeners()
Gets the (possibly empty) list of lifecycle listeners associated
with this Container.
|
void |
fireContainerEvent(String type,
Object data)
Notify all container event listeners that a particular event has
occurred for this Container.
|
int |
getBackgroundProcessorDelay()
Get the delay between the invocation of the backgroundProcess method on
this container and its children.
|
GlassFishValve |
getBasic()
Return the Valve instance that has been distinguished as the basic
Valve for this Pipeline (if any).
|
ObjectName[] |
getChildren() |
String |
getContainerSuffix() |
int |
getDebug()
Return the debugging detail level for this component.
|
String |
getDomain() |
String |
getInfo()
Return descriptive information about this Container implementation and
the corresponding version number, in the format
<description>/<version> . |
ObjectName |
getJmxName() |
Loader |
getLoader()
Return the Loader with which this Container is associated.
|
Logger |
getLogger()
Return the Logger with which this Container is associated.
|
Manager |
getManager()
Return the Manager with which this Container is associated.
|
Object |
getMappingObject()
Return an object which may be utilized for mapping to this component.
|
String |
getName()
Return a name string (suitable for use by humans) that describes this
Container.
|
String |
getObjectName() |
Container |
getParent()
Return the Container for which this Container is a child, if there is
one.
|
ClassLoader |
getParentClassLoader()
Return the parent class loader (if any) for this web application.
|
ObjectName |
getParentName()
Gets the name of the parent container
|
Pipeline |
getPipeline()
Return the Pipeline object that manages the Valves associated with
this Container.
|
Realm |
getRealm()
Return the Realm with which this Container is associated.
|
DirContext |
getResources()
Return the resources DirContext object with which this Container is
associated.
|
ObjectName[] |
getValveObjectNames()
Gets the name of all Tomcat valves
|
GlassFishValve[] |
getValves()
Return the set of Valves in the pipeline associated with this
Container, including the basic Valve (if any).
|
boolean |
hasCustomPipeline() |
boolean |
hasNonBasicValves() |
void |
init()
Init method, part of the MBean lifecycle.
|
void |
invoke(Request request,
Response response)
Process the specified Request, to produce the corresponding Response,
by invoking the first Valve in our pipeline (if any), or the basic
Valve otherwise.
|
boolean |
isCheckIfRequestIsSecure()
Indicates whether the request will be checked to see if it is secure
before adding Pragma and Cache-control headers when proxy caching has
been disabled.
|
protected void |
log(String message)
Log the specified message to our current Logger (if any).
|
protected void |
log(String message,
Throwable throwable)
Log the specified message and exception to our current Logger
(if any).
|
protected String |
logName()
Return the abbreviated name of this container for logging messages
|
void |
removeChild(Container child)
Remove an existing child Container from association with this parent
Container.
|
void |
removeContainerListener(ContainerListener listener)
Remove a container event listener from this component.
|
void |
removeLifecycleListener(LifecycleListener listener)
Removes the given lifecycle event listener from this Container.
|
void |
removeLifecycleListeners()
Removes any lifecycle event listeners from this Container.
|
void |
removePropertyChangeListener(PropertyChangeListener listener)
Remove a property change listener from this component.
|
void |
removeValve(GlassFishValve valve)
Remove the specified Valve from the pipeline associated with this
Container, if it is found; otherwise, do nothing.
|
void |
setBackgroundProcessorDelay(int delay)
Set the delay between the invocation of the execute method on this
container and its children.
|
void |
setBasic(GlassFishValve valve)
Set the Valve instance that has been distinguished as the basic
Valve for this Pipeline (if any).
|
void |
setCheckIfRequestIsSecure(boolean checkIfRequestIsSecure)
Sets the checkIfRequestIsSecure property of this Container.
|
void |
setDebug(int debug)
Set the debugging detail level for this component.
|
void |
setDomain(String domain) |
void |
setLoader(Loader loader)
Set the Loader with which this Container is associated.
|
void |
setLogger(Logger logger)
Set the Logger with which this Container is associated.
|
void |
setManager(Manager manager)
Set the Manager with which this Container is associated.
|
void |
setName(String name)
Set a name string (suitable for use by humans) that describes this
Container.
|
void |
setParent(Container container)
Set the parent Container to which this Container is being added as a
child.
|
void |
setParentClassLoader(ClassLoader parent)
Set the parent class loader (if any) for this web application.
|
void |
setRealm(Realm realm)
Set the Realm with which this Container is associated.
|
void |
setResources(DirContext resources)
Set the resources DirContext object with which this Container is
associated.
|
void |
start()
Prepare for active use of the public methods of this Component.
|
protected void |
startChildren()
Starts the children of this container.
|
void |
stop()
Gracefully shut down active use of the public methods of this Component.
|
protected void |
threadStart()
Start the background thread that will periodically check for
session timeouts.
|
protected void |
threadStop()
Stop the background thread that is periodically checking for
session timeouts.
|
protected static final Logger log
protected static final ResourceBundle rb
protected Map<String,Container> children
protected int debug
protected int backgroundProcessorDelay
protected boolean checkIfRequestIsSecure
protected LifecycleSupport lifecycle
protected ArrayList<ContainerListener> listeners
protected Loader loader
protected Lock readLock
protected Lock writeLock
protected Logger logger
protected Manager manager
protected String name
protected Container parent
protected ClassLoader parentClassLoader
protected Pipeline pipeline
protected boolean hasCustomPipeline
protected Realm realm
protected DirContext resources
protected volatile boolean started
protected boolean initialized
protected PropertyChangeSupport support
protected boolean notifyContainerListeners
protected String domain
protected ObjectName oname
protected ObjectName controller
public int getDebug()
public void setDebug(int debug)
debug
- The new debugging detail levelpublic int getBackgroundProcessorDelay()
getBackgroundProcessorDelay
in interface Container
public void setBackgroundProcessorDelay(int delay)
setBackgroundProcessorDelay
in interface Container
delay
- The delay in seconds between the invocation of
backgroundProcess methodspublic String getInfo()
<description>/<version>
.public Loader getLoader()
null
.public void setLoader(Loader loader)
public Logger getLogger()
null
.public void setLogger(Logger logger)
public Manager getManager()
null
.getManager
in interface Container
public void setManager(Manager manager)
setManager
in interface Container
manager
- The newly associated Managerpublic Object getMappingObject()
getMappingObject
in interface Container
public String getName()
public void setName(String name)
setName
in interface Container
name
- New name of this containerIllegalStateException
- if this Container has already been
added to the children of a parent Container (after which the name
may not be changed)public Container getParent()
null
.public void setParent(Container container)
setParent
in interface Container
container
- Container to which this Container is being added
as a childIllegalArgumentException
- if this Container refuses to become
attached to the specified Containerpublic ClassLoader getParentClassLoader()
getParentClassLoader
in interface Container
public void setParentClassLoader(ClassLoader parent)
setParentClassLoader
in interface Container
parent
- The new parent class loaderpublic Pipeline getPipeline()
getPipeline
in interface Container
public boolean hasCustomPipeline()
hasCustomPipeline
in interface Container
public boolean isCheckIfRequestIsSecure()
isCheckIfRequestIsSecure
in interface Container
public void setCheckIfRequestIsSecure(boolean checkIfRequestIsSecure)
setCheckIfRequestIsSecure
in interface Container
checkIfRequestIsSecure
- true if check is required, false
otherwisepublic Realm getRealm()
null
.public void setRealm(Realm realm)
public DirContext getResources()
null
.getResources
in interface Container
public void setResources(DirContext resources) throws Exception
setResources
in interface Container
resources
- The newly associated DirContextException
public void addChild(Container child)
setParent()
method must be called, with this
Container as an argument. This method may thrown an
IllegalArgumentException
if this Container chooses not
to be attached to the specified Container, in which case it is not addedaddChild
in interface Container
child
- New child Container to be addedIllegalArgumentException
- if this exception is thrown by
the setParent()
method of the child ContainerIllegalArgumentException
- if the new child does not have
a name unique from that of existing children of this ContainerIllegalStateException
- if this Container does not support
child Containerspublic void addContainerListener(ContainerListener listener)
addContainerListener
in interface Container
listener
- The listener to addpublic void addPropertyChangeListener(PropertyChangeListener listener)
addPropertyChangeListener
in interface Container
listener
- The listener to addpublic Container findChild(String name)
null
public Container[] findChildren()
findChildren
in interface Container
public ContainerListener[] findContainerListeners()
findContainerListeners
in interface Container
public void invoke(Request request, Response response) throws IOException, javax.servlet.ServletException
invoke
in interface Container
invoke
in interface Pipeline
request
- Request to be processedresponse
- Response to be producedIllegalStateException
- if neither a pipeline or a basic
Valve have been configured for this ContainerIOException
- if an input/output error occurred while
processingjavax.servlet.ServletException
- if a ServletException was thrown
while processing this requestpublic void removeChild(Container child)
This will also stop the child container.
removeChild
in interface Container
child
- Existing child Container to be removedpublic void removeContainerListener(ContainerListener listener)
removeContainerListener
in interface Container
listener
- The listener to removepublic void removePropertyChangeListener(PropertyChangeListener listener)
removePropertyChangeListener
in interface Container
listener
- The listener to removepublic void addLifecycleListener(LifecycleListener listener)
addLifecycleListener
in interface Lifecycle
listener
- The listener to addpublic List<LifecycleListener> findLifecycleListeners()
findLifecycleListeners
in interface Lifecycle
public void removeLifecycleListener(LifecycleListener listener)
removeLifecycleListener
in interface Lifecycle
listener
- The listener to removepublic void removeLifecycleListeners()
public void start() throws LifecycleException
start
in interface Lifecycle
LifecycleException
- if this component detects a fatal error
that prevents it from being startedpublic void stop() throws LifecycleException
stop
in interface Lifecycle
LifecycleException
- if this component detects a fatal error
that needs to be reportedpublic void init() throws Exception
Exception
public ObjectName getParentName() throws MalformedObjectNameException
MalformedObjectNameException
public void destroy() throws Exception
Exception
public void addValve(GlassFishValve valve)
setContainer
method must be called, with this Container
as an argument. The method may throw an
IllegalArgumentException
if this Valve chooses not to
be associated with this Container, or IllegalStateException
if it is already associated with a different Container.addValve
in interface Pipeline
valve
- Valve to be addedIllegalArgumentException
- if this Container refused to
accept the specified ValveIllegalArgumentException
- if the specified Valve refuses to be
associated with this ContainerIllegalStateException
- if the specified Valve is already
associated with a different Containerpublic void addValve(Valve valve)
public ObjectName[] getValveObjectNames()
ValveBase
public GlassFishValve getBasic()
Return the Valve instance that has been distinguished as the basic Valve for this Pipeline (if any).
public GlassFishValve[] getValves()
public boolean hasNonBasicValves()
hasNonBasicValves
in interface Pipeline
public void removeValve(GlassFishValve valve)
removeValve
in interface Pipeline
valve
- Valve to be removedpublic void setBasic(GlassFishValve valve)
Set the Valve instance that has been distinguished as the basic
Valve for this Pipeline (if any). Prior to setting the basic Valve,
the Valve's setContainer()
will be called, if it
implements Contained
, with the owning Container as an
argument. The method may throw an IllegalArgumentException
if this Valve chooses not to be associated with this Container, or
IllegalStateException
if it is already associated with
a different Container.
public void backgroundProcess()
backgroundProcess
in interface Container
public void fireContainerEvent(String type, Object data)
fireContainerEvent
in interface Container
type
- Event typedata
- Event dataprotected void startChildren()
protected void log(String message)
message
- Message to be loggedprotected void log(String message, Throwable throwable)
message
- Message to be loggedthrowable
- Related exceptionprotected String logName()
public ObjectName getJmxName()
public String getObjectName()
public String getDomain()
public void setDomain(String domain)
public ObjectName[] getChildren()
public ObjectName createObjectName(String domain, ObjectName parent) throws Exception
Exception
public String getContainerSuffix()
protected void threadStart()
protected void threadStop()
Copyright © 2019. All rights reserved.