Scenario
I'm going to be as succinct as possible. Basically with reference to this classdiag, I have a facade which manages a list of SocketManager ( which manages one Socket connection). Each SocketManager logs in to a remote server using a unique SocketUserId. Furthermore, each SocketManager will accept messages from clients destined for a specific list of Receipients. For discussion sake, consider these Receipients as simply as remote data buckets identified by a name.
Clients will send data like this:
SocketFacade facade = ...;
byte[] data = ...
facade.sendData( receipient, data );
When SocketFacade starts, it will query a mysql table which returns the 1-m relationship between SocketUserId and Receipients. I will use a MultiValuedMap to represent this 1-m relationship. Multiple SocketManager will be then be started by iterating through the map.
(1) Map< SocketUserId, List<Receipient> >
e.g. Suppose we have 2 SocketManagers with SocketUserIds "alice" & "tom" respectively
+----SocketManager1 ( "alice" ) for Receipients { "B", "C" }
|
SocketFacade
|
+----SocketManager2 ( "tom" ) for Receipients { "A", "D" }
Question
I am in a bind as to how to implement the sendData method. Basically I need a way to map from a Receipient (e.g. "B") to its responsible SocketManager (e.g. SocketManager1).
Let's suppose I do this
(2) Map< SocketUserId, SocketManager >
(3) Map< Receipient, SocketUserId >
- Would I need a SoftReference for the value in (2) ?
- Should I just map from Receipient directly to SocketManager ?
SocketFacade also supports methods that will mutate the relationship represented by (1). If I write to the database, the in-memory data structures in (1), (2), & (3) will need to change in sync. SocketFacade must be thread safe as well. Initial idea is to have some sort of a publish subscribe system whereby an add/remove to the DB will cause the changes to propagate via callbacks.
interface Callback { void receipientAdded( Receipient r ); void receipientDeleted( Receipient r ); }
Any comments much appreciated.