KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > knowgate > scheduler > AtomQueue


1 /*
2   Copyright (C) 2003 Know Gate S.L. All rights reserved.
3                       C/Oņa, 107 1š2 28050 Madrid (Spain)
4
5   Redistribution and use in source and binary forms, with or without
6   modification, are permitted provided that the following conditions
7   are met:
8
9   1. Redistributions of source code must retain the above copyright
10      notice, this list of conditions and the following disclaimer.
11
12   2. The end-user documentation included with the redistribution,
13      if any, must include the following acknowledgment:
14      "This product includes software parts from hipergate
15      (http://www.hipergate.org/)."
16      Alternately, this acknowledgment may appear in the software itself,
17      if and wherever such third-party acknowledgments normally appear.
18
19   3. The name hipergate must not be used to endorse or promote products
20      derived from this software without prior written permission.
21      Products derived from this software may not be called hipergate,
22      nor may hipergate appear in their name, without prior written
23      permission.
24
25   This library is distributed in the hope that it will be useful,
26   but WITHOUT ANY WARRANTY; without even the implied warranty of
27   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
28
29   You should have received a copy of hipergate License with this code;
30   if not, visit http://www.hipergate.org or mail to info@hipergate.org
31 */

32
33 package com.knowgate.scheduler;
34
35
36 import java.util.LinkedList JavaDoc;
37
38 /**
39  * <p>Memory FIFO Queue for job atoms pending of processing</p>
40  * @author Sergio Montoro Ten
41  * @version 1.0
42  */

43 public class AtomQueue extends LinkedList JavaDoc {
44   private int iMaxAtoms;
45
46   /**
47    * Create an empty queue with a maximum of 1000 atoms
48    */

49   public AtomQueue() {
50     iMaxAtoms = 1000;
51   }
52
53   /**
54    * Create an empty queue
55    * @param iMaxSize Maximum number of atoms that the queue can mantain in memory
56    */

57   public AtomQueue(int iMaxSize) {
58     iMaxAtoms = iMaxSize;
59   }
60
61   // ----------------------------------------------------------
62

63   /**
64    * @return Maximum number of atoms that the queue can mantain in memory
65    */

66   public int maxsize() {
67     return iMaxAtoms;
68   }
69
70   // ----------------------------------------------------------
71

72   /**
73    * <p>Add an atom to the end of the queue</p>
74    * @param oAtm Atom object to be added
75    */

76
77   public synchronized void push(Atom oAtm) {
78     addLast(oAtm);
79   }
80
81   // ----------------------------------------------------------
82

83   /**
84    * <p>Pop first available atom from queue</p>
85    */

86
87   public synchronized Atom pop() {
88     Atom oAtm;
89     if (this.size()>0) {
90       oAtm = (Atom) getFirst();
91       removeFirst();
92     } else {
93       oAtm = null;
94     }
95     return oAtm;
96   } // pop
97

98 } // AtomQueue
Popular Tags