Skip to content

Commit 2a74af2

Browse files
author
Stephane Landelle
committed
Clean up after AsyncHttpClient#498: license headers, format
1 parent 3d84b36 commit 2a74af2

15 files changed

+235
-99
lines changed

api/src/main/java/org/asynchttpclient/AsyncHttpClientFactory.java

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/*
2+
* Copyright (c) 2010-2014 Sonatype, Inc. All rights reserved.
3+
*
4+
* This program is licensed to you under the Apache License Version 2.0,
5+
* and you may not use this file except in compliance with the Apache License Version 2.0.
6+
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
7+
*
8+
* Unless required by applicable law or agreed to in writing,
9+
* software distributed under the Apache License Version 2.0 is distributed on an
10+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
12+
*/
113
package org.asynchttpclient;
214

315
import org.asynchttpclient.util.AsyncImplHelper;
@@ -38,25 +50,22 @@ public static AsyncHttpClient getAsyncHttpClient() {
3850
return (AsyncHttpClient) asyncHttpClientImplClass.newInstance();
3951
} catch (InstantiationException e) {
4052
throw new AsyncHttpClientImplException("Unable to create the class specified by system property : "
41-
+ AsyncImplHelper.ASYNC_HTTP_CLIENT_IMPL_SYSTEM_PROPERTY,e);
53+
+ AsyncImplHelper.ASYNC_HTTP_CLIENT_IMPL_SYSTEM_PROPERTY, e);
4254
} catch (IllegalAccessException e) {
4355
throw new AsyncHttpClientImplException("Unable to find the class specified by system property : "
44-
+ AsyncImplHelper.ASYNC_HTTP_CLIENT_IMPL_SYSTEM_PROPERTY,e);
56+
+ AsyncImplHelper.ASYNC_HTTP_CLIENT_IMPL_SYSTEM_PROPERTY, e);
4557
}
4658
return new DefaultAsyncHttpClient();
4759
}
4860

