Example usage for org.apache.http.util Asserts check

List of usage examples for org.apache.http.util Asserts check

Introduction

In this page you can find the example usage for org.apache.http.util Asserts check.

Prototype

public static void check(boolean z, String str) 

Source Link

Usage

From source file:org.apache.synapse.transport.nhttp.NhttpSharedOutputBuffer.java

/**
 * {@inheritDoc}//from   w  w  w .  j  a v  a 2  s  .c  om
 */
public void write(final int b) throws IOException {
    this.lock.lock();
    try {
        Asserts.check(!this.shutdown && !this.endOfStream, "Buffer already closed for writing");
        // Set buffer to write mode
        setInputMode();
        // At the moment buffer is in the write mode. So position equals to capacity.
        // if position >= limit(= capacity) -> true i.e. buffer is full
        // If this buffer is full, that means the data should be written to output buffer (Need to flush).
        if (!this.buffer.hasRemaining()) {
            flushContent();
            // If "awaitInterrupted" was set to false, that means something went wrong(timeout happened)
            // therefore, we clear the buffer and stop the flow with an exception.
            if (!awaitInterrupted) {
                this.buffer.clear();
                throw new IOException("Output buffer write time out exceeded");
            }
            // Set buffer to write mode. (Inside flushContent method, buffer was set to read mode)
            setInputMode();
        }
        this.buffer.put((byte) b);
    } finally {
        this.lock.unlock();
    }
}

From source file:com.serphacker.serposcope.scraper.http.extensions.CloseableBasicHttpClientConnectionManager.java

@Override
public void connect(final HttpClientConnection conn, final HttpRoute route, final int connectTimeout,
        final HttpContext context) throws IOException {
    Args.notNull(conn, "Connection");
    Args.notNull(route, "HTTP route");
    Asserts.check(conn == this.conn, "Connection not obtained from this manager");
    final HttpHost host;
    if (route.getProxyHost() != null) {
        host = route.getProxyHost();/*from w  w w.j a v  a 2  s.  co  m*/
    } else {
        host = route.getTargetHost();
    }
    final InetSocketAddress localAddress = route.getLocalSocketAddress();
    this.connectionOperator.connect(this.conn, host, localAddress, connectTimeout, this.socketConfig, context);
}

From source file:com.serphacker.serposcope.scraper.http.extensions.CloseableBasicHttpClientConnectionManager.java

@Override
public void upgrade(final HttpClientConnection conn, final HttpRoute route, final HttpContext context)
        throws IOException {
    Args.notNull(conn, "Connection");
    Args.notNull(route, "HTTP route");
    Asserts.check(conn == this.conn, "Connection not obtained from this manager");
    this.connectionOperator.upgrade(this.conn, route.getTargetHost(), context);
}

From source file:org.apache.http.impl.conn.BasicClientConnectionManager.java

private void assertNotShutdown() {
    Asserts.check(!this.shutdown, "Connection manager has been shut down");
}

From source file:org.apache.http.impl.conn.BasicClientConnectionManager.java

ManagedClientConnection getConnection(final HttpRoute route, final Object state) {
    Args.notNull(route, "Route");
    synchronized (this) {
        assertNotShutdown();//ww w.j  a  va  2s. c o  m
        if (this.log.isDebugEnabled()) {
            this.log.debug("Get connection for route " + route);
        }
        Asserts.check(this.conn == null, MISUSE_MESSAGE);
        if (this.poolEntry != null && !this.poolEntry.getPlannedRoute().equals(route)) {
            this.poolEntry.close();
            this.poolEntry = null;
        }
        if (this.poolEntry == null) {
            final String id = Long.toString(COUNTER.getAndIncrement());
            final OperatedClientConnection conn = this.connOperator.createConnection();
            this.poolEntry = new HttpPoolEntry(this.log, id, route, conn, 0, TimeUnit.MILLISECONDS);
        }
        final long now = System.currentTimeMillis();
        if (this.poolEntry.isExpired(now)) {
            this.poolEntry.close();
            this.poolEntry.getTracker().reset();
        }
        this.conn = new ManagedClientConnectionImpl(this, this.connOperator, this.poolEntry);
        return this.conn;
    }
}

From source file:org.apache.http.impl.conn.BasicClientConnectionManager.java

