List of usage examples for org.apache.commons.httpclient MultiThreadedHttpConnectionManager getConnectionsInPool
public int getConnectionsInPool()
From source file:com.twinsoft.convertigo.engine.util.HttpUtils.java
public static void logCurrentHttpConnection(HttpClient httpClient, HostConfiguration hostConfiguration, HttpPool poolMode) {/* w w w.j av a2s .c om*/ if (Engine.logEngine.isInfoEnabled() && httpClient != null) { if (poolMode == HttpPool.no) { Engine.logEngine .info("(HttpUtils) Use a not pooled HTTP connection for " + hostConfiguration.getHost()); } else { HttpConnectionManager httpConnectionManager = httpClient.getHttpConnectionManager(); if (httpConnectionManager != null && httpConnectionManager instanceof MultiThreadedHttpConnectionManager) { MultiThreadedHttpConnectionManager mtHttpConnectionManager = (MultiThreadedHttpConnectionManager) httpConnectionManager; int connections = mtHttpConnectionManager.getConnectionsInPool(); int connectionsForHost = mtHttpConnectionManager.getConnectionsInPool(hostConfiguration); Engine.logEngine.info("(HttpUtils) Use a " + poolMode.name() + " pool with " + connections + " HTTP connections, " + connectionsForHost + " for " + hostConfiguration.getHost() + "; Getting one ... [for instance " + httpClient.hashCode() + "]"); } } } }
From source file:org.mskcc.cbio.portal.remote.CgdsProtocol.java
/** * Connects to remote data server with the specified list of name / value pairs. * * @param data Array of NameValuePair Objects. * @return Text Response.//from w w w .j a v a 2 s .c om * @throws IOException IO / Network Error. */ public String connect(NameValuePair[] data, XDebug xdebug) throws IOException { // Create a key, based on the NameValuePair[] data String key = createKey(data); xdebug.logMsg(this, "Using Cache Key: " + key); // Check Cache CacheManager singletonManager = CacheManager.getInstance(); Cache memoryCache = singletonManager.getCache("memory_cache"); xdebug.logMsg(this, "Cache Status: " + memoryCache.getStatus().toString()); // If Content is found in cache, return it Element element = memoryCache.get(key); if (element != null) { xdebug.logMsg(this, "Cache Hit. Using Memory."); return (String) element.getObjectValue(); } else { xdebug.logMsg(this, "Cache Miss. Connecting to Web API."); // Otherwise, connect to Web API // Get CGDS URL Property String cgdsUrl = Config.getInstance().getProperty("cgds.url"); MultiThreadedHttpConnectionManager connectionManager = ConnectionManager.getConnectionManager(); xdebug.logMsg(this, "Number of connections in pool: " + connectionManager.getConnectionsInPool()); xdebug.logMsg(this, "Max Connections per host: " + connectionManager.getParams().getDefaultMaxConnectionsPerHost()); HttpClient client = new HttpClient(connectionManager); // Create GET / POST Method method = new PostMethod(cgdsUrl); method.setRequestBody(data); try { // Extract HTTP Status Code int statusCode = client.executeMethod(method); // If all is OK, extract the response text if (statusCode == HttpStatus.SC_OK) { String content = ResponseUtil.getResponseString(method); Element newElement = new Element(key, content); xdebug.logMsg(this, "Placing text in cache."); memoryCache.put(newElement); return content; } else { // Otherwise, throw HTTP Exception Object throw new HttpException( statusCode + ": " + HttpStatus.getStatusText(statusCode) + " Base URL: " + cgdsUrl); } } finally { // Must release connection back to Apache Commons Connection Pool method.releaseConnection(); } } }
From source file:org.sonatype.nexus.integrationtests.nexus412.Nexus412RemoteLeakIT.java
@Test public void nonTestSimplerAvailabilityCheckRemoteLeak() throws Exception { if (true) {// w w w .j av a 2 s .co m // this should be an UT printKnownErrorButDoNotFail(Nexus412RemoteLeakIT.class, "nonTestSimplerAvailabilityCheckRemoteLeak"); return; } // mangle one repos to have quasi different host, thus different HttpCommons HostConfig // but make it fail! (unknown host, so will not be able to connect) ProxyRepository repo1 = this.convertRepo("release-proxy-repo-1"); repo1.setRemoteUrl(repo1.getRemoteUrl().replace("localhost", "1.1.1.1")); ProxyRepository repo2 = this.convertRepo("tasks-snapshot-repo"); // loop until we have some "sensible" result (not unknown, since this is async op) // first unforced request will trigger the check, and wait until we have result RemoteStatus rs1 = RemoteStatus.UNKNOWN; RemoteStatus rs2 = RemoteStatus.UNKNOWN; while (RemoteStatus.UNKNOWN.equals(rs1) || RemoteStatus.UNKNOWN.equals(rs2)) { rs1 = repo1.getRemoteStatus(new ResourceStoreRequest(RepositoryItemUid.PATH_ROOT), false); rs2 = repo2.getRemoteStatus(new ResourceStoreRequest(RepositoryItemUid.PATH_ROOT), false); Thread.sleep(1000); } // get the default context, since they used it RemoteStorageContext ctx = new DefaultRemoteStorageContext(null); MultiThreadedHttpConnectionManager cm = (MultiThreadedHttpConnectionManager) ((HttpClient) ctx .getContextObject(CommonsHttpClientRemoteStorage.CTX_KEY_CLIENT)).getHttpConnectionManager(); Assert.assertEquals(2, cm.getConnectionsInPool()); }