1090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson/*
21d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Copyright (C) 2007 The Guava Authors
3090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson *
4090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * Licensed under the Apache License, Version 2.0 (the "License");
5090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * you may not use this file except in compliance with the License.
6090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * You may obtain a copy of the License at
7090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson *
8090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * http://www.apache.org/licenses/LICENSE-2.0
9090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson *
10090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * Unless required by applicable law or agreed to in writing, software
11090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS,
12090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * See the License for the specific language governing permissions and
14090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * limitations under the License.
15090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson */
16090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
17090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonpackage com.google.common.base;
18090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
19090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonimport java.lang.ref.PhantomReference;
201d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertimport java.lang.ref.ReferenceQueue;
21090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
22090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson/**
231d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Phantom reference with a {@code finalizeReferent()} method which a background thread invokes
241d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * after the garbage collector reclaims the referent. This is a simpler alternative to using a
251d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * {@link ReferenceQueue}.
26090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson *
271d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * <p>Unlike a normal phantom reference, this reference will be cleared automatically.
28090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson *
29090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * @author Bob Lee
301d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @since 2.0 (imported from Google Collections Library)
31090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson */
321d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertpublic abstract class FinalizablePhantomReference<T> extends PhantomReference<T>
331d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert    implements FinalizableReference {
34090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  /**
35090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson   * Constructs a new finalizable phantom reference.
36090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson   *
37090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson   * @param referent to phantom reference
38090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson   * @param queue that should finalize the referent
39090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson   */
401d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert  protected FinalizablePhantomReference(T referent, FinalizableReferenceQueue queue) {
41090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    super(referent, queue.queue);
42090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    queue.cleanUp();
43090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  }
44090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson}
45