@Override public Connection<CL> borrowConnection(Operation<CL, R> operation) throws ConnectionException { pool = null; connection = BagOfConnectionsConnectionPoolImpl.this.borrowConnection(operation); pool = connection.getHostConnectionPool(); return connection; }
@Override public int getReadTimeoutMillis() { return cpConfig.getSocketTimeout(); } }
@Override public void setHosts(Collection<Host> hosts) { if (hosts != null) { Logger.info("Setting hosts for listener here: " + listener.getClass().getName() + " " + hosts); lastHostList.set(hosts); } if (listener.get() != null) { Logger.info("Setting hosts for listener: " + listener.getClass().getName() + " " + hosts); listener.get().setHosts(hosts, cpConfig.getPort()); } }
public SimpleHostConnectionPool(Host host, ConnectionFactory<CL> factory, ConnectionPoolMonitor monitor, ConnectionPoolConfiguration config, Listener<CL> listener) { this.host = host; this.config = config; this.factory = factory; this.listener = listener; this.retryContext = config.getRetryBackoffStrategy().createInstance(); this.latencyStrategy = config.getLatencyScoreStrategy().createInstance(); this.badHostDetector = config.getBadHostDetector().createInstance(); this.monitor = monitor; this.availableConnections = new LinkedBlockingQueue<Connection<CL>>(); this.executor = config.getHostReconnectExecutor(); Preconditions.checkNotNull(config.getHostReconnectExecutor(), "HostReconnectExecutor cannot be null"); }
@Override public void shutdown() { isReconnecting.set(true); isShutdown.set(true); discardIdleConnections(); config.getLatencyScoreStrategy().removeInstance(this.latencyStrategy); config.getBadHostDetector().removeInstance(this.badHostDetector); }
/** * Starts the conn pool and resources associated with it */ @Override public void start() { ConnectionPoolMBeanManager.getInstance().registerMonitor(config.getName(), this); String seeds = config.getSeeds(); if (seeds != null && !seeds.isEmpty()) { setHosts(config.getSeedHosts()); } config.getLatencyScoreStrategy().start(new Listener() { @Override public void onUpdate() { rebuildPartitions(); } @Override public void onReset() { rebuildPartitions(); } }); }
final SSLConnectionContext sslCxt = cpConfig.getSSLConnectionContext(); if(sslCxt != null) { TSSLTransportParameters params = new TSSLTransportParameters(sslCxt.getSslProtocol(), sslCxt.getSslCipherSuites().toArray(new String[0])); params.setTrustStore(sslCxt.getSslTruststore(), sslCxt.getSslTruststorePassword()); socket = TSSLTransportFactory.getClientSocket(getHost().getIpAddress(), getHost().getPort(), cpConfig.getSocketTimeout(), params); } else { socket = new TSocket(getHost().getIpAddress(), getHost().getPort(), cpConfig.getConnectTimeout()); socket.getSocket().setSoLinger(false, 0); setTimeout(cpConfig.getSocketTimeout()); transport = new TFramedTransport(socket, maxThriftSize); if(!transport.isOpen()) monitor.incConnectionCreated(getHost()); AuthenticationCredentials credentials = cpConfig.getAuthenticationCredentials(); if (credentials != null) { Map<String, String> thriftCredentials = Maps.newHashMapWithExpectedSize(2); pool.addLatencySample(TimeUnit.NANOSECONDS.convert(cpConfig.getSocketTimeout(), TimeUnit.MILLISECONDS), System.nanoTime()); closeClient(); ConnectionException ce = ThriftConverter.ToConnectionPoolException(e).setHost(getHost()) pool.addLatencySample(TimeUnit.NANOSECONDS.convert(cpConfig.getSocketTimeout(), TimeUnit.MILLISECONDS), System.nanoTime()); closeClient(); ConnectionException ce = ThriftConverter.ToConnectionPoolException(new RuntimeException("Error openning connection", t)).setHost(getHost())
private ProtocolOptions getProtocolOptions() { int port = cpConfig.getPort(); AuthProvider authProvider = AuthProvider.NONE; AuthenticationCredentials creds = cpConfig.getAuthenticationCredentials(); if (creds != null) { authProvider = new PlainTextAuthProvider(creds.getUsername(), creds.getPassword()); } return new ProtocolOptions(port, ProtocolVersion.NEWEST_SUPPORTED, DEFAULT_MAX_SCHEMA_AGREEMENT_WAIT_SECONDS, null, authProvider); }
@Override public int getConnectTimeoutMillis() { return cpConfig.getConnectTimeout(); }
@Override public int getMaxConnectionsPerHost(HostDistance distance) { return cpConfig.getMaxConnsPerHost(); } }
public <T> AstyanaxContext<Keyspace> buildKeyspace(AstyanaxTypeFactory<T> factory) { this.cpConfig.initialize(); supplier = new RingDescribeHostSupplier(keyspace, cpConfig.getPort(), cpConfig.getLocalDatacenter()); break; supplier = new RingDescribeHostSupplier(keyspace, cpConfig.getPort(), cpConfig.getLocalDatacenter()); supplier = new FilteringHostSupplier(new RingDescribeHostSupplier(keyspace, cpConfig.getPort(), cpConfig.getLocalDatacenter()), hostSupplier);
Connection<CL> connection = null; if (activeCount.get() < config.getMaxConnsPerHost()) { try { if (activeCount.incrementAndGet() <= config.getMaxConnsPerHost()) { if (pendingConnections.incrementAndGet() > config.getMaxPendingConnectionsPerHost()) { pendingConnections.decrementAndGet();
@Override public boolean check(long currentTimeMillis) { int maxCount = config.getConnectionLimiterMaxPendingCount(); if (maxCount == 0) return true; // Haven't reached the count limit yet if (queue.size() < maxCount) { queue.addFirst(currentTimeMillis); return true; } else { long last = queue.getLast(); if (currentTimeMillis - last < config.getConnectionLimiterWindowSize()) { return false; } queue.addFirst(currentTimeMillis); queue.removeLast(); return true; } }
public NodeDiscoveryType getNodeDiscoveryType() { if (cpConfig.getSeeds() != null) { if (asConfig.getConnectionPoolType() == ConnectionPoolType.TOKEN_AWARE) return NodeDiscoveryType.RING_DESCRIBE; } else { if (asConfig.getConnectionPoolType() == ConnectionPoolType.TOKEN_AWARE) { return NodeDiscoveryType.TOKEN_AWARE; } else { return NodeDiscoveryType.DISCOVERY_SERVICE; } } return asConfig.getDiscoveryType(); }
final SSLConnectionContext sslCxt = cpConfig.getSSLConnectionContext(); if(sslCxt != null) { TSSLTransportParameters params = new TSSLTransportParameters(sslCxt.getSslProtocol(), sslCxt.getSslCipherSuites().toArray(new String[0])); params.setTrustStore(sslCxt.getSslTruststore(), sslCxt.getSslTruststorePassword()); socket = TSSLTransportFactory.getClientSocket(getHost().getIpAddress(), getHost().getPort(), cpConfig.getSocketTimeout(), params); } else { socket = new TSocket(getHost().getIpAddress(), getHost().getPort(), cpConfig.getConnectTimeout()); socket.getSocket().setSoLinger(false, 0); setTimeout(cpConfig.getSocketTimeout()); transport = new TFramedTransport(socket, maxThriftSize); if(!transport.isOpen()) monitor.incConnectionCreated(getHost()); AuthenticationCredentials credentials = cpConfig.getAuthenticationCredentials(); if (credentials != null) { Map<String, String> thriftCredentials = Maps.newHashMapWithExpectedSize(2); pool.addLatencySample(TimeUnit.NANOSECONDS.convert(cpConfig.getSocketTimeout(), TimeUnit.MILLISECONDS), System.nanoTime()); closeClient(); ConnectionException ce = ThriftConverter.ToConnectionPoolException(e).setHost(getHost()) pool.addLatencySample(TimeUnit.NANOSECONDS.convert(cpConfig.getSocketTimeout(), TimeUnit.MILLISECONDS), System.nanoTime()); closeClient(); ConnectionException ce = ThriftConverter.ToConnectionPoolException(new RuntimeException("Error openning connection", t)).setHost(getHost())
/** * Starts the conn pool and resources associated with it */ @Override public void start() { ConnectionPoolMBeanManager.getInstance().registerMonitor(config.getName(), this); String seeds = config.getSeeds(); if (seeds != null && !seeds.isEmpty()) { setHosts(config.getSeedHosts()); } config.getLatencyScoreStrategy().start(new Listener() { @Override public void onUpdate() { rebuildPartitions(); } @Override public void onReset() { rebuildPartitions(); } }); }
public SimpleHostConnectionPool(Host host, ConnectionFactory<CL> factory, ConnectionPoolMonitor monitor, ConnectionPoolConfiguration config, Listener<CL> listener) { this.host = host; this.config = config; this.factory = factory; this.listener = listener; this.retryContext = config.getRetryBackoffStrategy().createInstance(); this.latencyStrategy = config.getLatencyScoreStrategy().createInstance(); this.badHostDetector = config.getBadHostDetector().createInstance(); this.monitor = monitor; this.availableConnections = new LinkedBlockingQueue<Connection<CL>>(); this.executor = config.getHostReconnectExecutor(); Preconditions.checkNotNull(config.getHostReconnectExecutor(), "HostReconnectExecutor cannot be null"); }
connection = waitForConnection(isOpenning ? config.getConnectTimeout() : timeout); return connection;
@Override public int getCoreConnectionsPerHost(HostDistance distance) { return cpConfig.getMaxConnsPerHost() > 4 ? cpConfig.getMaxConnsPerHost()/2 : cpConfig.getMaxConnsPerHost(); }
Connection<CL> connection = null; if (activeCount.get() < config.getMaxConnsPerHost()) { try { if (activeCount.incrementAndGet() <= config.getMaxConnsPerHost()) { if (pendingConnections.incrementAndGet() > config.getMaxPendingConnectionsPerHost()) { pendingConnections.decrementAndGet();