Issue Details (XML | Word | Printable)

Key: DIRMINA-42
Type: New Feature New Feature
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Niklas Therning
Reporter: Trustin Lee
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
MINA

SessionManagers should manage list of sessions being managed.

Created: 17/May/05 02:45 PM   Updated: 23/Jan/06 12:06 PM
Return to search
Component/s: None
Affects Version/s: 0.7.0
Fix Version/s: 0.9.1

Time Tracking:
Not Specified

File Attachments:
  Size
Zip Archive Licensed for inclusion in ASF works DIRMINA-42.zip 2005-12-16 07:58 AM Federico Bonelli 21 kB
Issue Links:
Blocker
 

Resolution Date: 05/Jan/06 07:36 AM


 Description  « Hide
Users are maintaining the list of managed sessions in acceptors and connectors. It will be much better if MINA can handle this.

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Trustin Lee added a comment - 18/Oct/05 12:37 AM
We need to Implement IoSessionMap to hold the list of sessions, and then use it to resolve DIRMINA-93.

Federico Bonelli added a comment - 14/Dec/05 02:47 AM
I thought to do IoSessionMap an hashMap container, so we can have put-get-remove methods, considering that put and remove has just to be done 1 time for each IoSession (usually), and get() has to be invoked many more times.

Is that right? whatcan I use as key for that map?
Use the socket address is not a good task for VMPIPE, but what else?

Niklas Therning added a comment - 14/Dec/05 06:22 AM
I've been thinking a bit about this issue but I can't see why it has to be a Map. Couldn't it just be a Collection? And as Federico points out what would be the key if it's supposed to be a Map?

Federico, are you working on this issue? I was planning to start working on this and DIRMINA-93 but if you want to take care of it, please be my guest. Just let me know.

Federico Bonelli added a comment - 14/Dec/05 07:34 AM
Yes, I planned to work it out because I need to resolve DIRMINA-93 for my applications.

Well, I'd like to work at this, but I'm new to team-development tecnique (I always worked alone), so I need a large amount of tips, i'd like to discuss every single choice.

I was thinking about that, about the hashMap vs Collection, and I don't know. I have many structure that need of a unique identifier that match every single connection, in my applications, but for every application my key is different.

I'm thinking about an ftp server that need of couple nick-ipaddr, about a chat server that need only ipaddr before login, then the nick after login, the neededs of every application is protocol specified...

