ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/clientinterface/PacketSorter.java
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/clientinterface/PacketSorter.java (file contents):
Revision 1.11 by tdb, Thu Mar 1 17:29:46 2001 UTC vs.
Revision 1.15 by tdb, Tue Mar 13 18:37:08 2001 UTC

# Line 33 | Line 33 | class PacketSorter extends Thread {
33  
34      /**
35       * Creates a new PacketSorter.
36     *
37     * @param queueMonitorInterval The interval at which to monitor the Queue
36       */
37 <    public PacketSorter(int queueMonitorInterval) {
37 >    public PacketSorter() {
38 >        // set the Thread name
39 >        setName("clientinterface.PacketSorter");
40 >        
41          _queue = new Queue();
42 <        // startup a monitor on this queue, every minute
43 <        String queueName = _name + " PacketSorterQueue";
44 <        _queue.startMonitor(queueMonitorInterval*1000, queueName);
42 >        // startup a monitor on this queue
43 >        try {
44 >            // try to get the interval, if this fails, we won't start up the monitor
45 >            ConfigurationProxy cp = ConfigurationProxy.getInstance();
46 >            int queueMonitorInterval = Integer.parseInt(cp.getProperty("ClientInterface", "Queue.MonitorInterval"));
47 >            String queueName = _name + " PacketSorterQueue";
48 >            _queue.startMonitor(queueMonitorInterval*1000, queueName);
49 >        } catch (PropertyNotFoundException e) {
50 >            _logger.write(toString(), Logger.WARNING, "failed to find queue monitor config, disabling. " + e);
51 >        }
52 >        
53          _hostMap = new HashMap();
54          _allHostDataList = new LinkedList();
55          _allHostsList = new LinkedList();
# Line 54 | Line 63 | class PacketSorter extends Thread {
63       * loop forever processing and sending data.
64       */
65      public void run() {
66 +        XMLPacketMaker xmlPacketMaker = new XMLPacketMaker();
67          int qID = _queue.getQueue();
68          while(true) {
69              // attempt to get some data from the Queue
# Line 68 | Line 78 | class PacketSorter extends Thread {
78              XMLPacket packet = null;
79              
80              try {
81 <                XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml);
72 <                packet = xmlPacketMaker.createXMLPacket();
81 >                packet = xmlPacketMaker.createXMLPacket(xml);
82              } catch(InvalidXMLException e) {
83                  _logger.write(toString(), Logger.ERROR, "Invalid XML: "+e);
84                  // skip the rest of this loop iteration
# Line 128 | Line 137 | class PacketSorter extends Thread {
137       * @param dhQueue a Queue being used by the DataHandler that is registering
138       * @param hostList a semi-colon seperated list of hosts
139       */
140 <    public synchronized void register(Queue dhQueue, String hostList) {
140 >    public void register(Queue dhQueue, String hostList) {
141          // check to see if we want all hosts
142          if(hostList.equals("")) {
143 <            _allHostDataList.add(dhQueue);
143 >            synchronized(this) {
144 >                _allHostDataList.add(dhQueue);
145 >            }
146              _logger.write(toString(), Logger.SYSMSG, "registered DataHandler for all hosts");
147          }
148          else {
# Line 139 | Line 150 | class PacketSorter extends Thread {
150              StringTokenizer st = new StringTokenizer(hostList, ";");
151              while(st.hasMoreTokens()) {
152                  String host = st.nextToken();
153 <                // see if we already have a list in the map for this host
154 <                if(_hostMap.containsKey(host)) {
155 <                    // we do, so add to it
156 <                    List list = (List) _hostMap.get(host);
157 <                    list.add(dhQueue);
153 >                synchronized(this) {
154 >                    // see if we already have a list in the map for this host
155 >                    if(_hostMap.containsKey(host)) {
156 >                        // we do, so add to it
157 >                        List list = (List) _hostMap.get(host);
158 >                        list.add(dhQueue);
159 >                    }
160 >                    else {
161 >                        // we don't, so create a list and put it in the map
162 >                        LinkedList list = new LinkedList();
163 >                        list.add(dhQueue);
164 >                        _hostMap.put(host, list);
165 >                    }
166                  }
148                else {
149                    // we don't, so create a list and put it in the map
150                    LinkedList list = new LinkedList();
151                    list.add(dhQueue);
152                    _hostMap.put(host, list);
153                }
167              }
168              _logger.write(toString(), Logger.SYSMSG, "registered DataHandler for hosts: "+hostList);
169          }
170          // always add host to our complete host list
171 <        _allHostsList.add(dhQueue);
171 >        synchronized(this) {
172 >            _allHostsList.add(dhQueue);
173 >        }
174      }
175      
176      /**
# Line 169 | Line 184 | class PacketSorter extends Thread {
184       * @param dhQueue a Queue being used by the DataHandler that is deregistering
185       * @param hostList a semi-colon seperated list of hosts
186       */
187 <    public synchronized void deregister(Queue dhQueue, String hostList) {
187 >    public void deregister(Queue dhQueue, String hostList) {
188          // go through the list of hosts
189          if(hostList.equals("")) {
190 <            _allHostDataList.remove(dhQueue);
190 >            synchronized(this) {
191 >                _allHostDataList.remove(dhQueue);
192 >            }
193              _logger.write(toString(), Logger.SYSMSG, "deregistered DataHandler for all hosts");
194          }
195          else {
196              StringTokenizer st = new StringTokenizer(hostList, ";");
197              while(st.hasMoreTokens()) {
198                  String host = st.nextToken();
199 <                // this should in reality always be true, but best check
200 <                if(_hostMap.containsKey(host)) {
201 <                    // get the list and remove the host in question
202 <                    LinkedList list = (LinkedList) _hostMap.get(host);
203 <                    list.remove(dhQueue);
204 <                    // if the list is now empty, we might as well remove it
205 <                    if(list.size()==0) {
206 <                        _hostMap.remove(host);
199 >                synchronized(this) {
200 >                    // this should in reality always be true, but best check
201 >                    if(_hostMap.containsKey(host)) {
202 >                        // get the list and remove the host in question
203 >                        LinkedList list = (LinkedList) _hostMap.get(host);
204 >                        list.remove(dhQueue);
205 >                        // if the list is now empty, we might as well remove it
206 >                        if(list.size()==0) {
207 >                            _hostMap.remove(host);
208 >                        }
209                      }
210                  }
211              }
212              _logger.write(toString(), Logger.SYSMSG, "deregistered DataHandler for hosts: "+hostList);
213          }
214          // always remove host from our complete host list
215 <        _allHostsList.remove(dhQueue);
215 >        synchronized(this) {
216 >            _allHostsList.remove(dhQueue);
217 >        }
218      }
219      
220      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines