{"action":"created","issue":{"url":"https://api.github.com/repos/puniverse/comsat/issues/35","labels_url":"https://api.github.com/repos/puniverse/comsat/issues/35/labels{/name}","comments_url":"https://api.github.com/repos/puniverse/comsat/issues/35/comments","events_url":"https://api.github.com/repos/puniverse/comsat/issues/35/events","html_url":"https://github.com/puniverse/comsat/issues/35","id":97656836,"number":35,"title":"WebActor delegate to one or more actors and wait for response","user":{"login":"drkarl","id":756584,"avatar_url":"https://avatars.githubusercontent.com/u/756584?v=3","gravatar_id":"","url":"https://api.github.com/users/drkarl","html_url":"https://github.com/drkarl","followers_url":"https://api.github.com/users/drkarl/followers","following_url":"https://api.github.com/users/drkarl/following{/other_user}","gists_url":"https://api.github.com/users/drkarl/gists{/gist_id}","starred_url":"https://api.github.com/users/drkarl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/drkarl/subscriptions","organizations_url":"https://api.github.com/users/drkarl/orgs","repos_url":"https://api.github.com/users/drkarl/repos","events_url":"https://api.github.com/users/drkarl/events{/privacy}","received_events_url":"https://api.github.com/users/drkarl/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/puniverse/comsat/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":{"login":"circlespainter","id":6113296,"avatar_url":"https://avatars.githubusercontent.com/u/6113296?v=3","gravatar_id":"","url":"https://api.github.com/users/circlespainter","html_url":"https://github.com/circlespainter","followers_url":"https://api.github.com/users/circlespainter/followers","following_url":"https://api.github.com/users/circlespainter/following{/other_user}","gists_url":"https://api.github.com/users/circlespainter/gists{/gist_id}","starred_url":"https://api.github.com/users/circlespainter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/circlespainter/subscriptions","organizations_url":"https://api.github.com/users/circlespainter/orgs","repos_url":"https://api.github.com/users/circlespainter/repos","events_url":"https://api.github.com/users/circlespainter/events{/privacy}","received_events_url":"https://api.github.com/users/circlespainter/received_events","type":"User","site_admin":false},"milestone":null,"comments":1,"created_at":"2015-07-28T09:31:42Z","updated_at":"2015-07-28T12:26:39Z","closed_at":null,"body":"I have done a PoC for a project I'm considering using comsat. I have tried to use the Actors system, but there's not enough examples or documentation so I find myself trying to figure things up looking at existing classes, the comsat and quasar code and the examples.\r\n\r\nSorry but I'm new to the Actors model paradigm (I knew about actors before, since I've programmed in Scala and I've read about Akka actors a while ago but I haven't really used them. I know they're inspired by Erlang Actors).\r\n\r\nAlso I've read most of your blog posts in blog.paralleluniverse.co\r\n\r\nThis is the issue:\r\n\r\nI have a WebActor, it receives HttpRequest messages fine and in the examples it uses this pattern\r\n\r\n```java\r\nHttpRequest msg = (HttpRequest) message;\r\nmsg.getFrom().send(ok(self(), msg, body).build())\r\n```\r\nthis works fine, of course.\r\n\r\nThe problem is that my WebActor delegates to one or many other actors (looking at the classes in Comsat I thought the appropriate in this case was that the other actors should be BehaviourActor, is that right?)\r\nwhich receive the WebDataMessage fine, perform the operations they need to perform and then use the msg.getFrom() technique to reply to the original WebActor.\r\n\r\nAll that is fine, the WebActor receives the messages from the BehaviorActors, but then it needs to send a message with the HttpResponse to the virtual actor ServletActor. How can I do this if I've lost the original HttpRequest to do a .getFrom()? I've done it storing a reference to the HttpRequest in the WebActor like this\r\n\r\n```java\r\nprivate HttpRequest request;\r\n```\r\n\r\nand then doing\r\n\r\n```java\r\nif (message instanceof WebDataMessage) {\r\n    request.getFrom().send(ok(self(), request, ((WebDataMessage) message).getStringBody()).build());\r\n}\r\n```\r\n\r\nbut I don't think that is a good pattern, is it? There must be a better way...\r\n\r\nAlso, without actors, if my servlet depends on multiple async calls I can always use java Futures to wait for all the async calls to fulfill and then return a combined response, but with actors, after sending a message to several BehaviorActors how can I send a combined response with the message from all of the BehaviorActors? What's the proper way to do it?\r\n"},"comment":{"url":"https://api.github.com/repos/puniverse/comsat/issues/comments/125582500","html_url":"https://github.com/puniverse/comsat/issues/35#issuecomment-125582500","issue_url":"https://api.github.com/repos/puniverse/comsat/issues/35","id":125582500,"user":{"login":"circlespainter","id":6113296,"avatar_url":"https://avatars.githubusercontent.com/u/6113296?v=3","gravatar_id":"","url":"https://api.github.com/users/circlespainter","html_url":"https://github.com/circlespainter","followers_url":"https://api.github.com/users/circlespainter/followers","following_url":"https://api.github.com/users/circlespainter/following{/other_user}","gists_url":"https://api.github.com/users/circlespainter/gists{/gist_id}","starred_url":"https://api.github.com/users/circlespainter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/circlespainter/subscriptions","organizations_url":"https://api.github.com/users/circlespainter/orgs","repos_url":"https://api.github.com/users/circlespainter/repos","events_url":"https://api.github.com/users/circlespainter/events{/privacy}","received_events_url":"https://api.github.com/users/circlespainter/received_events","type":"User","site_admin":false},"created_at":"2015-07-28T12:26:39Z","updated_at":"2015-07-28T12:26:39Z","body":"In addition to the blog and the [docs](http://docs.paralleluniverse.co/comsat/#web-actors) (they were enough for me to build [quasar-stocks](https://github.com/circlespainter/quasar-stocks) which you probably have already found through the [comparison with Akka](http://blog.paralleluniverse.co/2015/05/21/quasar-vs-akka/)), there are examples [here](https://github.com/puniverse/comsat-examples/tree/master/comsat-examples-webactors), [here](https://github.com/puniverse/comsat-examples/tree/master/comsat-examples-spaceships) and [here](https://github.com/puniverse/comsat-examples/tree/master/comsat-examples-webactors-codeswap) as well as the [`comsat-actors-servlet` test actor](https://github.com/puniverse/comsat/blob/v0.4.0/comsat-actors-servlet/src/test/java/co/paralleluniverse/comsat/webactors/servlet/MyWebActor.java).\r\n\r\nIn addition all of them should be up-to-date (Comsat 0.4.0). What additional docs and examples do you think could be helpful to get started with Web Actors?\r\n\r\nAs for behavioural actors: the choice is up to you. Even just [basic behaviour functionality](http://docs.paralleluniverse.co/quasar/#behaviors) is quite convenient, so I don't see many reasons to do without it.\r\n\r\nAs for actor state management: a single actor's state is private to the actor and is never accessed concurrently so of course you can use it to store information there without much trouble; since by default a web actor instance is private of a session (unless you decide otherwise) there's even little risk of mismatching requests and responses. But since you can just block your fiber in a `receive` from the mailbox after having decoded the web request and sent messages around, with the request and its \"from\" still in scope (or being able to pass them to auxiliary methods anyway), why can't you just do this? Why do you lose the original request object?\r\n\r\nAs for combining responses coming from several actors, you can simply perform a blocking `receive` and then do whatever you want with the messages once you got them all (or progressively while you receive them). If it's more convenient for you, you can also perform [_selective receives_](http://docs.paralleluniverse.co/quasar/#sending-and-receiving-messages-actorref).\r\n\r\nQuasar/Comsat are just this simple: just use normal blocking calls and regular control flow constructs with the peace of mind of knowing that they are being run in fibers, which are much cheaper than regular Java threads. Simply use the tools you already know from regular imperative programming, no need for additional constructs and concepts like in Akka and other async frameworks."}}