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
Custom router and dead routees
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
  3 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
 
Banduk  
View profile  
 More options May 10 2012, 11:45 am
From: Banduk <ban...@gmail.com>
Date: Thu, 10 May 2012 08:45:37 -0700 (PDT)
Local: Thurs, May 10 2012 11:45 am
Subject: Custom router and dead routees

Hi guys,

I have some questions about the following custom router. I still a little
bit new on
scala and akka so maybe you'd do that in a completly different way.
Please let me know if it's the case!!!

So, I'm receiving messages of the type T and I want to route them by the
given field (of the type Node) to actors/routers (defined by p:Props)

here's the codehere's the code <http://pastebin.com/xgmSMKFq>

My questions/problems are:
  1. How to implement the commented (line 17) in a better/cleanner/safest
way? If I don't do it, I'll have only one router for all the actors (that's
not what I want).
  2. I don't know if it's related to the first question, but it's working
"fine" to the first messages, but after some time I receive the following
message:
      [05/10/2012 16:46:33.848]
[testsystem-akka.actor.default-dispatcher-3]
[akka://testsystem/user/route/purl_nsAutomobile] received dead letter from
Actor[akka://testsystem/deadLetters]:
tests.TEST_Routing$$anonfun$1$$anonfun$apply$mcV$sp$1$$anon$1@69ea25aa

ps. I already tried Camel, but I'd prefer to do that by my way so I can
have some more freedom and learn more scala/akka!

Thank you,
Banduk


 
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.
Björn Antonsson  
View profile  
 More options May 11 2012, 12:43 pm
From: Björn Antonsson <bjorn.antons...@typesafe.com>
Date: Fri, 11 May 2012 18:43:24 +0200
Local: Fri, May 11 2012 12:43 pm
Subject: Re: [akka-user] Custom router and dead routees

Hi Banduk,  

Your code in line 17 is just a

p.routerConfig match { case r: SimpleRouter[_] ⇒ whatever }

I'm not exactly sure what your code is supposed to do since the parameterized types (T in your code) are erased by the JVM and will match everything. You need a manifest to reify them, but that is a discussion for the scala-user mailing list.

>   2. I don't know if it's related to the first question, but it's working "fine" to the first messages, but after some time I receive the following message:
>       [05/10/2012 16:46:33.848] [testsystem-akka.actor.default-dispatcher-3] [akka://testsystem/user/route/purl_nsAutomobile] received dead letter from Actor[akka://testsystem/deadLetters]: tests.TEST_Routing$$anonfun$1$$anonfun$apply$mcV$sp$1$$anon$1@69ea25aa

I'm not sure exactly what happens with the error, but a comment about Routers. The API documentation http://doc.akka.io/api/akka/2.0/#akka.routing.RouterConfig states that the route function can (and will) be called concurrently by multiple threads at the same time, and your code is using unprotected mutable maps, that will definitely miss updates.

I've added this caution to the main docs.

The easiest way out of this would be to turn your router into an actor with the same functionality, that just forwards messages to the child actors. The receive method in an actor is guaranteed to be single threaded.

B/

> ps. I already tried Camel, but I'd prefer to do that by my way so I can have some more freedom and learn more scala/akka!

> Thank you,
> Banduk

> --  
> You received this message because you are subscribed to the Google Groups "Akka User List" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/akka-user/-/eoHmiNJ10kEJ.
> To post to this group, send email to akka-user@googlegroups.com (mailto:akka-user@googlegroups.com).
> To unsubscribe from this group, send email to akka-user+unsubscribe@googlegroups.com (mailto:akka-user+unsubscribe@googlegroups.com).
> For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.

--  
Björn Antonsson
Typesafe (http://www.typesafe.com) - The software stack for applications that scale

 
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.
Banduk  
View profile  
 More options May 14 2012, 9:52 am
From: Banduk <ban...@gmail.com>
Date: Mon, 14 May 2012 06:52:54 -0700 (PDT)
Local: Mon, May 14 2012 9:52 am
Subject: Re: [akka-user] Custom router and dead routees

Hi Björn,

Sorry about the delay on answering, I did not have access to my files until
today.
Thank you for the explanation and for the hints, I think I got to what I
want using an actor as you proposed.

PS:
I noticed that I set the code at pastebin to be available only for 30 days,
so here's the code If someone need it later.

class SimpleRouter[T](val filter: T => Node, val p: Props) extends
RouterConfig {
  def routerDispatcher: String = Dispatchers.DefaultDispatcherId
  def supervisorStrategy: SupervisorStrategy =
SupervisorStrategy.defaultStrategy
  override val resizer = Some(DefaultResizer(lowerBound = 0))

  val routees = collection.mutable.Map[Node, ActorRef]()

  def createRoute(props: Props, routeeProvider: RouteeProvider) = {
    {
      case (sender, message) =>
        message match {
          case msg: T =>
            val fieldVal = filter.apply(msg)
            val actor    = routees.get(fieldVal)

            List(Destination(sender, routees.get(fieldVal).getOrElse({
              // How to better implement this?
              val prop = if (p.routerConfig.isInstanceOf[SimpleRouter[T]]) {
                val rout = p.routerConfig.asInstanceOf[SimpleRouter[T]]
                p.withRouter(new SimpleRouter(rout.filter, rout.p))
              } else p

              val routee = routeeProvider.context.actorOf(p2,
(fieldVal.encoded))
              routeeProvider.registerRoutees(IndexedSeq(routee))
              routees += (fieldVal -> routee)

              routee
            })))
          case _ => {
            println("UNHANDLED MESSAGE: " + message)
            null
          }
        }
    }
  }


 
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 »