activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r1210715 - in /activemq/activemq-apollo/trunk: apollo-util/src/main/scala/org/apache/activemq/apollo/util.scala apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/Support.scala
Date Mon, 05 Dec 2011 23:52:52 GMT
Author: chirino
Date: Mon Dec  5 23:52:52 2011
New Revision: 1210715

URL: http://svn.apache.org/viewvc?rev=1210715&view=rev
Log:
Fixes APLO-98 Move FutureResult type and associated helpers from utility class in apollo-web
to apollo-utils package object

Patch provided by Stan Lewis. Thanks!

Added:
    activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util.scala
Modified:
    activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/Support.scala

Added: activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util.scala?rev=1210715&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util.scala
(added)
+++ activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util.scala
Mon Dec  5 23:52:52 2011
@@ -0,0 +1,73 @@
+/**
+ * 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.
+ */
+package org.apache.activemq.apollo
+
+import org.fusesource.hawtdispatch._
+import org.fusesource.hawtdispatch.Future
+
+/**
+ *
+ */
+package object util {
+
+  type FutureResult[T] = Future[Result[T, Throwable]]
+
+  def FutureResult[T]() = Future[Result[T, Throwable]]()
+
+  def FutureResult[T](value:Result[T, Throwable]) = {
+    val rc = Future[Result[T, Throwable]]()
+    rc.set(value)
+    rc
+  }
+
+  def sync[T](dispached:Dispatched)(func: =>FutureResult[T]):FutureResult[T] = {
+    val rc = Future[Result[T, Throwable]]()
+    dispached.dispatch_queue.apply {
+      try {
+        func.onComplete(x=> rc.apply(x))
+      } catch {
+        case e:Throwable => rc.apply(Failure(e))
+      }
+    }
+    rc
+  }
+
+  def sync_all[T,D<:Dispatched](values:Iterable[D])(func: (D)=>FutureResult[T]) = {
+    Future.all {
+      values.map { value=>
+        sync(value) {
+          func(value)
+        }
+      }
+    }
+  }
+
+  implicit def wrap_future_result[T](value:T):FutureResult[T] = {
+    val rc = FutureResult[T]()
+    rc.apply(Success(value))
+    rc
+  }
+
+  implicit def unwrap_future_result[T](value:FutureResult[T]):T = {
+    value.await() match {
+      case Success(value) => value
+      case Failure(value) => throw value
+    }
+  }
+
+
+}
\ No newline at end of file

Modified: activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/Support.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/Support.scala?rev=1210715&r1=1210714&r2=1210715&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/Support.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/Support.scala
Mon Dec  5 23:52:52 2011
@@ -224,56 +224,10 @@ abstract class Resource(parent:Resource=
     throw new WebApplicationException(response.build())
   }
 
-  type FutureResult[T] = Future[Result[T, Throwable]]
-
-  protected def FutureResult[T]() = Future[Result[T, Throwable]]()
-
-  protected def FutureResult[T](value:Result[T, Throwable]) = {
-    val rc = Future[Result[T, Throwable]]()
-    rc.set(value)
-    rc
-  }
-
-  protected def sync[T](dispached:Dispatched)(func: =>FutureResult[T]):FutureResult[T]
= {
-    val rc = Future[Result[T, Throwable]]()
-    dispached.dispatch_queue.apply {
-      try {
-        func.onComplete(x=> rc.apply(x))
-      } catch {
-        case e:Throwable => rc.apply(Failure(e))
-      }
-    }
-    rc
-  }
-
-
-  protected def sync_all[T,D<:Dispatched](values:Iterable[D])(func: (D)=>FutureResult[T])
= {
-    Future.all {
-      values.map { value=>
-        sync(value) {
-          func(value)
-        }
-      }
-    }
-  }
-
   protected implicit def to_local_router(host:VirtualHost):LocalRouter = {
     host.router.asInstanceOf[LocalRouter]
   }
 
-  protected implicit def wrap_future_result[T](value:T):FutureResult[T] = {
-    val rc = FutureResult[T]()
-    rc.apply(Success(value))
-    rc
-  }
-
-  protected implicit def unwrap_future_result[T](value:FutureResult[T]):T = {
-    value.await() match {
-      case Success(value) => value
-      case Failure(value) => throw value
-    }
-  }
-
   def now = BrokerRegistry.list.headOption.map(_.now).getOrElse(System.currentTimeMillis())
 
   protected def with_broker[T](func: (org.apache.activemq.apollo.broker.Broker)=>FutureResult[T]):FutureResult[T]
= {



Mime
View raw message