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