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