Skip to content

Commit 2049839

Browse files
committed
Merge pull request #466 from olivergondza/Fix-HttpExecutor-init
Do not throw Exceptions in static initializer
2 parents bf6e5b0 + 5ccc592 commit 2049839

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

core/src/main/java/org/openstack4j/core/transport/internal/HttpExecutor.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
/**
1414
* HttpExecutor is a delegate to the underline connector associated to OpenStack4j.
15-
*
15+
*
1616
* @author Jeremy Unruh
1717
*/
1818
public class HttpExecutor {
@@ -21,33 +21,33 @@ public class HttpExecutor {
2121
private static final HttpExecutor INSTANCE = new HttpExecutor();
2222
private HttpExecutorService service;
2323

24-
private HttpExecutor() {
25-
initService();
26-
}
24+
private HttpExecutor() {}
25+
26+
private HttpExecutorService service() {
27+
if (service != null) return service;
2728

28-
private void initService() {
2929
Iterator<HttpExecutorService> it = ServiceLoader.load(HttpExecutorService.class, getClass().getClassLoader()).iterator();
3030
if (!it.hasNext())
3131
{
3232
LOG.error("No OpenStack4j connector found in classpath");
3333
throw new ConnectorNotFoundException("No OpenStack4j connector found in classpath");
3434
}
35-
service = it.next();
35+
return service = it.next();
3636
}
3737

3838
public static HttpExecutor create() {
3939
return INSTANCE;
4040
}
41-
41+
4242
public String getExecutorName() {
43-
return service.getExecutorDisplayName();
43+
return service().getExecutorDisplayName();
4444
}
4545

4646
/**
47-
* Delegate to {@link HttpExecutorService#execute(HttpRequest)}
47+
* Delegate to {@link HttpExecutorService#execute(HttpRequest)}
4848
*/
4949
public <R> HttpResponse execute(HttpRequest<R> request) {
5050
LOG.debug("Executing Request: %s -> %s", request.getEndpoint(), request.getPath());
51-
return service.execute(request);
51+
return service().execute(request);
5252
}
5353
}

0 commit comments

Comments
 (0)