01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Dmitry B. Yershov
19: * @version $Revision: 1.1.2.1.4.3 $
20: */package java.lang.ref;
21:
22: /**
23: * @com.intel.drl.spec_ref
24: */
25: public class ReferenceQueue<T> extends Object {
26:
27: private Reference<? extends T> firstReference;
28:
29: /**
30: * @com.intel.drl.spec_ref
31: */
32: public ReferenceQueue() {
33: }
34:
35: /**
36: * @com.intel.drl.spec_ref
37: */
38: @SuppressWarnings("unchecked")
39: public synchronized Reference<? extends T> poll() {
40: if (firstReference == null)
41: return null;
42: Reference<? extends T> ref = firstReference;
43: firstReference = (firstReference.next == firstReference ? null
44: : firstReference.next);
45: ref.next = null;
46: return ref;
47: }
48:
49: /**
50: * @com.intel.drl.spec_ref
51: */
52: @SuppressWarnings("unchecked")
53: public synchronized Reference<? extends T> remove(long timeout)
54: throws IllegalArgumentException, InterruptedException {
55: if (firstReference == null)
56: wait(timeout);
57: if (firstReference == null)
58: return null;
59: Reference<? extends T> ref = firstReference;
60: firstReference = (firstReference.next == firstReference ? null
61: : firstReference.next);
62: ref.next = null;
63: return ref;
64: }
65:
66: /**
67: * @com.intel.drl.spec_ref
68: */
69: public Reference<? extends T> remove() throws InterruptedException {
70: return remove(0L);
71: }
72:
73: synchronized boolean enqueue(Reference<? extends T> ref) {
74: ref.next = (firstReference == null ? ref : firstReference);
75: firstReference = ref;
76: notify();
77: return true;
78: }
79: }
|