Example usage for java.lang InterruptedException InterruptedException

List of usage examples for java.lang InterruptedException InterruptedException

Introduction

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

Prototype

public InterruptedException(String s) 

Source Link

Document

Constructs an InterruptedException with the specified detail message.

Usage

From source file:Main.java

/**
 * /*from w w w .j av a  2s .c  o m*/
 * @param type
 *        component type
 * @param name
 *        component name
 * @param logger
 *        if not null is used to log a message at error level
 * @throws InterruptedException
 */
public static void checkInterrupted(String type, String name, Logger logger) throws InterruptedException {
    if (Thread.currentThread().isInterrupted()) {
        logger.error(type + "[" + name + "] interrupted.");
        throw new InterruptedException(type + "[" + name + "] interrupted.");
    }
}

From source file:com.netflix.spinnaker.halyard.cli.services.v1.ResponseUnwrapper.java

public static <C, T> T get(DaemonTask<C, T> task) {
    int lastTaskCount = 0;

    task = Daemon.getTask(task.getUuid());
    Set<String> loggedEvents = new HashSet<>();
    while (!task.getState().isTerminal()) {
        updateCycle();//w w  w.  ja va 2  s  .co  m
        if (interrupted) {
            Daemon.interruptTask(task.getUuid());
            throw TaskKilledException.interrupted(new InterruptedException("Interrupted by user"));
        }

        List<DaemonTask> aggregatedTasks = aggregateTasks(task);
        lastTaskCount = formatTasks(aggregatedTasks, lastTaskCount);
        logTasks(aggregatedTasks, loggedEvents);
        try {
            Thread.sleep(WAIT_MILLIS);
        } catch (InterruptedException ignored) {
        }

        task = Daemon.getTask(task.getUuid());
    }

    List<DaemonTask> aggregatedTasks = aggregateTasks(task);
    formatTasks(aggregatedTasks, lastTaskCount);
    logTasks(aggregatedTasks, loggedEvents);

    DaemonResponse<T> response = task.getResponse();

    formatProblemSet(response.getProblemSet());
    switch (task.getState()) {
    case TIMED_OUT:
        throw TaskKilledException.timeout();
    case INTERRUPTED:
        throw TaskKilledException.interrupted(task.getFatalError());
    case FAILED:
        Exception fatal = task.getFatalError();
        if (fatal == null) {
            throw new RuntimeException("Task failed without reason. This is a bug.");
        } else {
            throw new ExpectedDaemonFailureException(fatal);
        }
    default:
        return response.getResponseBody();
    }
}

From source file:Main.java

/**
 * /*from ww  w.  j  a  va 2  s.  c  om*/
 * @param message
 *        the error message
 * @param logger
 *        if not null is used to log a message at error level
 * @throws InterruptedException
 */
public static void checkInterrupted(String message, Logger logger) throws InterruptedException {
    if (Thread.currentThread().isInterrupted()) {
        logger.error(message);
        throw new InterruptedException(message);
    }
}

From source file:org.marketcetera.util.except.ExceptUtils.java

/**
 * Checks whether the calling thread has been interrupted, and, if
 * so, throws an {@link InterruptedException} with the default
 * interruption message and the given underlying cause. The given
 * underlying cause is set on the thrown exception. The
 * interrupted status of the thread is cleared.
 *
 * @param cause The cause.// ww w  . ja v a 2  s . c  om
 *
 * @throws InterruptedException Thrown if the calling thread
 * was interrupted.
 */

public static void checkInterruption(Throwable cause) throws InterruptedException {
    if (Thread.currentThread().isInterrupted()) {
        InterruptedException ex = new InterruptedException(Messages.THREAD_INTERRUPTED.getText());
        ex.initCause(cause);
        throw ex;
    }
}

From source file:org.talend.updates.runtime.ui.util.UIUtils.java

public static void checkMonitor(IProgressMonitor monitor) throws Exception {
    boolean isInterrupted = false;
    if (monitor != null) {
        if (monitor.isCanceled()) {
            isInterrupted = true;//w  ww . ja v a 2  s  . com
        }
    }
    if (Thread.currentThread().isInterrupted()) {
        isInterrupted = true;
    }
    if (isInterrupted) {
        throw new InterruptedException(Messages.getString("UIUtils.exception.interrupt")); //$NON-NLS-1$
    }
}

