I'm designing an instant messaging server as a personal exercise to improve my understanding and application of multi-threading and design patterns in Java. I'm still designing, there's no code yet.
My goal is to have a server that should make effective use of a multi-CPU box. I'd like the server to be distributable across multiple boxes, but wonder if that's running before I can walk.
My initial thoughts are:
ClientConnectionManager
hasServerSocket
object that constantly accepts clientSocket
connections.ClientConnectionManager
has a thread pool that spawns a newClientProxy
object when a client socket connection is accepted, handing in the clientSocket
object.- The
ClientProxy
objects represent the client app and handles sending/receiving messages across theSocket
stream.
Is it correct that only one ServerSocket
may bind to a Port? I take it there's no way to have a pool of objects accepting Socket connections?
I have two ideas for passing messages between ClientProxy
objects. Either directly between ClientProxy
objects that are "buddies" or via a central "Exchange" object, or better yet, pool of objects.
What are the Pros/Cons of the two approaches? Does the Exchange lend itself better to a distributed app?
Would the Observer and Mediator patterns, respectively, be appropriate?