I need to send message to clients from a netty server base on user names of clients. As a result I need to map channels with user name and find the channel each time I want to send message.
I have two approaches in my mind, the question is : Which approach is better, in term of performance in server side. do you have any better idea?
Map channels with user name in a hashmap.
//Send userName from client side in first request //Get userName in server side and put it in a map Map<String, Channel> userMap = new ConcurrentHashMap<String,Channel>(); //loop over userMap to find specific client
Set Attachment with user name.
//Set the attachment in client side ctx.getChannel().setAttachment(username); //Put all channels to a default channel group //Get all channels, search in their attachments to find specific client