From source file:edu.usc.pgroup.louvain.hadoop.ReduceCommunity.java

@Override
protected void reduce(Text key, Iterable<BytesWritable> values, Context context)
        throws IOException, InterruptedException {

    Graph g = null;/*from w w  w  . j  a  v  a2s.c om*/
    try {
        System.out.println("********************REDUCE****************");
        g = reconstructGraph(values);
    } catch (Exception e) {
        e.printStackTrace();
        throw new InterruptedException(e.toString());
    }
    System.out.println("REDUCE...... GRAPH DONE");
    Community c = new Community(g, -1, precision);

    double mod = c.modularity();

    boolean improvement = true;

    int level = 2;

    if (verbose) {
        System.out.print("level " + level);
        System.out.print("  start computation");
        System.out.println("  network size: " + c.getG().getNb_nodes() + " nodes, " + c.getG().getNb_links()
                + " links, " + c.getG().getTotal_weight() + " weight.");
    }

    improvement = c.one_level();
    double new_mod = c.modularity();

    if (++level == display_level)
        g.display();
    if (display_level == -1) {
        String filePath = outpath + File.separator + "out_" + (level - 1) + "_r.txt";
        try {
            c.display_partition(filePath);
        } catch (Exception e) {
            e.printStackTrace();
            throw new InterruptedException(e.toString());
        }
    }

    Graph g2 = c.partition2graph_binary();

    if (verbose) {
        System.out.println("  network size: " + c.getG().getNb_nodes() + " nodes, " + c.getG().getNb_links()
                + " links, " + c.getG().getTotal_weight() + " weight.");
    }

    c = new Community(g2, -1, precision);

    mod = new_mod;

    do {

        if (verbose) {
            System.out.print("level in loop" + level);
            System.out.print("  start computation");
            System.out.println("  network size: " + c.getG().getNb_nodes() + " nodes, " + c.getG().getNb_links()
                    + " links, " + c.getG().getTotal_weight() + " weight.");
        }

        improvement = c.one_level();
        new_mod = c.modularity();

        if (++level == display_level)
            g.display();
        if (display_level == -1) {

            String filePath = outpath + File.separator + "out_" + (level - 1) + "_r.txt";
            try {
                c.display_partition(filePath);
            } catch (Exception e) {
                e.printStackTrace();
                throw new InterruptedException(e.toString());
            }
        }

        g2 = c.partition2graph_binary();

        if (verbose) {
            System.out.print("  network size: " + c.getG().getNb_nodes() + " nodes, " + c.getG().getNb_links()
                    + " links, " + c.getG().getTotal_weight() + " weight.");
        }

        c = new Community(g2, -1, precision);

        mod = new_mod;

    } while (improvement);

}

From source file:tools.datasync.db2db.seed.DbSeedProducer.java

public boolean publish(JSON record) throws InterruptedException {

    if (stop) {/*  w w  w.j  a v  a2s .c  o m*/
        throw new InterruptedException("");
    }
    SeedRecord seed = null;
    try {
        String entityId = Ids.EntityId.get(record.getEntity());
        String recordId = String.valueOf(record.get(Ids.KeyColumn.get(record.getEntity())));
        String recordJson = jsonMapper.writeValueAsString(record);
        String recordHash = hashGenerator.generate(recordJson);
        String origin = me.getPeerId();
        seed = new SeedRecord(entityId, recordId, recordHash, recordJson, origin);
        logger.finest("generated seed record: " + seed);
    } catch (IOException e) {
        exceptionHandler.handle(e, Level.WARNING, "Error while JSON Serialization", record);
    }

    try {
        if (seed != null) {
            logger.finer("Publishing seed record: " + seed);
            dataHandler.seedOut(seed);
            return true;
        }
    } catch (Exception ex) {
        exceptionHandler.handle(ex, Level.WARNING, "Error while sending record to peer", record);
    }

    return false;
}

From source file:org.openhab.binding.neeo.internal.NeeoUtil.java

