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

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-09 14:01:03 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: package-import@ubuntu.com-20110909140103-hqokx61534tas9rg
Tags: 2.5.3.SP1-1
* Newer but not newest upstream release. Do not build samples.
* Change debian/watch to upstream's svn repo.
* Add patch to fix compile error caused by tomcat update.
  (Closes: #628303)
* Switch to source format 3.0.
* Switch to debhelper level 7.
* Remove useless Depends.
* Update Standards-Version: 3.9.2.
* Update README.source.

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.Serializable;
 
13
import java.util.ArrayList;
 
14
import java.util.Collection;
 
15
import java.util.Hashtable;
 
16
import java.util.Iterator;
 
17
 
 
18
import org.jboss.logging.Logger;
 
19
import org.jboss.remoting.samples.chat.client.ChatInfo;
 
20
import org.jboss.remoting.samples.chat.exceptions.ShuttingDownException;
 
21
import org.jboss.remoting.samples.chat.utility.ShutDownGate;
 
22
 
 
23
public class ChatStore implements Serializable
 
24
{
 
25
  private static final long serialVersionUID = 1;
 
26
  protected static final Logger log = Logger.getLogger(ChatStore.class);
 
27
 
 
28
  private Hashtable extendedChatInfoMap;
 
29
  private ShutDownGate shutDownGate;
 
30
 
 
31
  public ChatStore()
 
32
  {
 
33
    extendedChatInfoMap = new Hashtable();
 
34
    shutDownGate = new ShutDownGate();
 
35
    
 
36
//    try
 
37
//    {
 
38
//       databaseManager = new DatabaseManager();
 
39
//       
 
40
//       System.out.println("ChatStore(): created DatabaseManager");
 
41
//       
 
42
//       if (databaseManager.chatDBExists())
 
43
//       {
 
44
//          restoreExtendedChatInfoMap();
 
45
//          System.out.println("ChatStore(): restored chat store");
 
46
//       }
 
47
//       else
 
48
//       {
 
49
//          databaseManager.createChatDB();
 
50
//          System.out.println("ChatStore(): created new data base");
 
51
//       }
 
52
//    }
 
53
//    catch (DatabaseException e)
 
54
//    {
 
55
//       e.printStackTrace();
 
56
//    }
 
57
  }
 
58
 
 
59
 
 
60
  public ShutDownGate getShutDownGate()
 
61
  { return shutDownGate; }
 
62
 
 
63
  
 
64
  public void addChat(ExtendedChatInfo eci) throws ShuttingDownException
 
65
  {
 
66
    shutDownGate.enter();
 
67
    String key = eci.getChatInfo().get_key();
 
68
    extendedChatInfoMap.put(key, eci);
 
69
    log.info("adding chat " + key);
 
70
    shutDownGate.leave();
 
71
  }
 
72
 
 
73
  
 
74
/* fail-fast iterator*/
 
75
  ArrayList listChats() throws ShuttingDownException
 
76
  {
 
77
    shutDownGate.check();
 
78
    Collection c = extendedChatInfoMap.values();
 
79
    ArrayList chatArrayList = new ArrayList();
 
80
 
 
81
    Iterator it = c.iterator();
 
82
    while (it.hasNext())
 
83
    {
 
84
      ExtendedChatInfo eci = (ExtendedChatInfo) it.next();
 
85
      ChatInfo ci = eci.getChatInfo();
 
86
      ci.set_currentMembers(eci.getMembers().size());
 
87
      ci.set_size(eci.getMessages().size());
 
88
      chatArrayList.add(ci);
 
89
      log.debug("eci.getMembers(): " + eci.getMembers());
 
90
    }
 
91
 
 
92
    return chatArrayList;
 
93
  }
 
94
 
 
95
  
 
96
  public ExtendedChatInfo getChat(String key) throws ShuttingDownException
 
97
  {
 
98
    shutDownGate.check();
 
99
    ExtendedChatInfo eci = (ExtendedChatInfo) extendedChatInfoMap.get(key);
 
100
    return eci;
 
101
  }
 
102
 
 
103
  
 
104
  public Collection getChatKeySet()
 
105
  { return extendedChatInfoMap.keySet(); }
 
106
 
 
107
 
 
108
//  private void restoreExtendedChatInfoMap()
 
109
//  {
 
110
//    ArrayList chats = null;
 
111
//
 
112
//    try
 
113
//   {
 
114
//      chats = databaseManager.getChats();
 
115
//   }
 
116
//   catch (DatabaseException e)
 
117
//   {
 
118
//      e.printStackTrace();
 
119
//   }
 
120
//   Iterator it = chats.iterator();
 
121
//
 
122
//   while (it.hasNext())
 
123
//   {
 
124
//     ChatInfo chatInfo = (ChatInfo) it.next();
 
125
//     ExtendedChatInfo eci = new ExtendedChatInfo(chatInfo);
 
126
//
 
127
////        ArrayList members = databaseManager.getChatMembers(chatInfo.get_key());
 
128
////        Iterator mit = members.iterator();
 
129
////
 
130
////        while (mit.hasNext())
 
131
////        {
 
132
//     //          eci.addMember((ChatMember) it.next(), null);
 
133
//     //        }
 
134
//     
 
135
//     ArrayList messages;
 
136
//     try
 
137
//     {
 
138
//        messages = databaseManager.getChatMessages(chatInfo.get_key());
 
139
//        eci.addMessages(messages);
 
140
//     }
 
141
//     catch (DatabaseException e1)
 
142
//     {
 
143
//        e1.printStackTrace();
 
144
//     }
 
145
//     
 
146
//     
 
147
//     
 
148
//     try {
 
149
//        addChat(eci);
 
150
//     } catch (ShuttingDownException sde) {} // ignore: we're just starting up
 
151
//   }
 
152
//  }
 
153
  
 
154
}
 
155