- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Promise/flow cannot work in Typesafe1.1/Akka1.2
Sat, 2011-11-05, 08:40
D:\typesafe-stack>scala -version
Scala code runner version 2.9.1.final -- Copyright 2002-2011, LAMP/EPFL
D:\typesafe-stack>scala -P:continuations:enable
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) Client VM, Java 1.6.0_29)
.
Type in expressions to have them evaluated.
Type :help for more information.
scala> :cp D:\typesafe-stack\lib\akka\akka-actor-1.2.jar
Added 'D:\typesafe-stack\lib\akka\akka-actor-1.2.jar'. Your new classpath is:
".;D:\typesafe-stack\lib\akka\akka-actor-1.2.jar"
scala> import akka.dispatch._
import akka.dispatch._
scala> import Future.flow
import Future.flow
scala> val x, y, z = Promise[Int]()
x: akka.dispatch.CompletableFuture[Int] = akka.dispatch.DefaultCompletableFuture
@2fe032
y: akka.dispatch.CompletableFuture[Int] = akka.dispatch.DefaultCompletableFuture
@1282707
z: akka.dispatch.CompletableFuture[Int] = akka.dispatch.DefaultCompletableFuture
@11a6631
scala>
scala> flow {
| z << x() + y()
| println("z = " + z())
| }
res0: akka.dispatch.Future[Unit] = akka.dispatch.DefaultCompletableFuture@1b8cdd
5
scala> flow { x << 40 }
res1: akka.dispatch.Future[akka.dispatch.Future[Int]] = akka.dispatch.DefaultCom
pletableFuture@10848b9
scala> flow { y << 2 }
res2: akka.dispatch.Future[akka.dispatch.Future[Int]] = akka.dispatch.DefaultCom
pletableFuture@1203875
scala> z.get
akka.dispatch.FutureTimeoutException: Futures timed out after [-26221] milliseco
nds
[JYS-A110601423O_c95e86f0-06b8-11e1-87f5-f0def162c3cf]
at akka.dispatch.DefaultCompletableFuture.awaitThenThrow(Future.scala:81
4)
at akka.dispatch.DefaultCompletableFuture.await(Future.scala:818)
at akka.dispatch.DefaultCompletableFuture.await(Future.scala:788)
at akka.dispatch.Future$class.get(Future.scala:373)
at akka.dispatch.DefaultCompletableFuture.get(Future.scala:788)
at .<init>(<console>:13)
at .<clinit>(<console>)
at .<init>(<console>:11)
at .<clinit>(<console>)
at $print(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:704)
at scala.tools.nsc.interpreter.IMain$Request$$anonfun$14.apply(IMain.sca
la:920)
at scala.tools.nsc.interpreter.Line$$anonfun$1.apply$mcV$sp(Line.scala:4
3)
at scala.tools.nsc.io.package$$anon$2.run(package.scala:25)
at java.lang.Thread.run(Unknown Source)
scala> flow{ println("z = " + z()) }
res4: akka.dispatch.Future[Unit] = akka.dispatch.DefaultCompletableFuture@1ddcd5
f
scala> flow{ x() }
res5: akka.dispatch.Future[Int] = akka.dispatch.DefaultCompletableFuture@134a2a3
scala>
------------------------------------------------------------------------------------------------------------------------
So do not see the z = 42
-----------------------------------------------------------------------------------------------------------------------
import akka.dispatch._import Future.flow
object DataflowDemo extends App {
val x, y, z = Promise[Int]()
flow { z << x() + y() println("z = " + z()) } flow { x << 40 } flow { y << 2 }}
and run above in the Eclipse/Scala-ide(have added all Typesafe stack 1.1 jar in lib directory--surely include the akka-actor-1.2.jar),it shows
[ERROR] [11-11-4 下午1:19] [akka:event-driven:dispatcher:global-1] [Future$] java.lang.NoSuchMethodError: akka.dispatch.Future.apply()Ljava/lang/Object; at DataflowDemo$$anonfun$1.apply$mcV$sp(DataflowDemo.scala:9) at DataflowDemo$$anonfun$1.apply(DataflowDemo.scala:8) at DataflowDemo$$anonfun$1.apply(DataflowDemo.scala:8) at scala.util.continuations.package$.reifyR(package.scala:62) at akka.dispatch.Future$$anonfun$flow$1.apply$mcV$sp(Future.scala:316) at akka.dispatch.Future$$anonfun$dispatchTask$1.apply$mcV$sp(Future.scala:339) at akka.dispatch.TaskInvocation.run(MessageHandling.scala:35) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) at akka.dispatch.MonitorableThread.run(ThreadPoolBuilder.scala:184)
[ERROR] [11-11-4 下午1:19] [akka:event-driven:dispatcher:global-2] [Future$] java.lang.NoSuchMethodError: akka.dispatch.CompletableFuture.$less$less(Ljava/lang/Object;)Lakka/dispatch/Future; at DataflowDemo$$anonfun$2.apply(DataflowDemo.scala:12) at DataflowDemo$$anonfun$2.apply(DataflowDemo.scala:12) at scala.util.continuations.package$.reifyR(package.scala:62) at akka.dispatch.Future$$anonfun$flow$1.apply$mcV$sp(Future.scala:316) at akka.dispatch.Future$$anonfun$dispatchTask$1.apply$mcV$sp(Future.scala:339) at akka.dispatch.TaskInvocation.run(MessageHandling.scala:35) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) at akka.dispatch.MonitorableThread.run(ThreadPoolBuilder.scala:184)
[ERROR] [11-11-4 下午1:19] [akka:event-driven:dispatcher:global-3] [Future$] java.lang.NoSuchMethodError: akka.dispatch.CompletableFuture.$less$less(Ljava/lang/Object;)Lakka/dispatch/Future; at DataflowDemo$$anonfun$3.apply(DataflowDemo.scala:13) at DataflowDemo$$anonfun$3.apply(DataflowDemo.scala:13) at scala.util.continuations.package$.reifyR(package.scala:62) at akka.dispatch.Future$$anonfun$flow$1.apply$mcV$sp(Future.scala:316) at akka.dispatch.Future$$anonfun$dispatchTask$1.apply$mcV$sp(Future.scala:339) at akka.dispatch.TaskInvocation.run(MessageHandling.scala:35) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) at akka.dispatch.MonitorableThread.run(ThreadPoolBuilder.scala:184) --------------------------------------------------------------------------------------------------------------------------------------------------------------------- and directly run with scala -P:continuations:enable -cp .;D:\typesafe-stack\lib\akka\akka-actor-1.2.jar DataflowDemo ,have the error same as above...
regards.--
SolomonHUAWEIGoogle+: Qihui Sun
Scala code runner version 2.9.1.final -- Copyright 2002-2011, LAMP/EPFL
D:\typesafe-stack>scala -P:continuations:enable
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) Client VM, Java 1.6.0_29)
.
Type in expressions to have them evaluated.
Type :help for more information.
scala> :cp D:\typesafe-stack\lib\akka\akka-actor-1.2.jar
Added 'D:\typesafe-stack\lib\akka\akka-actor-1.2.jar'. Your new classpath is:
".;D:\typesafe-stack\lib\akka\akka-actor-1.2.jar"
scala> import akka.dispatch._
import akka.dispatch._
scala> import Future.flow
import Future.flow
scala> val x, y, z = Promise[Int]()
x: akka.dispatch.CompletableFuture[Int] = akka.dispatch.DefaultCompletableFuture
@2fe032
y: akka.dispatch.CompletableFuture[Int] = akka.dispatch.DefaultCompletableFuture
@1282707
z: akka.dispatch.CompletableFuture[Int] = akka.dispatch.DefaultCompletableFuture
@11a6631
scala>
scala> flow {
| z << x() + y()
| println("z = " + z())
| }
res0: akka.dispatch.Future[Unit] = akka.dispatch.DefaultCompletableFuture@1b8cdd
5
scala> flow { x << 40 }
res1: akka.dispatch.Future[akka.dispatch.Future[Int]] = akka.dispatch.DefaultCom
pletableFuture@10848b9
scala> flow { y << 2 }
res2: akka.dispatch.Future[akka.dispatch.Future[Int]] = akka.dispatch.DefaultCom
pletableFuture@1203875
scala> z.get
akka.dispatch.FutureTimeoutException: Futures timed out after [-26221] milliseco
nds
[JYS-A110601423O_c95e86f0-06b8-11e1-87f5-f0def162c3cf]
at akka.dispatch.DefaultCompletableFuture.awaitThenThrow(Future.scala:81
4)
at akka.dispatch.DefaultCompletableFuture.await(Future.scala:818)
at akka.dispatch.DefaultCompletableFuture.await(Future.scala:788)
at akka.dispatch.Future$class.get(Future.scala:373)
at akka.dispatch.DefaultCompletableFuture.get(Future.scala:788)
at .<init>(<console>:13)
at .<clinit>(<console>)
at .<init>(<console>:11)
at .<clinit>(<console>)
at $print(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:704)
at scala.tools.nsc.interpreter.IMain$Request$$anonfun$14.apply(IMain.sca
la:920)
at scala.tools.nsc.interpreter.Line$$anonfun$1.apply$mcV$sp(Line.scala:4
3)
at scala.tools.nsc.io.package$$anon$2.run(package.scala:25)
at java.lang.Thread.run(Unknown Source)
scala> flow{ println("z = " + z()) }
res4: akka.dispatch.Future[Unit] = akka.dispatch.DefaultCompletableFuture@1ddcd5
f
scala> flow{ x() }
res5: akka.dispatch.Future[Int] = akka.dispatch.DefaultCompletableFuture@134a2a3
scala>
------------------------------------------------------------------------------------------------------------------------
So do not see the z = 42
-----------------------------------------------------------------------------------------------------------------------
import akka.dispatch._import Future.flow
object DataflowDemo extends App {
val x, y, z = Promise[Int]()
flow { z << x() + y() println("z = " + z()) } flow { x << 40 } flow { y << 2 }}
and run above in the Eclipse/Scala-ide(have added all Typesafe stack 1.1 jar in lib directory--surely include the akka-actor-1.2.jar),it shows
[ERROR] [11-11-4 下午1:19] [akka:event-driven:dispatcher:global-1] [Future$] java.lang.NoSuchMethodError: akka.dispatch.Future.apply()Ljava/lang/Object; at DataflowDemo$$anonfun$1.apply$mcV$sp(DataflowDemo.scala:9) at DataflowDemo$$anonfun$1.apply(DataflowDemo.scala:8) at DataflowDemo$$anonfun$1.apply(DataflowDemo.scala:8) at scala.util.continuations.package$.reifyR(package.scala:62) at akka.dispatch.Future$$anonfun$flow$1.apply$mcV$sp(Future.scala:316) at akka.dispatch.Future$$anonfun$dispatchTask$1.apply$mcV$sp(Future.scala:339) at akka.dispatch.TaskInvocation.run(MessageHandling.scala:35) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) at akka.dispatch.MonitorableThread.run(ThreadPoolBuilder.scala:184)
[ERROR] [11-11-4 下午1:19] [akka:event-driven:dispatcher:global-2] [Future$] java.lang.NoSuchMethodError: akka.dispatch.CompletableFuture.$less$less(Ljava/lang/Object;)Lakka/dispatch/Future; at DataflowDemo$$anonfun$2.apply(DataflowDemo.scala:12) at DataflowDemo$$anonfun$2.apply(DataflowDemo.scala:12) at scala.util.continuations.package$.reifyR(package.scala:62) at akka.dispatch.Future$$anonfun$flow$1.apply$mcV$sp(Future.scala:316) at akka.dispatch.Future$$anonfun$dispatchTask$1.apply$mcV$sp(Future.scala:339) at akka.dispatch.TaskInvocation.run(MessageHandling.scala:35) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) at akka.dispatch.MonitorableThread.run(ThreadPoolBuilder.scala:184)
[ERROR] [11-11-4 下午1:19] [akka:event-driven:dispatcher:global-3] [Future$] java.lang.NoSuchMethodError: akka.dispatch.CompletableFuture.$less$less(Ljava/lang/Object;)Lakka/dispatch/Future; at DataflowDemo$$anonfun$3.apply(DataflowDemo.scala:13) at DataflowDemo$$anonfun$3.apply(DataflowDemo.scala:13) at scala.util.continuations.package$.reifyR(package.scala:62) at akka.dispatch.Future$$anonfun$flow$1.apply$mcV$sp(Future.scala:316) at akka.dispatch.Future$$anonfun$dispatchTask$1.apply$mcV$sp(Future.scala:339) at akka.dispatch.TaskInvocation.run(MessageHandling.scala:35) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) at akka.dispatch.MonitorableThread.run(ThreadPoolBuilder.scala:184) --------------------------------------------------------------------------------------------------------------------------------------------------------------------- and directly run with scala -P:continuations:enable -cp .;D:\typesafe-stack\lib\akka\akka-actor-1.2.jar DataflowDemo ,have the error same as above...
regards.--
SolomonHUAWEIGoogle+: Qihui Sun