| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
package net.sf.tlc.core.impl; |
| 7 |
|
|
| 8 |
|
import java.util.logging.Level; |
| 9 |
|
import java.util.logging.Logger; |
| 10 |
|
|
| 11 |
|
import net.sf.tlc.core.LifecycleAware; |
| 12 |
|
import net.sf.tlc.core.TargetFinder; |
| 13 |
|
import net.sf.tlc.core.TargetLauncher; |
| 14 |
|
import net.sf.tlc.model.Target; |
| 15 |
|
import net.sf.tlc.util.ClassUtils; |
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
4 |
|
| 22 |
1 |
public class DefaultLauncher implements TargetLauncher { |
| 23 |
10 |
|
| 24 |
5 |
private static final Logger logger = Logger.getLogger(DefaultLauncher.class.getName()); |
| 25 |
|
|
| 26 |
|
private final ClassLoader classLoader; |
| 27 |
|
|
| 28 |
|
private final TargetFinder finder; |
| 29 |
7 |
|
| 30 |
3 |
private final ThreadGroup threads = new ThreadGroup(this.getClass().getName()); |
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
7 |
|
| 38 |
10 |
public DefaultLauncher(final ClassLoader classLoader, class="keyword">final TargetFinder finder) { |
| 39 |
3 |
if (null == classLoader) { |
| 40 |
0 |
final RuntimeException r = new IllegalArgumentException("classLoader is null"); |
| 41 |
0 |
logger.throwing(this.getClass().getName(), "DefaultLauncher", r); |
| 42 |
0 |
throw r; |
| 43 |
7 |
} |
| 44 |
10 |
this.classLoader = classLoader; |
| 45 |
3 |
if (null == finder) { |
| 46 |
0 |
final RuntimeException r = new IllegalArgumentException("finder is null"); |
| 47 |
0 |
logger.throwing(this.getClass().getName(), "DefaultLauncher", r); |
| 48 |
0 |
throw r; |
| 49 |
7 |
} |
| 50 |
10 |
this.finder = finder; |
| 51 |
3 |
} |
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
public final void loadTargets() { |
| 59 |
0 |
final Target[] targets = finder.listTargets(); |
| 60 |
0 |
for (int i = 0; i < targets.length; ++i) { |
| 61 |
0 |
System.out.println(targets[i]); |
| 62 |
|
try { |
| 63 |
0 |
final Class theClass = classLoader.loadClass(targets[i].getName()); |
| 64 |
0 |
if (ClassUtils.isRunnable(theClass)) { |
| 65 |
0 |
final Runnable runnable = (Runnable) theClass.newInstance(); |
| 66 |
0 |
final Thread thread = new Thread(threads, runnable, theClass.getName()); |
| 67 |
0 |
thread.start(); |
| 68 |
0 |
} else if (Lclass="keyword">ifecycleAware.class.isAssignableFrom(theClass)) { |
| 69 |
|
|
| 70 |
|
} |
| 71 |
0 |
} catch (ClassNotFoundException e) { |
| 72 |
0 |
logger.log(Level.WARNING, "ClassNotFoundException: " + targets[i].getName(), e); |
| 73 |
0 |
} catch (InstantiationException e) { |
| 74 |
0 |
logger.log(Level.WARNING, "InstantiationException: " + targets[i].getName(), e); |
| 75 |
0 |
} catch (IllegalAccessException e) { |
| 76 |
0 |
logger.log(Level.WARNING, "IllegalAccessException: " + targets[i].getName(), e); |
| 77 |
0 |
} |
| 78 |
|
} |
| 79 |
0 |
while (threads.activeCount() > 0) { |
| 80 |
|
try { |
| 81 |
0 |
Thread.sleep(1000); |
| 82 |
0 |
} catch (InterruptedException e) { |
| 83 |
0 |
logger.log(Level.FINE, "Interrupted!", e); |
| 84 |
0 |
} |
| 85 |
|
} |
| 86 |
0 |
} |
| 87 |
|
|
| 88 |
|
} |