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
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@356
    20
import org.apidesign.bck2brwsr.launcher.Bck2BrwsrLauncher;
jaroslav@356
    21
jaroslav@356
    22
/**
jaroslav@356
    23
 *
jaroslav@356
    24
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@356
    25
 */
jaroslav@356
    26
final class Launcher {
jaroslav@356
    27
    private final String sen;
jaroslav@356
    28
    private Bck2BrwsrLauncher launcher;
jaroslav@356
    29
    
jaroslav@356
    30
    Launcher() {
jaroslav@356
    31
        this(null);
jaroslav@356
    32
    }
jaroslav@356
    33
    Launcher(String sen) {
jaroslav@356
    34
        this.sen = sen;
jaroslav@356
    35
    }
jaroslav@356
    36
jaroslav@356
    37
    synchronized Bck2BrwsrLauncher clear() {
jaroslav@356
    38
        Bck2BrwsrLauncher l = launcher;
jaroslav@356
    39
        launcher = null;
jaroslav@356
    40
        return l;
jaroslav@356
    41
    }
jaroslav@356
    42
jaroslav@356
    43
    synchronized Bck2BrwsrLauncher.MethodInvocation addMethod(Class<?> clazz, String name) {
jaroslav@356
    44
        if (launcher == null) {
jaroslav@356
    45
            launcher = new Bck2BrwsrLauncher();
jaroslav@368
    46
            launcher.setTimeout(180000);
jaroslav@356
    47
            if (sen != null) {
jaroslav@356
    48
                launcher.setScriptEngineName(sen);
jaroslav@356
    49
            }
jaroslav@356
    50
        }
jaroslav@356
    51
        return launcher.addMethod(clazz, name);
jaroslav@356
    52
    }
jaroslav@356
    53
jaroslav@356
    54
    void exec() throws Exception {
jaroslav@356
    55
        Bck2BrwsrLauncher l = clear();
jaroslav@356
    56
        if (l != null) {
jaroslav@356
    57
            l.execute();
jaroslav@356
    58
        }
jaroslav@356
    59
    }
jaroslav@356
    60
    
jaroslav@356
    61
}