Example usage for java.lang Runnable run

List of usage examples for java.lang Runnable run

Introduction

In this page you can find the example usage for java.lang Runnable run.

Prototype

public abstract void run();

Source Link

Document

When an object implementing interface Runnable is used to create a thread, starting the thread causes the object's run method to be called in that separately executing thread.

Usage

From source file:tech.sirwellington.alchemy.http.AlchemyMachineImplTest.java

@Test
public void testExecuteAsyncWhenFails() {
    AlchemyHttpException ex = new AlchemyHttpException();

    when(verb.execute(apacheClient, request)).thenThrow(ex);

    instance.executeAsync(request, responseClass, onSuccess, onFailure);

    verify(executorService).submit(taskCaptor.capture());

    Runnable task = taskCaptor.getValue();
    assertThat(task, notNullValue());// w  ww.j  ava2s.  c  o  m

    task.run();
    verify(onFailure).handleError(ex);
}

From source file:haven.Utils.java

public static void defer(final Runnable r) {
    Defer.later(new Defer.Callable<Object>() {
        public Object call() {
            r.run();
            return (null);
        }/*  w  w  w. ja  v a 2s . c o m*/
    });
}

From source file:com.microsoft.azureexplorer.helpers.IDEHelperImpl.java

@Override
public void executeOnPooledThread(final Runnable runnable) {
    Job job = new Job("Loading...") {

        @Override//from w ww  . j  a  v  a2 s .  c  o  m
        protected IStatus run(IProgressMonitor monitor) {
            monitor.beginTask("", IProgressMonitor.UNKNOWN);
            try {
                runnable.run();
            } catch (Exception ex) {
                monitor.done();
                return Status.CANCEL_STATUS;
            }
            monitor.done();
            return Status.OK_STATUS;
        }
    };
    job.schedule();
}

From source file:com.mgmtp.jfunk.core.module.ContainerModule.java

/**
 * Executes the added test modules and their callbacks in the order of their addition using
 * {@link ScriptContext#run(TestModule)}.
 */// w w  w.  j a va  2s. c  om
@Override
public void execute() {
    // save archive dir of the outer module so it can be reset later
    String previousArchiveDir = archiveDirProvider.get().getPath();

    try {
        // make sure archive dirs are within that of the container module
        moduleArchiveDir = moduleArchiveDirProvider.get().getPath();
        config.put(JFunkConstants.ARCHIVE_DIR, moduleArchiveDir);

        for (ModuleWithCallbacks moduleWithCallbacks : modulesWithCallbacks) {
            TestModule testModule = moduleWithCallbacks.testModule;

            Runnable beforeModuleCallback = moduleWithCallbacks.beforeModuleCallback;
            if (beforeModuleCallback != null) {
                beforeModuleCallback.run();
            }

            scriptContext.run(testModule);

            Runnable afterModuleCallback = moduleWithCallbacks.afterModuleCallback;
            if (afterModuleCallback != null) {
                afterModuleCallback.run();
            }
        }
    } finally {
        // reset for outer module, so property is correctly archived
        config.put(JFunkConstants.ARCHIVE_DIR, previousArchiveDir);

        // it does not make sense to archive datasets in the container module,
        // these would be those of the test module executed last
        config.put(JFunkConstants.ARCHIVE_DATASETS, "false");
    }
}

From source file:com.microsoft.azureexplorer.helpers.IDEHelperImpl.java

@Override
public void runInBackground(Object project, String name, boolean canBeCancelled, boolean isIndeterminate,
        final String indicatorText, final Runnable runnable) {
    Job job = new Job(name) {

        @Override//from w ww .j  a  v  a  2  s . co m
        protected IStatus run(IProgressMonitor monitor) {
            monitor.beginTask(indicatorText, IProgressMonitor.UNKNOWN);
            try {
                runnable.run();
            } catch (Exception ex) {
                monitor.done();
                return Status.CANCEL_STATUS;
            }
            monitor.done();
            return Status.OK_STATUS;
        }
    };
    job.schedule();
}

From source file:eu.delving.sip.base.VisualFeedback.java

