Search in sources :

Example 1 with ABSRuntime

use of abs.backend.java.lib.runtime.ABSRuntime in project abstools by abstools.

the class JavaBackendTest method assertValidJavaExecution.

void assertValidJavaExecution(boolean withStdLib, String... codeLines) throws Exception {
    StringBuilder absCode = new StringBuilder();
    for (String line : codeLines) {
        absCode.append(line);
        absCode.append("\n");
    }
    JavaCode javaCode = getJavaCode(absCode.toString(), withStdLib ? Config.WITH_STD_LIB : null);
    try {
        String genDir = javaCode.getSrcDir().getAbsolutePath() + "/gen/test";
        javaCode.compile("-classpath", "bin", "-d", genDir);
        final ABSRuntime r = makeAbsRuntime();
        r.enableDebugging(true);
        final boolean[] finished = new boolean[] { false };
        final List<ABSException> exceptions = Collections.synchronizedList(new ArrayList<ABSException>());
        r.addSystemObserver(new SystemObserver() {

            @Override
            public void systemStarted() {
            }

            @Override
            public void systemFinished() {
                synchronized (finished) {
                    finished[0] = true;
                    finished.notifyAll();
                }
            }

            @Override
            public void systemError(ABSException e) {
                exceptions.add(e);
            }

            @Override
            public void newCOGCreated(COGView cog, ObjectView initialObject) {
            }
        });
        r.start(new File(genDir), "Test.Main");
        while (!finished[0]) {
            synchronized (finished) {
                finished.wait(100);
            }
        }
        r.shutdown();
        for (ABSException e : exceptions) {
            throw e;
        }
    } catch (Exception e) {
        System.out.println(javaCode);
        throw e;
    } finally {
        javaCode.deleteCode();
    }
}
Also used : COGView(abs.backend.java.observing.COGView) SystemObserver(abs.backend.java.observing.SystemObserver) JavaCode(abs.backend.java.codegeneration.JavaCode) ObjectView(abs.backend.java.observing.ObjectView) JavaCodeGenerationException(abs.backend.java.codegeneration.JavaCodeGenerationException) ABSException(abs.backend.java.lib.runtime.ABSException) ABSRuntime(abs.backend.java.lib.runtime.ABSRuntime) ABSException(abs.backend.java.lib.runtime.ABSException)

Example 2 with ABSRuntime

use of abs.backend.java.lib.runtime.ABSRuntime in project abstools by abstools.

the class RuntimeUsageTest method main.

/**
 * @param args
 */
