Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Akka 2 future example problem
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  14 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Mic  
View profile  
 More options May 6 2012, 5:42 am
From: Mic <micta...@gmail.com>
Date: Sun, 6 May 2012 02:42:12 -0700 (PDT)
Local: Sun, May 6 2012 5:42 am
Subject: Akka 2 future example problem

Hello,
I am not able to compile the AKKA 2 example
http://doc.akka.io/docs/akka/2.0/scala/futures.html#Use_Directly
*
*
*import akka.dispatch.Await*
*import akka.dispatch.Future*
*import akka.util.duration._*
*
*
*
*
*object HelloWorldFuture {*
*  def main(args: Array[String]) {*
*    val future = Future {*
*      "Hello" + "World"*
*    }*
*    val result = Await.result(future, 1 second)*
*  }*
*} *

$ fsc -cp ../jars/akka/lib/akka/akka-actor-2.0.1.jar:.
HelloWorldFuture.scala
HelloWorldFuture.scala:8: error: could not find implicit value for
parameter executor: akka.dispatch.ExecutionContext
    val future = Future {
                        ^
one error found

What did I do wrong?

Thank you in advance.

Mic


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Viktor Klang  
View profile  
 More options May 6 2012, 8:05 am
From: Viktor Klang <viktor.kl...@gmail.com>
Date: Sun, 6 May 2012 14:05:18 +0200
Local: Sun, May 6 2012 8:05 am
Subject: Re: [akka-user] Akka 2 future example problem

Hi Mic,

You didn't read the docs :-)

http://doc.akka.io/docs/akka/2.0.1/scala/futures.html

Cheers,


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mic  
View profile  
 More options May 6 2012, 8:13 am
From: Mic <micta...@gmail.com>
Date: Sun, 6 May 2012 05:13:22 -0700 (PDT)
Local: Sun, May 6 2012 8:13 am
Subject: Re: [akka-user] Akka 2 future example problem

Hi Vic,
I read the docs and the example is from the docs, but unfortunately I did
not understand the docs.

Mic


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
√iktor Ҡlang  
View profile  
 More options May 6 2012, 8:15 am
From: √iktor Ҡlang <viktor.kl...@gmail.com>
Date: Sun, 6 May 2012 14:15:00 +0200
Subject: Re: [akka-user] Akka 2 future example problem

Hi Mic,

If you tell me which part of the following you do not understand, then I'll
try to elaborate:

"Execution Contexts

In order to execute callbacks and operations, Futures need something called
an ExecutionContext, which is very similar to a
java.util.concurrent.Executor. if you have an ActorSystem in scope, it will
use its default dispatcher as the ExecutionContext, or you can use the
factory methods provided by the ExecutionContextcompanion object to wrap
Executors and ExecutorServices, or even create your own.

   1. import akka.dispatch.{ ExecutionContext, Promise }
   2.
   3. implicit val ec =
ExecutionContext.fromExecutorService(yourExecutorServiceGoesHere)
   4.
   5. // Do stuff with your brand new shiny ExecutionContext
   6. val f = Promise.successful("foo")
   7.
   8. // Then shut your ExecutionContext down at some
   9. // appropriate place in your program/application
   10. ec.shutdown()

Cheers,

--
Viktor Klang

Akka Tech Lead
Typesafe <http://www.typesafe.com/> - The software stack for applications
that scale

Twitter: @viktorklang


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mic  
View profile  
 More options May 6 2012, 10:01 am
From: Mic <micta...@gmail.com>
Date: Sun, 6 May 2012 07:01:07 -0700 (PDT)
Local: Sun, May 6 2012 10:01 am
Subject: Re: Akka 2 future example problem

Thank you, the following complete code runs:

*import akka.dispatch.{Await, Future, ExecutionContext} *
*import akka.util.duration._ *
*import java.util.concurrent.Executors *
*
*
*object HelloWorldFuture {*
*  def main(args: Array[String]) {*
*    val pool = Executors.newCachedThreadPool() *
*    implicit val ec = ExecutionContext.fromExecutorService(pool) *
*    val future = Future {*
*      "Hello" + "World"*
*    }*
*    val result = Await.result(future, 1 second)*
*    println(result)*
*    pool.shutdown()*
*  }*
*} *

I have found the Actor doc better, because on the end there was a complete
code.

Mic


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
√iktor Ҡlang  
View profile  
 More options May 6 2012, 10:30 am
From: √iktor Ҡlang <viktor.kl...@gmail.com>
Date: Sun, 6 May 2012 16:30:37 +0200
Local: Sun, May 6 2012 10:30 am
Subject: Re: [akka-user] Re: Akka 2 future example problem

Hi Mic,

You'll want to avoid doing Await, it does do blocking, and blocking is bad.

*    implicit val ec = ExecutionContext.fromExecutorService(**
Executors.newCachedThreadPool()**) *
*    Future { **"Hello" + "World" **} map println andThen { case _ =>
ec.shutdown }*

The code above will run "Hello" + "World" async, then the println async and
then shut your ExecutionContext down when all is done.

Cheers,

--
Viktor Klang

Akka Tech Lead
Typesafe <http://www.typesafe.com/> - The software stack for applications
that scale

Twitter: @viktorklang


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mic  
View profile  
 More options May 6 2012, 7:49 pm
From: Mic <micta...@gmail.com>
Date: Sun, 6 May 2012 16:49:33 -0700 (PDT)
Local: Sun, May 6 2012 7:49 pm
Subject: Re: [akka-user] Re: Akka 2 future example problem

Hi Viktor,
Thank you. How to improve the output from the following code:
import akka.dispatch.{Future, ExecutionContext}
import akka.util.duration._
import java.util.concurrent.Executors

object Communication {
  def main(args: Array[String]) {
  implicit val ec = ExecutionContext.fromExecutorService(
      Executors.newCachedThreadPool());
  // send tasks to the dispather
  val results = Future.traverse(List.range(0,10)){i =>
    Future("%d x %d = %d" format (i, i, i*i))
  } map println andThen { case _ => ec.shutdown }

  }

}

Current OUTPUT:
List(0 x 0 = 0, 1 x 1 = 1, 2 x 2 = 4, 3 x 3 = 9, 4 x 4 = 16, 5 x 5 = 25, 6
x 6 = 36, 7 x 7 = 49, 8 x 8 = 64, 9 x 9 = 81)

Thank you in advance.

Mic


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
√iktor Ҡlang  
View profile  
 More options May 6 2012, 7:53 pm
From: √iktor Ҡlang <viktor.kl...@gmail.com>
Date: Mon, 7 May 2012 01:53:47 +0200
Local: Sun, May 6 2012 7:53 pm
Subject: Re: [akka-user] Re: Akka 2 future example problem

Hi Mic,

On Mon, May 7, 2012 at 1:49 AM, Mic <micta...@gmail.com> wrote:
> Hi Viktor,
> Thank you. How to improve the output from the following code:

How do I improve something without being given a metric?

Cheers,

--
Viktor Klang

Akka Tech Lead
Typesafe <http://www.typesafe.com/> - The software stack for applications
that scale

Twitter: @viktorklang


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mic  
View profile  
 More options May 6 2012, 8:03 pm
From: Mic <micta...@gmail.com>
Date: Sun, 6 May 2012 17:03:33 -0700 (PDT)
Local: Sun, May 6 2012 8:03 pm
Subject: Re: [akka-user] Re: Akka 2 future example problem

Hi Viktor,
I am sorry. I meant to get something like this:
0 x 0 = 0
1 x 1 = 1
2 x 2 = 4
3 x 3 = 9
4 x 4 = 16
5 x 5 = 25
6 x 6 = 36
7 x 7 = 49
8 x 8 = 64
9 x 9 = 81

Cheers,
Mic


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Roland Kuhn  
View profile  
 More options May 7 2012, 2:46 am
From: Roland Kuhn <goo...@rkuhn.info>
Date: Mon, 7 May 2012 08:46:13 +0200
Local: Mon, May 7 2012 2:46 am
Subject: Re: [akka-user] Akka 2 future example problem

Hi Mic,

you might be interested in searching for mkString here: http://www.scala-lang.org/api/current/index.html#scala.collection.Seq

Regards,

Roland

On May 7, 2012, at 02:03 , Mic wrote:

Roland Kuhn
Typesafe – The software stack for applications that scale.
twitter: @rolandkuhn

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mic  
View profile  
 More options May 7 2012, 9:33 am
From: Mic <micta...@gmail.com>
Date: Mon, 7 May 2012 23:33:05 +1000
Local: Mon, May 7 2012 9:33 am
Subject: Re: [akka-user] Akka 2 future example problem

Hi Roland,
I tried it out unsuccessful with the following code:
import akka.dispatch.{Future, ExecutionContext}
import akka.util.duration._
import java.util.concurrent.Executors

object Communication {
  def main(args: Array[String]) {
  implicit val ec = ExecutionContext.fromExecutorService(
      Executors.newCachedThreadPool());
  // send tasks to the dispather
  val results = Future.traverse(List.range(0,10)){i =>
    Future("%d x %d = %d" format (i, i, i*i))
  } map(_.mkString("\n")) println andThen { case _ => ec.shutdown }

  }

}

What did I do wrong?

Thank you in advance.

Mic


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
√iktor Ҡlang  
View profile  
 More options May 7 2012, 9:40 am
From: √iktor Ҡlang <viktor.kl...@gmail.com>
Date: Mon, 7 May 2012 15:40:12 +0200
Local: Mon, May 7 2012 9:40 am
Subject: Re: [akka-user] Akka 2 future example problem

Usually when one reports a problem, they include what the actual problem
was.

Follow the Scala compiler:

<console>:19: error: value println is not a member of
akka.dispatch.Future[String]
           } map(_.mkString("\n")) println andThen { case _ => ec.shutdown }