private void execWait(final Runnable runnable) {
    try {/*  w ww  .  java  2s.c  o  m*/
        Runnable wrapper = new Runnable() {
            @Override
            public void run() {
                try {
                    runnable.run();
                } catch (Exception e) {
                    alert(e.toString(), e); // todo: better idea?
                }
            }
        };
        SwingUtilities.invokeAndWait(wrapper);
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.thoughtworks.go.server.persistence.OauthRepository.java

public void transaction(final Runnable txn) {
    txnTemplate.execute(new TransactionCallbackWithoutResult() {
        @Override/*from w w w.ja  v a2 s.  co m*/
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            txn.run();
        }
    });
}

From source file:com.googlecode.fightinglayoutbugs.FightingLayoutBugs.java

/**
 * Runs all registered {@link LayoutBugDetector}s. Before you call this method, you might:<ul>
 * <li>register new detectors via {@link #enable},</li>
 * <li>remove unwanted detectors via {@link #disable},</li>
 * <li>configure a registered detector via {@link #configure},</li>
 * <li>configure the {@link TextDetector} to be used via {@link #setTextDetector},</li>
 * <li>configure the {@link EdgeDetector} to be used via {@link #setEdgeDetector}.</li>
 * </ul>/*  ww  w .  j  a v a 2  s  . co  m*/
 */
public Collection<LayoutBug> findLayoutBugsIn(@Nonnull WebPage webPage) {
    if (webPage == null) {
        throw new IllegalArgumentException("Method parameter webPage must not be null.");
    }
    if (_debugMode) {
        setLogLevelToDebug();
        registerDebugListener();
    }
    try {
        TextDetector textDetector = (_textDetector == null ? new AnimationAwareTextDetector() : _textDetector);
        EdgeDetector edgeDetector = (_edgeDetector == null ? new SimpleEdgeDetector() : _edgeDetector);
        try {
            LOG.debug("Analyzing " + webPage.getUrl() + " ...");
            webPage.setTextDetector(textDetector);
            webPage.setEdgeDetector(edgeDetector);
            final Collection<LayoutBug> result = new ArrayList<LayoutBug>();
            for (LayoutBugDetector detector : _detectors) {
                detector.setScreenshotDir(screenshotDir);
                LOG.debug("Running " + detector.getClass().getSimpleName() + " ...");
                result.addAll(detector.findLayoutBugsIn(webPage));
            }
            if (!result.isEmpty()) {
                StringBuilder sb = new StringBuilder();
                sb.append("Detected layout bug(s) on ").append(webPage.getUrl()).append("\n");
                if (_debugMode) {
                    sb.append(
                            "If there is a false positive, please send an email to fighting-layout-bugs@googlegroups.com with the following information:\n");
                    sb.append("    - your test code,\n");
                    sb.append("    - all logged output, and\n");
                    sb.append("    - all screenshot files located in: ").append(screenshotDir);
                    sb.append("      (You might want to pack those into an zip archive)\n");
                    sb.append("TextDetector: ").append(textDetector.getClass().getName()).append("\n");
                    sb.append("EdgeDetector: ").append(edgeDetector.getClass().getName()).append("\n");
                    sb.append(DebugHelper.getDiagnosticInfo(webPage.getDriver()));
                } else {
                    sb.append(
                            "If you call FightingLayoutBugs.enableDebugMode() before you call FightingLayoutBugs.findLayoutBugsIn(...) you can get more information.");
                }
                LOG.info(sb.toString());
            }
            return result;
        } catch (RuntimeException e) {
            String url = null;
            try {
                url = webPage.getUrl().toString();
            } catch (Exception ignored) {
            }
            StringBuilder sb = new StringBuilder();
            sb.append("Failed to analyze ").append(url == null ? "given WebPage" : url).append(" -- ")
                    .append(e.toString()).append("\n");
            if (_debugMode) {
                sb.append(
                        "If you want support (or want to support FLB) you can send an email to fighting-layout-bugs@googlegroups.com with the following information:\n");
                sb.append("    - your test code,\n");
                sb.append("    - all logged output, and\n");
                sb.append("    - all screenshot files located in: ").append(screenshotDir);
                sb.append("      (You might want to pack those into an zip archive)\n");
                sb.append("TextDetector: ").append(textDetector.getClass().getName()).append("\n");
                sb.append("EdgeDetector: ").append(edgeDetector.getClass().getName()).append("\n");
                sb.append(DebugHelper.getDiagnosticInfo(webPage.getDriver()));
            } else {
                sb.append(
                        "If you call FightingLayoutBugs.enableDebugMode() before you call FightingLayoutBugs.findLayoutBugsIn(...) you can get more information.");
            }
            String errorMessage = sb.toString();
            LOG.error(errorMessage);
            throw new RuntimeException(errorMessage, e);
        }
    } finally {
        for (Runnable runnable : _runAfterAnalysis) {
            try {
                runnable.run();
            } catch (RuntimeException e) {
                LOG.warn(runnable + " failed.", e);
            }
        }
    }
}

From source file:org.springframework.integration.splunk.support.SplunkHECWriter.java

public synchronized void stop(Runnable callback) {
    this.stop();
    callback.run();
}

From source file:de.codesourcery.eve.skills.ui.utils.PopupMenuBuilder.java

public PopupMenuBuilder addItem(String label, final Runnable r) {
    this.entries.add(new MyMenuItem(label, new AbstractAction() {

        @Override/* ww w .j  av  a2 s. co m*/
        public boolean isEnabled() {
            return true;
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            r.run();
        }
    }));
    return this;
}