Example usage for java.lang InterruptedException getMessage

List of usage examples for java.lang InterruptedException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.tascape.qa.th.Utils.java

public static void waitForProcess(final Process process, final long timeout) throws InterruptedException {
    Thread t = new Thread() {
        @Override/*from  w  w  w .  j av a  2  s. c o m*/
        public void run() {
            try {
                Thread.sleep(timeout);
            } catch (InterruptedException ex) {
                LOG.warn(ex.getMessage());
            } finally {
                if (process != null) {
                    process.destroy();
                }
            }
        }
    };
    t.setDaemon(true);
    t.start();
    if (process != null) {
        int exitValue = process.waitFor();
        LOG.trace("process {} exits with {}", process, exitValue);
    }
}

From source file:com.servioticy.api.commons.data.CouchBase.java

/**
 * @param so/*ww  w.j  av  a 2s. co  m*/
 */
public static void setSO(SO so) {
    // TODO check to insert unique so_id
    try {
        // Asynchronous set
        OperationFuture<Boolean> setOp = cli_so.set(so.getSOKey(), 0, so.getString());
        if (!setOp.get().booleanValue()) {
            throw new ServIoTWebApplicationException(Response.Status.INTERNAL_SERVER_ERROR,
                    "Error accessing CouchBase");
        }
    } catch (InterruptedException e) {
        LOG.error(e);
        throw new ServIoTWebApplicationException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
    } catch (ExecutionException e) {
        LOG.error(e);
        throw new ServIoTWebApplicationException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
    } catch (Exception e) {
        LOG.error(e);
        throw new ServIoTWebApplicationException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
    }
}

From source file:com.servioticy.api.commons.data.CouchBase.java

/** Store the new subscriptions
 *
 * @param subs/*from   w  w  w .  j ava2s  .  com*/
 */
public static void setSubscription(Subscription subs) {
    try {
        OperationFuture<Boolean> setOp;
        setOp = cli_subscriptions.set(subs.getKey(), 0, subs.getString());
        if (!setOp.get().booleanValue()) {
            throw new ServIoTWebApplicationException(Response.Status.INTERNAL_SERVER_ERROR,
                    "Error storing subscription document");
        }

        //      // Update the SO stream with the subscription
        //      subs.getSO().update();
        //      setOp = cli_so.set(subs.getSO().getSOKey(), 0, subs.getSO().getString());
        //      if (!setOp.get().booleanValue()) {
        //        throw new ServIoTWebApplicationException(Response.Status.INTERNAL_SERVER_ERROR, null);
        //      }
    } catch (InterruptedException e) {
        LOG.error(e);
        throw new ServIoTWebApplicationException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
    } catch (ExecutionException e) {
        LOG.error(e);
        throw new ServIoTWebApplicationException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
    } catch (Exception e) {
        LOG.error(e);
        throw new ServIoTWebApplicationException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
    }
}

From source file:com.servioticy.api.commons.data.CouchBase.java

/** Store new data
 *
 * @param data//from w ww  .  ja v  a 2s.  co m
 */
public static void setData(Data data) {
    try {
        OperationFuture<Boolean> setOp;
        setOp = cli_data.set(data.getKey(), 0, data.getString());
        if (!setOp.get().booleanValue()) {
            throw new ServIoTWebApplicationException(Response.Status.INTERNAL_SERVER_ERROR,
                    "Error storing data in CouchBase");
        }

        //      // TODO -> to maintain as Subscription (array) -> to improve
        //      // Update the SO stream with the data
        //      data.getSO().update();
        //      setOp = cli_so.set(data.getSO().getSOKey(), 0, data.getSO().getString());
        //      if (!setOp.get().booleanValue()) {
        //        throw new ServIoTWebApplicationException(Response.Status.INTERNAL_SERVER_ERROR, null);
        //      }
    } catch (InterruptedException e) {
        LOG.error(e);
        throw new ServIoTWebApplicationException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
    } catch (ExecutionException e) {
        LOG.error(e);
        throw new ServIoTWebApplicationException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
    } catch (Exception e) {
        LOG.error(e);
        throw new ServIoTWebApplicationException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
    }
}

From source file:com.servioticy.api.commons.data.CouchBase.java