Cheers,

--
Viktor Klang

Akka Tech Lead
Typesafe <http://www.typesafe.com/> - The software stack for applications
that scale

Twitter: @viktorklang


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mic  
View profile  
 More options May 7 2012, 10:14 pm
From: Mic <micta...@gmail.com>
Date: Tue, 8 May 2012 12:14:32 +1000
Local: Mon, May 7 2012 10:14 pm
Subject: Re: [akka-user] Akka 2 future example problem

Hi Viktor,
I am sorry, but Scala-IDE only print out:
Error: Could not find or load main class Communication

In the future I will provide scalac direct output.

Is the following solution a good solution:

*import akka.dispatch.{Future, ExecutionContext} *
*import akka.util.duration._ *
*import java.util.concurrent.Executors *
*
*
*object Communication {*
*  def main(args: Array[String]) {*
*   implicit val ec = ExecutionContext.fromExecutorService(*
*       Executors.newCachedThreadPool()); *
*   // send tasks to the dispather*
*   val results = Future.traverse(List.range(0,10)){i => *
*     Future("%d x %d = %d" format (i, i, i*i))*
*   } andThen { case _ => ec.shutdown }*
*   *
*   results.foreach{ res =>*
*     println(res.mkString("\n"))*
*   }   *
*  }*
*}*

Output:
0 x 0 = 0
1 x 1 = 1
2 x 2 = 4
3 x 3 = 9
4 x 4 = 16
5 x 5 = 25
6 x 6 = 36
7 x 7 = 49
8 x 8 = 64
9 x 9 = 81

Thank you in advance.

Mic

On Mon, May 7, 2012 at 11:40 PM, √iktor Ҡlang <viktor.kl...@gmail.com>wrote:

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jonas Boner  
View profile  
 More options May 11 2012, 8:24 am
From: Jonas Boner <jo...@jonasboner.com>
Date: Fri, 11 May 2012 14:24:25 +0200
Local: Fri, May 11 2012 8:24 am
Subject: Re: [akka-user] Akka 2 future example problem
Hi Mic.

This is a question for the Scala IDE docs I think. Nothing to do with Akka.

/Jonas

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »