~ubuntu-branches/ubuntu/raring/libjboss-remoting-java/raring

« back to all changes in this revision

Viewing changes to src/main/org/jboss/remoting/samples/chat/server/ExtendedChatInfo.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-09 14:01:03 UTC
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: package-import@ubuntu.com-20110909140103-o8ucrolqt5g25k57
Tags: upstream-2.5.3.SP1
ImportĀ upstreamĀ versionĀ 2.5.3.SP1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.jboss.remoting.samples.chat.server;
 
2
 
 
3
/**
 
4
 * <p>Title: Chat4</p>
 
5
 * <p>Description: </p>
 
6
 * <p>Copyright: Copyright (c) 2003</p>
 
7
 * <p>Company: </p>
 
8
 * @author not attributable
 
9
 * @version 1.0
 
10
 */
 
11
 
 
12
import java.io.IOException;
 
13
import java.io.Serializable;
 
14
import java.util.ArrayList;
 
15
import java.util.Collection;
 
16
import java.util.Collections;
 
17
import java.util.HashSet;
 
18
import java.util.Hashtable;
 
19
import java.util.Iterator;
 
20
 
 
21
import org.jboss.remoting.samples.chat.client.ChatInfo;
 
22
import org.jboss.remoting.samples.chat.client.ChatMember;
 
23
import org.jboss.remoting.samples.chat.exceptions.NameInUseException;
 
24
import org.jboss.remoting.samples.chat.utility.ReadWriteArrayList;
 
25
 
 
26
public class ExtendedChatInfo implements Serializable
 
27
{
 
28
  private static final long serialVersionUID = 3;
 
29
 
 
30
  private ChatInfo chatInfo;
 
31
  private ReadWriteArrayList messages;
 
32
  private Collection members;
 
33
  transient private Hashtable threadMap;
 
34
  transient private Collection chatReceivers;
 
35
 
 
36
  public ExtendedChatInfo(ChatInfo chatInfo)
 
37
  {
 
38
    this.chatInfo = chatInfo;
 
39
    messages = new ReadWriteArrayList();
 
40
    members =  Collections.synchronizedCollection(new HashSet());
 
41
    threadMap =  new Hashtable();
 
42
    chatReceivers = Collections.synchronizedCollection(new HashSet());
 
43
  }
 
44
 
 
45
  private void readObject(java.io.ObjectInputStream in)
 
46
     throws IOException, ClassNotFoundException
 
47
 {
 
48
   in.defaultReadObject();
 
49
   threadMap =  new Hashtable();
 
50
   chatReceivers = Collections.synchronizedCollection(new HashSet());
 
51
 }
 
52
 
 
53
  public ChatInfo getChatInfo()
 
54
  {return chatInfo;}
 
55
 
 
56
  public Collection getMembers()
 
57
  {return members;}
 
58
 
 
59
  public ReadWriteArrayList getMessages()
 
60
  {return messages;}
 
61
 
 
62
  public Collection getChatReceivers()
 
63
  {return chatReceivers;}
 
64
 
 
65
  public CallbackThread getChatReceiverThread(ChatMember member)
 
66
  { return (CallbackThread) threadMap.get(member.get_name()); }
 
67
 
 
68
  public void addMember(ChatMember member)
 
69
      throws NameInUseException
 
70
  {
 
71
    String name = member.get_name();
 
72
 
 
73
    if (members.contains(name))
 
74
        throw new NameInUseException();
 
75
 
 
76
    members.add(name);
 
77
  }
 
78
 
 
79
  public void removeMember(ChatMember member)
 
80
  {
 
81
    String name = member.get_name();
 
82
    threadMap.remove(name);
 
83
    members.remove(name);
 
84
  }
 
85
 
 
86
 
 
87
  public void addMessages(ArrayList messages)
 
88
  {
 
89
    Iterator it = messages.iterator();
 
90
    while (it.hasNext())
 
91
    {
 
92
      this.messages.add(it.next());
 
93
    }
 
94
  }
 
95
 
 
96
  public void addMessage(String message)
 
97
  {
 
98
    messages.add(message);
 
99
  }
 
100
 
 
101
 
 
102
}