Manar,

I would say that isn’t the regular use case for routers.

Built into the actor system there is an event bus which might be a better fit.

Actors can register to the event bus that they are interested in events of a 
specific type. This way you can publish the TimeUnit message from one place 
without knowing what actors should receive it, the actors themselves will be 
responsible to subscribe when they start up.

You can read more about the event bus in the docs here:
http://doc.akka.io/docs/akka/2.4.1/scala/event-bus.html

--
Johan Andrén
Typesafe -  Reactive apps on the JVM
Twitter: @apnylle

> 18 jan. 2016 kl. 10:03 skrev Manar Elkady <[email protected]>:
> 
> Johan,
> 
> Please forgive me for not illustrative question because I am a newcomer to 
> akka. I will illustrate to you what I mean.
> 
> I have three different actors types (actor1, actor2, actor3) in my 
> application and each one of them has different state and behaviors while 
> communicating with each other. Initially, I created set of instances from 
> each actor type. To synchronize the actions taken by them during the 
> application running I want broadcast a Time_Unit message to all instances of 
> these actors  by a controller actor. 
> 
> I decided to use routers because I don't have other options to broadcast 
> messages. Is there any other way to do that?
> 
> Manar,
>   
> 
> On Monday, January 18, 2016 at 10:10:13 AM UTC+2, Johan Andrén wrote:
> Not sure what you mean with "all actors in a system context", but if it is
> the broadcast to all routees of a router that you initially wanted to do, 
> then you can still do that, just that you need to use .route instead of !
> to send your message wrapped with akka.routing.Broadcast.
> 
> --
> Johan Andrén
> Typesafe -  Reactive apps on the JVM
> Twitter: @apnylle
> 
> On Monday, January 18, 2016 at 9:01:34 AM UTC+1, Manar Elkady wrote:
> Thanks, Johan,  for illustration, but do you mean that there is no way to 
> broadcast messages to all actors in a system context?
> 
> Manar
> 
> 
> On Sunday, January 17, 2016 at 4:40:52 PM UTC+2, Johan Andrén wrote:
> Hi Manar,
> 
> To send messages using a Router you would use the .route(message, sender) 
> method
> and not ! (this is because the router isn't an actor)
> 
> For more details about how routers work, look in the docs here:
> http://doc.akka.io/docs/akka/2.4.1/scala/routing.html 
> <http://doc.akka.io/docs/akka/2.4.1/scala/routing.html>
> 
> --
> Johan Andrén
> Typesafe -  Reactive apps on the JVM
> Twitter: @apnylle
> 
> On Saturday, January 16, 2016 at 12:05:01 PM UTC+1, Manar Elkady wrote:
> 
> Hi,
> 
> In my application, I'd like to broadcast a time unit every 2 sec to all 
> actors instances of Worker. The time unit is sent by the master to all the 
> worker
> I am trying to send a broadcast message to set of workers by the master 
> actor, but it doesn't work with me. I attach my test code here. There is a 
> compile error in the line 
>              router ! Broadcast("any message") 
> "Error: value is not a member of akka.routing.Router" Could anyone tell me 
> what is the problem here.
>  
> 
> import akka.actor._
> import akka.routing.{ ActorRefRoutee, RoundRobinRoutingLogic, Router }
> import akka.routing.Broadcast
> import akka.routing.Router
> import akka.routing.RouterActor
> 
> object Messages{
>  object Work
>  object Terminated
> }
> 
> object MainRouterDriver extends App {
>   import Messages._
>   // an actor needs an ActorSystem
> val system = ActorSystem("HelloSystem")
> // create and start the actor
> val routingMaster = system.actorOf(Props[Master], name = "helloactor")
> // send the actor two messages
> routingMaster ! Work
>   
> }
> 
> class Worker extends Actor{
>   def receive = {
>     case _ =>
>         println("Hi I am a Worker")
>   }
>   
>   
> }
> class Master extends Actor {
>   var router = {
>   val routees = Vector.fill(5) {
>       val r = context.actorOf(Props[Worker])
>       context watch r
>       ActorRefRoutee(r)
>     }
>   akka.routing.Router(RoundRobinRoutingLogic(), routees)
>   }
> def receive = {
>     case Work =>
>              router ! Broadcast("any message") 
>     
>   }
> 
> }
> 
> 
> 
> 
> 
> 
> 
> 
> -- 
> >>>>>>>>>> Read the docs: http://akka.io/docs/ <http://akka.io/docs/>
> >>>>>>>>>> Check the FAQ: 
> >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html 
> >>>>>>>>>> <http://doc.akka.io/docs/akka/current/additional/faq.html>
> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user 
> >>>>>>>>>> <https://groups.google.com/group/akka-user>
> --- 
> You received this message because you are subscribed to a topic in the Google 
> Groups "Akka User List" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/akka-user/y0hVf6fq58M/unsubscribe 
> <https://groups.google.com/d/topic/akka-user/y0hVf6fq58M/unsubscribe>.
> To unsubscribe from this group and all its topics, send an email to 
> [email protected] 
> <mailto:[email protected]>.
> To post to this group, send email to [email protected] 
> <mailto:[email protected]>.
> Visit this group at https://groups.google.com/group/akka-user 
> <https://groups.google.com/group/akka-user>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to