Please, would someone help me out and try running this Scala script...

30 views
Skip to first unread message

Ben Hutchison

unread,
Apr 21, 2012, 12:01:06 AM4/21/12
to scala...@googlegroups.com
I've been trying to resolve a problematic Akka example the last few
days and I'm now completely baffled. It doesn't work for me, on both
linux and Windows, but Viktor Klang from Akka cannot replicate my
issue.

Would someone who has SBT installed help me out by running the
following instruction and reporting back what you see happen. Would be
good to get another opinion/data-point. Should take less than 5 mins:

mkdir akkatest
cd akkatest

<copy the following into build.sbt>
name := "DataflowConcurrencyExample"

version := "1.0"

scalaVersion := "2.9.2"

autoCompilerPlugins := true

resolvers += "Typesafe Repository" at
"http://repo.typesafe.com/typesafe/releases/"

libraryDependencies += "com.typesafe.akka" % "akka-actor" % "2.0.1"
<end of build.sbt>

sbt
> console
scala> :paste

<paste the following into the terminal, then press ctl-D>
import akka.dispatch._
import Future.flow

object DataflowHelloWorld extends App {
implicit val dispatcher = akka.actor.ActorSystem().dispatcher
val x, y, z = Promise[Int]()

flow {
println("before z << x() + y()")
z << x() + y()
println("z = " + z())
}
flow {
println("before x << 40")
x << 40
println("x << 40")
}
flow {
println("before y << 2")
y << 2
println("y << 2")
}
}
<end of file>

scala> DataflowHelloWorld.main(Array())

<what do you see? does the program hang or terminate? please report back...>

See also: https://groups.google.com/forum/#!topic/akka-user/wHZBWRA5DOE

thanks
-Ben

Tony Morris

unread,
Apr 21, 2012, 12:32:04 AM4/21/12
to scala...@googlegroups.com
Hello Ben,
I see the following.

scala> DataflowHelloWorld.main(Array())


before z << x() + y()

before x << 40
before y << 2


--
Tony Morris
http://tmorris.net/


King Lung Chiu

unread,
Apr 21, 2012, 1:02:25 AM4/21/12
to scala...@googlegroups.com
Hi Ben,

My full screen dump is below. Similar result to Tony except the outputs are in different orders.

cheers,

King

-- start screen dump
F:\source-code\scalaTests\akkatest>dir
Volume in drive F is ST500GB_L1
Volume Serial Number is 456F-34AD

Directory of F:\source-code\scalaTests\akkatest

21/04/2012  02:50 PM    <DIR>          .
21/04/2012  02:50 PM    <DIR>          ..
21/04/2012  02:37 PM               272 build.sbt
21/04/2012  02:46 PM    <DIR>          target
              1 File(s)            272 bytes
              3 Dir(s)   7,090,388,992 bytes free

F:\source-code\scalaTests\akkatest>type build.sbt

name := "DataflowConcurrencyExample"

version := "1.0"

scalaVersion := "2.9.2"

autoCompilerPlugins := true

resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"

libraryDependencies += "com.typesafe.akka" % "akka-actor" % "2.0.1"
F:\source-code\scalaTests\akkatest>sbt

F:\source-code\scalaTests\akkatest>set SCRIPT_DIR=f:\zz_progs\bin\

F:\source-code\scalaTests\akkatest>java -Xmx512M -jar "f:\zz_progs\bin\sbt-launch.jar"
[info] Set current project to DataflowConcurrencyExample (in build file:/F:/source-code/scalaTests/akkatest/)
> console
Getting Scala 2.9.2 ...
downloading http://repo1.maven.org/maven2/org/scala-lang/scala-compiler/2.9.2/scala-compiler-2.9.2.jar ...
       [SUCCESSFUL ] org.scala-lang#scala-compiler;2.9.2!scala-compiler.jar (54008ms)
downloading http://repo1.maven.org/maven2/org/scala-lang/scala-library/2.9.2/scala-library-2.9.2.jar ...
       [SUCCESSFUL ] org.scala-lang#scala-library;2.9.2!scala-library.jar (44850ms)
downloading http://repo1.maven.org/maven2/org/scala-lang/jline/2.9.2/jline-2.9.2.jar ...
       [SUCCESSFUL ] org.scala-lang#jline;2.9.2!jline.jar (2200ms)
:: retrieving :: org.scala-tools.sbt#boot-scala
       confs: [default]
       4 artifacts copied, 0 already retrieved (20090kB/156ms)
