private Host(String jvmRoute, InetSocketAddress bindAddress, URI uri, XnioSsl ssl, OptionMap options) { this.connectionPool = new ProxyConnectionPool(this, bindAddress, uri, ssl, client, options); this.jvmRoute = jvmRoute; this.uri = uri; this.ssl = ssl; }
protected boolean checkAvailable(final boolean existingSession) { if (allAreClear(state, ERROR | REMOVED)) { // Check the state of the queue on the connection pool final ProxyConnectionPool.AvailabilityType availability = connectionPool.available(); if (availability == ProxyConnectionPool.AvailabilityType.AVAILABLE) { return true; } else if (availability == ProxyConnectionPool.AvailabilityType.FULL) { if (existingSession) { return true; } else if (nodeConfig.isQueueNewRequests()) { return true; } } } return false; }
protected void markRemoved() { int oldState, newState; for (;;) { oldState = this.state; newState = oldState | REMOVED; if (stateUpdater.compareAndSet(this, oldState, newState)) { connectionPool.close(); return; } } }
static void printProxyStat(StringBuilder buf, Node node, boolean reduceDisplay) { String status = "NOTOK"; if (node.getStatus() == NodeStatus.NODE_UP) status = "OK"; if (reduceDisplay) { buf.append(" " + status + " "); } else { buf.append(",Status: " + status + ",Elected: " + node.getElected() + ",Read: " + node.getConnectionPool().getClientStatistics().getRead() + ",Transferred: " + node.getConnectionPool().getClientStatistics().getWritten() + ",Connected: " + node.getConnectionPool().getOpenConnections() + ",Load: " + node.getLoad()); } }
HostThreadData data = getData(); ConnectionHolder connectionHolder = data.availableConnections.poll(); while (connectionHolder != null && !connectionHolder.clientConnection.isOpen()) { data.connections--; connectionReady(connectionHolder, callback, exchange, exclusive); } else if (exclusive || data.connections < maxConnections) { openConnection(exchange, callback, data, exclusive); } else {
HostThreadData hostData = getData(); if (closed) { con = hostData.availableConnections.poll(); redistributeQueued(hostData); return; connectionReady(connectionHolder, callback.getCallback(), callback.getExchange(), false); } else { final int cachedConnectionCount = hostData.availableConnections.size(); handleClosedConnection(hostData, connectionHolder);
@Override public void resetStatistics() { node.getConnectionPool().getClientStatistics().reset(); } }
@Override public URI getUri() { return node.getConnectionPool().getUri(); }
@Override public void run() { node.getConnectionPool().connect(null, exchange, new ProxyCallback<ProxyConnection>() { @Override public void completed(final HttpServerExchange exchange, ProxyConnection result) { final RequestExchangeListener exchangeListener = new RequestExchangeListener(callback, NodeHealthChecker.NO_CHECK, false); exchange.dispatch(SameThreadExecutor.INSTANCE, new ConnectionPoolPingTask(result, exchangeListener, node.getNodeConfig().getConnectionURI())); // Schedule timeout task scheduleCancelTask(exchange.getIoThread(), exchangeListener, timeout, TimeUnit.SECONDS); } @Override public void failed(HttpServerExchange exchange) { callback.failed(); } @Override public void queuedRequestFailed(HttpServerExchange exchange) { callback.failed(); } @Override public void couldNotResolveBackend(HttpServerExchange exchange) { callback.failed(); } }, timeout, TimeUnit.SECONDS, false); } });
@Override public int getOpenConnections() { return node.getConnectionPool().getOpenConnections(); }
void closeCurrentConnections() { connectionPool.closeCurrentConnections(); } }
public AvailabilityType available() { if (closed) { return AvailabilityType.CLOSED; } if (!connectionPoolManager.isAvailable()) { return AvailabilityType.PROBLEM; } HostThreadData data = getData(); if (data.connections < maxConnections) { return AvailabilityType.AVAILABLE; } if (!data.availableConnections.isEmpty()) { return AvailabilityType.AVAILABLE; } if (data.awaitingConnections.size() >= connectionPoolManager.getMaxQueueSize()) { return AvailabilityType.FULL_QUEUE; } return AvailabilityType.FULL; }
HostThreadData hostData = getData(); if (closed) { con = hostData.availableConnections.poll(); redistributeQueued(hostData); return; connectionReady(connectionHolder, callback.getCallback(), callback.getExchange(), false); } else { final int cachedConnectionCount = hostData.availableConnections.size(); handleClosedConnection(hostData, connectionHolder);
HostThreadData data = getData(); ConnectionHolder connectionHolder = data.availableConnections.poll(); while (connectionHolder != null && !connectionHolder.clientConnection.isOpen()) { data.connections--; connectionReady(connectionHolder, callback, exchange, exclusive); } else if (exclusive || data.connections < maxConnections) { openConnection(exchange, callback, data, exclusive); } else {
static void printInfo(final Node node, final StringBuilder builder) { builder.append("Node: ") .append("[").append(node.getId()).append("]") .append(",Name: ").append(node.getJvmRoute()) .append(",Balancer: ").append(node.getNodeConfig().getBalancer()) .append(",LBGroup: ").append(formatString(node.getNodeConfig().getDomain())) .append(",Host: ").append(node.getNodeConfig().getConnectionURI().getHost()) .append(",Port: ").append(node.getNodeConfig().getConnectionURI().getPort()) .append(",Type: ").append(node.getNodeConfig().getConnectionURI().getScheme()) .append(",Flushpackets: ").append(toStringOnOff(node.getNodeConfig().isFlushPackets())) .append(",Flushwait: ").append(node.getNodeConfig().getFlushwait()) .append(",Ping: ").append(node.getNodeConfig().getPing()) .append(",Smax: ").append(node.getNodeConfig().getSmax()) .append(",Ttl: ").append(TimeUnit.MILLISECONDS.toSeconds(node.getNodeConfig().getTtl())) .append(",Elected: ").append(node.getElected()) .append(",Read: ").append(node.getConnectionPool().getClientStatistics().getRead()) .append(",Transfered: ").append(node.getConnectionPool().getClientStatistics().getWritten()) .append(",Connected: ").append(node.getConnectionPool().getOpenConnections()) .append(",Load: ").append(node.getLoad()) .append(NEWLINE); }
@Override public long getRead() { return node.getConnectionPool().getClientStatistics().getRead(); }
UndertowLogger.PROXY_REQUEST_LOGGER.debugf("Attempting to reconnect to failed host %s", getUri()); client.connect(new ClientCallback<ClientConnection>() { @Override scheduleFailedHostRetry(exchange); }, bindAddress, getUri(), exchange.getIoThread(), ssl, exchange.getConnection().getByteBufferPool(), options);
/** * Handle a proxy request for this context. * * @param target the proxy target * @param exchange the http server exchange * @param callback the proxy callback * @param timeout the timeout * @param timeUnit the time unit * @param exclusive whether this connection is exclusive */ void handleRequest(final ModClusterProxyTarget target, final HttpServerExchange exchange, final ProxyCallback<ProxyConnection> callback, long timeout, TimeUnit timeUnit, boolean exclusive) { if (addRequest()) { exchange.addExchangeCompleteListener(new ExchangeCompletionListener() { @Override public void exchangeEvent(HttpServerExchange exchange, NextListener nextListener) { requestDone(); nextListener.proceed(); } }); node.getConnectionPool().connect(target, exchange, callback, timeout, timeUnit, exclusive); } else { callback.failed(exchange); } }
@Override public int getOpenConnections() { return node.getConnectionPool().getOpenConnections(); }
void closeCurrentConnections() { connectionPool.closeCurrentConnections(); } }