Another idea is to have a third type of remote actor, a session bound
remote actor:
With this, instead of registering an actor, you would register a
function that creates an actor, for example:
RemoteServer.register("myactor", () => actorOf[MyActor] )
every time a client connects, this function would be called to create
an actor for that session, when the client disconnects, your actor
would be stopped. If you want to keep state for the session, you would
just keep it as attributes of your actor. If you want to do some
initialization/cleanup, you would use the init() and postStop
callbacks as usual. All messages from the clients would be forwarded
to the session actor.
This would work for both typed and untyped remote actors, and to the
clients it would look just like any other server managed remote actor.
Maybe, instead of registering a function, you could set up a
supervisor to manage the instances, but tie the actors to the
sessions.
This would be like client managed actors meet server managed actors,
where the lifecycle of the actors is tied to the session, yet the
server has control over what the clients can do.
On Oct 31, 7:47 am, Paul Pacheco <
paulp...@gmail.com> wrote:
> Could the sender object in this case be a TypedActor? I dont know if that
> can be done without breaking the rest of akka. But if it was that way, then
> the sender object could have methods like: "getClientAddress" and
> "getAttribute"
>
> It would be up to the application to cast the server object to something
> like "RemoteSender" which would have these methods.
>
> The same RemoteSender could be passed to the RemoteServerClientDisconnected
> and friends. This would also have the interesting feature of allowing the
> server to send something to the client without the client sending anything
> to the server.
>
> This would also allow me to create an actor per session, and associate it
> with the session painlesly, and stopping it when the client disconnects.
>
>
>
>
>
>
>
> On Sun, Oct 31, 2010 at 7:28 AM, Jonas Bonér <
jo...@jonasboner.com> wrote:
> > How would I know? When a client disconnects the only think I have is
> > the host and port.
> > You would have to build the application in the way that for example
> > the messages in which a client connects with contains its host and
> > port (which is to be found in the self.homeAddress field) and then you
> > need to do the mapping.
> > Also you do have both the connect and disconnect life-cycle events to
> > hook into to do the mapping.
> > What are your suggestion on what we could add to solve the problem in
> > an easier way?
>
> > On 31 October 2010 13:16, Paul Pacheco <
paulp...@gmail.com> wrote:
> > > Thank you Jonas,
> > > But I think there is still something missing. In the chat example, you
> > > identify the sessions by username, yet these messages give you the
> > > InetSocketAddress. This is might be me being an akka n00b, but it is not
> > > obvious how to link the two. When you receive a message, there needs to
> > be a
> > > way to tell what InetSocketAddress the message came from. AFAIK, you have
> > > the sender object, but I don't know how to get the InetSocketAddress from
> > > the sender ActorRef. Otherwise, you still can not resolve the memory leak
> > in
> > > the chat tutorial example.
> > > On a somewhat related note, I think would it would be useful is if there
> > > was a way to associate objects with the session. In a web server, you can
> > > associate random objects with setAttribute on the HttpSession object.
> > This
> > > would help you not having to maintain a singleton Map with data related
> > to
> > > each session, and avoid unnecessary locking. So rather than passing the
> > > InetSocketAddress to the listener and the message handler, both of them
> > > could receive a "Session" object through which you could get the
> > > InetSocketAddress, as well as any user attribute.
>
> > > On Sun, Oct 31, 2010 at 5:25 AM, √iktor Klang <
viktor.kl...@gmail.com>
> > > wrote:
>
> > >> Ah, nice Jonas, I was thinking about how to solve that earlier, just
> > >> piping out the address is a sensible choice.
>
> > >> On Sun, Oct 31, 2010 at 7:00 AM, Jonas Bonér <
jo...@jonasboner.com>
> > wrote:
>
> > >>> Fixed in master now.
> > >>> Here is the new API:
>
> >
http://doc.akkasource.org/remote-actors-scala#Remote%20Actors%20(Scal...
>
> > >>> On 27 October 2010 22:30, Jonas Bonér <
jo...@jonasboner.com> wrote:
> > >>> > Thanks for the ticket. We'll try to get it done fast.
>
> > >>> > On 27 October 2010 17:57, Jonas Bonér <
jo...@jonasboner.com> wrote:
> > >>> >> That is a good point. Would be great to get the client info as part
> > of
> > >>> >> the
> > >>> >> listener callback on disconnect.
> > >>> >> Don't know if that is possible to get through Netty.
> > >>> >> Open a ticket.
>
> > >>> >>>
akka-user+...@googlegroups.com<akka-user%2Bunsubscribe@googlegroups .com>
> > .
> > >>>
akka-user+...@googlegroups.com<akka-user%2Bunsubscribe@googlegroups .com>
> > .
> > >>
akka-user+...@googlegroups.com<akka-user%2Bunsubscribe@googlegroups .com>
> > .
> > >
akka-user+...@googlegroups.com<akka-user%2Bunsubscribe@googlegroups .com>
> > .
> >
akka-user+...@googlegroups.com<akka-user%2Bunsubscribe@googlegroups .com>
> > .