geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xuhaih...@apache.org
Subject svn commit: r940394 - in /geronimo/external/trunk/tomcat-parent-7.0.0: catalina/src/main/java/org/apache/catalina/ catalina/src/main/java/org/apache/catalina/connector/ catalina/src/main/java/org/apache/catalina/core/ catalina/src/main/java/org/apache/...
Date Mon, 03 May 2010 08:33:53 GMT
Author: xuhaihong
Date: Mon May  3 08:33:53 2010
New Revision: 940394

URL: http://svn.apache.org/viewvc?rev=940394&view=rev
Log:
Merge changes from Tomcat trunk to rev 940382

Added:
    geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/LifecycleMBeanRegistration.java   (with props)
Modified:
    geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/Globals.java
    geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/connector/Connector.java
    geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/connector/CoyoteAdapter.java
    geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/StandardEngine.java
    geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/StandardServer.java
    geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/StandardService.java
    geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/StandardThreadExecutor.java
    geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/startup/Embedded.java
    geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/startup/Tomcat.java
    geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/util/LifecycleBase.java
    geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/resources/org/apache/catalina/core/LocalStrings.properties
    geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/resources/org/apache/catalina/util/LocalStrings.properties
    geronimo/external/trunk/tomcat-parent-7.0.0/util/src/main/java/org/apache/tomcat/util/buf/StringCache.java

Modified: geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/Globals.java
URL: http://svn.apache.org/viewvc/geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/Globals.java?rev=940394&r1=940393&r2=940394&view=diff
==============================================================================
--- geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/Globals.java (original)
+++ geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/Globals.java Mon May  3 08:33:53 2010
@@ -334,4 +334,9 @@ public final class Globals {
     public static final String ASYNC_SUPPORTED_ATTR = 
         "org.apache.catalina.ASYNC_SUPPORTED";
 
+    
+    /**
+     * Default domain for MBeans if none can be determined
+     */
+    public static final String DEFAULT_MBEAN_DOMAIN = "Catalina";
 }

Added: geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/LifecycleMBeanRegistration.java
URL: http://svn.apache.org/viewvc/geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/LifecycleMBeanRegistration.java?rev=940394&view=auto
==============================================================================
--- geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/LifecycleMBeanRegistration.java (added)
+++ geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/LifecycleMBeanRegistration.java Mon May  3 08:33:53 2010
@@ -0,0 +1,50 @@
+/*
+ * 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;
+
+import javax.management.MBeanRegistration;
+import javax.management.ObjectName;
+
+/**
+ * This interface extends the {@link MBeanRegistration} interface and adds
+ * methods for obtaining the domain and object name used to register this
+ * component. This interface is intended to be implemented by components that
+ * already implement {@link Lifecycle} to indicate that they require
+ * registration during {@link Lifecycle#init()} and de-registration during
+ * {@link Lifecycle#destroy()}. 
+ */
+public interface LifecycleMBeanRegistration extends MBeanRegistration {
+
+    /**
+     * Obtain the {@link ObjectName} under which this component will be / has
+     * been registered.
+     */
+    public ObjectName getObjectName();
+
+
+    /**
+     * Obtain the domain under which this component will be / has been
+     * registered.
+     */
+    public String getDomain();
+
+    /**
+     * Specify the domain under which this component should be registered.
+     */
+    public void setDomain(String domain);
+}

Propchange: geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/LifecycleMBeanRegistration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/LifecycleMBeanRegistration.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/LifecycleMBeanRegistration.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/connector/Connector.java
URL: http://svn.apache.org/viewvc/geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/connector/Connector.java?rev=940394&r1=940393&r2=940394&view=diff
==============================================================================
--- geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/connector/Connector.java (original)
+++ geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/connector/Connector.java Mon May  3 08:33:53 2010
@@ -25,7 +25,6 @@ import javax.management.MBeanServer;
 import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 
-import org.apache.catalina.Container;
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.LifecycleState;
 import org.apache.catalina.Service;
@@ -99,12 +98,6 @@ public class Connector extends Lifecycle
 
 
     /**
-     * The Container used for processing requests received by this Connector.
-     */
-    protected Container container = null;
-
-
-    /**
      * The "enable DNS lookups" flag for this Connector.
      */
     protected boolean enableLookups = false;
@@ -330,7 +323,6 @@ public class Connector extends Lifecycle
     public void setService(Service service) {
 
         this.service = service;
-        // FIXME: setProperty("service", service);
 
     }
 
@@ -357,34 +349,7 @@ public class Connector extends Lifecycle
 
     }
 
-
-    /**
-     * Return the Container used for processing requests received by this
-     * Connector.
-     */
-    public Container getContainer() {
-        if( container==null ) {
-            // Lazy - maybe it was added later
-            findContainer();
-        }
-        return (container);
-
-    }
-
-
-    /**
-     * Set the Container used for processing requests received by this
-     * Connector.
-     *
-     * @param container The new Container to use
-     */
-    public void setContainer(Container container) {
-
-        this.container = container;
-
-    }
-
-
+    
     /**
      * Return the "enable DNS lookups" flag.
      */
@@ -855,8 +820,7 @@ public class Connector extends Lifecycle
     /**
      * Pause the connector.
      */
