1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.module.launcher; |
12 | |
|
13 | |
import org.mule.module.reboot.MuleContainerBootstrapUtils; |
14 | |
import org.mule.util.FileUtils; |
15 | |
import org.mule.util.SystemUtils; |
16 | |
|
17 | |
import java.io.File; |
18 | |
import java.net.URL; |
19 | |
import java.util.Collection; |
20 | |
|
21 | |
import org.apache.commons.logging.Log; |
22 | |
import org.apache.commons.logging.LogFactory; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
public class MuleSharedDomainClassLoader extends GoodCitizenClassLoader |
28 | |
{ |
29 | |
|
30 | 0 | protected transient Log logger = LogFactory.getLog(getClass()); |
31 | |
|
32 | 0 | private final String domain = "undefined"; |
33 | |
|
34 | |
@SuppressWarnings("unchecked") |
35 | |
public MuleSharedDomainClassLoader(String domain, ClassLoader parent) |
36 | |
{ |
37 | 0 | super(new URL[0], parent); |
38 | |
try |
39 | |
{ |
40 | 0 | File domainDir = new File(MuleContainerBootstrapUtils.getMuleHome(), "lib/shared/" + domain); |
41 | 0 | if (!domainDir.exists()) |
42 | |
{ |
43 | 0 | throw new IllegalArgumentException( |
44 | |
String.format("Shared ClassLoader Domain '%s' doesn't exist", domain)); |
45 | |
} |
46 | |
|
47 | 0 | if (!domainDir.canRead()) |
48 | |
{ |
49 | 0 | throw new IllegalArgumentException( |
50 | |
String.format("Shared ClassLoader Domain '%s' is not accessible", domain)); |
51 | |
} |
52 | |
|
53 | 0 | Collection<File> jars = FileUtils.listFiles(domainDir, new String[] {"jar"}, false); |
54 | |
|
55 | 0 | if (logger.isDebugEnabled()) |
56 | |
{ |
57 | |
{ |
58 | 0 | StringBuilder sb = new StringBuilder(); |
59 | 0 | sb.append("Loading Shared ClassLoader Domain: ").append(domain).append(SystemUtils.LINE_SEPARATOR); |
60 | 0 | sb.append("=============================").append(SystemUtils.LINE_SEPARATOR); |
61 | |
|
62 | 0 | for (File jar : jars) |
63 | |
{ |
64 | 0 | sb.append(jar.toURI().toURL()).append(SystemUtils.LINE_SEPARATOR); |
65 | |
} |
66 | |
|
67 | 0 | sb.append("=============================").append(SystemUtils.LINE_SEPARATOR); |
68 | |
|
69 | 0 | logger.debug(sb.toString()); |
70 | |
} |
71 | |
} |
72 | |
|
73 | 0 | for (File jar : jars) |
74 | |
{ |
75 | 0 | addURL(jar.toURI().toURL()); |
76 | |
} |
77 | |
} |
78 | 0 | catch (Throwable t) |
79 | |
{ |
80 | 0 | throw new RuntimeException(t); |
81 | 0 | } |
82 | 0 | } |
83 | |
|
84 | |
public String getDomain() |
85 | |
{ |
86 | 0 | return domain; |
87 | |
} |
88 | |
|
89 | |
@Override |
90 | |
public String toString() |
91 | |
{ |
92 | 0 | return String.format("%s[%s]@%s", getClass().getName(), |
93 | |
domain, |
94 | |
Integer.toHexString(System.identityHashCode(this))); |
95 | |
} |
96 | |
|
97 | |
} |