12
12
13
13
/**
14
14
* HttpExecutor is a delegate to the underline connector associated to OpenStack4j.
15
- *
15
+ *
16
16
* @author Jeremy Unruh
17
17
*/
18
18
public class HttpExecutor {
@@ -21,33 +21,33 @@ public class HttpExecutor {
21
21
private static final HttpExecutor INSTANCE = new HttpExecutor ();
22
22
private HttpExecutorService service ;
23
23
24
- private HttpExecutor () {
25
- initService ();
26
- }
24
+ private HttpExecutor () {}
25
+
26
+ private HttpExecutorService service () {
27
+ if (service != null ) return service ;
27
28
28
- private void initService () {
29
29
Iterator <HttpExecutorService > it = ServiceLoader .load (HttpExecutorService .class , getClass ().getClassLoader ()).iterator ();
30
30
if (!it .hasNext ())
31
31
{
32
32
LOG .error ("No OpenStack4j connector found in classpath" );
33
33
throw new ConnectorNotFoundException ("No OpenStack4j connector found in classpath" );
34
34
}
35
- service = it .next ();
35
+ return service = it .next ();
36
36
}
37
37
38
38
public static HttpExecutor create () {
39
39
return INSTANCE ;
40
40
}
41
-
41
+
42
42
public String getExecutorName () {
43
- return service .getExecutorDisplayName ();
43
+ return service () .getExecutorDisplayName ();
44
44
}
45
45
46
46
/**
47
- * Delegate to {@link HttpExecutorService#execute(HttpRequest)}
47
+ * Delegate to {@link HttpExecutorService#execute(HttpRequest)}
48
48
*/
49
49
public <R > HttpResponse execute (HttpRequest <R > request ) {
50
50
LOG .debug ("Executing Request: %s -> %s" , request .getEndpoint (), request .getPath ());
51
- return service .execute (request );
51
+ return service () .execute (request );
52
52
}
53
53
}
0 commit comments