Package org.apache.catalina.core
Class StandardServer
- java.lang.Object
-
- org.apache.catalina.util.LifecycleBase
-
- org.apache.catalina.util.LifecycleMBeanBase
-
- org.apache.catalina.core.StandardServer
-
- All Implemented Interfaces:
javax.management.MBeanRegistration
,JmxEnabled
,Lifecycle
,Server
public final class StandardServer extends LifecycleMBeanBase implements Server
Standard implementation of the Server interface, available for use (but not required) when deploying and starting Catalina.- Author:
- Craig R. McClanahan
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.catalina.Lifecycle
Lifecycle.SingleUse
-
-
Field Summary
-
Fields inherited from class org.apache.catalina.util.LifecycleMBeanBase
mserver
-
Fields inherited from interface org.apache.catalina.Lifecycle
AFTER_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 Summary
Constructors Constructor Description StandardServer()
Construct a default instance of this class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Add a property change listener to this component.void
addService(Service service)
Add a new Service to the set of defined Services.void
await()
Wait until a proper shutdown command is received, then return.protected void
destroyInternal()
Subclasses implement this method to perform any instance destruction required.Service
findService(java.lang.String name)
Find the specified ServiceService[]
findServices()
java.lang.String
getAddress()
Catalina
getCatalina()
java.io.File
getCatalinaBase()
java.io.File
getCatalinaHome()
protected java.lang.String
getDomainInternal()
Method implemented by subclasses to identify the domain in which MBeans should be registered.javax.naming.Context
getGlobalNamingContext()
NamingResourcesImpl
getGlobalNamingResources()
java.lang.Object
getNamingToken()
protected java.lang.String
getObjectNameKeyProperties()
Allow subclasses to specify the key properties component of theObjectName
that will be used to register this component.java.lang.ClassLoader
getParentClassLoader()
int
getPeriodicEventDelay()
int
getPort()
int
getPortOffset()
Get the number that offsets the port used for shutdown commands.int
getPortWithOffset()
Get the actual port on which server is listening for the shutdown commands.java.lang.String
getServerBuilt()
Return the current server built timestampjava.lang.String
getServerInfo()
Report the current Tomcat Server Release numberjava.lang.String
getServerNumber()
Return the current server's version number.javax.management.ObjectName[]
getServiceNames()
java.lang.String
getShutdown()
java.util.concurrent.ScheduledExecutorService
getUtilityExecutor()
int
getUtilityThreads()
Get the utility thread count.boolean
getUtilityThreadsAsDaemon()
Get if the utility threads are daemon threads.protected void
initInternal()
Subclasses implement this method to perform any instance initialisation required.void
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Remove a property change listener from this component.void
removeService(Service service)
Remove the specified Service from the set associated from this Server.void
setAddress(java.lang.String address)
Set the address on which we listen to for shutdown commands.void
setCatalina(Catalina catalina)
Set the outer Catalina startup/shutdown component if present.void
setCatalinaBase(java.io.File catalinaBase)
Set the configured base (instance) directory.void
setCatalinaHome(java.io.File catalinaHome)
Set the configured home (binary) directory.void
setGlobalNamingContext(javax.naming.Context globalNamingContext)
Set the global naming resources context.void
setGlobalNamingResources(NamingResourcesImpl globalNamingResources)
Set the global naming resources.void
setParentClassLoader(java.lang.ClassLoader parent)
Set the parent class loader for this server.void
setPeriodicEventDelay(int periodicEventDelay)
Set the new period between two lifecycle events in seconds.void
setPort(int port)
Set the port number we listen to for shutdown commands.void
setPortOffset(int portOffset)
Set the number that offsets the server port used for shutdown commands.void
setShutdown(java.lang.String shutdown)
Set the shutdown command we are waiting for.void
setUtilityThreads(int utilityThreads)
Set the utility thread count.void
setUtilityThreadsAsDaemon(boolean utilityThreadsAsDaemon)
Set the utility threads daemon flag.protected void
startInternal()
Subclasses must ensure that the state is changed toLifecycleState.STARTING
during the execution of this method.void
stopAwait()
protected void
stopInternal()
Subclasses must ensure that the state is changed toLifecycleState.STOPPING
during the execution of this method.void
storeConfig()
Write the configuration information for this entireServer
out to the server.xml configuration file.void
storeContext(Context context)
Write the configuration information forContext
out to the specified configuration file.java.lang.String
toString()
-
Methods inherited from class org.apache.catalina.util.LifecycleMBeanBase
getDomain, getObjectName, postDeregister, postRegister, preDeregister, preRegister, register, setDomain, unregister, unregister
-
Methods inherited from class org.apache.catalina.util.LifecycleBase
addLifecycleListener, destroy, findLifecycleListeners, fireLifecycleEvent, getState, getStateName, getThrowOnFailure, init, removeLifecycleListener, setState, setState, setThrowOnFailure, start, stop
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.catalina.Lifecycle
addLifecycleListener, destroy, findLifecycleListeners, getState, getStateName, init, removeLifecycleListener, start, stop
-
-
-
-
Method Detail
-
getNamingToken
public java.lang.Object getNamingToken()
- Specified by:
getNamingToken
in interfaceServer
- Returns:
- the token necessary for operations on the associated JNDI naming context.
-
getGlobalNamingContext
public javax.naming.Context getGlobalNamingContext()
- Specified by:
getGlobalNamingContext
in interfaceServer
- Returns:
- the global naming resources context.
-
setGlobalNamingContext
public void setGlobalNamingContext(javax.naming.Context globalNamingContext)
Set the global naming resources context.- Parameters:
globalNamingContext
- The new global naming resource context
-
getGlobalNamingResources
public NamingResourcesImpl getGlobalNamingResources()
- Specified by:
getGlobalNamingResources
in interfaceServer
- Returns:
- the global naming resources.
-
setGlobalNamingResources
public void setGlobalNamingResources(NamingResourcesImpl globalNamingResources)
Description copied from interface:Server
Set the global naming resources.- Specified by:
setGlobalNamingResources
in interfaceServer
- Parameters:
globalNamingResources
- The new global naming resources
-
getServerInfo
public java.lang.String getServerInfo()
Report the current Tomcat Server Release number- Returns:
- Tomcat release identifier
-
getServerBuilt
public java.lang.String getServerBuilt()
Return the current server built timestamp- Returns:
- server built timestamp.
-
getServerNumber
public java.lang.String getServerNumber()
Return the current server's version number.- Returns:
- server's version number.
-
getPort
public int getPort()
- Specified by:
getPort
in interfaceServer
- Returns:
- the port number we listen to for shutdown commands.
- See Also:
Server.getPortOffset()
,Server.getPortWithOffset()
-
setPort
public void setPort(int port)
Description copied from interface:Server
Set the port number we listen to for shutdown commands.- Specified by:
setPort
in interfaceServer
- Parameters:
port
- The new port number- See Also:
Server.setPortOffset(int)
-
getPortOffset
public int getPortOffset()
Description copied from interface:Server
Get the number that offsets the port used for shutdown commands. For example, if port is 8005, and portOffset is 1000, the server listens at 9005.- Specified by:
getPortOffset
in interfaceServer
- Returns:
- the port offset
-
setPortOffset
public void setPortOffset(int portOffset)
Description copied from interface:Server
Set the number that offsets the server port used for shutdown commands. For example, if port is 8005, and you set portOffset to 1000, connector listens at 9005.- Specified by:
setPortOffset
in interfaceServer
- Parameters:
portOffset
- sets the port offset
-
getPortWithOffset
public int getPortWithOffset()
Description copied from interface:Server
Get the actual port on which server is listening for the shutdown commands. If you do not set port offset, port is returned. If you set port offset, port offset + port is returned.- Specified by:
getPortWithOffset
in interfaceServer
- Returns:
- the port with offset
-
getAddress
public java.lang.String getAddress()
- Specified by:
getAddress
in interfaceServer
- Returns:
- the address on which we listen to for shutdown commands.
-
setAddress
public void setAddress(java.lang.String address)
Description copied from interface:Server
Set the address on which we listen to for shutdown commands.- Specified by:
setAddress
in interfaceServer
- Parameters:
address
- The new address
-
getShutdown
public java.lang.String getShutdown()
- Specified by:
getShutdown
in interfaceServer
- Returns:
- the shutdown command string we are waiting for.
-
setShutdown
public void setShutdown(java.lang.String shutdown)
Description copied from interface:Server
Set the shutdown command we are waiting for.- Specified by:
setShutdown
in interfaceServer
- Parameters:
shutdown
- The new shutdown command
-
getCatalina
public Catalina getCatalina()
- Specified by:
getCatalina
in interfaceServer
- Returns:
- the outer Catalina startup/shutdown component if present.
-
setCatalina
public void setCatalina(Catalina catalina)
Description copied from interface:Server
Set the outer Catalina startup/shutdown component if present.- Specified by:
setCatalina
in interfaceServer
- Parameters:
catalina
- the outer Catalina component
-
getUtilityThreads
public int getUtilityThreads()
Description copied from interface:Server
Get the utility thread count.- Specified by:
getUtilityThreads
in interfaceServer
- Returns:
- the thread count
-
setUtilityThreads
public void setUtilityThreads(int utilityThreads)
Description copied from interface:Server
Set the utility thread count.- Specified by:
setUtilityThreads
in interfaceServer
- Parameters:
utilityThreads
- the new thread count
-
getUtilityThreadsAsDaemon
public boolean getUtilityThreadsAsDaemon()
Get if the utility threads are daemon threads.- Returns:
- the threads daemon flag
-
setUtilityThreadsAsDaemon
public void setUtilityThreadsAsDaemon(boolean utilityThreadsAsDaemon)
Set the utility threads daemon flag. The default value is true.- Parameters:
utilityThreadsAsDaemon
- the new thread daemon flag
-
getPeriodicEventDelay
public int getPeriodicEventDelay()
- Returns:
- The period between two lifecycle events, in seconds
-
setPeriodicEventDelay
public void setPeriodicEventDelay(int periodicEventDelay)
Set the new period between two lifecycle events in seconds.- Parameters:
periodicEventDelay
- The period in seconds, negative or zero will disable events
-
addService
public void addService(Service service)
Description copied from interface:Server
Add a new Service to the set of defined Services.- Specified by:
addService
in interfaceServer
- Parameters:
service
- The Service to be added
-
stopAwait
public void stopAwait()
-
await
public void await()
Description copied from interface:Server
Wait until a proper shutdown command is received, then return.
-
findService
public Service findService(java.lang.String name)
Description copied from interface:Server
Find the specified Service- Specified by:
findService
in interfaceServer
- Parameters:
name
- Name of the Service to be returned- Returns:
- the specified Service, or
null
if none exists.
-
findServices
public Service[] findServices()
- Specified by:
findServices
in interfaceServer
- Returns:
- the array of Services defined within this Server.
-
getServiceNames
public javax.management.ObjectName[] getServiceNames()
- Returns:
- the JMX service names.
-
removeService
public void removeService(Service service)
Description copied from interface:Server
Remove the specified Service from the set associated from this Server.- Specified by:
removeService
in interfaceServer
- Parameters:
service
- The Service to be removed
-
getCatalinaBase
public java.io.File getCatalinaBase()
- Specified by:
getCatalinaBase
in interfaceServer
- Returns:
- the configured base (instance) directory. Note that home and base may be the same (and are by default).
If this is not set the value returned by
Server.getCatalinaHome()
will be used.
-
setCatalinaBase
public void setCatalinaBase(java.io.File catalinaBase)
Description copied from interface:Server
Set the configured base (instance) directory. Note that home and base may be the same (and are by default).- Specified by:
setCatalinaBase
in interfaceServer
- Parameters:
catalinaBase
- the configured base directory
-
getCatalinaHome
public java.io.File getCatalinaHome()
- Specified by:
getCatalinaHome
in interfaceServer
- Returns:
- the configured home (binary) directory. Note that home and base may be the same (and are by default).
-
setCatalinaHome
public void setCatalinaHome(java.io.File catalinaHome)
Description copied from interface:Server
Set the configured home (binary) directory. Note that home and base may be the same (and are by default).- Specified by:
setCatalinaHome
in interfaceServer
- Parameters:
catalinaHome
- the configured home directory
-
addPropertyChangeListener
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Add a property change listener to this component.- Parameters:
listener
- The listener to add
-
removePropertyChangeListener
public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Remove a property change listener from this component.- Parameters:
listener
- The listener to remove
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
storeConfig
public void storeConfig() throws javax.management.InstanceNotFoundException, javax.management.MBeanException
Write the configuration information for this entireServer
out to the server.xml configuration file.- Throws:
javax.management.InstanceNotFoundException
- if the managed resource object cannot be foundjavax.management.MBeanException
- if the initializer of the object throws an exception, or persistence is not supportedjavax.management.RuntimeOperationsException
- if an exception is reported by the persistence mechanism
-
storeContext
public void storeContext(Context context) throws javax.management.InstanceNotFoundException, javax.management.MBeanException
Write the configuration information forContext
out to the specified configuration file.- Parameters:
context
- the context which should save its configuration- Throws:
javax.management.InstanceNotFoundException
- if the managed resource object cannot be foundjavax.management.MBeanException
- if the initializer of the object throws an exception or persistence is not supportedjavax.management.RuntimeOperationsException
- if an exception is reported by the persistence mechanism
-
startInternal
protected void startInternal() throws LifecycleException
Description copied from class:LifecycleBase
Subclasses must ensure that the state is changed toLifecycleState.STARTING
during the execution of this method. Changing state will trigger theLifecycle.START_EVENT
event. If a component fails to start it may either throw aLifecycleException
which will cause it's parent to fail to start, or it can place itself in the error state in which caseLifecycleBase.stop()
will be called on the failed component but the parent component will continue to start normally.- Specified by:
startInternal
in classLifecycleBase
- Throws:
LifecycleException
- Start error occurred
-
stopInternal
protected void stopInternal() throws LifecycleException
Description copied from class:LifecycleBase
Subclasses must ensure that the state is changed toLifecycleState.STOPPING
during the execution of this method. Changing state will trigger theLifecycle.STOP_EVENT
event.- Specified by:
stopInternal
in classLifecycleBase
- Throws:
LifecycleException
- Stop error occurred
-
initInternal
protected void initInternal() throws LifecycleException
Subclasses implement this method to perform any instance initialisation required.This is used to allow connectors to bind to restricted ports under Unix operating environments.
- Overrides:
initInternal
in classLifecycleMBeanBase
- Throws:
LifecycleException
- If the initialisation fails
-
destroyInternal
protected void destroyInternal() throws LifecycleException
Description copied from class:LifecycleBase
Subclasses implement this method to perform any instance destruction required.- Overrides:
destroyInternal
in classLifecycleMBeanBase
- Throws:
LifecycleException
- If the destruction fails
-
getParentClassLoader
public java.lang.ClassLoader getParentClassLoader()
- Specified by:
getParentClassLoader
in interfaceServer
- Returns:
- the parent class loader for this component. If not set, return
Server.getCatalina()
Catalina.getParentClassLoader()
. If catalina has not been set, return the system class loader.
-
setParentClassLoader
public void setParentClassLoader(java.lang.ClassLoader parent)
Description copied from interface:Server
Set the parent class loader for this server.- Specified by:
setParentClassLoader
in interfaceServer
- Parameters:
parent
- The new parent class loader
-
getDomainInternal
protected java.lang.String getDomainInternal()
Description copied from class:LifecycleMBeanBase
Method implemented by subclasses to identify the domain in which MBeans should be registered.- Specified by:
getDomainInternal
in classLifecycleMBeanBase
- Returns:
- the MBean domain for this server. The domain is obtained using the following search order:
-
getObjectNameKeyProperties
protected java.lang.String getObjectNameKeyProperties()
Description copied from class:LifecycleMBeanBase
Allow subclasses to specify the key properties component of theObjectName
that will be used to register this component.- Specified by:
getObjectNameKeyProperties
in classLifecycleMBeanBase
- Returns:
- The string representation of the key properties component of the desired
ObjectName
-
getUtilityExecutor
public java.util.concurrent.ScheduledExecutorService getUtilityExecutor()
- Specified by:
getUtilityExecutor
in interfaceServer
- Returns:
- the utility executor managed by the Service.
-
-