This is an automated email from the ASF dual-hosted git repository.
mrutkowski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git
The following commit(s) were added to refs/heads/master by this push:
new 76edd95 Add the license and notice for ConcurrentMapBackedCache.scala
(#3703)
76edd95 is described below
commit 76edd9544ff1c95c7bf7dd34da02a2ef73afb5c9
Author: Vincent <[email protected]>
AuthorDate: Wed May 30 12:13:12 2018 -0400
Add the license and notice for ConcurrentMapBackedCache.scala (#3703)
The source code file called ConcurrentMapBackedCache.scala uses the source
code of Spray.
Closes: apache/incubator-openwhisk-release#152
---
LICENSE.txt | 12 ++++
.../core/database/ConcurrentMapBackedCache.scala | 78 ++++++++++++++++++++++
.../MultipleReadersSingleWriterCache.scala | 57 +---------------
licenses/LICENSE-spray.txt | 15 +++++
4 files changed, 106 insertions(+), 56 deletions(-)
diff --git a/LICENSE.txt b/LICENSE.txt
index 0040af4..dc2f86c 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 0000000..c3521b5
--- /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 a2f5c46..0155e65 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 0000000..074a5a9
--- /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.
--
To stop receiving notification emails like this one, please contact
[email protected].