Package io.undertow.client

Examples of io.undertow.client.ClientConnection


    /**
     * @param exclusive - Is connection for the exclusive use of one client?
     */
    public void connect(ProxyClient.ProxyTarget proxyTarget, HttpServerExchange exchange, ProxyCallback<ProxyConnection> callback, final long timeout, final TimeUnit timeUnit, boolean exclusive) {
        HostThreadData data = getData();
        ClientConnection conn = data.availableConnections.poll();
        while (conn != null && !conn.isOpen()) {
            conn = data.availableConnections.poll();
        }
        if (conn != null) {
            if (exclusive) {
                data.connections--;
View Full Code Here


                public void run() {


                    ProxyConnection connectionAttachment = exchange.getAttachment(CONNECTION);
                    if (connectionAttachment != null) {
                        ClientConnection clientConnection = connectionAttachment.getConnection();
                        UndertowLogger.REQUEST_LOGGER.timingOutRequest(clientConnection.getPeerAddress() + "" + exchange.getRequestURI());
                        IoUtils.safeClose(clientConnection);
                    } else {
                        UndertowLogger.REQUEST_LOGGER.timingOutRequest(exchange.getRequestURI());
                    }
                    if (exchange.isResponseStarted()) {
View Full Code Here

                            connection.putAttachment(exclusiveConnectionKey, newHolder);
                            connection.addCloseListener(new ServerConnection.CloseListener() {

                                @Override
                                public void closed(ServerConnection connection) {
                                    ClientConnection clientConnection = newHolder.connection.getConnection();
                                    if (clientConnection.isOpen()) {
                                        safeClose(clientConnection);
                                    }
                                }
                            });
                        }
View Full Code Here

        DefaultServer.setRootHandler(SIMPLE_MESSAGE_HANDLER);
        final UndertowClient client = createClient();

        final List<ClientResponse> responses = new CopyOnWriteArrayList<ClientResponse>();
        final CountDownLatch latch = new CountDownLatch(10);
        final ClientConnection connection = client.connect(ADDRESS, worker, new ByteBufferSlicePool(1024, 1024), OptionMap.EMPTY).get();
        try {
            connection.getIoThread().execute(new Runnable() {
                @Override
                public void run() {
                    for (int i = 0; i < 10; i++) {
                        final ClientRequest request = new ClientRequest().setMethod(Methods.GET).setPath("/");
                        connection.sendRequest(request, createClientCallback(responses, latch));
                    }
                }

            });
View Full Code Here

        //
        DefaultServer.setRootHandler(SIMPLE_MESSAGE_HANDLER);
        final UndertowClient client = createClient();

        final CountDownLatch latch = new CountDownLatch(1);
        final ClientConnection connection = client.connect(ADDRESS, worker, new ByteBufferSlicePool(1024, 1024), OptionMap.EMPTY).get();
        try {
            ClientRequest request = new ClientRequest().setPath("/1324").setMethod(Methods.GET);
            final List<ClientResponse> responses = new CopyOnWriteArrayList<ClientResponse>();
            request.getRequestHeaders().add(Headers.CONNECTION, Headers.CLOSE.toString());
            connection.sendRequest(request, createClientCallback(responses, latch));
            latch.await();
            final ClientResponse response = responses.iterator().next();
            Assert.assertEquals(message, response.getAttachment(RESPONSE_BODY));
            Assert.assertEquals(false, connection.isOpen());
        } finally {
            IoUtils.safeClose(connection);
        }

    }
View Full Code Here

                @Override
                public void run() {
                    ProxyConnection connectionAttachment = exchange.getAttachment(CONNECTION);
                    if(connectionAttachment != null) {
                        //we rely on the close listener to end the exchange
                        ClientConnection clientConnection = connectionAttachment.getConnection();
                        IoUtils.safeClose(clientConnection);
                    } else {
                        exchange.setResponseCode(503);
                        exchange.endExchange();
                    }
View Full Code Here

    void returnConnection(final ClientConnection connection) {
        HostThreadData hostData = getData();
        if (closed) {
            //the host has been closed
            IoUtils.safeClose(connection);
            ClientConnection con = hostData.availbleConnections.poll();
            while (con != null) {
                IoUtils.safeClose(con);
                con = hostData.availbleConnections.poll();
            }
            redistributeQueued(hostData);
View Full Code Here

        return data;
    }

    public void connect(HttpServerExchange exchange, ProxyCallback<ProxyConnection> callback, final long timeout, final TimeUnit timeUnit) {
        HostThreadData data = getData();
        ClientConnection conn = data.availbleConnections.poll();
        if (conn != null) {
            connectionReady(conn, callback, exchange);
        } else if (data.connections < loadBalancingProxyClient.getConnectionsPerThread()) {
            openConnection(exchange, callback, data);
        } else {
View Full Code Here

                public void run() {
                    if (exchange.getConnection().isOpen()) {
                        UndertowLogger.REQUEST_LOGGER.proxyRequestTimedOut(exchange.getRequestURI());
                        IoUtils.safeClose(exchange.getConnection());
                    }
                    ClientConnection clientConnection = exchange.getAttachment(CONNECTION).getConnection();
                    IoUtils.safeClose(clientConnection);
                }
            }, maxRequestTime, TimeUnit.MILLISECONDS);
            exchange.putAttachment(TIMEOUT_KEY, key);
            exchange.addExchangeCompleteListener(new ExchangeCompletionListener() {
View Full Code Here

    private void returnConnection(final ClientConnection connection) {
        HostThreadData hostData = getData();
        if (closed) {
            //the host has been closed
            IoUtils.safeClose(connection);
            ClientConnection con = hostData.availbleConnections.poll();
            while (con != null) {
                IoUtils.safeClose(con);
                con = hostData.availbleConnections.poll();
            }
            redistributeQueued(hostData);
View Full Code Here

TOP

Related Classes of io.undertow.client.ClientConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.