[jboss-cvs] JBossAS SVN: r77035 - trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Aug 13 17:06:40 EDT 2008


Author: pferraro
Date: 2008-08-13 17:06:40 -0400 (Wed, 13 Aug 2008)
New Revision: 77035

Modified:
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/DefaultJBossWebEventHandler.java
Log:
Fixed init() condition for creating advertiseListener.
Code cleanup/formatting.

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/DefaultJBossWebEventHandler.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/DefaultJBossWebEventHandler.java	2008-08-13 20:52:31 UTC (rev 77034)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/DefaultJBossWebEventHandler.java	2008-08-13 21:06:40 UTC (rev 77035)
@@ -53,33 +53,31 @@
    protected static Logger log = Logger.getLogger(DefaultJBossWebEventHandler.class);
 
    // -----------------------------------------------------------------  Fields
-   
+
    /**
     * The string manager for this package.
     */
-   private StringManager sm = StringManager.getManager(Constants.Package);
-   
+   private final StringManager sm = StringManager.getManager(Constants.Package);
    private final NodeConfiguration nodeConfiguration;
    private final BalancerConfiguration balancerConfiguration;
    private final MCMPHandler mcmpHandler;
    private final LoadBalanceFactorProvider loadBalanceFactorProvider;
-   
+
    private boolean init;
+
    private AdvertiseListener advertiseListener;
-   
+
    // -----------------------------------------------------------  Constructors
-   
-   public DefaultJBossWebEventHandler(NodeConfiguration nodeConfiguration,
-                                      BalancerConfiguration balancerConfiguration,
-                                      MCMPHandler mcmpHandler,
-                                      LoadBalanceFactorProvider loadBalanceFactorProvider)
+
+   public DefaultJBossWebEventHandler(NodeConfiguration nodeConfiguration, BalancerConfiguration balancerConfiguration,
+         MCMPHandler mcmpHandler, LoadBalanceFactorProvider loadBalanceFactorProvider)
    {
       this.nodeConfiguration = nodeConfiguration;
       this.balancerConfiguration = balancerConfiguration;
       this.mcmpHandler = mcmpHandler;
       this.loadBalanceFactorProvider = loadBalanceFactorProvider;
    }
-   
+
    // ---------------------------------------------------- JBossWebEventHandler
 
    public synchronized void init()
@@ -88,18 +86,20 @@
       List<AddressPort> initialProxies = MCMPUtils.parseProxies(handlerConfig.getProxyList());
       this.mcmpHandler.init(initialProxies);
       
-      if (Boolean.TRUE.equals(handlerConfig) || (handlerConfig == null && initialProxies.size() == 0))
+      Boolean advertise = handlerConfig.getAdvertise();
+      
+      if (Boolean.TRUE.equals(advertise) || (advertise == null && initialProxies.size() == 0))
       {
          this.advertiseListener = new AdvertiseListener(this.mcmpHandler);
       }
-      
+
       this.init = true;
    }
-   
+
    public synchronized void shutdown()
    {
-      stopListener();
-      this.mcmpHandler.shutdown();      
+      this.stopListener();
+      this.mcmpHandler.shutdown();
       this.init = false;
    }
 
@@ -107,161 +107,155 @@
     * Send commands to the front end server associated with the startup of the
     * node.
     */
