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:org.openvpms.component.business.service.security.SecurityServiceTests.java

/**
 * Executes an operation by a user with the specified authorities.
 *
 * @param operation   the operation to execute
 * @param fail        if <tt>true</tt>, expect the operation to fail, otherwise expect it to succeed
 * @param authorities the user's authorities
 *//*  w  w w  .  j a  va  2 s .co  m*/
private void checkOperation(Runnable operation, boolean fail, String... authorities) {
    createSecurityContext("jima" + seed, "jima", authorities);
    ++seed;
    try {
        operation.run();
        if (fail) {
            fail("Expected operation to fail");
        }
    } catch (OpenVPMSAccessDeniedException exception) {
        if (!fail) {
            fail("Didn't expect operation to fail");
        }
        if (exception.getErrorCode() != OpenVPMSAccessDeniedException.ErrorCode.AccessDenied) {
            fail("Incorrect error code was specified during the exception");
        }
    }
}

From source file:com.yahoo.squidb.data.JSONPropertyTest.java

protected void testWithAllMappers(Runnable toTest) {
    for (JSONMapper mapper : MAPPERS) {
        database.clear();//from   ww w .j a  v a2  s. co m
        JSONPropertySupport.setJSONMapper(mapper);
        toTest.run();
    }
}

From source file:me.Wundero.Ray.variables.Variables.java

/**
 * Register a new variable wrapper/* w w w  .ja  v a  2 s  .c  o m*/
 */
public boolean registerWrapper(String key, Runnable r) {
    return registerWrapper(key, (BiConsumer<Variable, Text>) (v, t) -> {
        r.run();
    }, 0);
}

From source file:myfightinglayoutbugs.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>/*from   w ww.ja v a2s  .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));
            }
            // TODO: If layout bugs have been detected, LOG.info(diagnostic info + further instrcutions)
            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 code.\n");
                sb.append("    - All logged output.\n");
                sb.append("    - All screenshot files (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()));
                // TODO: We should create the zip file here ourselves.
            } 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:be.fgov.kszbcss.rhq.websphere.config.NamedThreadFactory.java

public Thread newThread(final Runnable runnable) {
    // The log4j MDC is stored in an InheritableThreadLocal. We need to clear it.
    Runnable runnableWrapper = new Runnable() {
        public void run() {
            Hashtable<?, ?> context = MDC.getContext();
            if (context != null) {
                context.clear();//from   w  ww  .j ava  2s .co  m
            }
            runnable.run();
        }
    };
    Thread t = new Thread(group, runnableWrapper, namePrefix + "-" + threadNumber.getAndIncrement());
    t.setDaemon(false);
    t.setUncaughtExceptionHandler(this);
    return t;
}

From source file:org.jspringbot.keyword.expression.ExpressionHelper.java

public void variableScope(List<Object> variables, Runnable runnable) throws Exception {
    try {// ww w .j av a  2  s. c  om
        ScopedVariableHolder.push(new HashMap<String, Object>());
        initVariables(variables);

        runnable.run();
    } finally {
        ScopedVariableHolder.pop();
    }
}

From source file:com.hp.alm.ali.Handler.java

public void done(Runnable runnable) {
    if (firstError == null) {
        try {/*from  w w w.  ja  v a  2s . co m*/
            runnable.run();
        } catch (Throwable t) {
            firstError = t;
        }
    }
    done();
}

From source file:de.jaetzold.philips.hue.HueLightGroup.java

@Override
public void stateChangeTransaction(Integer transitionTime, Runnable changes) {
    openStateChangeTransaction(transitionTime);
    try {/*  w  w w  .j a  v  a2 s  .  com*/
        changes.run();
    } catch (Throwable t) {
        stateTransactionJson.set(null);
        throw t;
    } finally {
        commitStateChangeTransaction();
    }
}

From source file:me.Wundero.Ray.variables.Variables.java

/**
 * Register a new variable//  www  .  j  av  a2s  .  co m
 */
public boolean registerVariable(String key, Runnable task) {
    return registerVariable(key.toLowerCase().trim(), (Consumer<Map<Param, Object>>) (objects) -> task.run());
}

From source file:org.openvpms.component.business.service.archetype.rule.ArchetypeRuleService.java

/**
 * Executes an operation in a transaction, as follows:
 * <ol>//from   w  w w.  j  a v  a  2s .  co m
 * <li>begin transaction
 * <li>execute <em>before</em> rules for {@code object}
 * <li>execute {@code operation}
 * <li>execute <em>after</em> rules for {@code object}
 * <li>commit on success/rollback on failure
 * </ol>
 *
 * @param name      the name of the operation
 * @param object    the object that will be supplied to before and after rules
 * @param operation the operation to execute
 */
private void execute(final String name, final IMObject object, final Runnable operation) {
    template.execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus status) {
            executeRules(name, object, true);
            operation.run();
            executeRules(name, object, false);
            return null;
        }
    });
}