Search code examples
red5

Red5: is it alright to store IConnection instances in a HashMap to retrieve later


I have a HashMap defined like this

HashMap<String, IConnection> connections = new HashMap<String, IConnection>();

inside application connect, I add values into it like this:

conn.setAttribute(“username”, username);
connections.put(username, conn); // username and conn are parameters passed to 
                                 // connect method

inside application disconnect method, I remove values from it like this

connections.remove((String)conn.getAttribute(“username”));

This seems to work, however is it correct/safe? Or am I doing it wrong?


Solution

  • Yes, it is alright but I suggest that you make sure the connection is still connected before you try to access or write to it.