Modified: websites/production/turbine/content/fulcrum/fulcrum-pool/apidocs/src-html/org/apache/fulcrum/pool/BoundedBuffer.html ============================================================================== --- websites/production/turbine/content/fulcrum/fulcrum-pool/apidocs/src-html/org/apache/fulcrum/pool/BoundedBuffer.html (original) +++ websites/production/turbine/content/fulcrum/fulcrum-pool/apidocs/src-html/org/apache/fulcrum/pool/BoundedBuffer.html Tue May 21 03:41:41 2019 @@ -1,157 +1,162 @@ -<HTML> -<BODY BGCOLOR="white"> -<PRE> -<FONT color="green">001</FONT> package org.apache.fulcrum.pool;<a name="line.1"></a> -<FONT color="green">002</FONT> <a name="line.2"></a> -<FONT color="green">003</FONT> <a name="line.3"></a> -<FONT color="green">004</FONT> /*<a name="line.4"></a> -<FONT color="green">005</FONT> * Licensed to the Apache Software Foundation (ASF) under one<a name="line.5"></a> -<FONT color="green">006</FONT> * or more contributor license agreements. See the NOTICE file<a name="line.6"></a> -<FONT color="green">007</FONT> * distributed with this work for additional information<a name="line.7"></a> -<FONT color="green">008</FONT> * regarding copyright ownership. The ASF licenses this file<a name="line.8"></a> -<FONT color="green">009</FONT> * to you under the Apache License, Version 2.0 (the<a name="line.9"></a> -<FONT color="green">010</FONT> * "License"); you may not use this file except in compliance<a name="line.10"></a> -<FONT color="green">011</FONT> * with the License. You may obtain a copy of the License at<a name="line.11"></a> -<FONT color="green">012</FONT> *<a name="line.12"></a> -<FONT color="green">013</FONT> * http://www.apache.org/licenses/LICENSE-2.0<a name="line.13"></a> -<FONT color="green">014</FONT> *<a name="line.14"></a> -<FONT color="green">015</FONT> * Unless required by applicable law or agreed to in writing,<a name="line.15"></a> -<FONT color="green">016</FONT> * software distributed under the License is distributed on an<a name="line.16"></a> -<FONT color="green">017</FONT> * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY<a name="line.17"></a> -<FONT color="green">018</FONT> * KIND, either express or implied. See the License for the<a name="line.18"></a> -<FONT color="green">019</FONT> * specific language governing permissions and limitations<a name="line.19"></a> -<FONT color="green">020</FONT> * under the License.<a name="line.20"></a> -<FONT color="green">021</FONT> */<a name="line.21"></a> -<FONT color="green">022</FONT> <a name="line.22"></a> -<FONT color="green">023</FONT> <a name="line.23"></a> -<FONT color="green">024</FONT> /**<a name="line.24"></a> -<FONT color="green">025</FONT> * Efficient array-based bounded buffer class.<a name="line.25"></a> -<FONT color="green">026</FONT> * Adapted from CPJ, chapter 8, which describes design.<a name="line.26"></a> -<FONT color="green">027</FONT> * Originally written by Doug Lea and released into the public domain.<a name="line.27"></a> -<FONT color="green">028</FONT> * <p>[<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>] <p><a name="line.28"></a> -<FONT color="green">029</FONT> *<a name="line.29"></a> -<FONT color="green">030</FONT> * @author <a href="mailto:[email protected]">Ilkka Priha</a><a name="line.30"></a> -<FONT color="green">031</FONT> * @version $Id: BoundedBuffer.java 535465 2007-05-05 06:58:06Z tv $<a name="line.31"></a> -<FONT color="green">032</FONT> */<a name="line.32"></a> -<FONT color="green">033</FONT> public class BoundedBuffer<a name="line.33"></a> -<FONT color="green">034</FONT> {<a name="line.34"></a> -<FONT color="green">035</FONT> /**<a name="line.35"></a> -<FONT color="green">036</FONT> * The default capacity.<a name="line.36"></a> -<FONT color="green">037</FONT> */<a name="line.37"></a> -<FONT color="green">038</FONT> public static final int DEFAULT_CAPACITY = 1024;<a name="line.38"></a> -<FONT color="green">039</FONT> <a name="line.39"></a> -<FONT color="green">040</FONT> protected final Object[] array_; // the elements<a name="line.40"></a> -<FONT color="green">041</FONT> <a name="line.41"></a> -<FONT color="green">042</FONT> protected int takePtr_ = 0; // circular indices<a name="line.42"></a> -<FONT color="green">043</FONT> protected int putPtr_ = 0;<a name="line.43"></a> -<FONT color="green">044</FONT> <a name="line.44"></a> -<FONT color="green">045</FONT> protected int usedSlots_ = 0; // length<a name="line.45"></a> -<FONT color="green">046</FONT> protected int emptySlots_; // capacity - length<a name="line.46"></a> -<FONT color="green">047</FONT> <a name="line.47"></a> -<FONT color="green">048</FONT> /**<a name="line.48"></a> -<FONT color="green">049</FONT> * Creates a buffer with the given capacity.<a name="line.49"></a> -<FONT color="green">050</FONT> *<a name="line.50"></a> -<FONT color="green">051</FONT> * @param capacity the capacity.<a name="line.51"></a> -<FONT color="green">052</FONT> * @throws IllegalArgumentException if capacity less or equal to zero.<a name="line.52"></a> -<FONT color="green">053</FONT> */<a name="line.53"></a> -<FONT color="green">054</FONT> public BoundedBuffer(int capacity)<a name="line.54"></a> -<FONT color="green">055</FONT> throws IllegalArgumentException<a name="line.55"></a> -<FONT color="green">056</FONT> {<a name="line.56"></a> -<FONT color="green">057</FONT> if (capacity <= 0)<a name="line.57"></a> -<FONT color="green">058</FONT> throw new IllegalArgumentException();<a name="line.58"></a> -<FONT color="green">059</FONT> <a name="line.59"></a> -<FONT color="green">060</FONT> array_ = new Object[capacity];<a name="line.60"></a> -<FONT color="green">061</FONT> emptySlots_ = capacity;<a name="line.61"></a> -<FONT color="green">062</FONT> }<a name="line.62"></a> -<FONT color="green">063</FONT> <a name="line.63"></a> -<FONT color="green">064</FONT> /**<a name="line.64"></a> -<FONT color="green">065</FONT> * Creates a buffer with the default capacity<a name="line.65"></a> -<FONT color="green">066</FONT> */<a name="line.66"></a> -<FONT color="green">067</FONT> public BoundedBuffer()<a name="line.67"></a> -<FONT color="green">068</FONT> {<a name="line.68"></a> -<FONT color="green">069</FONT> this(DEFAULT_CAPACITY);<a name="line.69"></a> -<FONT color="green">070</FONT> }<a name="line.70"></a> -<FONT color="green">071</FONT> <a name="line.71"></a> -<FONT color="green">072</FONT> /**<a name="line.72"></a> -<FONT color="green">073</FONT> * Returns the number of elements in the buffer.<a name="line.73"></a> -<FONT color="green">074</FONT> * This is only a snapshot value, that may change<a name="line.74"></a> -<FONT color="green">075</FONT> * immediately after returning.<a name="line.75"></a> -<FONT color="green">076</FONT> *<a name="line.76"></a> -<FONT color="green">077</FONT> * @return the size.<a name="line.77"></a> -<FONT color="green">078</FONT> */<a name="line.78"></a> -<FONT color="green">079</FONT> public synchronized int size()<a name="line.79"></a> -<FONT color="green">080</FONT> {<a name="line.80"></a> -<FONT color="green">081</FONT> return usedSlots_;<a name="line.81"></a> -<FONT color="green">082</FONT> }<a name="line.82"></a> -<FONT color="green">083</FONT> <a name="line.83"></a> -<FONT color="green">084</FONT> /**<a name="line.84"></a> -<FONT color="green">085</FONT> * Returns the capacity of the buffer.<a name="line.85"></a> -<FONT color="green">086</FONT> *<a name="line.86"></a> -<FONT color="green">087</FONT> * @return the capacity.<a name="line.87"></a> -<FONT color="green">088</FONT> */<a name="line.88"></a> -<FONT color="green">089</FONT> public int capacity()<a name="line.89"></a> -<FONT color="green">090</FONT> {<a name="line.90"></a> -<FONT color="green">091</FONT> return array_.length;<a name="line.91"></a> -<FONT color="green">092</FONT> }<a name="line.92"></a> -<FONT color="green">093</FONT> <a name="line.93"></a> -<FONT color="green">094</FONT> /**<a name="line.94"></a> -<FONT color="green">095</FONT> * Peeks, but does not remove the top item from the buffer.<a name="line.95"></a> -<FONT color="green">096</FONT> *<a name="line.96"></a> -<FONT color="green">097</FONT> * @return the object or null.<a name="line.97"></a> -<FONT color="green">098</FONT> */<a name="line.98"></a> -<FONT color="green">099</FONT> public synchronized Object peek()<a name="line.99"></a> -<FONT color="green">100</FONT> {<a name="line.100"></a> -<FONT color="green">101</FONT> if (usedSlots_ > 0)<a name="line.101"></a> -<FONT color="green">102</FONT> return array_[takePtr_];<a name="line.102"></a> -<FONT color="green">103</FONT> else<a name="line.103"></a> -<FONT color="green">104</FONT> return null;<a name="line.104"></a> -<FONT color="green">105</FONT> }<a name="line.105"></a> -<FONT color="green">106</FONT> <a name="line.106"></a> -<FONT color="green">107</FONT> /**<a name="line.107"></a> -<FONT color="green">108</FONT> * Puts an item in the buffer only if there is capacity available.<a name="line.108"></a> -<FONT color="green">109</FONT> *<a name="line.109"></a> -<FONT color="green">110</FONT> * @param item the item to be inserted.<a name="line.110"></a> -<FONT color="green">111</FONT> * @return true if accepted, else false.<a name="line.111"></a> -<FONT color="green">112</FONT> */<a name="line.112"></a> -<FONT color="green">113</FONT> public synchronized boolean offer(Object x)<a name="line.113"></a> -<FONT color="green">114</FONT> {<a name="line.114"></a> -<FONT color="green">115</FONT> if (x == null)<a name="line.115"></a> -<FONT color="green">116</FONT> throw new IllegalArgumentException();<a name="line.116"></a> -<FONT color="green">117</FONT> <a name="line.117"></a> -<FONT color="green">118</FONT> if (emptySlots_ > 0)<a name="line.118"></a> -<FONT color="green">119</FONT> {<a name="line.119"></a> -<FONT color="green">120</FONT> --emptySlots_;<a name="line.120"></a> -<FONT color="green">121</FONT> array_[putPtr_] = x;<a name="line.121"></a> -<FONT color="green">122</FONT> if (++putPtr_ >= array_.length)<a name="line.122"></a> -<FONT color="green">123</FONT> putPtr_ = 0;<a name="line.123"></a> -<FONT color="green">124</FONT> usedSlots_++;<a name="line.124"></a> -<FONT color="green">125</FONT> return true;<a name="line.125"></a> -<FONT color="green">126</FONT> }<a name="line.126"></a> -<FONT color="green">127</FONT> else<a name="line.127"></a> -<FONT color="green">128</FONT> return false;<a name="line.128"></a> -<FONT color="green">129</FONT> }<a name="line.129"></a> -<FONT color="green">130</FONT> <a name="line.130"></a> -<FONT color="green">131</FONT> /**<a name="line.131"></a> -<FONT color="green">132</FONT> * Polls and removes the top item from the buffer if one is available.<a name="line.132"></a> -<FONT color="green">133</FONT> *<a name="line.133"></a> -<FONT color="green">134</FONT> * @return the oldest item from the buffer, or null if the buffer is empty.<a name="line.134"></a> -<FONT color="green">135</FONT> */<a name="line.135"></a> -<FONT color="green">136</FONT> public synchronized Object poll()<a name="line.136"></a> -<FONT color="green">137</FONT> {<a name="line.137"></a> -<FONT color="green">138</FONT> if (usedSlots_ > 0)<a name="line.138"></a> -<FONT color="green">139</FONT> {<a name="line.139"></a> -<FONT color="green">140</FONT> --usedSlots_;<a name="line.140"></a> -<FONT color="green">141</FONT> Object old = array_[takePtr_];<a name="line.141"></a> -<FONT color="green">142</FONT> array_[takePtr_] = null;<a name="line.142"></a> -<FONT color="green">143</FONT> if (++takePtr_ >= array_.length)<a name="line.143"></a> -<FONT color="green">144</FONT> takePtr_ = 0;<a name="line.144"></a> -<FONT color="green">145</FONT> emptySlots_++;<a name="line.145"></a> -<FONT color="green">146</FONT> return old;<a name="line.146"></a> -<FONT color="green">147</FONT> }<a name="line.147"></a> -<FONT color="green">148</FONT> else<a name="line.148"></a> -<FONT color="green">149</FONT> return null;<a name="line.149"></a> -<FONT color="green">150</FONT> }<a name="line.150"></a> -<FONT color="green">151</FONT> }<a name="line.151"></a> +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<html lang="en"> +<head> +<title>Source code</title> +<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style"> +</head> +<body> +<div class="sourceContainer"> +<pre><span class="sourceLineNo">001</span>package org.apache.fulcrum.pool;<a name="line.1"></a> +<span class="sourceLineNo">002</span><a name="line.2"></a> +<span class="sourceLineNo">003</span><a name="line.3"></a> +<span class="sourceLineNo">004</span>/*<a name="line.4"></a> +<span class="sourceLineNo">005</span> * Licensed to the Apache Software Foundation (ASF) under one<a name="line.5"></a> +<span class="sourceLineNo">006</span> * or more contributor license agreements. See the NOTICE file<a name="line.6"></a> +<span class="sourceLineNo">007</span> * distributed with this work for additional information<a name="line.7"></a> +<span class="sourceLineNo">008</span> * regarding copyright ownership. The ASF licenses this file<a name="line.8"></a> +<span class="sourceLineNo">009</span> * to you under the Apache License, Version 2.0 (the<a name="line.9"></a> +<span class="sourceLineNo">010</span> * "License"); you may not use this file except in compliance<a name="line.10"></a> +<span class="sourceLineNo">011</span> * with the License. You may obtain a copy of the License at<a name="line.11"></a> +<span class="sourceLineNo">012</span> *<a name="line.12"></a> +<span class="sourceLineNo">013</span> * http://www.apache.org/licenses/LICENSE-2.0<a name="line.13"></a> +<span class="sourceLineNo">014</span> *<a name="line.14"></a> +<span class="sourceLineNo">015</span> * Unless required by applicable law or agreed to in writing,<a name="line.15"></a> +<span class="sourceLineNo">016</span> * software distributed under the License is distributed on an<a name="line.16"></a> +<span class="sourceLineNo">017</span> * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY<a name="line.17"></a> +<span class="sourceLineNo">018</span> * KIND, either express or implied. See the License for the<a name="line.18"></a> +<span class="sourceLineNo">019</span> * specific language governing permissions and limitations<a name="line.19"></a> +<span class="sourceLineNo">020</span> * under the License.<a name="line.20"></a> +<span class="sourceLineNo">021</span> */<a name="line.21"></a> +<span class="sourceLineNo">022</span><a name="line.22"></a> +<span class="sourceLineNo">023</span><a name="line.23"></a> +<span class="sourceLineNo">024</span>/**<a name="line.24"></a> +<span class="sourceLineNo">025</span> * Efficient array-based bounded buffer class.<a name="line.25"></a> +<span class="sourceLineNo">026</span> * Adapted from CPJ, chapter 8, which describes design.<a name="line.26"></a> +<span class="sourceLineNo">027</span> * Originally written by Doug Lea and released into the public domain.<a name="line.27"></a> +<span class="sourceLineNo">028</span> * <p>[<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>] <p><a name="line.28"></a> +<span class="sourceLineNo">029</span> *<a name="line.29"></a> +<span class="sourceLineNo">030</span> * @author <a href="mailto:[email protected]">Ilkka Priha</a><a name="line.30"></a> +<span class="sourceLineNo">031</span> * @version $Id: BoundedBuffer.java 1845817 2018-11-05 15:42:25Z painter $<a name="line.31"></a> +<span class="sourceLineNo">032</span> */<a name="line.32"></a> +<span class="sourceLineNo">033</span>public class BoundedBuffer<a name="line.33"></a> +<span class="sourceLineNo">034</span>{<a name="line.34"></a> +<span class="sourceLineNo">035</span> /**<a name="line.35"></a> +<span class="sourceLineNo">036</span> * The default capacity.<a name="line.36"></a> +<span class="sourceLineNo">037</span> */<a name="line.37"></a> +<span class="sourceLineNo">038</span> public static final int DEFAULT_CAPACITY = 1024;<a name="line.38"></a> +<span class="sourceLineNo">039</span><a name="line.39"></a> +<span class="sourceLineNo">040</span> protected final Object[] array_; // the elements<a name="line.40"></a> +<span class="sourceLineNo">041</span><a name="line.41"></a> +<span class="sourceLineNo">042</span> protected int takePtr_ = 0; // circular indices<a name="line.42"></a> +<span class="sourceLineNo">043</span> protected int putPtr_ = 0;<a name="line.43"></a> +<span class="sourceLineNo">044</span><a name="line.44"></a> +<span class="sourceLineNo">045</span> protected int usedSlots_ = 0; // length<a name="line.45"></a> +<span class="sourceLineNo">046</span> protected int emptySlots_; // capacity - length<a name="line.46"></a> +<span class="sourceLineNo">047</span><a name="line.47"></a> +<span class="sourceLineNo">048</span> /**<a name="line.48"></a> +<span class="sourceLineNo">049</span> * Creates a buffer with the given capacity.<a name="line.49"></a> +<span class="sourceLineNo">050</span> *<a name="line.50"></a> +<span class="sourceLineNo">051</span> * @param capacity the capacity.<a name="line.51"></a> +<span class="sourceLineNo">052</span> * @throws IllegalArgumentException if capacity less or equal to zero.<a name="line.52"></a> +<span class="sourceLineNo">053</span> */<a name="line.53"></a> +<span class="sourceLineNo">054</span> public BoundedBuffer(int capacity)<a name="line.54"></a> +<span class="sourceLineNo">055</span> throws IllegalArgumentException<a name="line.55"></a> +<span class="sourceLineNo">056</span> {<a name="line.56"></a> +<span class="sourceLineNo">057</span> if (capacity <= 0)<a name="line.57"></a> +<span class="sourceLineNo">058</span> throw new IllegalArgumentException();<a name="line.58"></a> +<span class="sourceLineNo">059</span><a name="line.59"></a> +<span class="sourceLineNo">060</span> array_ = new Object[capacity];<a name="line.60"></a> +<span class="sourceLineNo">061</span> emptySlots_ = capacity;<a name="line.61"></a> +<span class="sourceLineNo">062</span> }<a name="line.62"></a> +<span class="sourceLineNo">063</span><a name="line.63"></a> +<span class="sourceLineNo">064</span> /**<a name="line.64"></a> +<span class="sourceLineNo">065</span> * Creates a buffer with the default capacity<a name="line.65"></a> +<span class="sourceLineNo">066</span> */<a name="line.66"></a> +<span class="sourceLineNo">067</span> public BoundedBuffer()<a name="line.67"></a> +<span class="sourceLineNo">068</span> {<a name="line.68"></a> +<span class="sourceLineNo">069</span> this(DEFAULT_CAPACITY);<a name="line.69"></a> +<span class="sourceLineNo">070</span> }<a name="line.70"></a> +<span class="sourceLineNo">071</span><a name="line.71"></a> +<span class="sourceLineNo">072</span> /**<a name="line.72"></a> +<span class="sourceLineNo">073</span> * Returns the number of elements in the buffer.<a name="line.73"></a> +<span class="sourceLineNo">074</span> * This is only a snapshot value, that may change<a name="line.74"></a> +<span class="sourceLineNo">075</span> * immediately after returning.<a name="line.75"></a> +<span class="sourceLineNo">076</span> *<a name="line.76"></a> +<span class="sourceLineNo">077</span> * @return the size.<a name="line.77"></a> +<span class="sourceLineNo">078</span> */<a name="line.78"></a> +<span class="sourceLineNo">079</span> public synchronized int size()<a name="line.79"></a> +<span class="sourceLineNo">080</span> {<a name="line.80"></a> +<span class="sourceLineNo">081</span> return usedSlots_;<a name="line.81"></a> +<span class="sourceLineNo">082</span> }<a name="line.82"></a> +<span class="sourceLineNo">083</span><a name="line.83"></a> +<span class="sourceLineNo">084</span> /**<a name="line.84"></a> +<span class="sourceLineNo">085</span> * Returns the capacity of the buffer.<a name="line.85"></a> +<span class="sourceLineNo">086</span> *<a name="line.86"></a> +<span class="sourceLineNo">087</span> * @return the capacity.<a name="line.87"></a> +<span class="sourceLineNo">088</span> */<a name="line.88"></a> +<span class="sourceLineNo">089</span> public int capacity()<a name="line.89"></a> +<span class="sourceLineNo">090</span> {<a name="line.90"></a> +<span class="sourceLineNo">091</span> return array_.length;<a name="line.91"></a> +<span class="sourceLineNo">092</span> }<a name="line.92"></a> +<span class="sourceLineNo">093</span><a name="line.93"></a> +<span class="sourceLineNo">094</span> /**<a name="line.94"></a> +<span class="sourceLineNo">095</span> * Peeks, but does not remove the top item from the buffer.<a name="line.95"></a> +<span class="sourceLineNo">096</span> *<a name="line.96"></a> +<span class="sourceLineNo">097</span> * @return the object or null.<a name="line.97"></a> +<span class="sourceLineNo">098</span> */<a name="line.98"></a> +<span class="sourceLineNo">099</span> public synchronized Object peek()<a name="line.99"></a> +<span class="sourceLineNo">100</span> {<a name="line.100"></a> +<span class="sourceLineNo">101</span> if (usedSlots_ > 0)<a name="line.101"></a> +<span class="sourceLineNo">102</span> return array_[takePtr_];<a name="line.102"></a> +<span class="sourceLineNo">103</span> else<a name="line.103"></a> +<span class="sourceLineNo">104</span> return null;<a name="line.104"></a> +<span class="sourceLineNo">105</span> }<a name="line.105"></a> +<span class="sourceLineNo">106</span><a name="line.106"></a> +<span class="sourceLineNo">107</span> /**<a name="line.107"></a> +<span class="sourceLineNo">108</span> * Puts an item in the buffer only if there is capacity available.<a name="line.108"></a> +<span class="sourceLineNo">109</span> *<a name="line.109"></a> +<span class="sourceLineNo">110</span> * @param x the item to be inserted.<a name="line.110"></a> +<span class="sourceLineNo">111</span> * @return true if accepted, else false.<a name="line.111"></a> +<span class="sourceLineNo">112</span> */<a name="line.112"></a> +<span class="sourceLineNo">113</span> public synchronized boolean offer(Object x)<a name="line.113"></a> +<span class="sourceLineNo">114</span> {<a name="line.114"></a> +<span class="sourceLineNo">115</span> if (x == null)<a name="line.115"></a> +<span class="sourceLineNo">116</span> throw new IllegalArgumentException();<a name="line.116"></a> +<span class="sourceLineNo">117</span><a name="line.117"></a> +<span class="sourceLineNo">118</span> if (emptySlots_ > 0)<a name="line.118"></a> +<span class="sourceLineNo">119</span> {<a name="line.119"></a> +<span class="sourceLineNo">120</span> --emptySlots_;<a name="line.120"></a> +<span class="sourceLineNo">121</span> array_[putPtr_] = x;<a name="line.121"></a> +<span class="sourceLineNo">122</span> if (++putPtr_ >= array_.length)<a name="line.122"></a> +<span class="sourceLineNo">123</span> putPtr_ = 0;<a name="line.123"></a> +<span class="sourceLineNo">124</span> usedSlots_++;<a name="line.124"></a> +<span class="sourceLineNo">125</span> return true;<a name="line.125"></a> +<span class="sourceLineNo">126</span> }<a name="line.126"></a> +<span class="sourceLineNo">127</span> else<a name="line.127"></a> +<span class="sourceLineNo">128</span> return false;<a name="line.128"></a> +<span class="sourceLineNo">129</span> }<a name="line.129"></a> +<span class="sourceLineNo">130</span><a name="line.130"></a> +<span class="sourceLineNo">131</span> /**<a name="line.131"></a> +<span class="sourceLineNo">132</span> * Polls and removes the top item from the buffer if one is available.<a name="line.132"></a> +<span class="sourceLineNo">133</span> *<a name="line.133"></a> +<span class="sourceLineNo">134</span> * @return the oldest item from the buffer, or null if the buffer is empty.<a name="line.134"></a> +<span class="sourceLineNo">135</span> */<a name="line.135"></a> +<span class="sourceLineNo">136</span> public synchronized Object poll()<a name="line.136"></a> +<span class="sourceLineNo">137</span> {<a name="line.137"></a> +<span class="sourceLineNo">138</span> if (usedSlots_ > 0)<a name="line.138"></a> +<span class="sourceLineNo">139</span> {<a name="line.139"></a> +<span class="sourceLineNo">140</span> --usedSlots_;<a name="line.140"></a> +<span class="sourceLineNo">141</span> Object old = array_[takePtr_];<a name="line.141"></a> +<span class="sourceLineNo">142</span> array_[takePtr_] = null;<a name="line.142"></a> +<span class="sourceLineNo">143</span> if (++takePtr_ >= array_.length)<a name="line.143"></a> +<span class="sourceLineNo">144</span> takePtr_ = 0;<a name="line.144"></a> +<span class="sourceLineNo">145</span> emptySlots_++;<a name="line.145"></a> +<span class="sourceLineNo">146</span> return old;<a name="line.146"></a> +<span class="sourceLineNo">147</span> }<a name="line.147"></a> +<span class="sourceLineNo">148</span> else<a name="line.148"></a> +<span class="sourceLineNo">149</span> return null;<a name="line.149"></a> +<span class="sourceLineNo">150</span> }<a name="line.150"></a> +<span class="sourceLineNo">151</span>}<a name="line.151"></a> @@ -212,6 +217,7 @@ -</PRE> -</BODY> -</HTML> +</pre> +</div> +</body> +</html> \ No newline at end of file