4961
public static AsyncHttpClient getAsyncHttpClient(AsyncHttpProvider provider) {
5062
if (attemptInstantiation()) {
5163
try {
52-
Constructor<AsyncHttpClient> constructor = asyncHttpClientImplClass
53-
.getConstructor(AsyncHttpProvider.class);
64+
Constructor<AsyncHttpClient> constructor = asyncHttpClientImplClass.getConstructor(AsyncHttpProvider.class);
5465
return constructor.newInstance(provider);
55-
}catch (Exception e) {
56-
throw new AsyncHttpClientImplException(
57-
"Unable to find the instantiate the class specified by system property : "
58-
+ AsyncImplHelper.ASYNC_HTTP_CLIENT_IMPL_SYSTEM_PROPERTY
59-
+ "(AsyncHttpProvider) due to : " + e.getMessage(), e);
66+
} catch (Exception e) {
67+
throw new AsyncHttpClientImplException("Unable to find the instantiate the class specified by system property : "
68+
+ AsyncImplHelper.ASYNC_HTTP_CLIENT_IMPL_SYSTEM_PROPERTY + "(AsyncHttpProvider) due to : " + e.getMessage(), e);
6069
}
6170
}
6271
return new DefaultAsyncHttpClient(provider);
@@ -65,14 +74,11 @@ public static AsyncHttpClient getAsyncHttpClient(AsyncHttpProvider provider) {
6574
public static AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) {
6675
if (attemptInstantiation()) {
6776
try {
68-
Constructor<AsyncHttpClient> constructor = asyncHttpClientImplClass
69-
.getConstructor(AsyncHttpClientConfig.class);
77+
Constructor<AsyncHttpClient> constructor = asyncHttpClientImplClass.getConstructor(AsyncHttpClientConfig.class);
7078
return constructor.newInstance(config);
7179
} catch (Exception e) {
72-
throw new AsyncHttpClientImplException(
73-
"Unable to find the instantiate the class specified by system property : "
74-
+ AsyncImplHelper.ASYNC_HTTP_CLIENT_IMPL_SYSTEM_PROPERTY
75-
+ "(AsyncHttpProvider) due to : " + e.getMessage(), e);
80+
throw new AsyncHttpClientImplException("Unable to find the instantiate the class specified by system property : "
81+
+ AsyncImplHelper.ASYNC_HTTP_CLIENT_IMPL_SYSTEM_PROPERTY + "(AsyncHttpProvider) due to : " + e.getMessage(), e);
7682
}
7783
}
7884
return new DefaultAsyncHttpClient(config);
@@ -81,14 +87,12 @@ public static AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) {
8187
public static AsyncHttpClient getAsyncHttpClient(AsyncHttpProvider provider, AsyncHttpClientConfig config) {
8288
if (attemptInstantiation()) {
8389
try {
84-
Constructor<AsyncHttpClient> constructor = asyncHttpClientImplClass.getConstructor(
85-
AsyncHttpProvider.class, AsyncHttpClientConfig.class);
90+
Constructor<AsyncHttpClient> constructor = asyncHttpClientImplClass.getConstructor(AsyncHttpProvider.class,
91+
AsyncHttpClientConfig.class);
8692
return constructor.newInstance(provider, config);
8793
} catch (Exception e) {
88-
throw new AsyncHttpClientImplException(
89-
"Unable to find the instantiate the class specified by system property : "
90-
+ AsyncImplHelper.ASYNC_HTTP_CLIENT_IMPL_SYSTEM_PROPERTY
91-
+ "(AsyncHttpProvider) due to : " + e.getMessage(), e);
94+
throw new AsyncHttpClientImplException("Unable to find the instantiate the class specified by system property : "
95+
+ AsyncImplHelper.ASYNC_HTTP_CLIENT_IMPL_SYSTEM_PROPERTY + "(AsyncHttpProvider) due to : " + e.getMessage(), e);
9296
}
9397
}
9498
return new DefaultAsyncHttpClient(provider, config);
@@ -101,10 +105,8 @@ public static AsyncHttpClient getAsyncHttpClient(String providerClass, AsyncHttp
101105
AsyncHttpClientConfig.class);
102106
return constructor.newInstance(providerClass, config);
103107
} catch (Exception e) {
104-
throw new AsyncHttpClientImplException(
105-
"Unable to find the instantiate the class specified by system property : "
106-
+ AsyncImplHelper.ASYNC_HTTP_CLIENT_IMPL_SYSTEM_PROPERTY
107-
+ "(AsyncHttpProvider) due to : " + e.getMessage(), e);
108+
throw new AsyncHttpClientImplException("Unable to find the instantiate the class specified by system property : "
109+
+ AsyncImplHelper.ASYNC_HTTP_CLIENT_IMPL_SYSTEM_PROPERTY + "(AsyncHttpProvider) due to : " + e.getMessage(), e);
108110
}
109111
}
110112
return new DefaultAsyncHttpClient(providerClass, config);
@@ -115,8 +117,7 @@ private static boolean attemptInstantiation() {
115117
lock.lock();
116118
try {
117119
if (!instantiated) {
118-
asyncHttpClientImplClass = AsyncImplHelper
119-
.getAsyncImplClass(AsyncImplHelper.ASYNC_HTTP_CLIENT_IMPL_SYSTEM_PROPERTY);
120+
asyncHttpClientImplClass = AsyncImplHelper.getAsyncImplClass(AsyncImplHelper.ASYNC_HTTP_CLIENT_IMPL_SYSTEM_PROPERTY);
120121
instantiated = true;
121122
}
122123
} finally {

api/src/main/java/org/asynchttpclient/AsyncHttpClientImplException.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
1+
/*
2+
* Copyright (c) 2010-2014 Sonatype, Inc. All rights reserved.
3+
*
4+
* This program is licensed to you under the Apache License Version 2.0,
5+
* and you may not use this file except in compliance with the Apache License Version 2.0.
6+
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
7+
*
8+
* Unless required by applicable law or agreed to in writing,
9+
* software distributed under the Apache License Version 2.0 is distributed on an
10+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
12+
*/
113
package org.asynchttpclient;
214

15+
@SuppressWarnings("serial")
316
public class AsyncHttpClientImplException extends RuntimeException {
417

518
public AsyncHttpClientImplException(String msg) {
@@ -9,5 +22,4 @@ public AsyncHttpClientImplException(String msg) {
922
public AsyncHttpClientImplException(String msg, Exception e) {
1023
super(msg, e);
1124
}
12-
1325
}

api/src/main/java/org/asynchttpclient/AsyncHttpClientRegistry.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/*
2+
* Copyright (c) 2010-2014 Sonatype, Inc. All rights reserved.
3+
*
4+
* This program is licensed to you under the Apache License Version 2.0,
5+
* and you may not use this file except in compliance with the Apache License Version 2.0.
6+
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
7+
*
8+
* Unless required by applicable law or agreed to in writing,
9+
* software distributed under the Apache License Version 2.0 is distributed on an
10+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
12+
*/
113
package org.asynchttpclient;
214

315
import java.util.Set;
@@ -58,13 +70,12 @@ public interface AsyncHttpClientRegistry {
5870
*
5971
* @return
6072
*/
61-
73+
6274
Set<String> getAllRegisteredNames();
6375

6476
/**
6577
* Removes all instances from this registry.
6678
*/
67-
68-
void clearAllInstances();
6979

70-
}
80+
void clearAllInstances();
81+
}

api/src/main/java/org/asynchttpclient/AsyncHttpClientRegistryImpl.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/*
2+
* Copyright (c) 2010-2014 Sonatype, Inc. All rights reserved.
3+
*
4+
* This program is licensed to you under the Apache License Version 2.0,
5+
* and you may not use this file except in compliance with the Apache License Version 2.0.
6+
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
7+
*
8+
* Unless required by applicable law or agreed to in writing,
9+
* software distributed under the Apache License Version 2.0 is distributed on an
10+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
12+
*/
113
package org.asynchttpclient;
214

315
import org.asynchttpclient.util.AsyncImplHelper;
@@ -23,19 +35,17 @@ public static AsyncHttpClientRegistry getInstance() {
2335
lock.lock();
2436
try {
2537
if (_instance == null) {
26-
Class asyncHttpClientRegistryImplClass = AsyncImplHelper
38+
Class<?> asyncHttpClientRegistryImplClass = AsyncImplHelper
2739
.getAsyncImplClass(AsyncImplHelper.ASYNC_HTTP_CLIENT_REGISTRY_SYSTEM_PROPERTY);
2840
if (asyncHttpClientRegistryImplClass != null)
2941
_instance = (AsyncHttpClientRegistry) asyncHttpClientRegistryImplClass.newInstance();
3042
else
3143
_instance = new AsyncHttpClientRegistryImpl();
3244
}
3345
} catch (InstantiationException e) {
34-
throw new AsyncHttpClientImplException("Couldn't instantiate AsyncHttpClientRegistry : "
35-
+ e.getMessage(), e);
46+
throw new AsyncHttpClientImplException("Couldn't instantiate AsyncHttpClientRegistry : " + e.getMessage(), e);
3647
} catch (IllegalAccessException e) {
37-
throw new AsyncHttpClientImplException("Couldn't instantiate AsyncHttpClientRegistry : "
38-
+ e.getMessage(), e);
48+
throw new AsyncHttpClientImplException("Couldn't instantiate AsyncHttpClientRegistry : " + e.getMessage(), e);
3949
} finally {
4050
lock.unlock();
4151
}
@@ -74,7 +84,7 @@ public AsyncHttpClient addOrReplace(String name, AsyncHttpClient ahc) {
7484
*/
7585
@Override
7686
public boolean registerIfNew(String name, AsyncHttpClient ahc) {
77-
return asyncHttpClientMap.putIfAbsent(name, ahc)==null;
87+
return asyncHttpClientMap.putIfAbsent(name, ahc) == null;
7888
}
7989

8090
/*
@@ -107,5 +117,4 @@ public Set<String> getAllRegisteredNames() {
107117
public void clearAllInstances() {
108118
asyncHttpClientMap.clear();
109119
}
110-
111120
}

api/src/main/java/org/asynchttpclient/util/AsyncImplHelper.java

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/*
2+
* Copyright (c) 2010-2014 Sonatype, Inc. All rights reserved.
3+
*
4+
* This program is licensed to you under the Apache License Version 2.0,
5+
* and you may not use this file except in compliance with the Apache License Version 2.0.
6+
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
7+
*
8+
* Unless required by applicable law or agreed to in writing,
9+
* software distributed under the Apache License Version 2.0 is distributed on an
10+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
12+
*/
113
package org.asynchttpclient.util;
214

315
import org.asynchttpclient.AsyncHttpClient;
@@ -14,6 +26,10 @@
1426

1527
public class AsyncImplHelper {
1628

29+
public static final String ASYNC_HTTP_CLIENT_IMPL_SYSTEM_PROPERTY = "org.async.http.client.impl";
30+
public static final String ASYNC_HTTP_CLIENT_REGISTRY_SYSTEM_PROPERTY = "org.async.http.client.registry.impl";
31+
public static final String ASYNC_HTTP_CLIENT_IMPL_PROPERTIES_FILE = "asynchttpclient.properties";
32+
1733
private static String getSystemProperty(final String systemProperty) {
1834
return AccessController.doPrivileged(new PrivilegedAction<String>() {
1935
public String run() {
@@ -63,36 +79,31 @@ public Properties run() throws IOException {
6379
}
6480
});
6581
} catch (PrivilegedActionException e) {
66-
throw new AsyncHttpClientImplException("Unable to read properties file because of exception : "
67-
+ e.getMessage(), e);
82+
throw new AsyncHttpClientImplException("Unable to read properties file because of exception : " + e.getMessage(), e);
6883
}
6984
}
7085

7186
private static Class<AsyncHttpClient> getClass(final String asyncImplClassName) {
7287
try {
7388
return AccessController.doPrivileged(new PrivilegedExceptionAction<Class<AsyncHttpClient>>() {
74-
public Class run() throws ClassNotFoundException {
89+
@SuppressWarnings("unchecked")
90+
public Class<AsyncHttpClient> run() throws ClassNotFoundException {
7591
ClassLoader cl = Thread.currentThread().getContextClassLoader();
7692
if (cl != null)
7793
try {
78-
return cl.loadClass(asyncImplClassName);
94+
return (Class<AsyncHttpClient>) cl.loadClass(asyncImplClassName);
7995
} catch (ClassNotFoundException e) {
8096
AsyncHttpClientFactory.logger.info("Couldn't find class : " + asyncImplClassName
81-
+ " in thread context classpath " + "checking system class path next",e);
97+
+ " in thread context classpath " + "checking system class path next", e);
8298
}
8399

84100
cl = ClassLoader.getSystemClassLoader();
85-
return cl.loadClass(asyncImplClassName);
101+
return (Class<AsyncHttpClient>) cl.loadClass(asyncImplClassName);
86102
}
87103
});
88104
} catch (PrivilegedActionException e) {
89-
throw new AsyncHttpClientImplException("Class : " + asyncImplClassName + " couldn't be found in "
90-
+ " the classpath due to : " + e.getMessage(), e);
105+
throw new AsyncHttpClientImplException("Class : " + asyncImplClassName + " couldn't be found in " + " the classpath due to : "
106+
+ e.getMessage(), e);
91107
}
92108
}
93-
94-
public static final String ASYNC_HTTP_CLIENT_IMPL_SYSTEM_PROPERTY = "org.async.http.client.impl";
95-
public static final String ASYNC_HTTP_CLIENT_REGISTRY_SYSTEM_PROPERTY = "org.async.http.client.registry.impl";
96-
public static final String ASYNC_HTTP_CLIENT_IMPL_PROPERTIES_FILE = "asynchttpclient.properties";
97-
98109
}

0 commit comments

Comments
 (0)