|
1 /* |
|
2 * ==================================================================== |
|
3 * |
|
4 * Licensed to the Apache Software Foundation (ASF) under one or more |
|
5 * contributor license agreements. See the NOTICE file distributed with |
|
6 * this work for additional information regarding copyright ownership. |
|
7 * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
8 * (the "License"); you may not use this file except in compliance with |
|
9 * the License. You may obtain a copy of the License at |
|
10 * |
|
11 * http://www.apache.org/licenses/LICENSE-2.0 |
|
12 * |
|
13 * Unless required by applicable law or agreed to in writing, software |
|
14 * distributed under the License is distributed on an "AS IS" BASIS, |
|
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
16 * See the License for the specific language governing permissions and |
|
17 * limitations under the License. |
|
18 * ==================================================================== |
|
19 * |
|
20 * This software consists of voluntary contributions made by many |
|
21 * individuals on behalf of the Apache Software Foundation. For more |
|
22 * information on the Apache Software Foundation, please see |
|
23 * <http://www.apache.org/>. |
|
24 * |
|
25 */ |
|
26 |
|
27 package ch.boye.httpclientandroidlib.impl.conn.tsccm; |
|
28 |
|
29 |
|
30 import java.lang.ref.WeakReference; |
|
31 import java.lang.ref.ReferenceQueue; |
|
32 |
|
33 import ch.boye.httpclientandroidlib.annotation.Immutable; |
|
34 |
|
35 import ch.boye.httpclientandroidlib.conn.routing.HttpRoute; |
|
36 |
|
37 |
|
38 |
|
39 /** |
|
40 * A weak reference to a {@link BasicPoolEntry BasicPoolEntry}. |
|
41 * This reference explicitly keeps the planned route, so the connection |
|
42 * can be reclaimed if it is lost to garbage collection. |
|
43 * |
|
44 * @since 4.0 |
|
45 */ |
|
46 @Immutable |
|
47 public class BasicPoolEntryRef extends WeakReference<BasicPoolEntry> { |
|
48 |
|
49 /** The planned route of the entry. */ |
|
50 private final HttpRoute route; // HttpRoute is @Immutable |
|
51 |
|
52 |
|
53 /** |
|
54 * Creates a new reference to a pool entry. |
|
55 * |
|
56 * @param entry the pool entry, must not be <code>null</code> |
|
57 * @param queue the reference queue, or <code>null</code> |
|
58 */ |
|
59 public BasicPoolEntryRef(BasicPoolEntry entry, |
|
60 ReferenceQueue<Object> queue) { |
|
61 super(entry, queue); |
|
62 if (entry == null) { |
|
63 throw new IllegalArgumentException |
|
64 ("Pool entry must not be null."); |
|
65 } |
|
66 route = entry.getPlannedRoute(); |
|
67 } |
|
68 |
|
69 |
|
70 /** |
|
71 * Obtain the planned route for the referenced entry. |
|
72 * The planned route is still available, even if the entry is gone. |
|
73 * |
|
74 * @return the planned route |
|
75 */ |
|
76 public final HttpRoute getRoute() { |
|
77 return this.route; |
|
78 } |
|
79 |
|
80 } // class BasicPoolEntryRef |
|
81 |