/** * subscribte to the chatroom * * @param chatter */ public void subscribe(Chatter chatter) { chatter.addMessage(SIGNAL + "Welcome " + chatter.getSender() + SIGNAL); synchronized (_chatters) { _chatters.add(chatter); } say( chatter.getSender(), getDateTime() + ": " + SIGNAL + chatter.getSender() + " join this chatroom" + SIGNAL); }
/** * unsubsctibe to the chatroom * * @param chatter */ public void unsubscribe(Chatter chatter) { _chatters.remove(chatter); chatter.addMessage(SIGNAL + "Bye " + chatter.getSender() + SIGNAL); synchronized (_chatters) { for (Chatter _chatter : _chatters) _chatter.addMessage( getDateTime() + ": " + SIGNAL + chatter.getSender() + " leaves the chat room!" + SIGNAL); } }
private void say(String sender, String message) { synchronized (_chatters) { for (Chatter _chatter : _chatters) if (!_chatter.getSender().equals(sender)) _chatter.addMessage(message); } }