User: starksm 
  Date: 02/03/11 17:05:00

  Modified:    src/main/org/jboss/system ServiceController.java
  Log:
  Validate that the ctx proxy is not null to avoid NPEs during shutdown
  
  Revision  Changes    Path
  1.4       +72 -47    jboss-system/src/main/org/jboss/system/ServiceController.java
  
  Index: ServiceController.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss-system/src/main/org/jboss/system/ServiceController.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ServiceController.java    5 Mar 2002 03:10:05 -0000       1.3
  +++ ServiceController.java    12 Mar 2002 01:05:00 -0000      1.4
  @@ -46,7 +46,7 @@
    * 
    * @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>David Jencks</a>
  - * @version $Revision: 1.3 $ <p>
  + * @version $Revision: 1.4 $ <p>
    *
    * <b>Revisions:</b> <p>
    *
  @@ -104,10 +104,11 @@
         ListIterator iterator = installedServices.listIterator();
         
         for (int i = 0; i<installedServices.size() ; i++)
  -      {      
  -         deployed[i] = ((ServiceContext) iterator.next()).objectName;      
  +      {
  +         ServiceContext ctx = (ServiceContext) iterator.next();
  +         deployed[i] = ctx.objectName;
         }
  -      
  +
         return deployed;
      }
      
  @@ -149,17 +150,20 @@
         // It is not there so really create the component now, this registers the 
component in the mbeanserver
   
         // deal with those pesky JMX exceptions
  -      try {
  +      try
  +      {
            creator.install(mbeanElement);
         }
  -      catch (Exception e) {
  +      catch (Exception e)
  +      {
            JMXExceptionDecoder.rethrow(e);
         }
  -      
  +
         // We got this far
         ctx.state = ServiceContext.INSTALLED;
         
  -      try {
  +      try
  +      {
            // Configure the MBean
            synchronized (this)
            {
  @@ -196,8 +200,9 @@
         // We got this far
         ctx.state = ServiceContext.CONFIGURED;
         
  -      if ( !installedServices.contains(ctx)) installedServices.add(ctx);
  -         
  +      if ( !installedServices.contains(ctx))
  +         installedServices.add(ctx);
  +
         return ctx.objectName;
      }
      
  @@ -232,25 +237,28 @@
            int state = sc.state;
            
            // A dependent is not created or running
  -         if (!(state == ServiceContext.CREATED || state == ServiceContext.RUNNING)) 
{
  -            if (debug) {
  -            log.debug("waiting in create "+ serviceName +
  -                      " waiting on " + sc.objectName);
  -         }
  -
  +         if (!(state == ServiceContext.CREATED || state == ServiceContext.RUNNING))
  +         {
  +            if (debug)
  +            {
  +               log.debug("waiting in create "+ serviceName +
  +                  " waiting on " + sc.objectName);
  +            }
               ctx.state=oldState;
               return;
            }
         }
  -      
  +
         // Call create on the service Proxy  
  -      try { 
  +      try
  +      { 
            ctx.proxy.create(); 
         }   
  -      catch (Exception e){ 
  +      catch (Exception e)
  +      {
            ctx.state = ServiceContext.FAILED; throw e;
         }
  -      
  +
         // Those that depend on me are waiting for my creation, recursively create 
them
         Iterator iterator2 = ctx.dependsOnMe.iterator();
         while (iterator2.hasNext()) 
  @@ -272,13 +280,15 @@
   
         ServiceContext ctx = (ServiceContext) getServiceContext(serviceName);
   
  -      if (ctx == null) {
  +      if (ctx == null)
  +      {
            log.warn("Ignoring request to start non-existant service: " + serviceName);
            return;
         }
         
         // If we are already started (can happen in dependencies) just return
  -      if (ctx.state == ServiceContext.RUNNING) {
  +      if (ctx.state == ServiceContext.RUNNING)
  +      {
            return;
         }
            
  @@ -300,24 +310,25 @@
               ObjectName cac = new ObjectName("Test:name=test");
               ObjectName ca2 = new ObjectName("Test:name=test");
               
  -         if (debug) {
  -            log.debug("waiting in start "+serviceName+" on "+sctx.objectName);
  -         }
  -            
  +            if (debug)
  +               log.debug("waiting in start "+serviceName+" on "+sctx.objectName);
  +
               ctx.state=oldState;
               return;
            }
         }
         
         // Call create on the service Proxy  
  -      try {
  +      try
  +      {
            ctx.proxy.start(); 
         }   
  -      catch (Exception e){
  +      catch (Exception e)
  +      {
            ctx.state = ServiceContext.FAILED;
            throw e;
         }
  -      
  +
         // JSR 77
         ctx.state = ServiceContext.RUNNING;
         
  @@ -343,11 +354,13 @@
         boolean debug = log.isDebugEnabled();
         
         ServiceContext ctx = (ServiceContext) nameToServiceMap.get(serviceName);
  -      if (debug) {
  +      if (debug)
  +      {
            log.debug("stopping service: " + serviceName);
         }
         
  -      if (ctx == null) {
  +      if (ctx == null)
  +      {
            log.warn("Ignoring request to stop non-existant service: " + serviceName);
            return;
         }
  @@ -370,13 +383,18 @@
            stop(other);
         }
            
  -      // Call create on the service Proxy
  -      try {
  -         ctx.proxy.stop();
  -      }
  -      catch (Exception e) {
  -         ctx.state = ServiceContext.FAILED;
  -         throw e;
  +      // Call stop on the service Proxy
  +      if( ctx.proxy != null )
  +      {
  +         try
  +         {
  +            ctx.proxy.stop();
  +         }
  +         catch (Exception e)
  +         {
  +            ctx.state = ServiceContext.FAILED;
  +            throw e;
  +         }
         }
      }
      
  @@ -394,7 +412,8 @@
         if (debug)
            log.debug("destroying service: " + serviceName);
   
  -      if (ctx == null) {
  +      if (ctx == null)
  +      {
            log.warn("Ignoring request to destroy non-existant service: " + 
serviceName);
            return;
         }
  @@ -415,13 +434,18 @@
            destroy(other);
         }
         
  -      // Call create on the service Proxy  
  -      try {
  -         ctx.proxy.destroy();
  -      }   
  -      catch (Exception e){
  -         ctx.state = ServiceContext.FAILED;
  -         throw e;
  +      // Call destroy on the service Proxy  
  +      if( ctx.proxy != null )
  +      {
  +         try
  +         {
  +            ctx.proxy.destroy();
  +         }   
  +         catch (Exception e)
  +         {
  +            ctx.state = ServiceContext.FAILED;
  +            throw e;
  +         }
         }
      }   
      
  @@ -450,7 +474,8 @@
         if (debug)
            log.debug("removing service: " + objectName);
   
  -      if (ctx == null) {
  +      if (ctx == null)
  +      {
            log.warn("Ignoring request to remove non-existant service: " + objectName);
            return;
         }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to