Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one or more
   * contributor license agreements.  See the NOTICE file distributed with
   * this work for additional information regarding copyright ownership.
   * The ASF licenses this file to You under the Apache License, Version 2.0
   * (the "License"); you may not use this file except in compliance with
   * the License.  You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 
 package org.apache.catalina.core;
 
 
 
 
Standard implementation of the Server interface, available for use (but not required) when deploying and starting Catalina.

Author(s):
Craig R. McClanahan
Version:
$Revision: 1673 $ $Date: 2011-03-12 18:58:07 +0100 (Sat, 12 Mar 2011) $
 
 public final class StandardServer
     implements LifecycleServerMBeanRegistration 
  {
 
     // ------------------------------------------------------------ Constructor
 

    
Construct a default instance of this class.
 
     public StandardServer() {
     }
 
 
     // ----------------------------------------------------- Instance Variables
 

    
Descriptive information about this Server implementation.
 
     private static final String info =
         "org.apache.catalina.core.StandardServer/1.0";


    
The lifecycle event support for this component.
 
     private LifecycleSupport lifecycle = new LifecycleSupport(this);


    
The set of Services associated with this Server.
 
     private Service services[] = new Service[0];


    
Has this component been started?
 
     private boolean started = false;


    
Has this component been initialized?
 
     private boolean initialized = false;


    
The property change support for this component.
 
    protected PropertyChangeSupport support = new PropertyChangeSupport(this);
    // ------------------------------------------------------------- Properties


    
Return descriptive information about this Server implementation and the corresponding version number, in the format <description>/<version>.
    public String getInfo() {
        return ();
    }

    
Report the current Tomcat Server Release number

Returns:
Tomcat release identifier
    public String getServerInfo() {
        return ServerInfo.getServerInfo();
    }
    // --------------------------------------------------------- Server Methods


    
Add a new Service to the set of defined Services.

Parameters:
service The Service to be added
    public void addService(Service service) {
        service.setServer(this);
        synchronized () {
            Service results[] = new Service[. + 1];
            System.arraycopy(, 0, results, 0, .);
            results[.] = service;
             = results;
            if () {
                try {
                    service.initialize();
                } catch (LifecycleException e) {
                    ..errorInitializingService(e);
                }
            }
            if ( && (service instanceof Lifecycle)) {
                try {
                    ((Lifecycleservice).start();
                } catch (LifecycleException e) {
                    ..errorStartingService(e);
                }
            }
            // Report this property change to interested listeners
            .firePropertyChange("service"nullservice);
        }
    }

    
Return the specified Service (if it exists); otherwise return null.

Parameters:
name Name of the Service to be returned
    public Service findService(String name) {
        if (name == null) {
            return (null);
        }
        synchronized () {
            for (int i = 0; i < .i++) {
                if (name.equals([i].getName())) {
                    return ([i]);
                }
            }
        }
        return (null);
    }


    
Return the set of Services defined within this Server.
    public Service[] findServices() {
        return ();
    }
    
    
Return the JMX service names.
    public ObjectName[] getServiceNames() {
        ObjectName onames[]=new ObjectName. ];
        forint i=0; i<.i++ ) {
            onames[i]=((StandardService)[i]).getObjectName();
        }
        return onames;
    }


    
Remove the specified Service from the set associated from this Server.