-   public void startServer(Server server) 
-   {      
-      checkInit(); 
-               
-       Service[] services = server.findServices();
-       for (int i = 0; i < services.length; i++) {
-           
-           Engine engine = (Engine) services[i].getContainer();
-           
-           config(engine);
-           Container[] children = engine.findChildren();
-           for (int j = 0; j < children.length; j++) {
-               Container[] children2 = children[j].findChildren();
-               for (int k = 0; k < children2.length; k++) {
-                   addContext((Context) children2[k]);
-               }
-           }
-       }
+   public void startServer(Server server)
+   {
+      this.checkInit();
+
+      Service[] services = server.findServices();
+      for (Service service : services)
+      {
+         Engine engine = (Engine) service.getContainer();
+
+         this.config(engine);
+         Container[] children = engine.findChildren();
+         for (Container element : children)
+         {
+            Container[] children2 = element.findChildren();
+            for (Container element2 : children2)
+            {
+               this.addContext((Context) element2);
+            }
+         }
+      }
    }
-   
-   
+
    /**
     * Send commands to the front end server associated with the shutdown of the
     * node.
     */
-   public void stopServer(Server server) 
-   {      
-      checkInit(); 
+   public void stopServer(Server server)
+   {
+      this.checkInit();
 
-       Service[] services = server.findServices();
-       for (int i = 0; i < services.length; i++) {
-           removeAll((Engine) services[i].getContainer());
-           Container[] children = services[i].getContainer().findChildren();
-           for (int j = 0; j < children.length; j++) {
-               Container[] children2 = children[j].findChildren();
-               for (int k = 0; k < children2.length; k++) {
-                   removeContext((Context) children2[k]);
-               }
-           }
-       }
+      Service[] services = server.findServices();
+      for (Service service : services)
+      {
+         this.removeAll((Engine) service.getContainer());
+         Container[] children = service.getContainer().findChildren();
+         for (Container element : children)
+         {
+            Container[] children2 = element.findChildren();
+            for (Container element2 : children2)
+            {
+               this.removeContext((Context) element2);
+            }
+         }
+      }
    }
-   
+
    public void config(Engine engine)
    {
-      
-      if (log.isDebugEnabled()) {
-         log.debug(sm.getString("modcluster.engine.config", engine.getName()));
-      }
-      
+      log.debug(this.sm.getString("modcluster.engine.config", engine.getName()));
+
       // If needed, create automagical JVM route (address + port + engineName)
-      try {
+      try
+      {
          Utils.establishJvmRouteAndConnectorAddress(engine, this.mcmpHandler);
-      } catch (Exception e) {
-         mcmpHandler.markProxiesInError();
-         log.info(sm.getString("modcluster.error.addressJvmRoute"), e);
+      }
+      catch (Exception e)
+      {
+         this.mcmpHandler.markProxiesInError();
+         log.info(this.sm.getString("modcluster.error.addressJvmRoute"), e);
          return;
       }
-     
-     MCMPRequest request = MCMPUtils.createConfigRequest(engine, getNodeConfiguration(), getBalancerConfiguration());
-     
-     // Send CONFIG request
-     mcmpHandler.sendRequest(request);
-      
+
+      MCMPRequest request = MCMPUtils.createConfigRequest(engine, this.getNodeConfiguration(), this.getBalancerConfiguration());
+
+      // Send CONFIG request
+      this.mcmpHandler.sendRequest(request);
    }
-   
+
    public void addContext(Context context)
    {
-      checkInit();
-      
-      if (log.isDebugEnabled()) {
-         log.debug(sm.getString("modcluster.context.enable", context.getPath(), context.getParent().getName(), ((StandardContext) context).getState()));
-     }
+      this.checkInit();
 
-     // Send ENABLE-APP if state is started
-     if (context.isStarted()) {
-        MCMPRequest request = MCMPUtils.createEnableAppRequest(context);
-        mcmpHandler.sendRequest(request);
-     }
+      log.debug(this.sm.getString("modcluster.context.enable", context.getPath(), context.getParent().getName(), ((StandardContext) context).getState()));
+
+      // Send ENABLE-APP if state is started
+      if (context.isStarted())
+      {
+         MCMPRequest request = MCMPUtils.createEnableAppRequest(context);
+         this.mcmpHandler.sendRequest(request);
+      }
    }
 
    public void startContext(Context context)
    {
-      checkInit();
-      
-      if (log.isDebugEnabled()) {
-         log.debug(sm.getString("modcluster.context.start", context.getPath(), context.getParent().getName()));
-     }
+      this.checkInit();
 
-     // Send ENABLE-APP
-     MCMPRequest request = MCMPUtils.createEnableAppRequest(context);
-     mcmpHandler.sendRequest(request);
+      log.debug(this.sm.getString("modcluster.context.start", context.getPath(), context.getParent().getName()));
+
+      // Send ENABLE-APP
+      MCMPRequest request = MCMPUtils.createEnableAppRequest(context);
+      this.mcmpHandler.sendRequest(request);
    }
 
    public void stopContext(Context context)
    {
-      checkInit();
-      
-      if (log.isDebugEnabled()) {
-         log.debug(sm.getString("modcluster.context.stop", context.getPath(), context.getParent().getName()));
-     }
+      this.checkInit();
 
-     // Send STOP-APP
-     MCMPRequest request = MCMPUtils.createStopAppRequest(context);
-     mcmpHandler.sendRequest(request);
+      log.debug(this.sm.getString("modcluster.context.stop", context.getPath(), context.getParent().getName()));
+
+      // Send STOP-APP
+      MCMPRequest request = MCMPUtils.createStopAppRequest(context);
+      this.mcmpHandler.sendRequest(request);
    }
 
    public void removeContext(Context context)
    {
-      checkInit();
-      
-      if (log.isDebugEnabled()) {
-         log.debug(sm.getString("modcluster.context.disable", context.getPath(), context.getParent().getName(), ((StandardContext) context).getState()));
-     }
+      this.checkInit();
 
-     // JVMRoute can be null here if nothing was ever initialized
-     if (Utils.getJvmRoute(context) != null) {
-        MCMPRequest request = MCMPUtils.createRemoveAppRequest(context);
-        mcmpHandler.sendRequest(request);
-     }
+      log.debug(this.sm.getString("modcluster.context.disable", context.getPath(), context.getParent().getName(), ((StandardContext) context).getState()));
+
+      // JVMRoute can be null here if nothing was ever initialized
+      if (Utils.getJvmRoute(context) != null)
+      {
+         MCMPRequest request = MCMPUtils.createRemoveAppRequest(context);
+         this.mcmpHandler.sendRequest(request);
+      }
    }
 
    public void removeAll(Engine engine)
    {
-      checkInit();
-      
-      if (log.isDebugEnabled()) {
-         log.debug(sm.getString("modcluster.engine.stop", engine.getName()));
-     }
+      this.checkInit();
 
-     // JVMRoute can be null here if nothing was ever initialized
-     if (engine.getJvmRoute() != null) {
-        // Send REMOVE-APP * request
-        MCMPRequest request = MCMPUtils.createRemoveAllRequest(engine);
-        mcmpHandler.sendRequest(request);
-     }
+      log.debug(this.sm.getString("modcluster.engine.stop", engine.getName()));
+
+      // JVMRoute can be null here if nothing was ever initialized
+      if (engine.getJvmRoute() != null)
+      {
+         // Send REMOVE-APP * request
+         MCMPRequest request = MCMPUtils.createRemoveAllRequest(engine);
+         this.mcmpHandler.sendRequest(request);
+      }
    }
 
    public void status(Engine engine)
    {
-      checkInit();
-      
-      if (log.isDebugEnabled()) {
-          log.debug(sm.getString("modcluster.engine.status", engine.getName()));
-      }
-      
-      mcmpHandler.status();
-      
+      this.checkInit();
+
+      log.debug(this.sm.getString("modcluster.engine.status", engine.getName()));
+
+      this.mcmpHandler.status();
+
       // Send STATUS request
-      int lbf = getLoadBalanceFactorProvider().getLoadBalanceFactor();
+      int lbf = this.getLoadBalanceFactorProvider().getLoadBalanceFactor();
       MCMPRequest request = MCMPUtils.createStatusRequest(engine, lbf);
-      mcmpHandler.sendRequest(request);
+      this.mcmpHandler.sendRequest(request);
    }
 
    // -----------------------------------------------------------------  Public
-   
+
    public BalancerConfiguration getBalancerConfiguration()
    {
       return this.balancerConfiguration;
@@ -276,32 +270,33 @@
    {
       return this.loadBalanceFactorProvider;
    }
-   
+
    // ----------------------------------------------------------------  Private
-   
+
    private void checkInit()
    {
       if (!this.init)
-         throw new IllegalStateException(sm.getString("modcluster.error.uninitialized"));
+      {
+         throw new IllegalStateException(this.sm.getString("modcluster.error.uninitialized"));
+      }
    }
-   
 
    /**
     * Stop the advertise listener.
     */
-   private void stopListener() 
+   private void stopListener()
    {
-       if (this.advertiseListener != null) 
-       {
-           try 
-           {
-              this.advertiseListener.destroy();
-           } 
-           catch (IOException e) 
-           {
-               log.error(sm.getString("modcluster.error.stopListener"), e);
-           }
-           this.advertiseListener = null;
-       }
+      if (this.advertiseListener != null)
+      {
+         try
+         {
+            this.advertiseListener.destroy();
+         }
+         catch (IOException e)
+         {
+            log.error(this.sm.getString("modcluster.error.stopListener"), e);
+         }
+         this.advertiseListener = null;
+      }
    }
 }




More information about the jboss-cvs-commits mailing list