public static void main(String[] args) {
    try {
        for (int i = 0; i < 2; i++) {
            RuntimeUsageTest t = new RuntimeUsageTest("System " + i);
            ABSRuntime r = new ABSRuntime();
            r.addSystemObserver(t);
            r.setTotalSchedulingStrategy(t.getScheduler(r));
            r.enableDebugging(true);
            r.start(new File("javatest"), "LeaderElection.Main");
        }
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}
Also used : ABSRuntime(abs.backend.java.lib.runtime.ABSRuntime) File(java.io.File)

Example 3 with ABSRuntime

use of abs.backend.java.lib.runtime.ABSRuntime in project abstools by abstools.

the class Debugger method startABSRuntime.

/**
 * Used to start the ABS Runtime. If an earlier Runtime is present, it is shut down first.
 *
 * @param projectName
 * @param mainClassName
 * @param genPath
 * @param debuggerArgsSystemObserver
 * @param debuggerArgsTotalScheduler
 * @param debuggerIsInDebugMode
 * @param debuggerArgsRandomSeed
 * @param fliClassPath
 * @param outStream
 * @param ignoreMissingFLIClasses
 * @param useFifoSemantics
 * @throws InvalidRandomSeedException
 */
public static void startABSRuntime(final String projectName, final String mainClassName, final Path genPath, String debuggerArgsSystemObserver, String debuggerArgsTotalScheduler, boolean debuggerIsInDebugMode, String debuggerArgsRandomSeed, boolean terminateOnException, List<URL> fliClassPath, PrintStream outStream, PrintStream errStream, boolean ignoreMissingFLIClasses, boolean useFifoSemantics) throws InvalidRandomSeedException {
    if (DO_DEBUG)
        System.out.println("start internal debugger");
    final ABSRuntime r = new ABSRuntime();
    if (debuggerIsInDebugMode)
        r.enableDebugging(true);
    r.setOutStream(outStream);
    r.setErrStream(errStream);
    r.addFLIClassPath(fliClassPath);
    r.setIgnoreMissingFLIClasses(ignoreMissingFLIClasses);
    if (useFifoSemantics) {
        r.setScheduableTasksFilter(new ScheduableTasksFilterFifo());
    }
    r.terminateOnException(terminateOnException);
    boolean useOurScheduling = addSchedulingStrategy(debuggerArgsTotalScheduler, r);
    final boolean useOurSystemObserver = addSystemObservers(debuggerArgsSystemObserver, r);
    if (debuggerArgsRandomSeed != null && !debuggerArgsRandomSeed.isEmpty()) {
        String seedString = debuggerArgsRandomSeed.replace("-Dabs.randomseed=", "");
        Long seedNumber = getSeed(seedString);
        r.setRandomSeed(seedNumber);
    }
    final ThreadGroup tg = new ThreadGroup("ABS " + mainClassName);
    tg.setDaemon(true);
    final Thread debuggerRunner = new Thread(tg, new Runnable() {

        @Override
        public void run() {
            try {
                if (DO_DEBUG) {
                    System.out.println("Start ABSRuntime .. ");
                    System.out.println("path: " + genPath.toString());
                    System.out.println("name:" + mainClassName);
                }
                r.start(genPath.toFile(), mainClassName);
            } catch (ClassNotFoundException e) {
                exceptionHandling(e);
            } catch (InstantiationException e) {
                exceptionHandling(e);
            } catch (IllegalAccessException e) {
                exceptionHandling(e);
            }
        }

        private void exceptionHandling(final Exception e) {
            standardExceptionHandling(e);
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    showErrorMessage("Not able to start ABSRuntime.\n" + e.getMessage());
                }
            });
        }
    });
    if (useOurScheduling) {
        enableHightlighting();
        Display.getDefault().asyncExec(new Runnable() {

            @Override
            public void run() {
                try {
                    PlatformUI.getWorkbench().showPerspective(ABSDEBUGPERSPECTIVE_ID, PlatformUI.getWorkbench().getActiveWorkbenchWindow());
                    getDebugger().initDebugger(projectName, r, debuggerRunner, useOurSystemObserver);
                    if (DebugUtils.getRunAutomatically()) {
                        DebugUtils.getSchedulerRef().resumeAutomaticScheduling();
                    }
                } catch (WorkbenchException e) {
                    standardExceptionHandling(e);
                    showErrorMessage("Could not open ABS debug perspective");
                }
            }
        });
    } else {
        debuggerRunner.start();
    }
}
Also used : ScheduableTasksFilterFifo(abs.backend.java.scheduling.ScheduableTasksFilterFifo) WorkbenchException(org.eclipse.ui.WorkbenchException) WorkbenchException(org.eclipse.ui.WorkbenchException) ABSException(abs.backend.java.lib.runtime.ABSException) ABSRuntime(abs.backend.java.lib.runtime.ABSRuntime)

Aggregations

ABSRuntime (abs.backend.java.lib.runtime.ABSRuntime)3 ABSException (abs.backend.java.lib.runtime.ABSException)2 JavaCode (abs.backend.java.codegeneration.JavaCode)1 JavaCodeGenerationException (abs.backend.java.codegeneration.JavaCodeGenerationException)1 COGView (abs.backend.java.observing.COGView)1 ObjectView (abs.backend.java.observing.ObjectView)1 SystemObserver (abs.backend.java.observing.SystemObserver)1 ScheduableTasksFilterFifo (abs.backend.java.scheduling.ScheduableTasksFilterFifo)1 File (java.io.File)1 WorkbenchException (org.eclipse.ui.WorkbenchException)1