You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@onami.apache.org by ra...@apache.org on 2013/03/02 16:35:03 UTC

svn commit: r1451896 - in /incubator/onami/trunk/scopes/src/main/java/org/apache/onami/scopes: ConcurrentLazySingletonScope.java.orig ConcurrentLazySingletonScopeImpl.java

Author: randgalt
Date: Sat Mar  2 15:35:03 2013
New Revision: 1451896

URL: http://svn.apache.org/r1451896
Log:
ONAMI-93 - locks field doesn't need to be static

Added:
    incubator/onami/trunk/scopes/src/main/java/org/apache/onami/scopes/ConcurrentLazySingletonScope.java.orig
Modified:
    incubator/onami/trunk/scopes/src/main/java/org/apache/onami/scopes/ConcurrentLazySingletonScopeImpl.java

Added: incubator/onami/trunk/scopes/src/main/java/org/apache/onami/scopes/ConcurrentLazySingletonScope.java.orig
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/scopes/src/main/java/org/apache/onami/scopes/ConcurrentLazySingletonScope.java.orig?rev=1451896&view=auto
==============================================================================
--- incubator/onami/trunk/scopes/src/main/java/org/apache/onami/scopes/ConcurrentLazySingletonScope.java.orig (added)
+++ incubator/onami/trunk/scopes/src/main/java/org/apache/onami/scopes/ConcurrentLazySingletonScope.java.orig Sat Mar  2 15:35:03 2013
@@ -0,0 +1,50 @@
+package org.apache.onami.scopes;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import com.google.inject.Scope;
+
+/**
+ * A singleton factory that returns a Guice {@link Scope} that enables concurrent lazy singletons.
+ *
+ * @see ConcurrentLazySingleton
+ */
+public class ConcurrentLazySingletonScope
+{
+
+    private static final Scope instance = new ConcurrentLazySingletonScopeImpl();
+
+    /**
+     * Returns the scope
+     *
+     * @return scope
+     */
+    public static Scope get()
+    {
+        return instance;
+    }
+
+<<<<<<< HEAD
+=======
+    private ConcurrentLazySingletonScope()
+    {
+    }
+>>>>>>> ONAMI-92 - add private final constructor
+}

Modified: incubator/onami/trunk/scopes/src/main/java/org/apache/onami/scopes/ConcurrentLazySingletonScopeImpl.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/scopes/src/main/java/org/apache/onami/scopes/ConcurrentLazySingletonScopeImpl.java?rev=1451896&r1=1451895&r2=1451896&view=diff
==============================================================================
--- incubator/onami/trunk/scopes/src/main/java/org/apache/onami/scopes/ConcurrentLazySingletonScopeImpl.java (original)
+++ incubator/onami/trunk/scopes/src/main/java/org/apache/onami/scopes/ConcurrentLazySingletonScopeImpl.java Sat Mar  2 15:35:03 2013
@@ -34,14 +34,7 @@ class ConcurrentLazySingletonScopeImpl
 
     private static final Object NULL = new Object();
 
-    private static final Map<Key<?>, LockRecord> locks = new HashMap<Key<?>, LockRecord>();
-
-    private static class LockRecord
-    {
-        private final Object lock = new Object();
-
-        private int useCount = 0;
-    }
+    private final Map<Key<?>, LockRecord> locks = new HashMap<Key<?>, LockRecord>();
 
     public <T> Provider<T> scope( final Key<T> key, final Provider<T> creator )
     {
@@ -54,7 +47,7 @@ class ConcurrentLazySingletonScopeImpl
             private volatile Object instance;
 
             // DCL on a volatile is safe as of Java 5, which we obviously require.
-            @SuppressWarnings("DoubleCheckedLocking")
+            @SuppressWarnings( "DoubleCheckedLocking" )
             public T get()
             {
                 if ( instance == null )
@@ -93,8 +86,13 @@ class ConcurrentLazySingletonScopeImpl
 
                 Object localInstance = instance;
                 // This is safe because instance has type T or is equal to NULL
+<<<<<<< HEAD
                 @SuppressWarnings({ "unchecked", "UnnecessaryLocalVariable" })
                 T returnedInstance = ( localInstance != NULL ) ? (T) localInstance : null;
+=======
+                @SuppressWarnings( { "unchecked", "UnnecessaryLocalVariable" } ) T returnedInstance =
+                    ( localInstance != NULL ) ? (T) localInstance : null;
+>>>>>>> ONAMI-93 - locks field doesn't need to be static
                 return returnedInstance;
             }
 
@@ -105,7 +103,7 @@ class ConcurrentLazySingletonScopeImpl
         };
     }
 
-    @SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
+    @SuppressWarnings( "SynchronizationOnLocalVariableOrMethodParameter" )
     private Object getLock( Key<?> key )
     {
         synchronized ( locks )
@@ -142,4 +140,13 @@ class ConcurrentLazySingletonScopeImpl
         return "ConcurrentLazySingletonScope.SCOPE";
     }
 
+<<<<<<< HEAD
+=======
+    private static class LockRecord
+    {
+        private final Object lock = new Object();
+
+        private int useCount = 0;
+    }
+>>>>>>> ONAMI-93 - locks field doesn't need to be static
 }