jaroslav@356: /** jaroslav@356: * Back 2 Browser Bytecode Translator jaroslav@356: * Copyright (C) 2012 Jaroslav Tulach jaroslav@356: * jaroslav@356: * This program is free software: you can redistribute it and/or modify jaroslav@356: * it under the terms of the GNU General Public License as published by jaroslav@356: * the Free Software Foundation, version 2 of the License. jaroslav@356: * jaroslav@356: * This program is distributed in the hope that it will be useful, jaroslav@356: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@356: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@356: * GNU General Public License for more details. jaroslav@356: * jaroslav@356: * You should have received a copy of the GNU General Public License jaroslav@356: * along with this program. Look for COPYING file in the top folder. jaroslav@356: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@356: */ jaroslav@356: package org.apidesign.bck2brwsr.vmtest; jaroslav@356: jaroslav@370: import java.io.IOException; jaroslav@356: import org.apidesign.bck2brwsr.launcher.Bck2BrwsrLauncher; jaroslav@370: import org.apidesign.bck2brwsr.launcher.JSLauncher; jaroslav@370: import org.apidesign.bck2brwsr.launcher.MethodInvocation; jaroslav@356: jaroslav@356: /** jaroslav@356: * jaroslav@356: * @author Jaroslav Tulach jaroslav@356: */ jaroslav@356: final class Launcher { jaroslav@356: private final String sen; jaroslav@370: private Object launcher; jaroslav@356: jaroslav@356: Launcher() { jaroslav@356: this(null); jaroslav@356: } jaroslav@356: Launcher(String sen) { jaroslav@356: this.sen = sen; jaroslav@356: } jaroslav@356: jaroslav@370: synchronized Object clear() { jaroslav@370: Object l = launcher; jaroslav@356: launcher = null; jaroslav@356: return l; jaroslav@356: } jaroslav@356: jaroslav@370: synchronized MethodInvocation addMethod(Class clazz, String name) throws IOException { jaroslav@356: if (launcher == null) { jaroslav@356: if (sen != null) { jaroslav@370: JSLauncher js = new JSLauncher(); jaroslav@370: js.addClassLoader(clazz.getClassLoader()); jaroslav@370: js.initialize(); jaroslav@370: launcher = js; jaroslav@370: } else { jaroslav@370: Bck2BrwsrLauncher l = new Bck2BrwsrLauncher(); jaroslav@371: l.initialize(); jaroslav@370: l.setTimeout(180000); jaroslav@370: launcher = l; jaroslav@356: } jaroslav@356: } jaroslav@370: if (launcher instanceof JSLauncher) { jaroslav@370: return ((JSLauncher)launcher).addMethod(clazz, name); jaroslav@370: } else { jaroslav@370: return ((Bck2BrwsrLauncher)launcher).addMethod(clazz, name); jaroslav@370: } jaroslav@356: } jaroslav@356: jaroslav@356: void exec() throws Exception { jaroslav@370: Object l = clear(); jaroslav@356: } jaroslav@356: jaroslav@356: }