-    public void pause()
-        throws LifecycleException {
+    public void pause() {
         try {
             protocolHandler.pause();
         } catch (Exception e) {
@@ -869,8 +833,7 @@ public class Connector extends Lifecycle
     /**
      * Pause the connector.
      */
-    public void resume()
-        throws LifecycleException {
+    public void resume() {
         try {
             protocolHandler.resume();
         } catch (Exception e) {
@@ -990,15 +953,6 @@ public class Connector extends Lifecycle
     protected String domain;
     protected ObjectName oname;
     protected MBeanServer mserver;
-    ObjectName controller;
-
-    public ObjectName getController() {
-        return controller;
-    }
-
-    public void setController(ObjectName controller) {
-        this.controller = controller;
-    }
 
     public ObjectName getObjectName() {
         return oname;
@@ -1017,9 +971,11 @@ public class Connector extends Lifecycle
     }
 
     public void postRegister(Boolean registrationDone) {
+        // NOOP
     }
 
     public void preDeregister() throws Exception {
+        // NOOP
     }
 
     public void postDeregister() {
@@ -1032,56 +988,18 @@ public class Connector extends Lifecycle
         }
     }
 
-    protected void findContainer() {
-        try {
-            // Register to the service
-            ObjectName parentName=new ObjectName( domain + ":" +
-                    "type=Service");
-
-            if(log.isDebugEnabled())
-                log.debug("Adding to " + parentName );
-            if( mserver.isRegistered(parentName )) {
-                mserver.invoke(parentName, "addConnector", new Object[] { this },
-                        new String[] {"org.apache.catalina.connector.Connector"});
-                // As a side effect we'll get the container field set
-                // Also initialize will be called
-                //return;
-            }
-            // XXX Go directly to the Engine
-            // initialize(); - is called by addConnector
-            ObjectName engName=new ObjectName( domain + ":" + "type=Engine");
-            if( mserver.isRegistered(engName )) {
-                Object obj=mserver.getAttribute(engName, "managedResource");
-                if(log.isDebugEnabled())
-                      log.debug("Found engine " + obj + " " + obj.getClass());
-                container=(Container)obj;
-
-                if(log.isDebugEnabled())
-                    log.debug("Initialized");
-                // As a side effect we'll get the container field set
-                // Also initialize will be called
-                return;
-            }
-        } catch( Exception ex ) {
-            log.error( "Error finding container " + ex);
-        }
-    }
 
     @Override
     protected void initInternal() throws LifecycleException {
 
-        if( container==null ) {
-            findContainer();
-        }
-        
         if (oname == null) {
             try {
                 // we are loaded directly, via API - and no name was given to us
                 // Engine name is used as domain name for MBeans
-                oname = createObjectName(container.getName(), "Connector");
+                oname = createObjectName(
+                        getService().getContainer().getName(), "Connector");
                 Registry.getRegistry(null, null)
                     .registerComponent(this, oname, null);
-                controller=oname;
             } catch (Exception e) {
                 log.error( "Error registering connector ", e);
             }
@@ -1108,7 +1026,7 @@ public class Connector extends Lifecycle
 
     @Override
     protected void destroyInternal() {
-        if( oname!=null && controller==oname ) {
+        if (oname!=null) {
             if(log.isDebugEnabled())
                  log.debug("Unregister itself " + oname );
             Registry.getRegistry(null, null).unregisterComponent(oname);

Modified: geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/connector/CoyoteAdapter.java
URL: http://svn.apache.org/viewvc/geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/connector/CoyoteAdapter.java?rev=940394&r1=940393&r2=940394&view=diff
==============================================================================
--- geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/connector/CoyoteAdapter.java (original)
+++ geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/connector/CoyoteAdapter.java Mon May  3 08:33:53 2010
@@ -209,7 +209,7 @@ public class CoyoteAdapter implements Ad
                 req.getRequestProcessor().setWorkerThreadName(Thread.currentThread().getName());
                 
                 // Calling the container
-                connector.getContainer().getPipeline().getFirst().event(request, response, request.getEvent());
+                connector.getService().getContainer().getPipeline().getFirst().event(request, response, request.getEvent());
 
                 if (!error && !response.isClosed() && (request.getAttribute(Globals.EXCEPTION_ATTR) != null)) {
                     // An unexpected exception occurred while processing the event, so
@@ -217,7 +217,7 @@ public class CoyoteAdapter implements Ad
                     request.getEvent().setEventType(CometEvent.EventType.ERROR);
                     request.getEvent().setEventSubType(null);
                     error = true;
-                    connector.getContainer().getPipeline().getFirst().event(request, response, request.getEvent());
+                    connector.getService().getContainer().getPipeline().getFirst().event(request, response, request.getEvent());
                 }
                 if (response.isClosed() || !request.isComet()) {
                     if (status==SocketStatus.OPEN) {
@@ -225,7 +225,7 @@ public class CoyoteAdapter implements Ad
                         request.getEvent().setEventType(CometEvent.EventType.END);
                         request.getEvent().setEventSubType(null);
                         error = true;
-                        connector.getContainer().getPipeline().getFirst().event(request, response, request.getEvent());
+                        connector.getService().getContainer().getPipeline().getFirst().event(request, response, request.getEvent());
                     }
                     res.action(ActionCode.ACTION_COMET_END, null);
                 } else if (!error && read && request.getAvailable()) {
@@ -234,7 +234,7 @@ public class CoyoteAdapter implements Ad
                     request.getEvent().setEventType(CometEvent.EventType.ERROR);
                     request.getEvent().setEventSubType(CometEvent.EventSubType.IOEXCEPTION);
                     error = true;
-                    connector.getContainer().getPipeline().getFirst().event(request, response, request.getEvent());
+                    connector.getService().getContainer().getPipeline().getFirst().event(request, response, request.getEvent());
                 }
                 return (!error);
             } catch (Throwable t) {
@@ -289,7 +289,7 @@ public class CoyoteAdapter implements Ad
                     // Calling the container
                     try {
                         impl.complete();
-                        connector.getContainer().getPipeline().getFirst().invoke(request, response);
+                        connector.getService().getContainer().getPipeline().getFirst().invoke(request, response);
                     } finally {
                         success = false;
                     }
@@ -305,10 +305,10 @@ public class CoyoteAdapter implements Ad
                 } else if (impl.getState()==AsyncContextImpl.AsyncState.ERROR_DISPATCHING) {
                     async = false;
                     success = false;
-                    connector.getContainer().getPipeline().getFirst().invoke(request, response);
+                    connector.getService().getContainer().getPipeline().getFirst().invoke(request, response);
                 } else {
                     try {
-                        connector.getContainer().getPipeline().getFirst().invoke(request, response);
+                        connector.getService().getContainer().getPipeline().getFirst().invoke(request, response);
                     } catch (RuntimeException x) {
                         impl.setErrorState(x);
                     }
@@ -406,9 +406,9 @@ public class CoyoteAdapter implements Ad
             req.getRequestProcessor().setWorkerThreadName(Thread.currentThread().getName());
             if (postParseRequest(req, request, res, response)) {
                 //check valves if we support async
-                request.setAsyncSupported(connector.getContainer().getPipeline().isAsyncSupported());
+                request.setAsyncSupported(connector.getService().getContainer().getPipeline().isAsyncSupported());
                 // Calling the container
-                connector.getContainer().getPipeline().getFirst().invoke(request, response);
+                connector.getService().getContainer().getPipeline().getFirst().invoke(request, response);
 
                 if (request.isComet()) {
                     if (!response.isClosed() && !response.isError()) {

Modified: geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/StandardEngine.java
URL: http://svn.apache.org/viewvc/geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/StandardEngine.java?rev=940394&r1=940393&r2=940394&view=diff
==============================================================================
--- geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/StandardEngine.java (original)
+++ geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/StandardEngine.java Mon May  3 08:33:53 2010
@@ -367,10 +367,6 @@ public class StandardEngine
     @Override
     protected void destroyInternal() throws LifecycleException {
         
-        // if we created it, make sure it's also destroyed
-        // this call implizit this.stop()
-        ((StandardService)service).destroy();
-
         if( mbeans != null ) {
             try {
                 Registry.getRegistry(null, null)

Modified: geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/StandardServer.java
URL: http://svn.apache.org/viewvc/geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/StandardServer.java?rev=940394&r1=940393&r2=940394&view=diff
==============================================================================
--- geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/StandardServer.java (original)
+++ geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/StandardServer.java Mon May  3 08:33:53 2010
@@ -29,16 +29,20 @@ import java.net.Socket;
 import java.security.AccessControlException;
 import java.util.Random;
 
-import javax.management.MBeanRegistration;
 import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 
+import org.apache.catalina.Container;
 import org.apache.catalina.Context;
+import org.apache.catalina.Globals;
 import org.apache.catalina.LifecycleException;
+import org.apache.catalina.LifecycleMBeanRegistration;
 import org.apache.catalina.LifecycleState;
 import org.apache.catalina.Server;
 import org.apache.catalina.Service;
 import org.apache.catalina.deploy.NamingResources;
+import org.apache.catalina.mbeans.MBeanFactory;
 import org.apache.catalina.util.LifecycleBase;
 import org.apache.tomcat.util.res.StringManager;
 import org.apache.catalina.util.ServerInfo;
@@ -48,7 +52,6 @@ import org.apache.tomcat.util.buf.String
 import org.apache.tomcat.util.modeler.Registry;
 
 
-
 /**
  * Standard implementation of the <b>Server</b> interface, available for use
  * (but not required) when deploying and starting Catalina.
@@ -57,7 +60,7 @@ import org.apache.tomcat.util.modeler.Re
  * @version $Id$
  */
 public final class StandardServer extends LifecycleBase
-        implements Server, MBeanRegistration {
+        implements Server, LifecycleMBeanRegistration {
 
     private static final Log log = LogFactory.getLog(StandardServer.class);
    
@@ -682,65 +685,130 @@ public final class StandardServer extend
     @Override
     protected void initInternal() throws LifecycleException {
 
-        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
+        // Note although the cache is global, if there are multiple Servers
+        // present in the JVM (may happen when embedding) then the same cache
+        // will be registered under multiple names
         try {
-            ObjectName oname2 = 
+            onameStringCache = 
                 new ObjectName(oname.getDomain() + ":type=StringCache");
             Registry.getRegistry(null, null)
-                .registerComponent(new StringCache(), oname2, null );
+                .registerComponent(new StringCache(), onameStringCache, null);
         } catch (Exception e) {
             log.error("Error registering ",e);
         }
 
+        // Register the MBeanFactory
+        try {
+            onameMBeanFactory = 
+                new ObjectName(oname.getDomain() + ":type=MBeanFactory");
+            Registry.getRegistry(null, null)
+                .registerComponent(new MBeanFactory(), onameMBeanFactory, null);
+        } catch (Exception e) {
+            log.error("Error registering ",e);
+        }
+        
         // Initialize our defined Services
         for (int i = 0; i < services.length; i++) {
             services[i].init();
         }
     }
     
-    protected void destroyInternal() {
-        // NOOP
+    @Override
+    protected void destroyInternal() throws LifecycleException {
+        Registry registry = Registry.getRegistry(null, null);
+        
+        if (onameStringCache != null) {
+            registry.unregisterComponent(onameStringCache);
+        }
+        if (onameMBeanFactory != null) {
+            registry.unregisterComponent(onameMBeanFactory);
+        }
+        
+        // Destroy our defined Services
+        for (int i = 0; i < services.length; i++) {
+            services[i].destroy();
+        }
     }
 
-    protected String type;
-    protected String domain;
-    protected String suffix;
-    protected ObjectName oname;
+    protected volatile String domain;
+    protected volatile ObjectName oname;
     protected MBeanServer mserver;
+    private ObjectName onameStringCache;
+    private ObjectName onameMBeanFactory;
+    
+    /**
+     * Obtain the MBean domain for this server. The domain is obtained using
+     * the following search order:
+     * <ol>
+     * <li>Name of first {@link Engine}.</li>
+     * <li>Name of first {@link Service}.</li>
+     * <li>Global default defined by {@link Globals#DEFAULT_MBEAN_DOMAIN}</li>
+     * </ol>
+     */
+    public String getDomain() {
+        if (domain == null) {
+            Service[] services = findServices();
+            if (services.length > 0) {
+                Service service = services[0];
+                if (service != null) {
+                    Container container = service.getContainer();
+                    if (container != null) {
+                        domain = container.getName();
+                    } else {
+                        domain = service.getName();
+                    }
+                }
+            }
+            if (domain == null) {
+                domain = Globals.DEFAULT_MBEAN_DOMAIN;
+            }
+        }
+        return domain;
+    }
 
+    
+    public void setDomain(String domain) {
+        this.domain = domain;
+    }
+    
+    
     public ObjectName getObjectName() {
+        if (oname == null) {
+            StringBuilder name = new StringBuilder(getDomain());
+            name.append(":type=Server");
+            
+            try {
+                oname = new ObjectName(name.toString());
+            } catch (MalformedObjectNameException e) {
+                log.warn(sm.getString("standardServer.onameFail", name), e);
+            } catch (NullPointerException e) {
+                // Never going to happen
+            }
+        }
+        
         return oname;
     }
 
-    public String getDomain() {
-        return domain;
-    }
 
     public ObjectName preRegister(MBeanServer server,
                                   ObjectName name) throws Exception {
-        oname=name;
-        mserver=server;
-        domain=name.getDomain();
+        oname = name;
+        mserver = server;
+        domain = name.getDomain();
         return name;
     }
 
     public void postRegister(Boolean registrationDone) {
+        // NOOP
     }
 
     public void preDeregister() throws Exception {
+        // NOOP
     }
 
     public void postDeregister() {
+        // NOOP
     }
     
 }

Modified: geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/StandardService.java
URL: http://svn.apache.org/viewvc/geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/StandardService.java?rev=940394&r1=940393&r2=940394&view=diff
==============================================================================
--- geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/StandardService.java (original)
+++ geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/StandardService.java Mon May  3 08:33:53 2010
@@ -21,13 +21,15 @@ package org.apache.catalina.core;
 
 import java.beans.PropertyChangeListener;
 import java.beans.PropertyChangeSupport;
-import javax.management.MBeanRegistration;
 import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 import org.apache.catalina.Container;
 import org.apache.catalina.Engine;
+import org.apache.catalina.Globals;
 import org.apache.catalina.Lifecycle;
 import org.apache.catalina.LifecycleException;
+import org.apache.catalina.LifecycleMBeanRegistration;
 import org.apache.catalina.LifecycleState;
 import org.apache.catalina.Server;
 import org.apache.catalina.Service;
@@ -50,7 +52,7 @@ import org.apache.catalina.Executor;
  */
 
 public class StandardService extends LifecycleBase
-        implements Service, MBeanRegistration {
+        implements Service, LifecycleMBeanRegistration {
 
     private static final Log log = LogFactory.getLog(StandardService.class);
    
@@ -141,10 +143,6 @@ public class StandardService extends Lif
                 // Ignore
             }
         }
-        synchronized (connectors) {
-            for (int i = 0; i < connectors.length; i++)
-                connectors[i].setContainer(this.container);
-        }
         if (getState().isAvailable() && (oldContainer != null)) {
             try {
                 oldContainer.stop();
@@ -234,7 +232,6 @@ public class StandardService extends Lif
     public void addConnector(Connector connector) {
 
         synchronized (connectors) {
-            connector.setContainer(this.container);
             connector.setService(this);
             Connector results[] = new Connector[connectors.length + 1];
             System.arraycopy(connectors, 0, results, 0, connectors.length);
@@ -312,7 +309,6 @@ public class StandardService extends Lif
                     log.error("Connector.stop", e);
                 }
             }
-            connectors[j].setContainer(null);
             connector.setService(null);
             int k = 0;
             Connector results[] = new Connector[connectors.length - 1];
@@ -503,19 +499,6 @@ public class StandardService extends Lif
                 executors.get(i).stop();
             }
         }
-
-
-        Registry.getRegistry(null, null).unregisterComponent(oname);
-        Executor[] executors = findExecutors();
-        for (int i = 0; i < executors.length; i++) {
-            try {
-                ObjectName executorObjectName = 
-                    new ObjectName(domain + ":type=Executor,name=" + executors[i].getName());
-                Registry.getRegistry(null, null).unregisterComponent(executorObjectName);
-            } catch (Exception e) {
-                // Ignore (invalid ON, which cannot happen)
-            }
-        }
     }
 
 
@@ -526,84 +509,124 @@ public class StandardService extends Lif
     @Override
     protected void initInternal() throws LifecycleException {
 
-        if( oname==null ) {
-            try {
-                // Hack - Server should be deprecated...
-                Container engine=this.getContainer();
-                domain = engine.getName();
-                oname=new ObjectName(domain + ":type=Service");
-                Registry.getRegistry(null, null)
-                    .registerComponent(this, oname, null);
-                
-                Executor[] executors = findExecutors();
-                for (int i = 0; i < executors.length; i++) {
-                    ObjectName executorObjectName = 
-                        new ObjectName(domain + ":type=Executor,name=" + executors[i].getName());
-                    Registry.getRegistry(null, null)
-                        .registerComponent(executors[i], executorObjectName, null);
-                }
-                
-            } catch (Exception e) {
-                log.error(sm.getString("standardService.register.failed",domain),e);
-            }
-            
-            
+        if (container != null) {
+            container.init();
         }
-        if( server==null ) {
-            // If no server was defined - create one
-            server = new StandardServer();
-            server.addService(this);
+
+        // Initialize any Executors
+        for (Executor executor : findExecutors()) {
+            if (executor instanceof LifecycleMBeanRegistration) {
+                ((LifecycleMBeanRegistration) executor).setDomain(getDomain());
+            }
+            executor.init();
         }
-               
 
         // Initialize our defined Connectors
         synchronized (connectors) {
-                for (int i = 0; i < connectors.length; i++) {
-                    try {
-                        connectors[i].init();
-                    } catch (Exception e) {
-                        log.error(sm.getString(
-                                "standardService.connector.failed",
-                                connectors[i]), e);
-                    }
+            for (Connector connector : connectors) {
+                try {
+                    connector.init();
+                } catch (Exception e) {
+                    log.error(sm.getString(
+                            "standardService.connector.initFailed", connector),
+                            e);
                 }
+            }
         }
     }
     
     @Override
-    protected void destroyInternal() {
-        // FIXME unregister should be here probably -- stop doing that ?
-    }
+    protected void destroyInternal() throws LifecycleException {
+        Registry.getRegistry(null, null).unregisterComponent(oname);
+        
+        // Destroy our defined Connectors
+        synchronized (connectors) {
+            for (Connector connector : connectors) {
+                try {
+                    connector.destroy();
+                } catch (Exception e) {
+                    log.error(sm.getString(
+                            "standardService.connector.destroyfailed",
+                            connector), e);
+                }
+            }
+        }
 
-    protected String type;
-    protected String domain;
-    protected String suffix;
-    protected ObjectName oname;
-    protected MBeanServer mserver;
+        // Destroy any Executors
+        for (Executor executor : findExecutors()) {
+            executor.destroy();
+        }
+
+        if (container != null) {
+            container.destroy();
+        }
 
-    public ObjectName getObjectName() {
-        return oname;
     }
 
+    protected volatile String domain;
+    protected volatile ObjectName oname;
+
+    /**
+     * Obtain the MBean domain for this server. The domain is obtained using
+     * the following search order:
+     * <ol>
+     * <li>Name of the {@link Engine}.</li>
+     * <li>Name of the {@link Service}.</li>
+     * <li>Global default defined by {@link Globals#DEFAULT_MBEAN_DOMAIN}</li>
+     * </ol>
+     */
     public String getDomain() {
+        if (domain == null) {
+            Container container = getContainer();
+            if (container != null) {
+                domain = container.getName();
+            } else {
+                domain = getName();
+            }
+            if (domain == null) {
+                domain = Globals.DEFAULT_MBEAN_DOMAIN;
+            }
+        }
         return domain;
     }
 
+    public void setDomain(String domain) {
+        this.domain = domain;
+    }
+    
+    public ObjectName getObjectName() {
+        if (oname == null) {
+            StringBuilder name = new StringBuilder(getDomain());
+            name.append(":type=Service");
+            
+            try {
+                oname = new ObjectName(name.toString());
+            } catch (MalformedObjectNameException e) {
+                log.warn(sm.getString("standardService.onameFail", name), e);
+            } catch (NullPointerException e) {
+                // Never going to happen
+            }
+        }
+        
+        return oname;
+    }
     public ObjectName preRegister(MBeanServer server,
                                   ObjectName name) throws Exception {
         oname=name;
-        mserver=server;
         domain=name.getDomain();
         return name;
     }
 
     public void postRegister(Boolean registrationDone) {
+        // NOOP
     }
 
     public void preDeregister() throws Exception {
+        // NOOP
     }
 
     public void postDeregister() {
+        // NOOP
     }
 
 }

Modified: geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/StandardThreadExecutor.java
URL: http://svn.apache.org/viewvc/geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/StandardThreadExecutor.java?rev=940394&r1=940393&r2=940394&view=diff
==============================================================================
--- geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/StandardThreadExecutor.java (original)
+++ geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/StandardThreadExecutor.java Mon May  3 08:33:53 2010
@@ -20,18 +20,35 @@ package org.apache.catalina.core;
 import java.util.concurrent.RejectedExecutionException;
 import java.util.concurrent.TimeUnit;
 
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
 import org.apache.catalina.Executor;
 import org.apache.catalina.LifecycleException;
+import org.apache.catalina.LifecycleMBeanRegistration;
 import org.apache.catalina.LifecycleState;
 import org.apache.catalina.util.LifecycleBase;
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
+import org.apache.tomcat.util.res.StringManager;
 import org.apache.tomcat.util.threads.ResizableExecutor;
 import org.apache.tomcat.util.threads.TaskQueue;
 import org.apache.tomcat.util.threads.TaskThreadFactory;
 import org.apache.tomcat.util.threads.ThreadPoolExecutor;
 
 public class StandardThreadExecutor extends LifecycleBase
-        implements Executor, ResizableExecutor {
+        implements Executor, ResizableExecutor, LifecycleMBeanRegistration {
+    
+    private static final Log log =
+        LogFactory.getLog(StandardThreadExecutor.class);
     
+    /**
+     * The string manager for this package.
+     */
+    private static final StringManager sm =
+        StringManager.getManager(Constants.Package);
+
     // ---------------------------------------------- Properties
     /**
      * Default thread priority
@@ -290,6 +307,58 @@ public class StandardThreadExecutor exte
         return false;
     }
     
+
+    protected volatile String domain;
+    protected volatile ObjectName oname;
+
+    /**
+     * Obtain the MBean domain for this server. The domain is set by the
+     * containing Service.
+     */
+    public String getDomain() {
+        return domain;
+    }
+
+    public void setDomain(String domain) {
+        this.domain = domain;
+    }
+    
+    public ObjectName getObjectName() {
+        if (oname == null) {
+            StringBuilder name = new StringBuilder(getDomain());
+            name.append(":type=Executor,name=");
+            name.append(getName());
+            
+            try {
+                oname = new ObjectName(name.toString());
+            } catch (MalformedObjectNameException e) {
+                log.warn(sm.getString(
+                        "standardThreadExecutor.onameFail", name), e);
+            } catch (NullPointerException e) {
+                // Never going to happen
+            }
+        }
+        
+        return oname;
+    }
     
+    public ObjectName preRegister(MBeanServer server,
+                                  ObjectName name) throws Exception {
+        oname=name;
+        domain=name.getDomain();
+        return name;
+    }
+
+    public void postRegister(Boolean registrationDone) {
+        // NOOP
+    }
+
+    public void preDeregister() throws Exception {
+        // NOOP
+    }
+
+    public void postDeregister() {
+        // NOOP
+    }
     
 }

Modified: geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/startup/Embedded.java
URL: http://svn.apache.org/viewvc/geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/startup/Embedded.java?rev=940394&r1=940393&r2=940394&view=diff
==============================================================================
--- geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/startup/Embedded.java (original)
+++ geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/startup/Embedded.java Mon May  3 08:33:53 2010
@@ -655,7 +655,7 @@ public class Embedded  extends StandardS
         while (true) {
             int n = -1;
             for (int i = 0; i < connectors.length; i++) {
-                if (connectors[i].getContainer() == engine) {
+                if (connectors[i].getService().getContainer() == engine) {
                     n = i;
                     break;
                 }

Modified: geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/startup/Tomcat.java
URL: http://svn.apache.org/viewvc/geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/startup/Tomcat.java?rev=940394&r1=940393&r2=940394&view=diff
==============================================================================
--- geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/startup/Tomcat.java (original)
+++ geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/startup/Tomcat.java Mon May  3 08:33:53 2010
@@ -278,11 +278,22 @@ public class Tomcat {
         return sw;
     }
     
+
+    /**
+     * Initialise the server.
+     * 
+     * @throws LifecycleException
+     */
+    public void init() throws LifecycleException {
+        getServer();
+        getConnector();
+        server.init();
+    }
+    
     
     /**
-     * Initialize and start the server, assuming that the Server implementation
-     * implements {@link Lifecycle} (the standard implementation does). If it
-     * does not, the {@link Server} must be started directly.
+     * Start the server.
+     * 
      * @throws LifecycleException 
      */
     public void start() throws LifecycleException {
@@ -292,9 +303,8 @@ public class Tomcat {
     }
 
     /** 
-     * Stop the server, assuming that the Server implementation implements
-     * {@link Lifecycle} (the standard implementation does). If it does not, the
-     * {@link Server} must be stopped directly.
+     * Stop the server.
+     * 
      * @throws LifecycleException 
      */
     public void stop() throws LifecycleException {
@@ -303,6 +313,16 @@ public class Tomcat {
     }
 
 
+    /**
+     * Destroy the server. This object cannot be used once this method has been
+     * called.
+     */
+    public void destroy() throws LifecycleException {
+        getServer();
+        server.destroy();
+        // Could null out obejcts here
+    }
+    
     /** 
      * Add a user for the in-memory realm. All created apps use this 
      * by default, can be replaced using setRealm().

Modified: geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/util/LifecycleBase.java
URL: http://svn.apache.org/viewvc/geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/util/LifecycleBase.java?rev=940394&r1=940393&r2=940394&view=diff
==============================================================================
--- geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/util/LifecycleBase.java (original)
+++ geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/util/LifecycleBase.java Mon May  3 08:33:53 2010
@@ -17,12 +17,16 @@
 
 package org.apache.catalina.util;
 
+import javax.management.ObjectName;
+
 import org.apache.catalina.Lifecycle;
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.LifecycleListener;
+import org.apache.catalina.LifecycleMBeanRegistration;
 import org.apache.catalina.LifecycleState;
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
+import org.apache.tomcat.util.modeler.Registry;
 import org.apache.tomcat.util.res.StringManager;
 
 
@@ -95,7 +99,19 @@ public abstract class LifecycleBase impl
             invalidTransition(Lifecycle.INIT_EVENT);
         }
 
-        // TODO - Check for JMX support and register if required
+        // Register MBean if required
+        if (this instanceof LifecycleMBeanRegistration) {
+            ObjectName oname =
+                ((LifecycleMBeanRegistration) this).getObjectName();
+            
+            try {
+                Registry.getRegistry(null, null).registerComponent(
+                        this, oname, null);
+            } catch (Exception e) {
+                log.warn(sm.getString("lifecycleBase.initMBeanFail", toString(),
+                        oname), e);
+            }
+        }
         
         initInternal();
         
@@ -242,15 +258,34 @@ public abstract class LifecycleBase impl
 
 
     public synchronized final void destroy() throws LifecycleException {
+        if (LifecycleState.DESTROYED.equals(state)) {
+
+            if (log.isDebugEnabled()) {
+                Exception e = new LifecycleException();
+                log.debug(sm.getString("lifecycleBase.alreadyDestroyed",
+                        toString()), e);
+            } else if (log.isInfoEnabled()) {
+                log.info(sm.getString("lifecycleBase.alreadyDestroyed",
+                        toString()));
+            }
+            
+            return;
+        }
+        
         if (!state.equals(LifecycleState.STOPPED) &&
                 !state.equals(LifecycleState.FAILED)) {
             invalidTransition(Lifecycle.DESTROY_EVENT);
         }
 
-        // TODO - Check for JMX support and de-register if required
-        
         destroyInternal();
         
+        // De-register MBean if required
+        if (this instanceof LifecycleMBeanRegistration) {
+            ObjectName oname =
+                ((LifecycleMBeanRegistration) this).getObjectName();
+            Registry.getRegistry(null, null).unregisterComponent(oname);
+        }
+
         setState(LifecycleState.DESTROYED);
     }
     

Modified: geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/resources/org/apache/catalina/core/LocalStrings.properties
URL: http://svn.apache.org/viewvc/geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/resources/org/apache/catalina/core/LocalStrings.properties?rev=940394&r1=940393&r2=940394&view=diff
==============================================================================
--- geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/resources/org/apache/catalina/core/LocalStrings.properties (original)
+++ geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/resources/org/apache/catalina/core/LocalStrings.properties Mon May  3 08:33:53 2010
@@ -188,12 +188,16 @@ standardHost.warRequired=URL to web appl
 standardHost.warURL=Invalid URL for web application archive: {0}
 standardHost.validationEnabled=XML validation enabled
 standardHost.validationDisabled=XML validation disabled
+standardServer.onameFail=MBean name specified for Server [{0}] is not valid
 standardServer.shutdownViaPort=A valid shutdown command was received via the shutdown port. Stopping the Server instance.
-standardService.connector.failed=Failed to start connector [{0}]
+standardService.connector.initFailed=Failed to initialise connector [{0}]
+standardService.connector.destroyFailed=Failed to destroy connector [{0}]
 standardService.initialize.failed=Service initializing at {0} failed
+standardService.onameFail=MBean name specified for Service [{0}] is not valid
 standardService.register.failed=Error registering Service at domain {0}
 standardService.start.name=Starting service {0}
 standardService.stop.name=Stopping service {0}
+standardThreadExecutor.onameFail=MBean name specified for Thread Executor [{0}] is not valid
 standardWrapper.allocate=Error allocating a servlet instance
 standardWrapper.allocateException=Allocate exception for servlet {0}
 standardWrapper.containerServlet=Loading container servlet {0}

Modified: geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/resources/org/apache/catalina/util/LocalStrings.properties
URL: http://svn.apache.org/viewvc/geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/resources/org/apache/catalina/util/LocalStrings.properties?rev=940394&r1=940393&r2=940394&view=diff
==============================================================================
--- geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/resources/org/apache/catalina/util/LocalStrings.properties (original)
+++ geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/resources/org/apache/catalina/util/LocalStrings.properties Mon May  3 08:33:53 2010
@@ -22,8 +22,10 @@ extensionValidator.web-application-manif
 extensionValidator.extension-not-found-error=ExtensionValidator[{0}][{1}]: Required extension [{2}] not found.
 extensionValidator.extension-validation-error=ExtensionValidator[{0}]: Failure to find [{1}] required extension(s).
 extensionValidator.failload=Failure loading extension [{0}]
+lifecycleBase.initMBeanFail=Failed to register component [{0}] with MBean name [{1}]
 lifecycleBase.alreadyStarted=The start() method was called on component [{0}] after start() had already been called. The second call will be ignored.
 lifecycleBase.alreadyStopped=The stop() method was called on component [{0}] after stop() had already been called. The second call will be ignored.
+lifecycleBase.alreadyDestroyed=The destroy() method was called on component [{0}] after destroy() had already been called. The second call will be ignored.
 lifecycleBase.invalidTransition=An invalid Lifecycle transition was attempted ([{0}]) for component [{1}] in state [{2}]
 requestUtil.convertHexDigit.notHex=[{0}] is not a hexadecimal digit
 requestUtil.parseParameters.uee=Unable to parse the parameters since the encoding [{0}] is not supported.

Modified: geronimo/external/trunk/tomcat-parent-7.0.0/util/src/main/java/org/apache/tomcat/util/buf/StringCache.java
URL: http://svn.apache.org/viewvc/geronimo/external/trunk/tomcat-parent-7.0.0/util/src/main/java/org/apache/tomcat/util/buf/StringCache.java?rev=940394&r1=940393&r2=940394&view=diff
==============================================================================
--- geronimo/external/trunk/tomcat-parent-7.0.0/util/src/main/java/org/apache/tomcat/util/buf/StringCache.java (original)
+++ geronimo/external/trunk/tomcat-parent-7.0.0/util/src/main/java/org/apache/tomcat/util/buf/StringCache.java Mon May  3 08:33:53 2010
@@ -40,24 +40,24 @@ public class StringCache {
     /**
      * Enabled ?
      */
-    protected static boolean byteEnabled = 
-        ("true".equals(System.getProperty("tomcat.util.buf.StringCache.byte.enabled", "false")));
+    protected static boolean byteEnabled = ("true".equals(System.getProperty(
+            "tomcat.util.buf.StringCache.byte.enabled", "false")));
 
     
-    protected static boolean charEnabled = 
-        ("true".equals(System.getProperty("tomcat.util.buf.StringCache.char.enabled", "false")));
+    protected static boolean charEnabled = ("true".equals(System.getProperty(
+            "tomcat.util.buf.StringCache.char.enabled", "false")));
 
     
-    protected static int trainThreshold = 
-        Integer.parseInt(System.getProperty("tomcat.util.buf.StringCache.trainThreshold", "20000"));
+    protected static int trainThreshold = Integer.parseInt(System.getProperty(
+            "tomcat.util.buf.StringCache.trainThreshold", "20000"));
     
 
-    protected static int cacheSize = 
-        Integer.parseInt(System.getProperty("tomcat.util.buf.StringCache.cacheSize", "200"));
+    protected static int cacheSize = Integer.parseInt(System.getProperty(
+            "tomcat.util.buf.StringCache.cacheSize", "200"));
     
 
-    protected static int maxStringSize = 
-        Integer.parseInt(System.getProperty("tomcat.util.buf.StringCache.maxStringSize", "128"));
+    protected static int maxStringSize = Integer.parseInt(System.getProperty(
+            "tomcat.util.buf.StringCache.maxStringSize", "128"));
     
 
    /**
@@ -220,20 +220,20 @@ public class StringCache {
                 // If training, everything is synced
                 synchronized (bcStats) {
                     // If the cache has been generated on a previous invocation
-                    // while waiting for the lock, just return the toString value
-                    // we just calculated
+                    // while waiting for the lock, just return the toString
+                    // value we just calculated
                     if (bcCache != null) {
                         return value;
                     }
-                    // Two cases: either we just exceeded the train count, in which
-                    // case the cache must be created, or we just update the count for
-                    // the string
+                    // Two cases: either we just exceeded the train count, in
+                    // which case the cache must be created, or we just update
+                    // the count for the string
                     if (bcCount > trainThreshold) {
                         long t1 = System.currentTimeMillis();
                         // Sort the entries according to occurrence
                         TreeMap<Integer,ArrayList<ByteEntry>> tempMap =
                             new TreeMap<Integer,ArrayList<ByteEntry>>();
-                        for (Entry<ByteEntry, int[]> item : bcStats.entrySet()) {
+                        for (Entry<ByteEntry,int[]> item : bcStats.entrySet()) {
                             ByteEntry entry = item.getKey();
                             int[] countA = item.getValue();
                             Integer count = new Integer(countA[0]);
@@ -261,13 +261,16 @@ public class StringCache {
                             ArrayList<ByteEntry> list = tempMap.get(key);
                             for (int i = 0; i < list.size() && n < size; i++) {
                                 ByteEntry entry = list.get(i);
-                                tempChunk.setBytes(entry.name, 0, entry.name.length);
-                                int insertPos = findClosest(tempChunk, tempbcCache, n);
+                                tempChunk.setBytes(entry.name, 0,
+                                        entry.name.length);
+                                int insertPos = findClosest(tempChunk,
+                                        tempbcCache, n);
                                 if (insertPos == n) {
                                     tempbcCache[n + 1] = entry;
                                 } else {
-                                    System.arraycopy(tempbcCache, insertPos + 1, tempbcCache, 
-                                            insertPos + 2, n - insertPos - 1);
+                                    System.arraycopy(tempbcCache, insertPos + 1,
+                                            tempbcCache, insertPos + 2,
+                                            n - insertPos - 1);
                                     tempbcCache[insertPos + 1] = entry;
                                 }
                                 n++;
@@ -279,7 +282,8 @@ public class StringCache {
                         bcCache = tempbcCache;
                         if (log.isDebugEnabled()) {
                             long t2 = System.currentTimeMillis();
-                            log.debug("ByteCache generation time: " + (t2 - t1) + "ms");
+                            log.debug("ByteCache generation time: " +
+                                    (t2 - t1) + "ms");
                         }
                     } else {
                         bcCount++;
@@ -292,7 +296,8 @@ public class StringCache {
                             int start = bc.getStart();
                             // Create byte array and copy bytes
                             entry.name = new byte[bc.getLength()];
-                            System.arraycopy(bc.getBuffer(), start, entry.name, 0, end - start);
+                            System.arraycopy(bc.getBuffer(), start, entry.name,
+                                    0, end - start);
                             // Set encoding
                             entry.enc = bc.getEncoding();
                             // Initialize occurrence count to one 
@@ -332,20 +337,20 @@ public class StringCache {
                 // If training, everything is synced
                 synchronized (ccStats) {
                     // If the cache has been generated on a previous invocation
-                    // while waiting fot the lock, just return the toString value
-                    // we just calculated
+                    // while waiting for the lock, just return the toString
+                    // value we just calculated
                     if (ccCache != null) {
                         return value;
                     }
-                    // Two cases: either we just exceeded the train count, in which
-                    // case the cache must be created, or we just update the count for
-                    // the string
+                    // Two cases: either we just exceeded the train count, in
+                    // which case the cache must be created, or we just update
+                    // the count for the string
                     if (ccCount > trainThreshold) {
                         long t1 = System.currentTimeMillis();
                         // Sort the entries according to occurrence
                         TreeMap<Integer,ArrayList<CharEntry>> tempMap =
                             new TreeMap<Integer,ArrayList<CharEntry>>();
-                        for (Entry<CharEntry, int[]> item : ccStats.entrySet()) {
+                        for (Entry<CharEntry,int[]> item : ccStats.entrySet()) {
                             CharEntry entry = item.getKey();
                             int[] countA = item.getValue();
                             Integer count = new Integer(countA[0]);
@@ -373,13 +378,16 @@ public class StringCache {
                             ArrayList<CharEntry> list = tempMap.get(key);
                             for (int i = 0; i < list.size() && n < size; i++) {
                                 CharEntry entry = list.get(i);
-                                tempChunk.setChars(entry.name, 0, entry.name.length);
-                                int insertPos = findClosest(tempChunk, tempccCache, n);
+                                tempChunk.setChars(entry.name, 0,
+                                        entry.name.length);
+                                int insertPos = findClosest(tempChunk,
+                                        tempccCache, n);
                                 if (insertPos == n) {
                                     tempccCache[n + 1] = entry;
                                 } else {
-                                    System.arraycopy(tempccCache, insertPos + 1, tempccCache, 
-                                            insertPos + 2, n - insertPos - 1);
+                                    System.arraycopy(tempccCache, insertPos + 1,
+                                            tempccCache, insertPos + 2,
+                                            n - insertPos - 1);
                                     tempccCache[insertPos + 1] = entry;
                                 }
                                 n++;
@@ -391,7 +399,8 @@ public class StringCache {
                         ccCache = tempccCache;
                         if (log.isDebugEnabled()) {
                             long t2 = System.currentTimeMillis();
-                            log.debug("CharCache generation time: " + (t2 - t1) + "ms");
+                            log.debug("CharCache generation time: " +
+                                    (t2 - t1) + "ms");
                         }
                     } else {
                         ccCount++;
@@ -404,7 +413,8 @@ public class StringCache {
                             int start = cc.getStart();
                             // Create char array and copy chars
                             entry.name = new char[cc.getLength()];
-                            System.arraycopy(cc.getBuffer(), start, entry.name, 0, end - start);
+                            System.arraycopy(cc.getBuffer(), start, entry.name,
+                                    0, end - start);
                             // Initialize occurrence count to one 
                             count = new int[1];
                             count[0] = 1;
@@ -469,7 +479,8 @@ public class StringCache {
 
     
     /**
-     * Find an entry given its name in the cache and return the associated String.
+     * Find an entry given its name in the cache and return the associated
+     * String.
      */
     protected static final String find(ByteChunk name) {
         int pos = findClosest(name, bcCache, bcCache.length);
@@ -487,7 +498,8 @@ public class StringCache {
      * This will return the index for the closest inferior or equal item in the
      * given array.
      */
-    protected static final int findClosest(ByteChunk name, ByteEntry[] array, int len) {
+    protected static final int findClosest(ByteChunk name, ByteEntry[] array,
+            int len) {
 
         int a = 0;
         int b = len - 1;
@@ -562,7 +574,8 @@ public class StringCache {
 
     
     /**
-     * Find an entry given its name in the cache and return the associated String.
+     * Find an entry given its name in the cache and return the associated
+     * String.
      */
     protected static final String find(CharChunk name) {
         int pos = findClosest(name, ccCache, ccCache.length);
@@ -579,7 +592,8 @@ public class StringCache {
      * This will return the index for the closest inferior or equal item in the
      * given array.
      */
-    protected static final int findClosest(CharChunk name, CharEntry[] array, int len) {
+    protected static final int findClosest(CharChunk name, CharEntry[] array,
+            int len) {
 
         int a = 0;
         int b = len - 1;



Mime
View raw message