root / extensions / httpnio / src / main / java / org / jclouds / http / pool / config / ConnectionPoolCommandExecutorServiceModule.java @ 35e7942d
History | View | Annotate | Download (2 kB)
1 |
/**
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
4 |
*
|
5 |
* ====================================================================
|
6 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
7 |
* you may not use this file except in compliance with the License.
|
8 |
* You may obtain a copy of the License at
|
9 |
*
|
10 |
* http://www.apache.org/licenses/LICENSE-2.0
|
11 |
*
|
12 |
* Unless required by applicable law or agreed to in writing, software
|
13 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
14 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15 |
* See the License for the specific language governing permissions and
|
16 |
* limitations under the License.
|
17 |
* ====================================================================
|
18 |
*/
|
19 |
package org.jclouds.http.pool.config; |
20 |
|
21 |
import java.util.concurrent.BlockingQueue; |
22 |
import java.util.concurrent.Semaphore; |
23 |
import java.util.concurrent.atomic.AtomicInteger; |
24 |
|
25 |
import org.jclouds.http.HttpUtils; |
26 |
import org.jclouds.lifecycle.config.LifeCycleModule; |
27 |
|
28 |
import com.google.inject.AbstractModule; |
29 |
import com.google.inject.Provides; |
30 |
|
31 |
/**
|
32 |
*
|
33 |
* @author Adrian Cole
|
34 |
*/
|
35 |
public abstract class ConnectionPoolCommandExecutorServiceModule<C> extends AbstractModule { |
36 |
|
37 |
protected void configure() { |
38 |
install(new LifeCycleModule());
|
39 |
bind(AtomicInteger.class).toInstance(new AtomicInteger());// max errors |
40 |
binder().requestInjection(this);
|
41 |
} |
42 |
|
43 |
@Provides
|
44 |
// @Singleton per uri...
|
45 |
public abstract BlockingQueue<C> provideAvailablePool(HttpUtils utils) throws Exception; |
46 |
|
47 |
/**
|
48 |
* controls production and destruction of real connections.
|
49 |
* <p/>
|
50 |
* aquire before a new connection is created release after an error has occurred
|
51 |
*
|
52 |
* @param max
|
53 |
* @throws Exception
|
54 |
*/
|
55 |
@Provides
|
56 |
// @Singleton per uri...
|
57 |
public Semaphore provideTotalConnectionSemaphore(HttpUtils utils) throws Exception { |
58 |
return new Semaphore(utils.getMaxConnectionsPerHost() != 0 ? utils.getMaxConnectionsPerHost() |
59 |
: utils.getMaxConnections(), true);
|
60 |
} |
61 |
} |