/** Store new actuation
*
* @param actuation/*from   w ww.  j  a v a2 s.co  m*/
*/
public static void setActuation(Actuation actuation) {
    try {
        OperationFuture<Boolean> setOp;
        setOp = cli_actuations.set(actuation.getId(), 0, actuation.getStatus());
        if (!setOp.get().booleanValue()) {
            throw new ServIoTWebApplicationException(Response.Status.INTERNAL_SERVER_ERROR,
                    "Error storing actuation in CouchBase");
        }

        //     // TODO -> to maintain as Subscription (array) -> to improve
        //     // Update the SO stream with the data
        //     data.getSO().update();
        //     setOp = cli_so.set(data.getSO().getSOKey(), 0, data.getSO().getString());
        //     if (!setOp.get().booleanValue()) {
        //       throw new ServIoTWebApplicationException(Response.Status.INTERNAL_SERVER_ERROR, null);
        //     }
    } catch (InterruptedException e) {
        LOG.error(e);
        throw new ServIoTWebApplicationException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
    } catch (ExecutionException e) {
        LOG.error(e);
        throw new ServIoTWebApplicationException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
    } catch (Exception e) {
        LOG.error(e);
        throw new ServIoTWebApplicationException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
    }
}

From source file:com.tascape.qa.th.Utils.java

public static void waitForOutputLine(final Process process, String lineExpected, final long timeout)
        throws IOException {
    Thread t = new Thread() {
        @Override/*from   w  w  w  .j  a v a2  s.com*/
        public void run() {
            try {
                Thread.sleep(timeout);
            } catch (InterruptedException ex) {
                LOG.warn(ex.getMessage());
            } finally {
                if (process != null) {
                    process.destroy();
                }
            }
        }
    };
    t.setName(Thread.currentThread().getName() + "-" + t.hashCode());
    t.setDaemon(true);
    t.start();

    try (BufferedReader stdIn = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
        for (String line = stdIn.readLine(); line != null;) {
            if (line.contains(lineExpected)) {
                break;
            }
            line = stdIn.readLine();
        }
    }
    t.interrupt();
}

From source file:com.tascape.qa.th.Utils.java

/**
 *
 * @param path          directory to clean
 * @param keepAliveHour any file/directory having last modified time longer than keepAliveHour will be deleted
 * @param namePrefix    file name prefix
 *//*from w w w  .  j av a2s. c  o m*/
public static void cleanDirectory(final String path, final float keepAliveHour, final String namePrefix) {
    final long intervalMillis = 3600000;
    final File dir = new File(path);
    if (!dir.exists()) {
        return;
    }
    Thread thread = new Thread() {
        @Override
        public void run() {
            while (true) {
                long lastModifiedMillis = (long) (System.currentTimeMillis() - keepAliveHour * 3600000);
                Collection<File> files = FileUtils.listFiles(dir, null, true);
                for (File file : files) {
                    if (file.lastModified() < lastModifiedMillis && file.getName().startsWith(namePrefix)) {
                        LOG.debug("Delete {}", file);
                        if (!FileUtils.deleteQuietly(file)) {
                            LOG.debug("Cannot delete {}", file);
                        }
                    }
                }
                try {
                    LOG.debug("Waiting for next cleanup...");
                    Thread.sleep(intervalMillis);
                } catch (InterruptedException ex) {
                    LOG.warn(ex.getMessage());
                    return;
                }
            }
        }
    };
    thread.setName(Thread.currentThread().getName() + "-cleaning-" + thread.hashCode());
    thread.setDaemon(true);
    LOG.info(
            "Starting directory cleaning thread (scanning hourly), all files/directories in {} and older than {} "
                    + "hour(s) and starts with {} will be deleted",
            dir, keepAliveHour, namePrefix);
    thread.start();
}

From source file:gridool.db.partitioning.phihash.csv.grace.CsvGraceHashPartitioningTask.java

