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