/**
 * Checks whether the current thread has been interrupted and throws {@link InterruptedException} if it's been
 * interrupted// w  w w .j  a  va 2  s.  co  m
 *
 * @throws InterruptedException the interrupted exception
 */
public static void checkInterrupt() throws InterruptedException {
    if (Thread.currentThread().isInterrupted()) {
        throw new InterruptedException("thread interrupted");
    }
}

From source file:org.talend.designer.esb.runcontainer.ui.wizard.AddRuntimeWizard.java

@Override
public boolean performFinish() {
    if (dirPage.shouldInstallNewContainer()) {
        target = dirPage.getTargetDir();
        if (target == null) {
            target = RunContainerPreferenceInitializer.P_DEFAULT_ESB_RUNTIME_LOCATION;
        }/*from  w w  w. j a  v a  2 s.co m*/
        try {
            getContainer().run(true, true, new IRunnableWithProgress() {

                @Override
                public void run(IProgressMonitor monitor)
                        throws InvocationTargetException, InterruptedException {
                    try {
                        FileUtil.unzipContainer(dirPage.getRuntimeArchive(), target, monitor);
                    } catch (IOException e) {
                        throw new InterruptedException(
                                RunContainerMessages.getString("AddRuntimeWizard.ErrorCopy"));
                    }
                }
            });
        } catch (Exception e) {
            MessageDialog.openError(getContainer().getShell(),
                    RunContainerMessages.getString("AddRuntimeWizard.ErrorCopy"), //$NON-NLS-1$
                    ExceptionUtils.getStackTrace(e));
        }
    } else {
        target = dirPage.getRuntimeHome();
    }
    /*
     * if (dirPage.isCopyNeeded()) { try { String runtimeHome = dirPage.getRuntimeHome(); getContainer().run(true,
     * true, new IRunnableWithProgress() {
     * 
     * @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
     * try { FileUtil.copyContainer(runtimeHome, target, monitor); } catch (IOException e) { } }
     * 
     * }); } catch (Exception e) { MessageDialog.openError(this.getShell(),
     * RunContainerMessages.getString("AddRuntimeWizard.ErrorCopy"), ExceptionUtils.getStackTrace(e)); //$NON-NLS-1$
     * return false; } } else { target = dirPage.getRuntimeHome(); }
     */
    // MessageDialog.openInformation(this.getShell(), "Not implemented", "Only copying is supported");

    // return false;
    return true;
}

From source file:de.hybris.platform.b2b.WorkflowIntegrationTest.java

public boolean waitForProcessAction(final String businessProcessCode, final String actionCode,
        final long maxWait) throws InterruptedException {
    final long start = System.currentTimeMillis();

    while (true) {
        final BusinessProcessModel bp = businessProcessService.getProcess(businessProcessCode);
        modelService.refresh(bp); // without refresh this object is stale

        final String currentAction = bp.getCurrentTasks() != null && bp.getCurrentTasks().iterator().hasNext()
                ? bp.getCurrentTasks().iterator().next().getAction()
                : null;// w w w  .  j  a va2s. c  o m
        if (StringUtils.equals(actionCode, currentAction)) {
            return true;
        }

        if (System.currentTimeMillis() - start > maxWait) {
            throw new InterruptedException(String.format(
                    "BusinessProcess %s [%s] did not go into a specified action %s, " + "current action %s, "
                            + "waited for %s ",
                    bp.getCode(), bp.getProcessState(), actionCode, currentAction,
                    Utilities.formatTime(System.currentTimeMillis() - start)));
        } else {
            Thread.sleep(1000);
            if (bp instanceof B2BApprovalProcessModel) {
                final OrderModel order = ((B2BApprovalProcessModel) bp).getOrder();
                //               this.modelService.refresh(order);
                final WorkflowModel workflow = order.getWorkflow();
                if (LOG.isInfoEnabled() && workflow != null) {
                    LOG.debug(String.format("Workflow %s [$s] for order %s [%s] has status %s",
                            workflow.getCode(), workflow.getDescription(), order.getCode(), order.getStatus(),
                            workflow.getStatus()));
                }
            }
            LOG.debug(String.format("Waited for process state of %s for %s current state is %s", actionCode,
                    Utilities.formatTime(System.currentTimeMillis() - start), bp.getProcessState()));
        }
    }
}