1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.module.launcher.application; |
12 | |
|
13 | |
import org.mule.api.MuleContext; |
14 | |
import org.mule.module.launcher.DeploymentStartException; |
15 | |
import org.mule.module.launcher.GoodCitizenClassLoader; |
16 | |
import org.mule.module.launcher.InstallException; |
17 | |
import org.mule.module.launcher.descriptor.ApplicationDescriptor; |
18 | |
|
19 | |
import java.io.IOException; |
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
public class ApplicationWrapper implements Application |
28 | |
{ |
29 | |
|
30 | |
private Application delegate; |
31 | |
|
32 | |
protected ApplicationWrapper(Application delegate) throws IOException |
33 | 0 | { |
34 | 0 | this.delegate = delegate; |
35 | 0 | } |
36 | |
|
37 | |
public void dispose() |
38 | |
{ |
39 | 0 | final ClassLoader originalCl = Thread.currentThread().getContextClassLoader(); |
40 | |
try |
41 | |
{ |
42 | 0 | ClassLoader appCl = getDeploymentClassLoader(); |
43 | |
|
44 | 0 | if (appCl != null) |
45 | |
{ |
46 | 0 | Thread.currentThread().setContextClassLoader(appCl); |
47 | |
} |
48 | 0 | delegate.dispose(); |
49 | 0 | if (appCl != null) |
50 | |
{ |
51 | |
|
52 | 0 | if (appCl instanceof GoodCitizenClassLoader) |
53 | |
{ |
54 | 0 | GoodCitizenClassLoader classLoader = (GoodCitizenClassLoader) appCl; |
55 | 0 | classLoader.close(); |
56 | |
} |
57 | |
} |
58 | |
} |
59 | |
finally |
60 | |
{ |
61 | 0 | Thread.currentThread().setContextClassLoader(originalCl); |
62 | 0 | } |
63 | 0 | } |
64 | |
|
65 | |
public ClassLoader getDeploymentClassLoader() |
66 | |
{ |
67 | 0 | return delegate.getDeploymentClassLoader(); |
68 | |
} |
69 | |
|
70 | |
public MuleContext getMuleContext() |
71 | |
{ |
72 | 0 | return delegate.getMuleContext(); |
73 | |
} |
74 | |
|
75 | |
public void init() |
76 | |
{ |
77 | 0 | final ClassLoader originalCl = Thread.currentThread().getContextClassLoader(); |
78 | |
try |
79 | |
{ |
80 | 0 | ClassLoader appCl = getDeploymentClassLoader(); |
81 | |
|
82 | 0 | if (appCl != null) |
83 | |
{ |
84 | 0 | Thread.currentThread().setContextClassLoader(appCl); |
85 | |
} |
86 | 0 | delegate.init(); |
87 | |
} |
88 | |
finally |
89 | |
{ |
90 | 0 | Thread.currentThread().setContextClassLoader(originalCl); |
91 | 0 | } |
92 | 0 | } |
93 | |
|
94 | |
public void install() throws InstallException |
95 | |
{ |
96 | 0 | final ClassLoader originalCl = Thread.currentThread().getContextClassLoader(); |
97 | |
try |
98 | |
{ |
99 | 0 | ClassLoader appCl = getDeploymentClassLoader(); |
100 | |
|
101 | 0 | if (appCl != null) |
102 | |
{ |
103 | 0 | Thread.currentThread().setContextClassLoader(appCl); |
104 | |
} |
105 | 0 | delegate.install(); |
106 | |
} |
107 | |
finally |
108 | |
{ |
109 | 0 | Thread.currentThread().setContextClassLoader(originalCl); |
110 | 0 | } |
111 | 0 | } |
112 | |
|
113 | |
public void redeploy() |
114 | |
{ |
115 | 0 | delegate.redeploy(); |
116 | 0 | } |
117 | |
|
118 | |
public void start() throws DeploymentStartException |
119 | |
{ |
120 | 0 | final ClassLoader originalCl = Thread.currentThread().getContextClassLoader(); |
121 | |
try |
122 | |
{ |
123 | 0 | ClassLoader appCl = getDeploymentClassLoader(); |
124 | |
|
125 | 0 | if (appCl != null) |
126 | |
{ |
127 | 0 | Thread.currentThread().setContextClassLoader(appCl); |
128 | |
} |
129 | 0 | delegate.start(); |
130 | |
} |
131 | |
finally |
132 | |
{ |
133 | 0 | Thread.currentThread().setContextClassLoader(originalCl); |
134 | 0 | } |
135 | 0 | } |
136 | |
|
137 | |
public void stop() |
138 | |
{ |
139 | 0 | final ClassLoader originalCl = Thread.currentThread().getContextClassLoader(); |
140 | |
try |
141 | |
{ |
142 | 0 | ClassLoader appCl = getDeploymentClassLoader(); |
143 | |
|
144 | 0 | if (appCl != null) |
145 | |
{ |
146 | 0 | Thread.currentThread().setContextClassLoader(appCl); |
147 | |
} |
148 | 0 | delegate.stop(); |
149 | |
} |
150 | |
finally |
151 | |
{ |
152 | 0 | Thread.currentThread().setContextClassLoader(originalCl); |
153 | 0 | } |
154 | 0 | } |
155 | |
|
156 | |
public String getAppName() |
157 | |
{ |
158 | 0 | return delegate.getAppName(); |
159 | |
} |
160 | |
|
161 | |
public ApplicationDescriptor getDescriptor() |
162 | |
{ |
163 | 0 | return delegate.getDescriptor(); |
164 | |
} |
165 | |
|
166 | |
@Override |
167 | |
public String toString() |
168 | |
{ |
169 | 0 | return String.format("%s(%s)", getClass().getName(), delegate); |
170 | |
} |
171 | |
|
172 | |
public Application getDelegate() |
173 | |
{ |
174 | 0 | return delegate; |
175 | |
} |
176 | |
} |