| Method from org.apache.catalina.core.StandardServer Detail: |
public void addLifecycleListener(LifecycleListener listener) {
lifecycle.addLifecycleListener(listener);
}
Add a LifecycleEvent listener to this component. |
public void addPropertyChangeListener(PropertyChangeListener listener) {
support.addPropertyChangeListener(listener);
}
Add a property change listener to this component. |
public void addService(Service service) {
service.setServer(this);
synchronized (services) {
Service results[] = new Service[services.length + 1];
System.arraycopy(services, 0, results, 0, services.length);
results[services.length] = service;
services = results;
if (initialized) {
try {
service.initialize();
} catch (LifecycleException e) {
log.error(e);
}
}
if (started && (service instanceof Lifecycle)) {
try {
((Lifecycle) service).start();
} catch (LifecycleException e) {
;
}
}
// Report this property change to interested listeners
support.firePropertyChange("service", null, service);
}
}
Add a new Service to the set of defined Services. |
public void await() {
// Negative values - don't wait on port - tomcat is embedded or we just don't like ports
if( port == -2 ) {
// undocumented yet - for embedding apps that are around, alive.
return;
}
if( port==-1 ) {
while( true ) {
try {
Thread.sleep( 10000 );
} catch( InterruptedException ex ) {
}
if( stopAwait ) return;
}
}
// Set up a server socket to wait on
ServerSocket serverSocket = null;
try {
serverSocket =
new ServerSocket(port, 1,
InetAddress.getByName("localhost"));
} catch (IOException e) {
log.error("StandardServer.await: create[" + port
+ "]: ", e);
System.exit(1);
}
// Loop waiting for a connection and a valid command
while (true) {
// Wait for the next connection
Socket socket = null;
InputStream stream = null;
try {
socket = serverSocket.accept();
socket.setSoTimeout(10 * 1000); // Ten seconds
stream = socket.getInputStream();
} catch (AccessControlException ace) {
log.warn("StandardServer.accept security exception: "
+ ace.getMessage(), ace);
continue;
} catch (IOException e) {
log.error("StandardServer.await: accept: ", e);
System.exit(1);
}
// Read a set of characters from the socket
StringBuffer command = new StringBuffer();
int expected = 1024; // Cut off to avoid DoS attack
while (expected < shutdown.length()) {
if (random == null)
random = new Random();
expected += (random.nextInt() % 1024);
}
while (expected > 0) {
int ch = -1;
try {
ch = stream.read();
} catch (IOException e) {
log.warn("StandardServer.await: read: ", e);
ch = -1;
}
if (ch < 32) // Control character or EOF terminates loop
break;
command.append((char) ch);
expected--;
}
// Close the socket now that we are done with it
try {
socket.close();
} catch (IOException e) {
;
}
// Match against our command string
boolean match = command.toString().equals(shutdown);
if (match) {
break;
} else
log.warn("StandardServer.await: Invalid command '" +
command.toString() + "' received");
}
// Close the server socket and return
try {
serverSocket.close();
} catch (IOException e) {
;
}
}
Wait until a proper shutdown command is received, then return.
This keeps the main thread alive - the thread pool listening for http
connections is daemon threads. |
public LifecycleListener[] findLifecycleListeners() {
return lifecycle.findLifecycleListeners();
}
Get the lifecycle listeners associated with this lifecycle. If this
Lifecycle has no listeners registered, a zero-length array is returned. |
public Service findService(String name) {
if (name == null) {
return (null);
}
synchronized (services) {
for (int i = 0; i < services.length; i++) {
if (name.equals(services[i].getName())) {
return (services[i]);
}
}
}
return (null);
}
Return the specified Service (if it exists); otherwise return
null. |
public Service[] findServices() {
return (services);
}
Return the set of Services defined within this Server. |
public String getDomain() {
return domain;
}
|
public Context getGlobalNamingContext() {
return (this.globalNamingContext);
}
Return the global naming resources context. |
public NamingResources getGlobalNamingResources() {
return (this.globalNamingResources);
}
Return the global naming resources. |
public String getInfo() {
return (info);
}
Return descriptive information about this Server implementation and
the corresponding version number, in the format
<description>/<version>. |
public ObjectName getObjectName() {
return oname;
}
|
public int getPort() {
return (this.port);
}
Return the port number we listen to for shutdown commands. |
public String getServerInfo() {
return ServerInfo.getServerInfo();
}
Report the current Tomcat Server Release number |
public ObjectName[] getServiceNames() {
ObjectName onames[]=new ObjectName[ services.length ];
for( int i=0; i< services.length; i++ ) {
onames[i]=((StandardService)services[i]).getObjectName();
}
return onames;
}
Return the JMX service names. |
public String getShutdown() {
return (this.shutdown);
}
Return the shutdown command string we are waiting for. |
public void init() throws Exception {
initialize();
}
|
public void initialize() throws LifecycleException {
if (initialized) {
log.info(sm.getString("standardServer.initialize.initialized"));
return;
}
lifecycle.fireLifecycleEvent(INIT_EVENT, null);
initialized = true;
if( oname==null ) {
try {
oname=new ObjectName( "Catalina:type=Server");
Registry.getRegistry(null, null)
.registerComponent(this, oname, null );
} catch (Exception e) {
log.error("Error registering ",e);
}
}
// Register global String cache
try {
ObjectName oname2 =
new ObjectName(oname.getDomain() + ":type=StringCache");
Registry.getRegistry(null, null)
.registerComponent(new StringCache(), oname2, null );
} catch (Exception e) {
log.error("Error registering ",e);
}
// Initialize our defined Services
for (int i = 0; i < services.length; i++) {
services[i].initialize();
}
}
Invoke a pre-startup initialization. This is used to allow connectors
to bind to restricted ports under Unix operating environments. |
public void postDeregister() {
}
|
public void postRegister(Boolean registrationDone) {
}
|
public void preDeregister() throws Exception {
}
|
public ObjectName preRegister(MBeanServer server,
ObjectName name) throws Exception {
oname=name;
mserver=server;
domain=name.getDomain();
return name;
}
|
public void removeLifecycleListener(LifecycleListener listener) {
lifecycle.removeLifecycleListener(listener);
}
Remove a LifecycleEvent listener from this component. |
public void removePropertyChangeListener(PropertyChangeListener listener) {
support.removePropertyChangeListener(listener);
}
Remove a property change listener from this component. |
public void removeService(Service service) {
synchronized (services) {
int j = -1;
for (int i = 0; i < services.length; i++) {
if (service == services[i]) {
j = i;
break;
}
}
if (j < 0)
return;
if (services[j] instanceof Lifecycle) {
try {
((Lifecycle) services[j]).stop();
} catch (LifecycleException e) {
;
}
}
int k = 0;
Service results[] = new Service[services.length - 1];
for (int i = 0; i < services.length; i++) {
if (i != j)
results[k++] = services[i];
}
services = results;
// Report this property change to interested listeners
support.firePropertyChange("service", service, null);
}
}
Remove the specified Service from the set associated from this
Server. |
public void setGlobalNamingContext(Context globalNamingContext) {
this.globalNamingContext = globalNamingContext;
}
Set the global naming resources context. |
public void setGlobalNamingResources(NamingResources globalNamingResources) {
NamingResources oldGlobalNamingResources =
this.globalNamingResources;
this.globalNamingResources = globalNamingResources;
this.globalNamingResources.setContainer(this);
support.firePropertyChange("globalNamingResources",
oldGlobalNamingResources,
this.globalNamingResources);
}
Set the global naming resources. |
public void setPort(int port) {
this.port = port;
}
Set the port number we listen to for shutdown commands. |
public void setShutdown(String shutdown) {
this.shutdown = shutdown;
}
Set the shutdown command we are waiting for. |
public void start() throws LifecycleException {
// Validate and update our current component state
if (started) {
log.debug(sm.getString("standardServer.start.started"));
return;
}
// Notify our interested LifecycleListeners
lifecycle.fireLifecycleEvent(BEFORE_START_EVENT, null);
lifecycle.fireLifecycleEvent(START_EVENT, null);
started = true;
// Start our defined Services
synchronized (services) {
for (int i = 0; i < services.length; i++) {
if (services[i] instanceof Lifecycle)
((Lifecycle) services[i]).start();
}
}
// Notify our interested LifecycleListeners
lifecycle.fireLifecycleEvent(AFTER_START_EVENT, null);
}
Prepare for the beginning of active use of the public methods of this
component. This method should be called before any of the public
methods of this component are utilized. It should also send a
LifecycleEvent of type START_EVENT to any registered listeners. |
public void stop() throws LifecycleException {
// Validate and update our current component state
if (!started)
return;
// Notify our interested LifecycleListeners
lifecycle.fireLifecycleEvent(BEFORE_STOP_EVENT, null);
lifecycle.fireLifecycleEvent(STOP_EVENT, null);
started = false;
// Stop our defined Services
for (int i = 0; i < services.length; i++) {
if (services[i] instanceof Lifecycle)
((Lifecycle) services[i]).stop();
}
// Notify our interested LifecycleListeners
lifecycle.fireLifecycleEvent(AFTER_STOP_EVENT, null);
if (port == -1)
stopAwait();
}
Gracefully terminate the active use of the public methods of this
component. This method should be the last one called on a given
instance of this component. It should also send a LifecycleEvent
of type STOP_EVENT to any registered listeners. |
public void stopAwait() {
stopAwait=true;
}
|
public synchronized void storeConfig() throws Exception {
ObjectName sname = null;
try {
sname = new ObjectName("Catalina:type=StoreConfig");
if(mserver.isRegistered(sname)) {
mserver.invoke(sname, "storeConfig", null, null);
} else
log.error("StoreConfig mbean not registered" + sname);
} catch (Throwable t) {
log.error(t);
}
}
Write the configuration information for this entire Server
out to the server.xml configuration file. |
public synchronized void storeContext(Context context) throws Exception {
ObjectName sname = null;
try {
sname = new ObjectName("Catalina:type=StoreConfig");
if(mserver.isRegistered(sname)) {
mserver.invoke(sname, "store",
new Object[] {context},
new String [] { "java.lang.String"});
} else
log.error("StoreConfig mbean not registered" + sname);
} catch (Throwable t) {
log.error(t);
}
}
Write the configuration information for Context
out to the specified configuration file. |
public String toString() {
StringBuffer sb = new StringBuffer("StandardServer[");
sb.append(getPort());
sb.append("]");
return (sb.toString());
}
Return a String representation of this component. |