You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@etch.apache.org by Aleksandar Kanchev <al...@googlemail.com> on 2010/06/30 19:48:33 UTC

Signals

Hello list,

I'm new to etch and I like the idea of having a bidirectional connection.
This way I could make the server send messages (or signals) to the client if
something interesting happened.  The problem is how to send a message to all
the clients? I was thinking about making all the Impl objects register to a
message bus and simply forward the messages. The problem is that for C# and
Java there are no destructors, so when should the Impl object deregister
from the message bus? Can I listen for session disposal events?
Thanks!

best regards
Aleksandar

Re: Signals

Posted by scott comer <we...@mac.com>.
  On 6/30/2010 12:48 PM, Aleksandar Kanchev wrote:
> Hello list,
>
> I'm new to etch and I like the idea of having a bidirectional 
> connection. This way I could make the server send messages (or 
> signals) to the client if something interesting happened.  The problem 
> is how to send a message to all the clients? I was thinking about 
> making all the Impl objects register to a message bus and simply 
> forward the messages. The problem is that for C# and Java there are no 
> destructors, so when should the Impl object deregister from the 
> message bus? Can I listen for session disposal events?
> Thanks!
>
> best regards
> Aleksandar
if you look at the chat example, you can see how when users register 
they are added to a map by name with the value being their connection 
object. then when chat wants to send a particular user a message, it 
looks them up in the map to see if they are there. this notion of 
presence has such a variety of possible implementations that it isn't 
really possible for etch to try to support it. but you can easily 
implement it yourself.

you will also see chat remove the user from the map when they logout, 
and also when the session goes down (see _sessionNotify message, with 
event = Session.DOWN). essentially, when the session goes down, logout 
is called.

if you just want to keep track of sessions, then add the connection to a 
set upon _sessionNotify event Session.UP, and remove it upon Session.DOWN.

then you'll have to write something to do something to all active sessions:

doToActiveSessions( new ThingToDo() {
    public void doit(BlahServerImpl impl) {
       impl.client.sayHello();
    }
}

doToActiveSessions would (while synchronized) make a copy of the current 
set of active sessions and then (while not synchronized) iterate over it 
calling the doit method (wrapped with a try, of course).

scott out