Author: ogusakov Date: Tue May 5 04:15:53 2009 New Revision: 771551 URL: http://svn.apache.org/viewvc?rev=771551&view=rev Log: [MERCURY-124] - started adding http clients pool
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/DefaultHttpClientPool.java (with props) maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/HttpClientPool.java (with props) maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/HttpClientPoolException.java (with props) maven/mercury/trunk/mercury-core/src/main/resources/org/apache/maven/mercury/spi/ maven/mercury/trunk/mercury-core/src/main/resources/org/apache/maven/mercury/spi/http/ maven/mercury/trunk/mercury-core/src/main/resources/org/apache/maven/mercury/spi/http/client/ maven/mercury/trunk/mercury-core/src/main/resources/org/apache/maven/mercury/spi/http/client/Messages.properties (with props) Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/DefaultHttpClientPool.java URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/DefaultHttpClientPool.java?rev=771551&view=auto ============================================================================== --- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/DefaultHttpClientPool.java (added) +++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/DefaultHttpClientPool.java Tue May 5 04:15:53 2009 @@ -0,0 +1,77 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +*/ + +package org.apache.maven.mercury.spi.http.client; + +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.ConcurrentMap; + +import org.apache.maven.mercury.artifact.api.ConfigurationException; +import org.apache.maven.mercury.crypto.pgp.PgpStreamVerifier; +import org.codehaus.plexus.lang.DefaultLanguage; +import org.codehaus.plexus.lang.Language; +import org.mortbay.jetty.client.HttpClient; + +/** + * + * + * @author Oleg Gusakov + * @version $Id$ + * + */ +public class DefaultHttpClientPool + implements HttpClientPool +{ + private static final Language LANG = new DefaultLanguage( DefaultHttpClientPool.class ); + + private static int _poolSize = DEFAULT_POOL_SIZE; + + private static ConcurrentLinkedQueue<HttpClient> _pool = new ConcurrentLinkedQueue<HttpClient>(); + + public DefaultHttpClientPool() + { + this( DEFAULT_POOL_SIZE); + } + + public DefaultHttpClientPool( int sz ) + { + for( int i=0; i<sz; i++ ) + _pool.offer( new HttpClient() ); + } + + public HttpClient getHttpClient() + throws HttpClientPoolException + { + if( _pool.isEmpty() ) + throw new HttpClientPoolException( LANG.getMessage( "pool.empty" ) ); + + return _pool.poll(); + } + + public void returnHttpClient( HttpClient client ) + throws HttpClientPoolException + { + _pool.offer( client ); + } + +} Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/DefaultHttpClientPool.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/DefaultHttpClientPool.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/HttpClientPool.java URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/HttpClientPool.java?rev=771551&view=auto ============================================================================== --- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/HttpClientPool.java (added) +++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/HttpClientPool.java Tue May 5 04:15:53 2009 @@ -0,0 +1,41 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +*/ + +package org.apache.maven.mercury.spi.http.client; + +import org.apache.maven.mercury.artifact.api.Configurable; +import org.mortbay.jetty.client.HttpClient; + +/** + * an abstraction to use instead actual HttpClient + * + * @author Oleg Gusakov + * @version $Id$ + * + */ +public interface HttpClientPool +{ + public static final int DEFAULT_POOL_SIZE = 3; + + HttpClient getHttpClient() + throws HttpClientPoolException; + + void returnHttpClient( HttpClient client ) + throws HttpClientPoolException; +} Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/HttpClientPool.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/HttpClientPool.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/HttpClientPoolException.java URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/HttpClientPoolException.java?rev=771551&view=auto ============================================================================== --- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/HttpClientPoolException.java (added) +++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/HttpClientPoolException.java Tue May 5 04:15:53 2009 @@ -0,0 +1,69 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +*/ + +package org.apache.maven.mercury.spi.http.client; + +/** + * + * + * @author Oleg Gusakov + * @version $Id$ + * + */ +public class HttpClientPoolException + extends Exception +{ + + /** + * + */ + public HttpClientPoolException() + { + // TODO Auto-generated constructor stub + } + + /** + * @param message + */ + public HttpClientPoolException( String message ) + { + super( message ); + // TODO Auto-generated constructor stub + } + + /** + * @param cause + */ + public HttpClientPoolException( Throwable cause ) + { + super( cause ); + // TODO Auto-generated constructor stub + } + + /** + * @param message + * @param cause + */ + public HttpClientPoolException( String message, Throwable cause ) + { + super( message, cause ); + // TODO Auto-generated constructor stub + } + +} Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/HttpClientPoolException.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/spi/http/client/HttpClientPoolException.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/mercury/trunk/mercury-core/src/main/resources/org/apache/maven/mercury/spi/http/client/Messages.properties URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/resources/org/apache/maven/mercury/spi/http/client/Messages.properties?rev=771551&view=auto ============================================================================== --- maven/mercury/trunk/mercury-core/src/main/resources/org/apache/maven/mercury/spi/http/client/Messages.properties (added) +++ maven/mercury/trunk/mercury-core/src/main/resources/org/apache/maven/mercury/spi/http/client/Messages.properties Tue May 5 04:15:53 2009 @@ -0,0 +1 @@ +pool.empty=HttpClientPool of initial size {0}, is empty Propchange: maven/mercury/trunk/mercury-core/src/main/resources/org/apache/maven/mercury/spi/http/client/Messages.properties ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/mercury/trunk/mercury-core/src/main/resources/org/apache/maven/mercury/spi/http/client/Messages.properties ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision