You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hivemind.apache.org by hl...@apache.org on 2005/03/31 18:07:04 UTC

cvs commit: jakarta-hivemind/framework/src/java/org/apache/hivemind Registry.java

hlship      2005/03/31 08:07:04

  Modified:    framework/src/java/org/apache/hivemind/internal
                        RegistryInfrastructure.java
               .        status.xml
               framework/src/java/org/apache/hivemind/impl
                        RegistryInfrastructureImpl.java RegistryImpl.java
               framework/src/java/org/apache/hivemind/internal/ser
                        SerMessages.java SerStrings.properties
                        ServiceSerializationHelper.java
               framework/src/test/org/apache/hivemind/internal/ser
                        TestServiceSerializationHelper.java
               framework/src/java/org/apache/hivemind/servlet
                        HiveMindFilter.java
               framework/src/java/org/apache/hivemind Registry.java
  Log:
  HIVEMIND-83: Allow for running with multiple Registries.
  
  Revision  Changes    Path
  1.12      +11 -0     jakarta-hivemind/framework/src/java/org/apache/hivemind/internal/RegistryInfrastructure.java
  
  Index: RegistryInfrastructure.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/internal/RegistryInfrastructure.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- RegistryInfrastructure.java	19 Feb 2005 11:17:17 -0000	1.11
  +++ RegistryInfrastructure.java	31 Mar 2005 16:07:03 -0000	1.12
  @@ -215,6 +215,17 @@
       public void shutdown();
   
       /**
  +     * To be invoked at the start of each request in a multi-threaded environment. Ensures that the
  +     * receiving Registry will be used if any service proxies are de-serialized.
  +     * 
  +     * @since 3.1
  +     * @see org.apache.hivemind.internal.ser.ServiceSerializationHelper
  +     * @see org.apache.hivemind.internal.ser.ServiceSerializationSupport
  +     */
  +
  +    public void setupThread();
  +
  +    /**
        * Convienience for invoking
        * {@link org.apache.hivemind.service.ThreadEventNotifier#fireThreadCleanup()}.
        * 
  
  
  
  1.119     +1 -0      jakarta-hivemind/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/status.xml,v
  retrieving revision 1.118
  retrieving revision 1.119
  diff -u -r1.118 -r1.119
  --- status.xml	31 Mar 2005 15:35:05 -0000	1.118
  +++ status.xml	31 Mar 2005 16:07:03 -0000	1.119
  @@ -36,6 +36,7 @@
         <action type="update" dev="HLS"> Rename AdapterRegistry to StrategyRegistry, and AdapterRegistryFactory to StrategyFactory, to better reflect the relationship to the Gang-of-Four Strategy pattern.</action>
         <action type="update" dev="HLS"> Make the interface attribute of &lt;service-point&gt; optional, and default to the service point's id. </action>
         <action type="fix" dev="HLS" fixes-bug="HIVEMIND-104">Remove a potential deadlock related to the pooled service model.</action>
  +      <action type="fix" dev="HLS" fixes-bug="HIVEMIND-83"> Allow for running with multiple Registries. </action>
       </release>
       <release version="1.1-alpha-3" date="Mar 22 2005">
         <action type="fix" dev="JC" fixes-bug="HIVEMIND-96" >Interceptors can now be ordered by name rather than interceptor factory id.</action>
  
  
  
  1.11      +17 -7     jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/RegistryInfrastructureImpl.java
  
  Index: RegistryInfrastructureImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/RegistryInfrastructureImpl.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- RegistryInfrastructureImpl.java	31 Mar 2005 15:35:05 -0000	1.10
  +++ RegistryInfrastructureImpl.java	31 Mar 2005 16:07:03 -0000	1.11
  @@ -308,7 +308,7 @@
       {
           checkShutdown();
   
  -        ServiceSerializationHelper.resetServiceSerializationSupport(this);
  +        ServiceSerializationHelper.setServiceSerializationSupport(null);
   
           // Allow service implementations and such to shutdown.
   
  @@ -320,7 +320,7 @@
           coordinatorService.shutdown();
   
           // TODO: Shoudl this be moved earlier?
  -        
  +
           _shutdown = true;
   
           // Shutdown infrastructure items, such as proxies.
  @@ -343,12 +343,10 @@
       }
   
       /**
  -     * Technically, this should be a synchronized method, but the _shutdown
  -     * variable hardly ever changes, and the consequences are pretty minimal.
  -     * See HIVEMIND-104.
  -     * 
  +     * Technically, this should be a synchronized method, but the _shutdown variable hardly ever
  +     * changes, and the consequences are pretty minimal. See HIVEMIND-104.
        */
  -    
  +
       private void checkShutdown()
       {
           if (_shutdown)
  @@ -518,4 +516,16 @@
   
           return result;
       }
  +
  +    /**
  +     * Sets the current RI up as the ServiceSerializationSupport. Any service proxy tokens that are
  +     * de-serialized will find their proxies within this Registry.
  +     * 
  +     * @since 1.1
  +     */
  +
  +    public void setupThread()
  +    {
  +        ServiceSerializationHelper.setServiceSerializationSupport(this);
  +    }
   }
  \ No newline at end of file
  
  
  
  1.23      +5 -0      jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/RegistryImpl.java
  
  Index: RegistryImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/RegistryImpl.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- RegistryImpl.java	5 Jan 2005 18:04:10 -0000	1.22
  +++ RegistryImpl.java	31 Mar 2005 16:07:03 -0000	1.23
  @@ -91,4 +91,9 @@
           return _infrastructure.valueForSymbol(name);
       }
   
  +    /** @since 1.1 */
  +    public void setupThread()
  +    {
  +        _infrastructure.setupThread();
  +    }
   }
  \ No newline at end of file
  
  
  
  1.3       +0 -5      jakarta-hivemind/framework/src/java/org/apache/hivemind/internal/ser/SerMessages.java
  
  Index: SerMessages.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/internal/ser/SerMessages.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SerMessages.java	6 Jan 2005 01:45:13 -0000	1.2
  +++ SerMessages.java	31 Mar 2005 16:07:03 -0000	1.3
  @@ -29,9 +29,4 @@
       {
           return _formatter.getMessage("no-support-set");
       }
  -
  -    public static String supportAlreadySet(Object newSupport, Object oldSupport)
  -    {
  -        return _formatter.format("support-already-set", newSupport, oldSupport);
  -    }
   }
  \ No newline at end of file
  
  
  
  1.3       +0 -1      jakarta-hivemind/framework/src/java/org/apache/hivemind/internal/ser/SerStrings.properties
  
  Index: SerStrings.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/internal/ser/SerStrings.properties,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SerStrings.properties	6 Jan 2005 01:45:13 -0000	1.2
  +++ SerStrings.properties	31 Mar 2005 16:07:03 -0000	1.3
  @@ -13,4 +13,3 @@
   # limitations under the License.
   
   no-support-set=The ServiceSerializationSupport instance has not been set; this indicates that the HiveMind Registry has not been created within this JVM.
  -support-already-set=Replacing ServiceSerializationSupport instance {0} with {1}; this indicates that multiple HiveMind Registies have been created, and conflicts may occur.
  \ No newline at end of file
  
  
  
  1.3       +13 -23    jakarta-hivemind/framework/src/java/org/apache/hivemind/internal/ser/ServiceSerializationHelper.java
  
  Index: ServiceSerializationHelper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/internal/ser/ServiceSerializationHelper.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ServiceSerializationHelper.java	6 Jan 2005 01:45:13 -0000	1.2
  +++ ServiceSerializationHelper.java	31 Mar 2005 16:07:03 -0000	1.3
  @@ -14,6 +14,8 @@
   
   package org.apache.hivemind.internal.ser;
   
  +import java.lang.ref.WeakReference;
  +
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.apache.hivemind.ApplicationRuntimeException;
  @@ -30,7 +32,7 @@
   {
       private static final Log LOG = LogFactory.getLog(ServiceSerializationHelper.class);
   
  -    private static ServiceSerializationSupport _serviceSerializationSupport;
  +    private static final ThreadLocal _threadLocal = new ThreadLocal();
   
       /**
        * Returns the previously stored SSS.
  @@ -40,10 +42,16 @@
        */
       public static ServiceSerializationSupport getServiceSerializationSupport()
       {
  -        if (_serviceSerializationSupport == null)
  +        ServiceSerializationSupport result = null;
  +
  +        WeakReference reference = (WeakReference) _threadLocal.get();
  +        if (reference != null)
  +            result = (ServiceSerializationSupport) reference.get();
  +
  +        if (result == null)
               throw new ApplicationRuntimeException(SerMessages.noSupportSet());
   
  -        return _serviceSerializationSupport;
  +        return result;
       }
   
       /**
  @@ -54,26 +62,8 @@
       public static void setServiceSerializationSupport(
               ServiceSerializationSupport serviceSerializationSupport)
       {
  -        if (serviceSerializationSupport != null && _serviceSerializationSupport != null)
  -            LOG.error(SerMessages.supportAlreadySet(
  -                    serviceSerializationSupport,
  -                    _serviceSerializationSupport));
  +        WeakReference reference = new WeakReference(serviceSerializationSupport);
   
  -        _serviceSerializationSupport = serviceSerializationSupport;
  +        _threadLocal.set(reference);
       }
  -
  -    /**
  -     * Invoked to clear the SSS, if it matches the provide parameter. This is necessary, rather than
  -     * blindly setting it to null, because of a tricky case related to
  -     * {@link org.apache.hivemind.servlet.HiveMindFilter}, which includes the ability to create a
  -     * new Registry on the fly and has to leave both Registry's running for a brief window.
  -     */
  -
  -    public static void resetServiceSerializationSupport(
  -            ServiceSerializationSupport serviceSerializationSupport)
  -    {
  -        if (_serviceSerializationSupport == serviceSerializationSupport)
  -            _serviceSerializationSupport = null;
  -    }
  -
   }
  \ No newline at end of file
  
  
  
  1.3       +0 -61     jakarta-hivemind/framework/src/test/org/apache/hivemind/internal/ser/TestServiceSerializationHelper.java
  
  Index: TestServiceSerializationHelper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/test/org/apache/hivemind/internal/ser/TestServiceSerializationHelper.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestServiceSerializationHelper.java	6 Jan 2005 01:45:14 -0000	1.2
  +++ TestServiceSerializationHelper.java	31 Mar 2005 16:07:03 -0000	1.3
  @@ -63,67 +63,6 @@
           verifyControls();
       }
   
  -    public void testOverwrite()
  -    {
  -        ServiceSerializationSupport sa = newSupport();
  -        ServiceSerializationSupport sb = newSupport();
  -
  -        replayControls();
  -
  -        interceptLogging("org.apache.hivemind.internal.ser");
  -
  -        ServiceSerializationHelper.setServiceSerializationSupport(sa);
  -        ServiceSerializationHelper.setServiceSerializationSupport(sb);
  -
  -        assertSame(sb, ServiceSerializationHelper.getServiceSerializationSupport());
  -
  -        assertLoggedMessage(SerMessages.supportAlreadySet(sb, sa));
  -
  -        verifyControls();
  -    }
  -
  -    public void testReset()
  -    {
  -        ServiceSerializationSupport s = newSupport();
  -
  -        replayControls();
  -
  -        ServiceSerializationHelper.setServiceSerializationSupport(s);
  -
  -        ServiceSerializationHelper.resetServiceSerializationSupport(s);
  -
  -        try
  -        {
  -            ServiceSerializationHelper.getServiceSerializationSupport();
  -            unreachable();
  -        }
  -        catch (ApplicationRuntimeException ex)
  -        {
  -            // Back to same as never set.
  -        }
  -
  -        verifyControls();
  -    }
  -
  -    public void testResetMismatch()
  -    {
  -        ServiceSerializationSupport sa = newSupport();
  -        ServiceSerializationSupport sb = newSupport();
  -
  -        replayControls();
  -
  -        interceptLogging("org.apache.hivemind.internal.ser");
  -
  -        ServiceSerializationHelper.setServiceSerializationSupport(sa);
  -        ServiceSerializationHelper.setServiceSerializationSupport(sb);
  -
  -        ServiceSerializationHelper.resetServiceSerializationSupport(sa);
  -
  -        assertSame(sb, ServiceSerializationHelper.getServiceSerializationSupport());
  -
  -        verifyControls();
  -    }
  -
       public void testIntegration() throws Exception
       {
           Registry r = buildFrameworkRegistry("SerIntegration.xml");
  
  
  
  1.19      +5 -7      jakarta-hivemind/framework/src/java/org/apache/hivemind/servlet/HiveMindFilter.java
  
  Index: HiveMindFilter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/servlet/HiveMindFilter.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- HiveMindFilter.java	19 Feb 2005 02:40:54 -0000	1.18
  +++ HiveMindFilter.java	31 Mar 2005 16:07:03 -0000	1.19
  @@ -34,7 +34,6 @@
   import org.apache.hivemind.impl.DefaultClassResolver;
   import org.apache.hivemind.impl.RegistryBuilder;
   import org.apache.hivemind.impl.XmlModuleDescriptorProvider;
  -import org.apache.hivemind.internal.ser.ServiceSerializationHelper;
   import org.apache.hivemind.util.ContextResource;
   
   /**
  @@ -110,12 +109,6 @@
   
           addWebInfDescriptor(config.getServletContext(), resolver, builder);
   
  -        // This avoids an error message when replacing the SSS (really, the RegistryInfrastructure).
  -        // HiveMindFilter's reload-the-registry functionality is an exception to the rule
  -        // that there should just be one Registry per JVM.
  -
  -        ServiceSerializationHelper.setServiceSerializationSupport(null);
  -
           return builder.constructRegistry(getRegistryLocale());
       }
   
  @@ -169,6 +162,11 @@
       {
           try
           {
  +            // I believe the _registry will only be null in a couple of test situations.
  +
  +            if (_registry != null)
  +                _registry.setupThread();
  +
               request.setAttribute(REQUEST_KEY, _registry);
   
               chain.doFilter(request, response);
  
  
  
  1.10      +11 -0     jakarta-hivemind/framework/src/java/org/apache/hivemind/Registry.java
  
  Index: Registry.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/Registry.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Registry.java	19 Feb 2005 02:40:54 -0000	1.9
  +++ Registry.java	31 Mar 2005 16:07:03 -0000	1.10
  @@ -126,6 +126,17 @@
       public void shutdown();
   
       /**
  +     * To be invoked at the start of each request in a multi-threaded environment. Ensures that the
  +     * receiving Registry will be used if any service proxies are de-serialized.
  +     * 
  +     * @since 3.1
  +     * @see org.apache.hivemind.internal.ser.ServiceSerializationHelper
  +     * @see org.apache.hivemind.internal.ser.ServiceSerializationSupport
  +     */
  +
  +    public void setupThread();
  +
  +    /**
        * Convienience for invoking
        * {@link org.apache.hivemind.service.ThreadEventNotifier#fireThreadCleanup()}.
        */
  
  
  

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