tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r750087 - in /tapestry/tapestry5/trunk/tapestry-ioc/src: main/java/org/apache/tapestry5/ioc/internal/services/ test/java/org/apache/tapestry5/ioc/ test/java/org/apache/tapestry5/ioc/internal/services/
Date Wed, 04 Mar 2009 17:33:29 GMT
Author: hlship
Date: Wed Mar  4 17:33:25 2009
New Revision: 750087

URL: http://svn.apache.org/viewvc?rev=750087&view=rev
Log:
TAP5-84: Change proxy generation to use volatile fields rather than synchronized blocks

Modified:
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/JustInTimeObjectCreator.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/JustInTimeObjectCreatorTest.java

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/JustInTimeObjectCreator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/JustInTimeObjectCreator.java?rev=750087&r1=750086&r2=750087&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/JustInTimeObjectCreator.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/JustInTimeObjectCreator.java
Wed Mar  4 17:33:25 2009
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2009 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.
@@ -31,11 +31,9 @@
 {
     private final ServiceActivityTracker tracker;
 
-    private ObjectCreator creator;
+    private volatile ObjectCreator creator;
 
-    private boolean shutdown;
-
-    private Object object;
+    private volatile Object object;
 
     private final String serviceId;
 
@@ -53,30 +51,32 @@
      *
      * @throws IllegalStateException if the registry has been shutdown
      */
-    public synchronized Object createObject()
+    public Object createObject()
     {
-        if (shutdown)
-            throw new IllegalStateException(ServiceMessages.registryShutdown(serviceId));
-
         if (object == null)
+            obtainObjectFromCreator();
+
+        return object;
+    }
+
+    private synchronized void obtainObjectFromCreator()
+    {
+        if (object != null) return;
+
+        try
         {
-            try
-            {
-                object = creator.createObject();
+            object = creator.createObject();
 
-                // And if that's successful ...
+            // And if that's successful ...
 
-                tracker.setStatus(serviceId, Status.REAL);
+            tracker.setStatus(serviceId, Status.REAL);
 
-                creator = null;
-            }
-            catch (RuntimeException ex)
-            {
-                throw new RuntimeException(ServiceMessages.serviceBuildFailure(serviceId,
ex), ex);
-            }
+            creator = null;
+        }
+        catch (RuntimeException ex)
+        {
+            throw new RuntimeException(ServiceMessages.serviceBuildFailure(serviceId, ex),
ex);
         }
-
-        return object;
     }
 
     /**
@@ -92,11 +92,17 @@
     /**
      * Sets the shutdown flag and releases the object and the creator.
      */
-    public synchronized void registryDidShutdown()
+    public void registryDidShutdown()
     {
-        shutdown = true;
+        creator = new ObjectCreator()
+        {
+            public Object createObject()
+            {
+                throw new IllegalStateException(ServiceMessages.registryShutdown(serviceId));
+            }
+        };
+
         object = null;
-        creator = null;
     }
 
 }

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java?rev=750087&r1=750086&r2=750087&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java
Wed Mar  4 17:33:25 2009
@@ -124,10 +124,10 @@
             service.run();
             unreachable();
         }
-        catch (IllegalStateException ex)
+        catch (RuntimeException ex)
         {
-            assertEquals(ex.getMessage(),
-                         "Proxy for service Fred is no longer active because the IOC Registry
has been shut down.");
+            assertMessageContains(ex,
+                                  "Proxy for service Fred is no longer active because the
IOC Registry has been shut down.");
         }
 
         // Show that toString() still works, even for a shutdown proxy.

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/JustInTimeObjectCreatorTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/JustInTimeObjectCreatorTest.java?rev=750087&r1=750086&r2=750087&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/JustInTimeObjectCreatorTest.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/JustInTimeObjectCreatorTest.java
Wed Mar  4 17:33:25 2009
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2009 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.
@@ -40,11 +40,10 @@
             j.createObject();
             unreachable();
         }
-        catch (IllegalStateException ex)
+        catch (RuntimeException ex)
         {
-            assertEquals(
-                    ex.getMessage(),
-                    "Proxy for service FooBar is no longer active because the IOC Registry
has been shut down.");
+            assertMessageContains(ex,
+                                  "Proxy for service FooBar is no longer active because the
IOC Registry has been shut down.");
         }
     }
 



Mime
View raw message