[info] Updating {file:/F:/source-code/scalaTests/akkatest/}default-6e86e0...
[info] Resolving org.scala-lang#scala-library;2.9.2 ...
[info] Resolving com.typesafe.akka#akka-actor;2.0.1 ...
[info] downloading http://repo.typesafe.com/typesafe/releases/com/typesafe/akka/akka-actor/2.0.1/akka-actor-2.0.1.j
ar ...
[info]  [SUCCESSFUL ] com.typesafe.akka#akka-actor;2.0.1!akka-actor.jar (12729ms)
[info] Done updating.
[info] 'compiler-interface' not yet compiled for Scala 2.9.2. Compiling...
[info]   Compilation completed in 16.929 s
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.9.2 (Java HotSpot(TM) Client VM, Java 1.7.0_02).
Type in expressions to have them evaluated.
Type :help for more information.

scala> :paste
// Entering paste mode (ctrl-D to finish)


import akka.dispatch._
import Future.flow

object DataflowHelloWorld extends App {
implicit val dispatcher = akka.actor.ActorSystem().dispatcher
val x, y, z = Promise[Int]()

flow {
  println("before z << x() + y()")
  z << x() + y()
  println("z = " + z())
}
flow {
  println("before x << 40")
  x << 40
  println("x << 40")
}
flow {
  println("before y << 2")
  y << 2
  println("y << 2")
}
}

// Exiting paste mode, now interpreting.

import akka.dispatch._
import Future.flow
defined module DataflowHelloWorld

scala> DataflowHelloWorld.main(Array())

before x << 40
before y << 2
before z << x() + y()

scala>
-- end screen dump



> --
> You received this message because you are subscribed to the Google Groups "Melbourne Scala User Group" group.
> To post to this group, send an email to scala...@googlegroups.com.
> To unsubscribe from this group, send email to scala-melb+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/scala-melb?hl=en-GB.
>

King Lung Chiu

unread,
Apr 21, 2012, 1:08:49 AM4/21/12
to scala...@googlegroups.com
And a heads up that my scala console seems to have hanged: :q doesn't quit it after running the example.

Background threads still running?

Other info of my setup:

C:\>java -version
java version "1.7.0_02"
Java(TM) SE Runtime Environment (build 1.7.0_02-b13)
Java HotSpot(TM) Client VM (build 22.0-b10, mixed mode, sharing)

C:\>mvn -version
Apache Maven 3.0.3 (r1075438; 2011-03-01 04:31:09+1100)
Maven home: F:\zz_progs\apache-maven-3.0.3\bin\..
Java version: 1.7.0_02, vendor: Oracle Corporation
Java home: C:\Program Files (x86)\Java\jre7
Default locale: en_US, platform encoding: MS950
OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"

And I'm using the latest sbt launcher (just downloaded 20 minutes ago).

cheers,

King

Tony Morris

unread,
Apr 21, 2012, 1:11:31 AM4/21/12
to scala...@googlegroups.com
Ah yes, my scala console refused to quit as well.

Kristian Domagala

unread,
Apr 21, 2012, 1:28:09 AM4/21/12
to scala...@googlegroups.com
Mac OSX 10.7.3
java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b04-415-11M3635)
Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01-415, mixed mode)

scala> DataflowHelloWorld.main(Array())

before z << x() + y()
before x << 40
before y << 2

The hanging console may be caused by the actor system not being shutdown gracefully. In Akka 1.3, akka.actor.Actors.registry.shutdownAll would usually fix that, but I'm not sure what the equivalent is in Akka 2.

Cheers,
Kristian.

Ben Hutchison

unread,
Apr 21, 2012, 5:34:20 AM4/21/12
to scala...@googlegroups.com
Thanks Tony, King, Kristian - really helpful!

Ben Hutchison

unread,
Apr 21, 2012, 8:37:36 AM4/21/12
to scala...@googlegroups.com
FYI: Viktor helped me to resolve the issue with this script. It wasn't
running correctly because all of us, I guess, did not have the
Continuations plugin enabled in our compilers. Once I did so, the flow
completed and all the println statements fire. :)

Yay for 2.10 having continuations enabled by default so these kind of
problems don't happen any more.

What's a bit surprising to me is that the compiler plugin is needed to
compile the application code. I'd thought that it was only needed when
you compile the code with the @suspendable tag and continuations
instructions themselves. And since it was needed, why were there no
error or warnings during compile, just wrong execution logic?

-Ben

Ken Scambler

unread,
Apr 21, 2012, 9:39:29 AM4/21/12
to scala...@googlegroups.com

I think I remember someone requesting a "@requireCompilerPlugin" annotation on the list for this same reason, but I'm not sure what became of it.

On Apr 21, 2012 10:37 PM, "Ben Hutchison" <brhut...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages