1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.camel.util; |
18 |
|
|
19 |
|
import java.util.Collection; |
20 |
|
|
21 |
|
import org.apache.camel.Service; |
22 |
|
import org.apache.commons.logging.Log; |
23 |
|
import org.apache.commons.logging.LogFactory; |
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
public class ServiceHelper { |
31 |
3 |
private static final transient Log LOG = LogFactory.getLog(ServiceHelper.class); |
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
0 |
private ServiceHelper() { |
37 |
0 |
} |
38 |
|
|
39 |
|
public static void startService(Object value) throws Exception { |
40 |
1860 |
if (value instanceof Service) { |
41 |
1038 |
Service service = (Service)value; |
42 |
1038 |
service.start(); |
43 |
1038 |
} else if (value instanceof Collection) { |
44 |
6 |
startServices((Collection)value); |
45 |
|
} |
46 |
1860 |
} |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
public static void startServices(Object... services) throws Exception { |
52 |
3399 |
for (Object value : services) { |
53 |
1836 |
startService(value); |
54 |
|
} |
55 |
1563 |
} |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
public static void startServices(Collection services) throws Exception { |
61 |
321 |
for (Object value : services) { |
62 |
609 |
if (value instanceof Service) { |
63 |
597 |
Service service = (Service)value; |
64 |
597 |
service.start(); |
65 |
|
} |
66 |
609 |
} |
67 |
321 |
} |
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
public static void stopServices(Object... services) throws Exception { |
73 |
963 |
Exception firstException = null; |
74 |
2196 |
for (Object value : services) { |
75 |
1233 |
if (value instanceof Service) { |
76 |
993 |
Service service = (Service)value; |
77 |
|
try { |
78 |
993 |
service.stop(); |
79 |
0 |
} catch (Exception e) { |
80 |
0 |
LOG.debug("Caught exception shutting down: " + e, e); |
81 |
0 |
if (firstException == null) { |
82 |
0 |
firstException = e; |
83 |
|
} |
84 |
993 |
} |
85 |
|
} |
86 |
|
} |
87 |
963 |
if (firstException != null) { |
88 |
0 |
throw firstException; |
89 |
|
} |
90 |
963 |
} |
91 |
|
|
92 |
|
public static void stopService(Object value) throws Exception { |
93 |
24 |
if (value instanceof Service) { |
94 |
24 |
Service service = (Service)value; |
95 |
24 |
service.stop(); |
96 |
24 |
} else if (value instanceof Collection) { |
97 |
0 |
stopServices((Collection)value); |
98 |
|
} |
99 |
24 |
} |
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
public static void stopServices(Collection services) throws Exception { |
105 |
315 |
Exception firstException = null; |
106 |
315 |
for (Object value : services) { |
107 |
597 |
if (value instanceof Service) { |
108 |
585 |
Service service = (Service)value; |
109 |
|
try { |
110 |
585 |
service.stop(); |
111 |
0 |
} catch (Exception e) { |
112 |
0 |
LOG.debug("Caught exception shutting down: " + e, e); |
113 |
0 |
if (firstException == null) { |
114 |
0 |
firstException = e; |
115 |
|
} |
116 |
585 |
} |
117 |
|
} |
118 |
597 |
} |
119 |
315 |
if (firstException != null) { |
120 |
0 |
throw firstException; |
121 |
|
} |
122 |
315 |
} |
123 |
|
} |