You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hivemind.apache.org by jc...@apache.org on 2005/03/29 00:33:36 UTC

cvs commit: jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/servicemodel PrimitiveServiceModel.java SingletonServiceModel.java AbstractServiceModelImpl.java PooledServiceModel.java

jcarman     2005/03/28 14:33:36

  Modified:    framework/src/test/org/apache/hivemind/impl/servicemodel
                        Simple.java SimpleImpl.java
               framework/src/java/org/apache/hivemind/impl
                        ShutdownCoordinatorImpl.java
               framework/src/java/org/apache/hivemind/impl/servicemodel
                        PrimitiveServiceModel.java
                        SingletonServiceModel.java
                        AbstractServiceModelImpl.java
                        PooledServiceModel.java
  Added:       framework/src/test/org/apache/hivemind/impl/servicemodel
                        ShutdownListenerServices.xml
                        TestRegistryShutdownListenerServices.java
                        Counter.java
  Removed:     framework/src/test/org/apache/hivemind/impl/servicemodel
                        TestPooledServiceModel.java
                        SingletonShutdownListenerService.xml
                        PrimitiveShutdownListenerService.xml
                        TestSingletonServiceModel.java
                        PooledShutdownListenerService.xml
                        TestPrimitiveServiceModel.java BooleanHolder.java
  Log:
  Core service implementations which implement RegistryShutdownListener are not notified for primitive, singleton, and pooled service models
  PR: HIVEMIND-103
  
  Revision  Changes    Path
  1.3       +1 -1      jakarta-hivemind/framework/src/test/org/apache/hivemind/impl/servicemodel/Simple.java
  
  Index: Simple.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/test/org/apache/hivemind/impl/servicemodel/Simple.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Simple.java	28 Mar 2005 01:31:18 -0000	1.2
  +++ Simple.java	28 Mar 2005 22:33:36 -0000	1.3
  @@ -20,5 +20,5 @@
    */
   public interface Simple
   {
  -    public void setHolder( BooleanHolder holder );
  +    public void setCounter( Counter counter );
   }
  
  
  
  1.3       +11 -5     jakarta-hivemind/framework/src/test/org/apache/hivemind/impl/servicemodel/SimpleImpl.java
  
  Index: SimpleImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/test/org/apache/hivemind/impl/servicemodel/SimpleImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SimpleImpl.java	28 Mar 2005 01:31:18 -0000	1.2
  +++ SimpleImpl.java	28 Mar 2005 22:33:36 -0000	1.3
  @@ -14,6 +14,7 @@
   
   package org.apache.hivemind.impl.servicemodel;
   
  +import org.apache.hivemind.ShutdownCoordinator;
   import org.apache.hivemind.events.RegistryShutdownListener;
   
   /**
  @@ -22,16 +23,21 @@
    */
   public class SimpleImpl implements Simple, RegistryShutdownListener
   {
  -    private BooleanHolder holder;
  +    private Counter counter;
  +
       
  -    public void setHolder(BooleanHolder holder)
  +    public SimpleImpl( ShutdownCoordinator coordinator )
       {
  -        this.holder = holder;
  -
  +        coordinator.addRegistryShutdownListener( this );
  +    }
  +    
  +    public void setCounter( Counter counter )
  +    {
  +        this.counter = counter;
       }
       
       public void registryDidShutdown()
       {
  -        holder.setValue( true );
  +        counter.increment();
       }
   }
  
  
  
  1.1                  jakarta-hivemind/framework/src/test/org/apache/hivemind/impl/servicemodel/ShutdownListenerServices.xml
  
  Index: ShutdownListenerServices.xml
  ===================================================================
  <?xml version="1.0"?>
  <!-- 
     Copyright 2004, 2005 The Apache Software Foundation
  
     Licensed 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.
  -->
  
  <module id="hivemind.lib.test" version="1.0.0">
    
    <service-point id="singletonSimple" interface="org.apache.hivemind.impl.servicemodel.Simple">
      <invoke-factory model="singleton">
        <construct class="org.apache.hivemind.impl.servicemodel.SimpleImpl" />
      </invoke-factory>
    </service-point>
    <service-point id="primitiveSimple" interface="org.apache.hivemind.impl.servicemodel.Simple">
      <invoke-factory model="primitive">
        <construct class="org.apache.hivemind.impl.servicemodel.SimpleImpl" />
      </invoke-factory>
    </service-point>
    <service-point id="pooledSimple" interface="org.apache.hivemind.impl.servicemodel.Simple">
      <invoke-factory model="pooled">
        <construct class="org.apache.hivemind.impl.servicemodel.SimpleImpl" />
      </invoke-factory>
    </service-point>
  </module>
  
  
  1.1                  jakarta-hivemind/framework/src/test/org/apache/hivemind/impl/servicemodel/TestRegistryShutdownListenerServices.java
  
  Index: TestRegistryShutdownListenerServices.java
  ===================================================================
  // Copyright 2004, 2005 The Apache Software Foundation
  //
  // Licensed 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.hivemind.impl.servicemodel;
  
  import org.apache.hivemind.Registry;
  import org.apache.hivemind.test.HiveMindTestCase;
  
  /**
   * @author James Carman
   * @version 1.0
   */
  public class TestRegistryShutdownListenerServices extends HiveMindTestCase
  {
      private void executeShutdownListenerTest(String type) throws Exception
      {
          Registry registry = buildFrameworkRegistry("ShutdownListenerServices.xml");
          Simple simple = (Simple) registry.getService("hivemind.lib.test."
                  + type + "Simple", Simple.class);
          final Counter counter = new Counter();
          simple.setCounter(counter);
          registry.shutdown();
          assertEquals(1, counter.getValue());
      }
  
      public void testPooled() throws Exception
      {
          executeShutdownListenerTest("pooled");
      }
  
      public void testSingleton() throws Exception
      {
          executeShutdownListenerTest("singleton");
      }
  
      public void testPrimitive() throws Exception
      {
          executeShutdownListenerTest("primitive");
      }
  
  }
  
  
  
  1.1                  jakarta-hivemind/framework/src/test/org/apache/hivemind/impl/servicemodel/Counter.java
  
  Index: Counter.java
  ===================================================================
  // Copyright 2004, 2005 The Apache Software Foundation
  //
  // Licensed 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.hivemind.impl.servicemodel;
  
  /**
   * @author James Carman
   * @version 1.0
   */
  public class Counter
  {
      private int value = 0;
      
      public void increment()
      {
          value++;
      }
      
      public int getValue()
      {
          return value;
      }
  }
  
  
  
  1.6       +27 -9     jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ShutdownCoordinatorImpl.java
  
  Index: ShutdownCoordinatorImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ShutdownCoordinatorImpl.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ShutdownCoordinatorImpl.java	6 Jan 2005 01:45:12 -0000	1.5
  +++ ShutdownCoordinatorImpl.java	28 Mar 2005 22:33:36 -0000	1.6
  @@ -14,7 +14,9 @@
   
   package org.apache.hivemind.impl;
   
  +import java.util.HashSet;
   import java.util.Iterator;
  +import java.util.Set;
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  @@ -24,14 +26,16 @@
   
   /**
    * Manages a list of objects that implement the
  - * {@link org.apache.hivemind.events.RegistryShutdownListener} interface.
  - *
  + * {@link org.apache.hivemind.events.RegistryShutdownListener}interface.
  + * 
    * @author Howard Lewis Ship
    */
   public final class ShutdownCoordinatorImpl implements ShutdownCoordinator
   {
       private final Log _log;
   
  +    private Set alreadyShutdown;
  +
       public ShutdownCoordinatorImpl()
       {
           this(LogFactory.getLog(ShutdownCoordinatorImpl.class));
  @@ -39,12 +43,13 @@
   
       public ShutdownCoordinatorImpl(Log log)
       {
  -        _log = log;
  +        _log = log;        
       }
   
       private EventListenerList _listenerList;
   
  -    public synchronized void addRegistryShutdownListener(RegistryShutdownListener s)
  +    public synchronized void addRegistryShutdownListener(
  +            RegistryShutdownListener s)
       {
           if (_listenerList == null)
               _listenerList = new EventListenerList();
  @@ -52,7 +57,8 @@
           _listenerList.addListener(s);
       }
   
  -    public synchronized void removeRegistryShutdownListener(RegistryShutdownListener s)
  +    public synchronized void removeRegistryShutdownListener(
  +            RegistryShutdownListener s)
       {
           if (_listenerList != null)
               _listenerList.removeListener(s);
  @@ -79,13 +85,25 @@
   
       private void shutdown(RegistryShutdownListener s)
       {
  -        try
  +        if (alreadyShutdown == null)
           {
  -            s.registryDidShutdown();
  +            alreadyShutdown = new HashSet();
           }
  -        catch (RuntimeException ex)
  +        final Long id = new Long(System.identityHashCode(s));
  +        if (!alreadyShutdown.contains(id))
           {
  -            _log.error(ImplMessages.shutdownCoordinatorFailure(s, ex), ex);
  +            try
  +            {
  +                s.registryDidShutdown();
  +            }
  +            catch (RuntimeException ex)
  +            {
  +                _log.error(ImplMessages.shutdownCoordinatorFailure(s, ex), ex);
  +            }
  +            finally
  +            {
  +                alreadyShutdown.add(id);
  +            }
           }
       }
   
  
  
  
  1.10      +1 -1      jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/servicemodel/PrimitiveServiceModel.java
  
  Index: PrimitiveServiceModel.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/servicemodel/PrimitiveServiceModel.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- PrimitiveServiceModel.java	28 Mar 2005 01:08:49 -0000	1.9
  +++ PrimitiveServiceModel.java	28 Mar 2005 22:33:36 -0000	1.10
  @@ -42,7 +42,7 @@
               _constructedService = constructServiceImplementation();
               if( _constructedService instanceof RegistryShutdownListener )
               {
  -                getServicePoint().getShutdownCoordinator().addRegistryShutdownListener( ( RegistryShutdownListener )_constructedService );
  +                getShutdownCoordinatorService().addRegistryShutdownListener( ( RegistryShutdownListener )_constructedService );
               }
           }
   
  
  
  
  1.12      +6 -2      jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/servicemodel/SingletonServiceModel.java
  
  Index: SingletonServiceModel.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/servicemodel/SingletonServiceModel.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- SingletonServiceModel.java	28 Mar 2005 01:08:49 -0000	1.11
  +++ SingletonServiceModel.java	28 Mar 2005 22:33:36 -0000	1.12
  @@ -67,6 +67,10 @@
           if (_constructedService == null)
               _constructedService = constructServiceImplementation();
   
  +        if( _constructedService instanceof RegistryShutdownListener )
  +        {
  +            getShutdownCoordinatorService().addRegistryShutdownListener( ( RegistryShutdownListener )_constructedService );
  +        }
           // The inner proxy needs the service to implement the service interface.
           // For bean services (not interface services) with no interceptors,
           // the implementation may be the bean provided by the factory ... which
  @@ -74,7 +78,7 @@
           // So we introduce a "bridge" between the two.
   
           Class serviceInterface = getServicePoint().getServiceInterface();
  -
  +    
           if (!serviceInterface.isInstance(_constructedService))
               _constructedService = constructBridgeProxy(_constructedService);
   
  @@ -153,7 +157,7 @@
           classFab.addInterface(RegistryShutdownListener.class);
   
           classFab.addMethod(Modifier.PUBLIC | Modifier.FINAL, new MethodSignature(void.class,
  -                "registryDidShutdown", null, null), "{ _shutdown = true; if( _inner instanceof org.apache.hivemind.events.RegistryShutdownListener ) { ( ( org.apache.hivemind.events.RegistryShutdownListener )_inner ).registryDidShutdown(); } }");
  +                "registryDidShutdown", null, null), "{ _shutdown = true; } }");
   
           classFab.addMethod(
                   Modifier.PUBLIC | Modifier.SYNCHRONIZED | Modifier.FINAL,
  
  
  
  1.10      +6 -0      jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/servicemodel/AbstractServiceModelImpl.java
  
  Index: AbstractServiceModelImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/servicemodel/AbstractServiceModelImpl.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- AbstractServiceModelImpl.java	19 Feb 2005 02:40:54 -0000	1.9
  +++ AbstractServiceModelImpl.java	28 Mar 2005 22:33:36 -0000	1.10
  @@ -20,6 +20,7 @@
   import org.apache.commons.logging.LogFactory;
   import org.apache.hivemind.ApplicationRuntimeException;
   import org.apache.hivemind.HiveMind;
  +import org.apache.hivemind.ShutdownCoordinator;
   import org.apache.hivemind.impl.ConstructableServicePoint;
   import org.apache.hivemind.impl.InterceptorStackImpl;
   import org.apache.hivemind.impl.ProxyBuilder;
  @@ -211,4 +212,9 @@
           return cf.createClass();
       }
   
  +    protected ShutdownCoordinator getShutdownCoordinatorService()
  +    {
  +        return ( ( ShutdownCoordinator )getServicePoint().getModule().getService( ShutdownCoordinator.class ) );
  +    }
  +
   }
  \ No newline at end of file
  
  
  
  1.14      +1 -1      jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/servicemodel/PooledServiceModel.java
  
  Index: PooledServiceModel.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/servicemodel/PooledServiceModel.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- PooledServiceModel.java	28 Mar 2005 01:31:53 -0000	1.13
  +++ PooledServiceModel.java	28 Mar 2005 22:33:36 -0000	1.14
  @@ -228,7 +228,7 @@
                   core = constructBridgeProxy(core);
               if( core instanceof RegistryShutdownListener )
               {
  -                getServicePoint().getShutdownCoordinator().addRegistryShutdownListener( ( RegistryShutdownListener )core );
  +                getShutdownCoordinatorService().addRegistryShutdownListener( ( RegistryShutdownListener )core );
               }
               return new PooledService(core);
           }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-cvs-help@jakarta.apache.org