Coverage Report - com.sun.grizzly.connectioncache.client.CacheableConnectorHandlerPool
 
Classes in this File Line Coverage Branch Coverage Complexity
CacheableConnectorHandlerPool
100 %
19/19
N/A
0
CacheableConnectorHandlerPool$1
N/A
N/A
0
CacheableConnectorHandlerPool$CacheableConnectorInstanceHandler
100 %
2/2
N/A
0
 
 1  
 /*
 2  
  * 
 3  
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 4  
  * 
 5  
  * Copyright 2007-2008 Sun Microsystems, Inc. All rights reserved.
 6  
  * 
 7  
  * The contents of this file are subject to the terms of either the GNU
 8  
  * General Public License Version 2 only ("GPL") or the Common Development
 9  
  * and Distribution License("CDDL") (collectively, the "License").  You
 10  
  * may not use this file except in compliance with the License. You can obtain
 11  
  * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
 12  
  * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
 13  
  * language governing permissions and limitations under the License.
 14  
  * 
 15  
  * When distributing the software, include this License Header Notice in each
 16  
  * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
 17  
  * Sun designates this particular file as subject to the "Classpath" exception
 18  
  * as provided by Sun in the GPL Version 2 section of the License file that
 19  
  * accompanied this code.  If applicable, add the following below the License
 20  
  * Header, with the fields enclosed by brackets [] replaced by your own
 21  
  * identifying information: "Portions Copyrighted [year]
 22  
  * [name of copyright owner]"
 23  
  * 
 24  
  * Contributor(s):
 25  
  * 
 26  
  * If you wish your version of this file to be governed by only the CDDL or
 27  
  * only the GPL Version 2, indicate your decision by adding "[Contributor]
 28  
  * elects to include this software in this distribution under the [CDDL or GPL
 29  
  * Version 2] license."  If you don't indicate a single choice of license, a
 30  
  * recipient has the option to distribute your version of this file under
 31  
  * either the CDDL, the GPL Version 2 or to extend the choice of license to
 32  
  * its licensees as provided above.  However, if you add GPL Version 2 code
 33  
  * and therefore, elected the GPL Version 2 license, then the option applies
 34  
  * only if the new code is made subject to such option by the copyright
 35  
  * holder.
 36  
  *
 37  
  */
 38  
 
 39  
 package com.sun.grizzly.connectioncache.client;
 40  
 
 41  
 
 42  
 import com.sun.grizzly.ConnectorHandler;
 43  
 import com.sun.grizzly.ConnectorHandlerPool;
 44  
 import com.sun.grizzly.ConnectorInstanceHandler;
 45  
 import com.sun.grizzly.Controller;
 46  
 import com.sun.grizzly.Controller.Protocol;
 47  
 import com.sun.grizzly.DefaultConnectorHandlerPool;
 48  
 import com.sun.grizzly.connectioncache.spi.transport.ConnectionCacheFactory;
 49  
 import com.sun.grizzly.connectioncache.spi.transport.ConnectionFinder;
 50  
 import com.sun.grizzly.connectioncache.spi.transport.OutboundConnectionCache;
 51  
 
 52  
 /**
 53  
  * <code>ConnectorInstanceHandler</code> which use a
 54  
  * <code>ConcurrentQueue</code> to pool <code>CacheableConnectorHandler</code>
 55  
  *
 56  
  * @author Alexey Stashok
 57  
  */
 58  20
 public class CacheableConnectorHandlerPool implements 
 59  
         ConnectorHandlerPool<CacheableConnectorHandler> {
 60  
     
 61  
     private Controller controller;
 62  
     private ConnectorHandlerPool protocolConnectorHandlerPool;
 63  
     private ConnectorInstanceHandler<CacheableConnectorHandler> connectorInstanceHandler;
 64  
     private OutboundConnectionCache<ConnectorHandler> outboundConnectionCache;
 65  
     private ConnectionFinder<ConnectorHandler> connectionFinder;
 66  
     
 67  
     public CacheableConnectorHandlerPool(Controller controller, int highWaterMark,
 68  
             int numberToReclaim, int maxParallel) {
 69  1
             this(controller, highWaterMark, numberToReclaim, maxParallel, null);
 70  1
     }
 71  
     
 72  
     public CacheableConnectorHandlerPool(Controller controller, int highWaterMark,
 73  1
             int numberToReclaim, int maxParallel, ConnectionFinder<ConnectorHandler> connectionFinder) {
 74  1
         this.controller = controller;
 75  1
         this.outboundConnectionCache = 
 76  
                 ConnectionCacheFactory.<ConnectorHandler>makeBlockingOutboundConnectionCache(
 77  
                 "Grizzly outbound connection cache", highWaterMark, 
 78  
                 numberToReclaim, maxParallel, Controller.logger());
 79  1
         this.connectionFinder = connectionFinder;
 80  1
         protocolConnectorHandlerPool = new DefaultConnectorHandlerPool(controller);
 81  1
         connectorInstanceHandler = new CacheableConnectorInstanceHandler();
 82  1
     }
 83  
 
 84  
     public CacheableConnectorHandler acquireConnectorHandler(Protocol protocol) {
 85  10
         CacheableConnectorHandler connectorHandler = connectorInstanceHandler.acquire();
 86  10
         connectorHandler.setProtocol(protocol);
 87  10
         return connectorHandler;
 88  
     }
 89  
     
 90  
     public void releaseConnectorHandler(CacheableConnectorHandler connectorHandler) {
 91  10
         connectorInstanceHandler.release(connectorHandler);
 92  10
     }
 93  
     
 94  
     OutboundConnectionCache<ConnectorHandler> getOutboundConnectionCache() {
 95  20
         return outboundConnectionCache;
 96  
     }
 97  
 
 98  
     ConnectionFinder getConnectionFinder() {
 99  10
         return connectionFinder;
 100  
     }
 101  
 
 102  
     Controller getController() {
 103  9
         return controller;
 104  
     }
 105  
     
 106  
     ConnectorHandlerPool getProtocolConnectorHandlerPool() {
 107  1
         return protocolConnectorHandlerPool;
 108  
     }
 109  
             
 110  
     /**
 111  
      * Default <code>ConnectorInstanceHandler</code> which use a
 112  
      * <code>ConcurrentQueue</code> to pool {@link ConnectorHandler}
 113  
      */
 114  3
     private class CacheableConnectorInstanceHandler extends
 115  
             ConnectorInstanceHandler.ConcurrentQueueConnectorInstanceHandler<CacheableConnectorHandler> {
 116  
         
 117  
         public CacheableConnectorHandler newInstance() {
 118  1
             return new CacheableConnectorHandler(CacheableConnectorHandlerPool.this);
 119  
         }
 120  
     }
 121  
 }