You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2018/05/30 16:13:15 UTC

[GitHub] mrutkows closed pull request #3703: Add the license and notice for ConcurrentMapBackedCache.scala

mrutkows closed pull request #3703: Add the license and notice for ConcurrentMapBackedCache.scala
URL: https://github.com/apache/incubator-openwhisk/pull/3703
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/LICENSE.txt b/LICENSE.txt
index 0040af4a18..dc2f86c7da 100644
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -200,3 +200,15 @@
    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.
+
+
+========================================================================
+Apache License 2.0
+========================================================================
+
+This distribution bundles the following components, which are available under an Apache License 2.0 (https://opensource.org/licenses/Apache-2.0).
+Spray Caching 1.3.4 (io.spray:spray-caching_2.11:1.3.4 - http://spray.io/documentation/1.2.4/spray-caching/)
+  ConcurrentMapBackedCache.scala under common/scala/src/main/scala/whisk/core/database contains implementation
+  from Spray's [[spray.caching.Cache]] and [[spray.caching.SimpleLruCache]] respectively.
+  License included at licenses/LICENSE-spray.txt, or https://github.com/spray/spray/blob/master/LICENSE
+  Copyright (C) 2017 Lightbend Inc. <http://www.lightbend.com/>
diff --git a/common/scala/src/main/scala/whisk/core/database/ConcurrentMapBackedCache.scala b/common/scala/src/main/scala/whisk/core/database/ConcurrentMapBackedCache.scala
new file mode 100644
index 0000000000..c3521b525a
--- /dev/null
+++ b/common/scala/src/main/scala/whisk/core/database/ConcurrentMapBackedCache.scala
@@ -0,0 +1,78 @@
+/*
+ * 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.
+ */
+
+/*
+ * Cache base implementation:
+ * Copyright (C) 2017 Lightbend Inc. <http://www.lightbend.com/>
+ */
+
+package whisk.core.database
+
+import java.util.concurrent.ConcurrentMap
+
+import scala.concurrent.{ExecutionContext, Future}
+import scala.util.control.NonFatal
+
+/**
+ * A thread-safe implementation of [[spray.caching.cache]] backed by a plain
+ * [[java.util.concurrent.ConcurrentMap]].
+ *
+ * The implementation is entirely copied from Spray's [[spray.caching.Cache]] and
+ * [[spray.caching.SimpleLruCache]] respectively, the only difference being the store type.
+ * Implementation otherwise is identical.
+ */
+private class ConcurrentMapBackedCache[V](store: ConcurrentMap[Any, Future[V]]) {
+  val cache = this
+
+  def apply(key: Any) = new Keyed(key)
+
+  class Keyed(key: Any) {
+    def apply(magnet: => ValueMagnet[V])(implicit ec: ExecutionContext): Future[V] =
+      cache.apply(
+        key,
+        () =>
+          try magnet.future
+          catch { case NonFatal(e) => Future.failed(e) })
+  }
+
+  def apply(key: Any, genValue: () => Future[V])(implicit ec: ExecutionContext): Future[V] = {
+    store.computeIfAbsent(
+      key,
+      new java.util.function.Function[Any, Future[V]]() {
+        override def apply(key: Any): Future[V] = {
+          val future = genValue()
+          future.onComplete { value =>
+            // in case of exceptions we remove the cache entry (i.e. try again later)
+            if (value.isFailure) store.remove(key, future)
+          }
+          future
+        }
+      })
+  }
+
+  def remove(key: Any) = Option(store.remove(key))
+
+  def size = store.size
+}
+
+class ValueMagnet[V](val future: Future[V])
+object ValueMagnet {
+  import scala.language.implicitConversions
+
+  implicit def fromAny[V](block: V): ValueMagnet[V] = fromFuture(Future.successful(block))
+  implicit def fromFuture[V](future: Future[V]): ValueMagnet[V] = new ValueMagnet(future)
+}
diff --git a/common/scala/src/main/scala/whisk/core/database/MultipleReadersSingleWriterCache.scala b/common/scala/src/main/scala/whisk/core/database/MultipleReadersSingleWriterCache.scala
index a2f5c46f9b..0155e655f9 100644
--- a/common/scala/src/main/scala/whisk/core/database/MultipleReadersSingleWriterCache.scala
+++ b/common/scala/src/main/scala/whisk/core/database/MultipleReadersSingleWriterCache.scala
@@ -15,21 +15,14 @@
  * limitations under the License.
  */
 
-/*
- * Cache base implementation:
- * Copyright (C) 2017 Lightbend Inc. <http://www.lightbend.com/>
- */
-
 package whisk.core.database
 
-import java.util.concurrent.{ConcurrentMap, TimeUnit}
+import java.util.concurrent.TimeUnit
 import java.util.concurrent.atomic.AtomicReference
 
 import scala.concurrent.{ExecutionContext, Future, Promise}
-import scala.language.implicitConversions
 import scala.util.Failure
 import scala.util.Success
-import scala.util.control.NonFatal
 import com.github.benmanes.caffeine.cache.Caffeine
 import whisk.common.Logging
 import whisk.common.LoggingMarkers
@@ -474,51 +467,3 @@ trait MultipleReadersSingleWriterCache[W, Winfo] {
           .asMap())
   }
 }
-
-/**
- * A thread-safe implementation of [[spray.caching.cache]] backed by a plain
- * [[java.util.concurrent.ConcurrentMap]].
- *
- * The implementation is entirely copied from Spray's [[spray.caching.Cache]] and
- * [[spray.caching.SimpleLruCache]] respectively, the only difference being the store type.
- * Implementation otherwise is identical.
- */
-private class ConcurrentMapBackedCache[V](store: ConcurrentMap[Any, Future[V]]) {
-  val cache = this
-
-  def apply(key: Any) = new Keyed(key)
-
-  class Keyed(key: Any) {
-    def apply(magnet: => ValueMagnet[V])(implicit ec: ExecutionContext): Future[V] =
-      cache.apply(
-        key,
-        () =>
-          try magnet.future
-          catch { case NonFatal(e) => Future.failed(e) })
-  }
-
-  def apply(key: Any, genValue: () => Future[V])(implicit ec: ExecutionContext): Future[V] = {
-    store.computeIfAbsent(
-      key,
-      new java.util.function.Function[Any, Future[V]]() {
-        override def apply(key: Any): Future[V] = {
-          val future = genValue()
-          future.onComplete { value =>
-            // in case of exceptions we remove the cache entry (i.e. try again later)
-            if (value.isFailure) store.remove(key, future)
-          }
-          future
-        }
-      })
-  }
-
-  def remove(key: Any) = Option(store.remove(key))
-
-  def size = store.size
-}
-
-class ValueMagnet[V](val future: Future[V])
-object ValueMagnet {
-  implicit def fromAny[V](block: V): ValueMagnet[V] = fromFuture(Future.successful(block))
-  implicit def fromFuture[V](future: Future[V]): ValueMagnet[V] = new ValueMagnet(future)
-}
diff --git a/licenses/LICENSE-spray.txt b/licenses/LICENSE-spray.txt
new file mode 100644
index 0000000000..074a5a9105
--- /dev/null
+++ b/licenses/LICENSE-spray.txt
@@ -0,0 +1,15 @@
+This software is licensed under the Apache 2 license, quoted below.
+
+Copyright © 2011-2015 the spray project <http://spray.io>
+
+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.


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services