For mina purpouse only (DIRMINA-93) a collection is all we need, but if we want to make this IoSessionMap usable for the highlevel application we need to develop a userdefinable hashing, pointing to our own collection, or maybe to another parallel mina-useless data structure dedicated for user-usage (that's the goal of DIRMINA-42)

So the key problem is worse then I thougth. What do you think about it?

Federico Bonelli added a comment - 16/Dec/05 07:58 AM
I have inserted the first stub of classes and interfaces to resolve DIRMINA-42, the implementation should be completed for the TCP part.

There are many parts of the code that need to be discussed, that's just a stub.

Ryan Rhodes added a comment - 17/Dec/05 07:31 PM
Speaking for my application, I think MINA needs a Map but that it doesn't need an application specific key.

I would like to use MINA to build a MUD server, which is basically an extended chat server that exists in a coordinate space. I implemented a simple chat server with MINA for experimenting.

Imagine a user shouts, and you want that to write output to every other user's session, but you don't want it to write output to users that are executing a character creation workflow and are not actually in the game yet. Image a user says something that should only be output to the users that are standing in the room with him.

I'm thinking that all the contexts that a user's commands will execute under will be game specific contexts that have their own lists of users associated with them, like a room or a set of rooms. An executing command will navigate the object model from the point of the user it is executing under to some collection of users that it wants to write output to.

In my case these collections will be the result of database queries so I think what I actually need is just to be able to store a handle to a session in the database along with the users object, so that when I need to output to a set of users, I can fetch the session that goes with the user data in the result of my query. Since there isn't any data associated with the handle I don't think there are any database specific issues related to the key.

Niklas Therning added a comment - 17/Dec/05 08:05 PM
You are using UDP right? The session handle in the database is the remote host+port of the client? You would use that handle as a key when querying your DatagramConnector for a previously connected session (from its IoSessionMap)?

Ryan Rhodes added a comment - 17/Dec/05 08:09 PM
No, the connection is over TCP.

Niklas Therning added a comment - 17/Dec/05 08:16 PM
Ok. I guess all I'm trying to find out is what the key should be in the Map. That would be what your'e storing in the db (your session handle), right?

Ryan Rhodes added a comment - 17/Dec/05 08:27 PM
I think so. This is all new territory for me, but I think you would fetch a room from the db or the cash, iterate over the other users in the room, possibly filtering the list because some are hidden or invisible or whatever. So... it seems like I just need to get from the database object that my game logic produced back to the session that mina is holding for me.

Niklas Therning added a comment - 18/Dec/05 07:20 PM
I've been taking a look at Federico's patch and it looks very promising. As he pointed out it only solves this issue for SocketAcceptors. But it shouldn't be to hard to add this support to VmPipeAcceptors. For DatagramAcceptors I don't think this issue applies?

Then come the IoConnectors. They are IoSessionManagers as well. I think it will be trivial to extend Federico's approach to include SocketConnector.

One thing I still can't figure out though is what the key should be in the IoSessionMap. In the SocketAcceptor case it should probably be the remote address. But that won't work in the SocketConnector case (it's very likely that sessions will be connected to the same remote address). Then it would have to be the local address instead.

For the VMPIPE transport neither will work without some refactoring.

As pointed out by Federico previously the key is, in most cases, probably protocol specific. Because of that the user will have to maintain some kind of app specific key to socket address string mapping anyway. In Ryan's case he's using a database to maintain this kind of mapping. I don't think it would be too hard on the user if he would have to maintain the mapping to IoSession himself.

What I'm trying to say is that I think it would suffice with a Collection instead of a Map. That would be enough to solve DIRMINA-93. I propose that the method

Collection getManagedSessions(SocketAddress)

is added to IoSessionManager (or at least IoAcceptor to solve DIRMINA-93). The returned collection should be unmodifiable of course. WDYT?

Trustin Lee added a comment - 19/Dec/05 01:13 AM
Creating unmodifiable collection will get very tricky because we'll not be able to iterate it if we wrapped the original collection simply; iteration loop will definitely throw a ConcurrentModificationException. So we need to compromise here.

1. Create a special data structure which can be iterated without synchronization
2. MINA returns a copy of the collection

I think the first one is the best. We'll also have to provide a way to synchronize with MINA in case users don't want to see that ghost sessions(which is already closed) are returned.


Trustin Lee added a comment - 03/Jan/06 05:27 PM
There was an interesting conversation among MINA users that it would be great if MINA provide session grouping.

We could rename IoSessionMap to IoSessionGroup and provide more advance features like that.

Niklas Therning added a comment - 03/Jan/06 06:10 PM
Yes, I can see that an IoSessionGroup could be useful as a kind of broadcast/multicast interface.

But, as I argued in a previous comment I don't think IoAcceptors should return an IoSessionMap when asking for the managed sessions. Why don't we create a new issue for the IoSessionGroup feature?

I'm still working on this issue. It's almost finished and the patch will also solve DIRMINA-93. I've added code to the VmPipe and Socket transports (inspired by Federico's patch) which keep track of managed sessions and closes all client sessions when unbind() is called. What's still missing is the method which returns the managed sessions. I'm thinking of adding

Collection getManagedSessions(SocketAddress)

to IoAcceptor

and

Collection getManagedSessions()

to IoConnector. For now I'm thinking of just copying the internal Set of sessions to a new Set instead of creating some smart collection impl. WDYT?

Note that I haven't done anything for Datagram transport yet. I'm not sure if this issue and DIRMINA-93 are applicable to datagrams?

Trustin Lee added a comment - 03/Jan/06 06:20 PM
My idea is to provide IoSessionGroup which implements Collection. I think it is basically same with you.

You're right. DIRMINA-93 is only for transport types with connections.

BTW you don't need to create a patch; you have karma, why don't you create a branch?

Niklas Therning added a comment - 03/Jan/06 06:46 PM
:-) I know that I can branch and I will. Was waiting for the repository reorg to be completed. The correct way is to create a personal branch in /directory/sandbox/niklas, right?

Trustin Lee added a comment - 03/Jan/06 06:55 PM
Exactly. :)

Niklas Therning added a comment - 05/Jan/06 07:36 AM
Collection getManagedSessions(SocketAddress) has been added to IoAcceptor. SocketAcceptorDelegate as well as VmPipeAcceptor will return the currently connected sessions on the specified local address. DatagramAcceptorDelegate doesn't support this method. It will throw an UnsupportedOperationException.

Note that no support for retrieving the currently connected sessions on an IoConnector has been added. But if needed it should not be that hard to add that kind of support.

Trustin Lee added a comment - 23/Jan/06 12:06 PM
Looks good. Great job!