author | Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
Sun, 23 Dec 2012 18:24:18 +0100 | |
branch | launcher |
changeset 371 | bafc670aa10d |
parent 370 | ed48023d1d85 |
permissions | -rw-r--r-- |
jaroslav@356 | 1 |
/** |
jaroslav@356 | 2 |
* Back 2 Browser Bytecode Translator |
jaroslav@356 | 3 |
* Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
jaroslav@356 | 4 |
* |
jaroslav@356 | 5 |
* This program is free software: you can redistribute it and/or modify |
jaroslav@356 | 6 |
* it under the terms of the GNU General Public License as published by |
jaroslav@356 | 7 |
* the Free Software Foundation, version 2 of the License. |
jaroslav@356 | 8 |
* |
jaroslav@356 | 9 |
* This program is distributed in the hope that it will be useful, |
jaroslav@356 | 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
jaroslav@356 | 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
jaroslav@356 | 12 |
* GNU General Public License for more details. |
jaroslav@356 | 13 |
* |
jaroslav@356 | 14 |
* You should have received a copy of the GNU General Public License |
jaroslav@356 | 15 |
* along with this program. Look for COPYING file in the top folder. |
jaroslav@356 | 16 |
* If not, see http://opensource.org/licenses/GPL-2.0. |
jaroslav@356 | 17 |
*/ |
jaroslav@356 | 18 |
package org.apidesign.bck2brwsr.vmtest; |
jaroslav@356 | 19 |
|
jaroslav@370 | 20 |
import java.io.IOException; |
jaroslav@356 | 21 |
import org.apidesign.bck2brwsr.launcher.Bck2BrwsrLauncher; |
jaroslav@370 | 22 |
import org.apidesign.bck2brwsr.launcher.JSLauncher; |
jaroslav@370 | 23 |
import org.apidesign.bck2brwsr.launcher.MethodInvocation; |
jaroslav@356 | 24 |
|
jaroslav@356 | 25 |
/** |
jaroslav@356 | 26 |
* |
jaroslav@356 | 27 |
* @author Jaroslav Tulach <jtulach@netbeans.org> |
jaroslav@356 | 28 |
*/ |
jaroslav@356 | 29 |
final class Launcher { |
jaroslav@356 | 30 |
private final String sen; |
jaroslav@370 | 31 |
private Object launcher; |
jaroslav@356 | 32 |
|
jaroslav@356 | 33 |
Launcher() { |
jaroslav@356 | 34 |
this(null); |
jaroslav@356 | 35 |
} |
jaroslav@356 | 36 |
Launcher(String sen) { |
jaroslav@356 | 37 |
this.sen = sen; |
jaroslav@356 | 38 |
} |
jaroslav@356 | 39 |
|
jaroslav@370 | 40 |
synchronized Object clear() { |
jaroslav@370 | 41 |
Object l = launcher; |
jaroslav@356 | 42 |
launcher = null; |
jaroslav@356 | 43 |
return l; |
jaroslav@356 | 44 |
} |
jaroslav@356 | 45 |
|
jaroslav@370 | 46 |
synchronized MethodInvocation addMethod(Class<?> clazz, String name) throws IOException { |
jaroslav@356 | 47 |
if (launcher == null) { |
jaroslav@356 | 48 |
if (sen != null) { |
jaroslav@370 | 49 |
JSLauncher js = new JSLauncher(); |
jaroslav@370 | 50 |
js.addClassLoader(clazz.getClassLoader()); |
jaroslav@370 | 51 |
js.initialize(); |
jaroslav@370 | 52 |
launcher = js; |
jaroslav@370 | 53 |
} else { |
jaroslav@370 | 54 |
Bck2BrwsrLauncher l = new Bck2BrwsrLauncher(); |
jaroslav@371 | 55 |
l.initialize(); |
jaroslav@370 | 56 |
l.setTimeout(180000); |
jaroslav@370 | 57 |
launcher = l; |
jaroslav@356 | 58 |
} |
jaroslav@356 | 59 |
} |
jaroslav@370 | 60 |
if (launcher instanceof JSLauncher) { |
jaroslav@370 | 61 |
return ((JSLauncher)launcher).addMethod(clazz, name); |
jaroslav@370 | 62 |
} else { |
jaroslav@370 | 63 |
return ((Bck2BrwsrLauncher)launcher).addMethod(clazz, name); |
jaroslav@370 | 64 |
} |
jaroslav@356 | 65 |
} |
jaroslav@356 | 66 |
|
jaroslav@356 | 67 |
void exec() throws Exception { |
jaroslav@370 | 68 |
Object l = clear(); |
jaroslav@356 | 69 |
} |
jaroslav@356 | 70 |
|
jaroslav@356 | 71 |
} |