launcher/src/main/java/org/apidesign/bck2brwsr/launcher/MethodInvocation.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Sun, 23 Dec 2012 18:24:18 +0100
branchlauncher
changeset 371 bafc670aa10d
parent 370 ed48023d1d85
child 385 2a00bdf753bb
permissions -rw-r--r--
Separating initialization and method execution on HTTP launcher as well
jaroslav@370
     1
/**
jaroslav@370
     2
 * Back 2 Browser Bytecode Translator
jaroslav@370
     3
 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@370
     4
 *
jaroslav@370
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@370
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@370
     7
 * the Free Software Foundation, version 2 of the License.
jaroslav@370
     8
 *
jaroslav@370
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@370
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@370
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@370
    12
 * GNU General Public License for more details.
jaroslav@370
    13
 *
jaroslav@370
    14
 * You should have received a copy of the GNU General Public License
jaroslav@370
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@370
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
jaroslav@370
    17
 */
jaroslav@370
    18
package org.apidesign.bck2brwsr.launcher;
jaroslav@370
    19
jaroslav@371
    20
import java.util.concurrent.CountDownLatch;
jaroslav@371
    21
import java.util.concurrent.TimeUnit;
jaroslav@371
    22
jaroslav@370
    23
/**
jaroslav@370
    24
 *
jaroslav@370
    25
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@370
    26
 */
jaroslav@370
    27
public final class MethodInvocation {
jaroslav@371
    28
    final CountDownLatch wait = new CountDownLatch(1);
jaroslav@370
    29
    final String className;
jaroslav@370
    30
    final String methodName;
jaroslav@371
    31
    private String result;
jaroslav@371
    32
    private Exception exception;
jaroslav@370
    33
jaroslav@370
    34
    MethodInvocation(String className, String methodName) {
jaroslav@370
    35
        this.className = className;
jaroslav@370
    36
        this.methodName = methodName;
jaroslav@370
    37
    }
jaroslav@371
    38
    
jaroslav@371
    39
    void await(long timeOut) throws InterruptedException {
jaroslav@371
    40
        wait.await(timeOut, TimeUnit.MILLISECONDS);
jaroslav@371
    41
    }
jaroslav@371
    42
    
jaroslav@371
    43
    void result(String r, Exception e) {
jaroslav@371
    44
        this.result = r;
jaroslav@371
    45
        this.exception = e;
jaroslav@371
    46
        wait.countDown();
jaroslav@371
    47
    }
jaroslav@370
    48
jaroslav@370
    49
    @Override
jaroslav@370
    50
    public String toString() {
jaroslav@370
    51
        if (exception != null) {
jaroslav@370
    52
            return exception.toString();
jaroslav@370
    53
        }
jaroslav@370
    54
        return result;
jaroslav@370
    55
    }
jaroslav@370
    56
    
jaroslav@370
    57
}