How can the TCP socket creation class gets notified that one new peer is added to the registry?
I am implementing a P2P service. The idea is using UDP to search for peers and build it's own registry. And using TCP to do the real communication. I want to create one more new TCP socket connection, if there's one more peer added to this peer's registry. The registry is implemented in hashmap . How can the TCP socket creation class gets notified that one new peer is added to the registry?
Simply implement a class like 'TcpConnectionManager' which registers itself with the registry - lets call it 'P2PConnectionRegistry' at startup. (The registry has to be a class maintaining a HashMap - it cannot be a HashMap.).
If a new connection has to be created, you call p2pConnRegistry.addConnection(...); from somewhere (e.g. UI).
This method adds the required params it's internal data structure (e.g. the HashMap) - and then calls registryListener.connectionAdded(...); This registryListener is a instance of TcpConnectionManager.
This is a very simple model for "seperation of concerns".
I hope this was your question it it helps, greetings, Michael