Пример #1
0
 /**
  * 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);
 }
Пример #2
0
 /**
  * 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);
   }
 }
Пример #3
0
 private void say(String sender, String message) {
   synchronized (_chatters) {
     for (Chatter _chatter : _chatters)
       if (!_chatter.getSender().equals(sender)) _chatter.addMessage(message);
   }
 }