Parameters:
service The Service to be removed
    public void removeService(Service service) {
        synchronized () {
            int j = -1;
            for (int i = 0; i < .i++) {
                if (service == [i]) {
                    j = i;
                    break;
                }
            }
            if (j < 0)
                return;
            if ([jinstanceof Lifecycle) {
                try {
                    ((Lifecycle[j]).stop();
                } catch (LifecycleException e) {
                    ;
                }
            }
            int k = 0;
            Service results[] = new Service[. - 1];
            for (int i = 0; i < .i++) {
                if (i != j)
                    results[k++] = [i];
            }
             = results;
            // Report this property change to interested listeners
            .firePropertyChange("service"servicenull);
        }
    }
    // --------------------------------------------------------- Public Methods


    
Add a property change listener to this component.

Parameters:
listener The listener to add
    public void addPropertyChangeListener(PropertyChangeListener listener) {
        .addPropertyChangeListener(listener);
    }


    
Remove a property change listener from this component.

Parameters:
listener The listener to remove
    public void removePropertyChangeListener(PropertyChangeListener listener) {
        .removePropertyChangeListener(listener);
    }


    
Return a String representation of this component.
    public String toString() {
        return ("StandardServer[]");
    }
    // ------------------------------------------------------ Lifecycle Methods


    
Add a LifecycleEvent listener to this component.

Parameters:
listener The listener to add
    public void addLifecycleListener(LifecycleListener listener) {
        .addLifecycleListener(listener);
    }


    
Get the lifecycle listeners associated with this lifecycle. If this Lifecycle has no listeners registered, a zero-length array is returned.
        return .findLifecycleListeners();
    }


    
Remove a LifecycleEvent listener from this component.

Parameters:
listener The listener to remove
    public void removeLifecycleListener(LifecycleListener listener) {
        .removeLifecycleListener(listener);
    }


    
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.

Throws:
org.apache.catalina.LifecycleException if this component detects a fatal error that prevents this component from being used
    public void start() throws LifecycleException {
        // Validate and update our current component state
        if () {
            return;
        }
        // Notify our interested LifecycleListeners
         = true;
        // Start our defined Services
        synchronized () {
            for (int i = 0; i < .i++) {
                if ([iinstanceof Lifecycle)
                    ((Lifecycle[i]).start();
            }
        }
        // Notify our interested LifecycleListeners
    }


    
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.

Throws:
org.apache.catalina.LifecycleException if this component detects a fatal error that needs to be reported
    public void stop() throws LifecycleException {
        // Validate and update our current component state
        if (!)
            return;
        // Notify our interested LifecycleListeners
        .fireLifecycleEvent(null);
         = false;
        // Stop our defined Services
        for (int i = 0; i < .i++) {
            if ([iinstanceof Lifecycle)
                ((Lifecycle[i]).stop();
        }
        // Notify our interested LifecycleListeners
    }
    public void init() throws Exception {
        initialize();
    }
    
    
Invoke a pre-startup initialization. This is used to allow connectors to bind to restricted ports under Unix operating environments.
    public void initialize()
        throws LifecycleException 
    {
        if () {
            return;
        }
        .fireLifecycleEvent(null);
         = true;
        if (.....) {
            if==null ) {
                try {
                    =new ObjectName"Catalina:type=Server");
                    Registry.getRegistry(nullnull)
                    .registerComponent(thisnull );
                } catch (Exception e) {
                    ..failedServerJmxRegistration(e);
                }
            }
            // Register global String cache
            try {
                ObjectName oname2 = 
                    new ObjectName(.getDomain() + ":type=StringCache");
                Registry.getRegistry(nullnull)
                .registerComponent(new StringCache(), oname2null );
            } catch (Exception e) {
                ..failedServerJmxRegistration(e);
            }
        }
        // Initialize our defined Services
        for (int i = 0; i < .i++) {
            [i].initialize();
        }
    }
    
    protected String type;
    protected String domain;
    protected String suffix;
    protected ObjectName oname;
    protected MBeanServer mserver;
    public ObjectName getObjectName() {
        return ;
    }
    public String getDomain() {
        return ;
    }
    public ObjectName preRegister(MBeanServer server,
                                  ObjectName namethrows Exception {
        =name;
        =server;
        =name.getDomain();
        return name;
    }
    public void postRegister(Boolean registrationDone) {
    }
    public void preDeregister() throws Exception {
    }
    public void postDeregister() {
    }
    
New to GrepCode? Check out our FAQ X