public void releaseConnection(final ManagedClientConnection conn, final long keepalive, final TimeUnit tunit) {
    Args.check(conn instanceof ManagedClientConnectionImpl,
            "Connection class mismatch, " + "connection not obtained from this manager");
    final ManagedClientConnectionImpl managedConn = (ManagedClientConnectionImpl) conn;
    synchronized (managedConn) {
        if (this.log.isDebugEnabled()) {
            this.log.debug("Releasing connection " + conn);
        }/*w w w  .  j a  v  a  2  s  . co m*/
        if (managedConn.getPoolEntry() == null) {
            return; // already released
        }
        final ClientConnectionManager manager = managedConn.getManager();
        Asserts.check(manager == this, "Connection not obtained from this manager");
        synchronized (this) {
            if (this.shutdown) {
                shutdownConnection(managedConn);
                return;
            }
            try {
                if (managedConn.isOpen() && !managedConn.isMarkedReusable()) {
                    shutdownConnection(managedConn);
                }
                if (managedConn.isMarkedReusable()) {
                    this.poolEntry.updateExpiry(keepalive, tunit != null ? tunit : TimeUnit.MILLISECONDS);
                    if (this.log.isDebugEnabled()) {
                        final String s;
                        if (keepalive > 0) {
                            s = "for " + keepalive + " " + tunit;
                        } else {
                            s = "indefinitely";
                        }
                        this.log.debug("Connection can be kept alive " + s);
                    }
                }
            } finally {
                managedConn.detach();
                this.conn = null;
                if (this.poolEntry.isClosed()) {
                    this.poolEntry = null;
                }
            }
        }
    }
}

From source file:org.apache.http.impl.conn.BasicHttpClientConnectionManager.java

synchronized HttpClientConnection getConnection(final HttpRoute route, final Object state) {
    Asserts.check(!this.shutdown, "Connection manager has been shut down");
    if (this.log.isDebugEnabled()) {
        this.log.debug("Get connection for route " + route);
    }/*from   ww w  .ja  v a 2  s.c  om*/
    Asserts.check(!this.leased, "Connection is still allocated");
    if (!LangUtils.equals(this.route, route) || !LangUtils.equals(this.state, state)) {
        closeConnection();
    }
    this.route = route;
    this.state = state;
    checkExpiry();
    if (this.conn == null) {
        this.conn = this.connFactory.create(route, this.connConfig);
    }
    this.leased = true;
    return this.conn;
}

From source file:org.apache.http.impl.conn.BasicHttpClientConnectionManager.java

public synchronized void releaseConnection(final HttpClientConnection conn, final Object state,
        final long keepalive, final TimeUnit tunit) {
    Args.notNull(conn, "Connection");
    Asserts.check(conn == this.conn, "Connection not obtained from this manager");
    if (this.log.isDebugEnabled()) {
        this.log.debug("Releasing connection " + conn);
    }/*from w w w . j av a 2s.c  o  m*/
    if (this.shutdown) {
        shutdownConnection();
        return;
    }
    try {
        this.updated = System.currentTimeMillis();
        if (!this.conn.isOpen()) {
            this.conn = null;
            this.route = null;
            this.conn = null;
            this.expiry = Long.MAX_VALUE;
        } else {
            this.state = state;
            if (this.log.isDebugEnabled()) {
                final String s;
                if (keepalive > 0) {
                    s = "for " + keepalive + " " + tunit;
                } else {
                    s = "indefinitely";
                }
                this.log.debug("Connection can be kept alive " + s);
            }
            if (keepalive > 0) {
                this.expiry = this.updated + tunit.toMillis(keepalive);
            } else {
                this.expiry = Long.MAX_VALUE;
            }
        }
    } finally {
        this.leased = false;
    }
}

From source file:org.apache.http.impl.conn.BasicHttpClientConnectionManager.java

public void connect(final HttpClientConnection conn, final HttpRoute route, final int connectTimeout,
        final HttpContext context) throws IOException {
    Args.notNull(conn, "Connection");
    Args.notNull(route, "HTTP route");
    Asserts.check(conn == this.conn, "Connection not obtained from this manager");
    final HttpHost host;
    if (route.getProxyHost() != null) {
        host = route.getProxyHost();/*from w ww  .  java  2  s .c o  m*/
    } else {
        host = route.getTargetHost();
    }
    final InetSocketAddress localAddress = route.getLocalSocketAddress();
    this.connectionOperator.connect(this.conn, host, localAddress, connectTimeout, this.socketConfig, context);
}

From source file:org.apache.http.impl.conn.BasicHttpClientConnectionManager.java

public void upgrade(final HttpClientConnection conn, final HttpRoute route, final HttpContext context)
        throws IOException {
    Args.notNull(conn, "Connection");
    Args.notNull(route, "HTTP route");
    Asserts.check(conn == this.conn, "Connection not obtained from this manager");
    this.connectionOperator.upgrade(this.conn, route.getTargetHost(), context);
}