private static void runShuffleJob(final GridKernel kernel, final PartitioningJobConf conf,
        final Map<GridNode, MutableLong> recMap, final Map<String, OutputStream> outputMap,
        final String deploymentGroup) {
    if (outputMap != null) {
        conf.setOutputMap(outputMap);//from  ww w .  ja va  2 s  .  c om
    }
    PartitioningJobType jobType = conf.getJobConf().getJobType();
    Class<? extends GridJob<PartitioningJobConf, Map<GridNode, MutableInt>>> jobClass = jobType
            .getFirstPartitioningJobClass();
    //final GridJobFuture<Map<GridNode, MutableInt>> future = kernel.execute(CsvGraceHashPartitioningJob.class, conf);
    final GridJobFuture<Map<GridNode, MutableInt>> future = kernel.execute(jobClass, conf);
    final Map<GridNode, MutableInt> map;
    try {
        map = future.get(); // wait for execution
    } catch (InterruptedException ie) {
        LOG.error(ie.getMessage(), ie);
        throw new IllegalStateException(ie);
    } catch (ExecutionException ee) {
        LOG.error(ee.getMessage(), ee);
        throw new IllegalStateException(ee);
    }
    synchronized (recMap) {
        for (final Map.Entry<GridNode, MutableInt> e : map.entrySet()) {
            GridNode node = e.getKey();
            MutableInt assigned = e.getValue();
            long v = assigned.longValue();
            MutableLong prev = recMap.get(node);
            if (prev == null) {
                recMap.put(node, new MutableLong(v));
            } else {
                prev.add(v);
            }
        }
    }
}

From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.kubernetes.KubernetesProviderUtils.java

static void storeInstanceLogs(JobExecutor jobExecutor, AccountDeploymentDetails<KubernetesAccount> details,
        String namespace, String instanceName, String containerName, File outputFile) {
    List<String> command = kubectlAccountCommand(details);
    command.add("--namespace");
    command.add(namespace);/* w  ww . j  a va 2s.  c o m*/
    command.add("logs");
    command.add(instanceName);
    command.add(containerName);

    JobRequest request = new JobRequest().setTokenizedCommand(command);

    JobStatus status;
    try {
        status = jobExecutor.backoffWait(jobExecutor.startJob(request));
    } catch (InterruptedException e) {
        throw new DaemonTaskInterrupted(e);
    }

    try {
        IOUtils.write(status.getStdOut().getBytes(), new FileOutputStream(new File(outputFile, containerName)));
    } catch (IOException e) {
        throw new HalException(Severity.FATAL, "Unable to store logs: " + e.getMessage(), e);
    }
}

From source file:com.datatorrent.stram.StramMiniClusterTest.java

@BeforeClass
public static void setup() throws InterruptedException, IOException {
    LOG.info("Starting up YARN cluster");
    conf = StramClientUtils.addDTDefaultResources(conf);
    conf.setInt(YarnConfiguration.RM_SCHEDULER_MINIMUM_ALLOCATION_MB, 64);
    conf.setInt("yarn.nodemanager.vmem-pmem-ratio", 20); // workaround to avoid containers being killed because java allocated too much vmem
    conf.setStrings("yarn.scheduler.capacity.root.queues", "default");
    conf.setStrings("yarn.scheduler.capacity.root.default.capacity", "100");

    StringBuilder adminEnv = new StringBuilder(1024);
    if (System.getenv("JAVA_HOME") == null) {
        adminEnv.append("JAVA_HOME=").append(System.getProperty("java.home"));
        adminEnv.append(",");
    }/*from  w  w w  .j  av  a 2 s.  c o  m*/
    adminEnv.append("MALLOC_ARENA_MAX=4"); // see MAPREDUCE-3068, MAPREDUCE-3065
    adminEnv.append(",");
    adminEnv.append("CLASSPATH=").append(getTestRuntimeClasspath());

    conf.set(YarnConfiguration.NM_ADMIN_USER_ENV, adminEnv.toString());

    if (yarnCluster == null) {
        yarnCluster = new MiniYARNCluster(StramMiniClusterTest.class.getName(), 1, 1, 1);
        yarnCluster.init(conf);
        yarnCluster.start();
    }

    conf = yarnCluster.getConfig();
    URL url = Thread.currentThread().getContextClassLoader().getResource("yarn-site.xml");
    if (url == null) {
        LOG.error("Could not find 'yarn-site.xml' dummy file in classpath");
        throw new RuntimeException("Could not find 'yarn-site.xml' dummy file in classpath");
    }
    File confFile = new File(url.getPath());
    yarnCluster.getConfig().set("yarn.application.classpath", confFile.getParent());
    OutputStream os = new FileOutputStream(confFile);
    LOG.debug("Conf file: {}", confFile);
    yarnCluster.getConfig().writeXml(os);
    os.close();

    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        LOG.info("setup thread sleep interrupted. message=" + e.getMessage());
    }
}