how to handle multiple sessions?

asked 2015-02-26 07:02:56 -0700

markus_andreasson gravatar image

Context: Android

Hi, According to the sample signalclient, it is possible to join multiple sessions: "It is possible to join multiple session however joining multiple sessions is not shown in this sample.". I would like to accomplish this. I have peers that need to create sessions with multiple peers of a particular type in the network.

Each peer currently has one BusObject with a registered BusListener and it receives one foundAdvertisedName for every other peer in the network. I can easily create separate signal emitter interfaces for each session (in either sessionJoined() or after mBus.joinSession()) and store them with the corresponding session ID. However, each peer also has a registered signal handler which receives signals from other peers. This is where the problem arises. I don't know which session a call to the signal handler corresponds to. My signal handler looks kind of like this:

class MyClass implements MyInterface, BusObject {
        @BusSignalHandler(iface = "some.interface", signal = "MySignal")
        public void MySignal(int something) throws BusException {
                // Interesting stuff happens here, but which session am I in??

What is the general approach for this? Can I extract the current session when the signal handler executes somehow, or do I have to solve this over the top, e.g. by creating a unique identifier for each session which is sent over each time a peer sends a signal? This would probaly work, but doesn't feel right to do.

Or, should I rather go down the path to make separate BusObjects for all sessions? This also doesn't feel right...

Any help is appreciated,


edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-02-27 07:29:12 -0700

markus_andreasson gravatar image

updated 2015-02-27 07:30:50 -0700

I managed to get multiple session to work nicely after finding the sessionId in the signal handler like this:

@BusSignalHandler(iface = "some.interface", signal = "MySignal")
public void MySignal(int something) throws BusException {
    int sessionId = mBus.getMessageContext().sessionId;
edit flag offensive delete publish link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2015-02-26 07:02:56 -0700

Seen: 92 times

Last updated: Feb 27 '15