1 22 package org.xsocket.stream; 23 24 import java.io.IOException ; 25 import java.lang.annotation.Inherited ; 26 import java.net.InetAddress ; 27 import java.net.InetSocketAddress ; 28 import java.util.concurrent.Executor ; 29 30 31 32 33 76 public final class BlockingConnectionPool extends AbstractConnectionPool { 77 78 public static final long UNLIMITED_TIMEOUT = AbstractConnectionPool.MAX_TIMEOUT; 79 80 85 public BlockingConnectionPool(long timeToIdleMillis) { 86 this(timeToIdleMillis, Integer.MAX_VALUE, NULL); 87 } 88 89 96 public BlockingConnectionPool(long timeToIdleMillis, int maxActive, long maxWaitTimeMillis) { 97 super(timeToIdleMillis, MAX_TIMEOUT, maxActive, maxWaitTimeMillis, MAX_SIZE); 98 } 99 100 101 109 public BlockingConnectionPool(long timeToIdleMillis, int maxActive, long maxWaitTimeMillis, int maxIdle) { 110 super(timeToIdleMillis, MAX_TIMEOUT, maxActive, maxWaitTimeMillis, maxIdle); 111 } 112 113 114 126 public IBlockingConnection getBlockingConnection(String host, int port) throws IOException , WaitTimeoutException { 127 return (IBlockingConnection) getConnection(new InetSocketAddress (host, port), null); 128 } 129 130 131 143 public IBlockingConnection getBlockingConnection(InetAddress address, int port) throws IOException , WaitTimeoutException { 144 return (IBlockingConnection) getConnection(new InetSocketAddress (address, port), null); 145 } 146 147 148 151 @Override 152 PoolableConnection createConnection(InetSocketAddress address, Executor workerPool) throws IOException { 153 return new PoolableBlockingConnection(address); 154 } 155 156 157 158 private final class PoolableBlockingConnection extends PoolableConnection implements IBlockingConnection { 159 160 public PoolableBlockingConnection(InetSocketAddress address) throws IOException { 161 super(BlockingConnectionPool.this, new BlockingConnection(address.getAddress(), address.getPort()), address); 162 } 163 164 public void setReceiveTimeoutMillis(long timeout) { 165 ((BlockingConnection) getDelegee()).setReceiveTimeoutMillis(timeout); 166 } 167 168 public IBlockingConnection setOption(String name, Object value) throws IOException { 169 return ((BlockingConnection) getDelegee()).setOption(name, value); 170 } 171 } 172 } 173 | Popular Tags |