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

Comparing projects/cms/source/util/uk/org/iscream/cms/util/Queue.java (file contents):
Revision 1.19 by tdb, Thu Mar 22 18:23:27 2001 UTC vs.
Revision 1.24 by tdb, Sat May 18 18:16:03 2002 UTC

# Line 1 | Line 1
1 + /*
2 + * i-scream central monitoring system
3 + * Copyright (C) 2000-2002 i-scream
4 + *
5 + * This program is free software; you can redistribute it and/or
6 + * modify it under the terms of the GNU General Public License
7 + * as published by the Free Software Foundation; either version 2
8 + * of the License, or (at your option) any later version.
9 + *
10 + * This program is distributed in the hope that it will be useful,
11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 + * GNU General Public License for more details.
14 + *
15 + * You should have received a copy of the GNU General Public License
16 + * along with this program; if not, write to the Free Software
17 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 + */
19 +
20   //---PACKAGE DECLARATION---
21 < package uk.org.iscream.util;
21 > package uk.org.iscream.cms.server.util;
22  
23   //---IMPORTS---
24   import java.util.LinkedList;
25   import java.util.NoSuchElementException;
26   import java.util.Random;
27 < import uk.org.iscream.util.*;
27 > import uk.org.iscream.cms.server.util.*;
28  
29   /**
30   * A Queue class designed to operate in a multi-threaded environment, with
# Line 94 | Line 113 | public class Queue {
113          for(int i=0; i < _lists.size(); i++) {
114              // skip over any gaps left in the list
115              if(_lists.get(i) != null) {
116 <                // get size before adding to the Queue
117 <                int s = ((LinkedList) _lists.get(i)).size();
118 <                // check whether we need to remove an item from the current Queue
119 <                if(_maxSize!=-1 && s==_maxSize && _removeAlgorithm!=DROP) {
120 <                    // we need to remove an item
121 <                    removeQueueItem((LinkedList) _lists.get(i));
122 <                }
104 <                // check if we should add (not if Queue full, and using DROP algorithm)
105 <                if(!(s==_maxSize && _removeAlgorithm==DROP)) {
106 <                    // add the next item, ensuring we lock
107 <                    synchronized(this) {
108 <                        // LinkedList.add() does the same thing, but this ensures behaviour
109 <                        ((LinkedList) _lists.get(i)).addLast(o);
116 >                synchronized(((LinkedList) _lists.get(i))) {
117 >                    // get size before adding to the Queue
118 >                    int s = ((LinkedList) _lists.get(i)).size();
119 >                    // check whether we need to remove an item from the current Queue
120 >                    if(_maxSize!=-1 && s>=_maxSize && _removeAlgorithm!=DROP) {
121 >                        // we need to remove an item
122 >                        removeQueueItem((LinkedList) _lists.get(i));
123                      }
124 <                }
125 <                // if the queue was empty before the add it is possible
126 <                // that a consumer is waiting... so we notify them
127 <                if (s == 0) {
128 <                    synchronized(((LinkedList) _lists.get(i))) {
129 <                        ((LinkedList) _lists.get(i)).notifyAll();
124 >                    // check if we should add (not if Queue full, and using DROP algorithm)
125 >                    if(!(s>=_maxSize && _removeAlgorithm==DROP)) {
126 >                        // add the next item, ensuring we lock
127 >                        synchronized(this) {
128 >                            // LinkedList.add() does the same thing, but this ensures behaviour
129 >                            ((LinkedList) _lists.get(i)).addLast(o);
130 >                        }
131 >                        // if the queue was empty before the add it is possible
132 >                        // that a consumer is waiting... so we notify them
133 >                        //synchronized(((LinkedList) _lists.get(i))) {
134 >                            ((LinkedList) _lists.get(i)).notifyAll();
135 >                        //}
136                      }
137                  }
138              }
# Line 228 | Line 247 | public class Queue {
247      
248      /**
249       * Returns the total numer of elements to have passed
250 <     * through this queue (ie. a counter on the add method).
250 >     * through this queue. This is essentially a counter
251 >     * on the add method.
252       *
253       * @return the element-ometer.
254       */
# Line 332 | Line 352 | public class Queue {
352       * Overrides the {@link java.lang.Object#toString() Object.toString()}
353       * method to provide clean logging (every class should have this).
354       *
355 <     * This uses the uk.org.iscream.util.FormatName class
355 >     * This uses the uk.org.iscream.cms.server.util.FormatName class
356       * to format the toString()
357       *
358       * @return the name of this class and its CVS revision.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines