Hi Endre,

thank you for the info.

All,

I tested this example and noticed that AnActor is instanced only ones when 
Router.createRoute is called.
Does this mean that one instance of AnActor is used for all websocket 
connections (if you have multiple parallel connections)?
I thought that AnActor represents each websocket connection (so multiple 
AnActor instances are created when you have multiple websocket connections).

Thank you in advance.

P.S. I'm new with akka and more and more enthusiastic about it while 
learning it. Also community is great. Thanks to all :)

Br,
Alan

Dana četvrtak, 31. ožujka 2016. u 16:12:12 UTC+2, korisnik drewhk napisao 
je:
>
>
>
> On Thu, Mar 31, 2016 at 4:08 PM, Alan Klikic <akl...@gmail.com 
> <javascript:>> wrote:
>
>> Hi all,
>>
>>  Sink<Message, NotUsed> sink = Flow.<Message>create()
>>         .map((msg) -> new Incoming(msg.asTextMessage().getStrictText()))
>>        * .to(Sink.actorRef(actor, PoisonPill.getInstance()));*
>>
>> Can you please explain what does bolded part of the code do? 
>> My first thought was that PoisonPill is sent when websocket disconnects. 
>>
>
> Yes, that is it. You can specify the stop message that is sent to the 
> actor on upstream completion, which is in this case the built-in PoisonPill 
> message -- but you can of course change this to whatever you want.
>
> -Endre
>
>  
>
>> Please correct me if I'm wrong.
>>
>> Thank you in advance.
>>
>> BR,
>> Alan
>>
>> Dana utorak, 8. ožujka 2016. u 15:59:26 UTC+1, korisnik Johan Andrén 
>> napisao je:
>>
>>> Here is an adaptation of the Scala sample, but in Java:
>>>
>>> import akka.NotUsed;
>>> import akka.actor.*;
>>> import akka.http.javadsl.model.ws.Message;
>>> import akka.http.javadsl.model.ws.TextMessage;
>>> import akka.http.javadsl.server.HttpApp;
>>> import akka.http.javadsl.server.Route;
>>> import akka.japi.pf.ReceiveBuilder;
>>> import akka.stream.OverflowStrategy;
>>> import akka.stream.javadsl.Flow;
>>> import akka.stream.javadsl.Sink;
>>> import akka.stream.javadsl.Source;
>>>
>>> import java.util.Optional;
>>>
>>> public class WebSocketServer {
>>>   private static final class Router extends HttpApp {
>>>
>>>     private final ActorSystem system;
>>>
>>>     public Router(ActorSystem system) {
>>>       this.system = system;
>>>     }
>>>
>>>     public Route createRoute() {
>>>       return route(
>>>         path("test").route(
>>>           get(handleWebSocketMessages(createWebSocketFlow()))
>>>         )
>>>       );
>>>     }
>>>
>>>     private Flow<Message, Message, NotUsed> createWebSocketFlow() {
>>>       ActorRef actor = system.actorOf(Props.create(AnActor.class));
>>>
>>>       Source<Message, NotUsed> source = Source.<Outgoing>actorRef(5, 
>>> OverflowStrategy.fail())
>>>         .map((outgoing) -> (Message) TextMessage.create(outgoing.message))
>>>         .<NotUsed>mapMaterializedValue(destinationRef -> {
>>>           actor.tell(new OutgoingDestination(destinationRef), 
>>> ActorRef.noSender());
>>>           return NotUsed.getInstance();
>>>         });
>>>
>>>       Sink<Message, NotUsed> sink = Flow.<Message>create()
>>>         .map((msg) -> new Incoming(msg.asTextMessage().getStrictText()))
>>>         .to(Sink.actorRef(actor, PoisonPill.getInstance()));
>>>
>>>
>>>       return Flow.fromSinkAndSource(sink, source);
>>>     }
>>>
>>>   }
>>>
>>>
>>>
>>>
>>>     public static void main(String[] args) {
>>>         ActorSystem actorSystem = ActorSystem.create();
>>>
>>>         Router router = new Router(actorSystem);
>>>         router.bindRoute("127.0.0.1", 8082, actorSystem);
>>>     }
>>>
>>>   static class Incoming {
>>>     public final String message;
>>>     public Incoming(String message) {
>>>       this.message = message;
>>>     }
>>>   }
>>>
>>>   static class Outgoing {
>>>     public final String message;
>>>     public Outgoing(String message) {
>>>       this.message = message;
>>>     }
>>>   }
>>>
>>>   static class OutgoingDestination {
>>>     public final ActorRef destination;
>>>     OutgoingDestination(ActorRef destination) {
>>>       this.destination = destination;
>>>     }
>>>   }
>>>
>>>   static class AnActor extends AbstractActor {
>>>
>>>     private Optional<ActorRef> outgoing = Optional.empty();
>>>
>>>     public AnActor() {
>>>       receive(ReceiveBuilder.match(
>>>         OutgoingDestination.class, (msg) -> outgoing = 
>>> Optional.of(msg.destination)
>>>       ).match(
>>>         Incoming.class, (in) -> outgoing.ifPresent((out) -> out.tell(new 
>>> Outgoing("got it"), self()))
>>>       ).build());
>>>     }
>>>   }
>>> }
>>>
>>>
>>> Hope this helps.
>>>
>>> --
>>> Johan Andrén
>>> Akka Team, Lightbend Inc.
>>>
>> -- 
>> >>>>>>>>>> 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 akka-user+...@googlegroups.com <javascript:>.
>> To post to this group, send email to akka...@googlegroups.com 
>> <javascript:>.
>> Visit this group at https://groups.google.com/group/akka-user.
>> For more options, visit 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 akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
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