Example usage for java.lang InterruptedException printStackTrace

List of usage examples for java.lang InterruptedException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.l2jfree.gameserver.instancemanager.GameTimeManager.java

public static void stopTimer() {
    try {/*w  w  w.  j  av a  2s  . com*/
        _timingThread.shutdown();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:utils.Utils.java

public static boolean isNfvoStarted(String ip, String port) {
    int i = 0;/*  w w w. j a  v a 2s . c om*/
    log.info("Waiting until NFVO is available...");
    while (!Utils.available(ip, port)) {
        i++;
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        if (i > 600) {
            return false;
        }
    }
    return true;
}

From source file:IndexService.IndexMR.java

public static void running(Configuration conf2, String inputfiles, boolean column, String ids,
        String outputdir) {//w  w w.  j  ava  2s. c  o m
    RunningJob job = run(conf2, inputfiles, column, ids, outputdir);
    try {

        String lastReport = "";
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss,SSS");
        long reportTime = System.currentTimeMillis();
        long maxReportInterval = 3 * 1000;

        while (!job.isComplete()) {
            Thread.sleep(1000);

            int mapProgress = Math.round(job.mapProgress() * 100);
            int reduceProgress = Math.round(job.reduceProgress() * 100);

            String report = " map = " + mapProgress + "%,  reduce = " + reduceProgress + "%";

            if (!report.equals(lastReport) || System.currentTimeMillis() >= reportTime + maxReportInterval) {

                String output = dateFormat.format(Calendar.getInstance().getTime()) + report;
                System.err.println(output);
                lastReport = report;
                reportTime = System.currentTimeMillis();
            }
        }

    } catch (IOException e1) {
        e1.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

}

From source file:com.ery.estorm.util.Threads.java

/**
 * If interrupted, just prints out the interrupt on STDOUT, resets interrupt and returns
 * //from   w w w  .  j  av a2s.c o  m
 * @param millis
 *            How long to sleep for in milliseconds.
 */
public static void sleep(long millis) {
    try {
        Thread.sleep(millis);
    } catch (InterruptedException e) {
        e.printStackTrace();
        Thread.currentThread().interrupt();
    }
}

From source file:com.baidu.api.client.core.ReportUtil.java

/**
 * Get the report file Url by report Id. We will check the file status internally.
 *
 * @param service  The instance of ReportService
 * @param reportId The report Id.//from  w ww  . j a  v a 2s  .c  o m
 * @param retryNum Retry times, we will check the file status every 30 seconds.
 * @return
 */
public static GetReportFileUrlResponse getReportFileUrl(ReportService service, String reportId, int retryNum) {
    LOGGER.info("We will check the file status every 30 seconds, please wait...");
    // This is the request
    GetReportStateRequest parameters = new GetReportStateRequest();
    parameters.setReportId(reportId);
    int lastStatus = -1;
    while (retryNum-- > 0) {
        try {
            TimeUnit.SECONDS.sleep(30);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        // Invoke the method.
        GetReportStateResponse ret = service.getReportState(parameters);
        // Deal with the response header, the second parameter controls whether to print the response header to
        // console
        // or not.
        ResHeader rheader = ResHeaderUtil.getResHeader(service, true);
        // If status equals zero, there is no error. Otherwise, you need to check the errors in the response header.
        if (rheader.getStatus() == 0) {
            LOGGER.info("getReportState.result\n" + ObjToStringUtil.objToString(ret));
            if (ret.getIsGenerated() == 3) {
                lastStatus = 3;
                break;
            }
        } else {
            throw new ClientBusinessException(rheader, ret);
        }
    }
    if (lastStatus == 3) {
        // This is the request
        GetReportFileUrlRequest parameters2 = new GetReportFileUrlRequest();
        parameters2.setReportId(reportId);
        // Invoke the method.
        GetReportFileUrlResponse ret = service.getReportFileUrl(parameters2);
        // Deal with the response header, the second parameter controls whether to print the response header to
        // console
        // or not.
        ResHeader rheader = ResHeaderUtil.getResHeader(service, true);
        // If status equals zero, there is no error. Otherwise, you need to check the errors in the response header.
        if (rheader.getStatus() == 0) {
            LOGGER.info("getReportFileUrl.result\n" + ObjToStringUtil.objToString(ret));
            return ret;
        } else {
            throw new ClientBusinessException(rheader, ret);
        }
    }
    throw new ClientInternalException(
            "We tried to get file for " + retryNum / 2 + " minites, but file still not ready!");
}

From source file:com.ksc.http.timers.ClientExecutionAndRequestTimerTestUtils.java

public static void interruptCurrentThreadAfterDelay(final long delay) {
    final Thread currentThread = Thread.currentThread();
    new Thread() {
        public void run() {
            try {
                Thread.sleep(delay);
                currentThread.interrupt();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }//from w  w  w.  j a va  2  s. c o  m
        };
    }.start();
}

From source file:com.baidu.api.client.core.ReportUtil.java

/**
 * Get the account file Url by file Id. We will check the file status internally.
 *
 * @param service  The instance of AccountFileService
 * @param fileId   The file Id./*from  w  ww. j a  va 2 s.  c om*/
 * @param retryNum Retry times, we will check the file status every 30 seconds.
 * @return
 */
public static GetAccountFileUrlResponse getAccountFileUrl(AccountFileService service, String fileId,
        int retryNum) {
    LOGGER.info("We will check the file status every 30 seconds, please wait...");
    // This is the request
    GetAccountFileStateRequest parameters = new GetAccountFileStateRequest();
    parameters.setFileId(fileId);
    int lastStatus = -1;
    while (retryNum-- > 0) {
        try {
            Thread.sleep(30000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        // Invoke the method.
        GetAccountFileStateResponse ret = service.getAccountFileState(parameters);
        // Deal with the response header, the second parameter controls whether to print the response header to
        // console
        // or not.
        ResHeader rheader = ResHeaderUtil.getResHeader(service, true);
        // If status equals zero, there is no error. Otherwise, you need to check the errors in the response header.
        if (rheader.getStatus() == 0) {
            LOGGER.info("getAccountFileState.result\n" + ObjToStringUtil.objToString(ret));
            if (ret.getIsGenerated() == 3) {
                lastStatus = 3;
                break;
            }
        } else {
            throw new ClientBusinessException(rheader, ret);
        }
    }
    if (lastStatus == 3) {
        // This is the request
        GetAccountFileUrlRequest parameters2 = new GetAccountFileUrlRequest();
        parameters2.setFileId(fileId);
        // Invoke the method.
        GetAccountFileUrlResponse ret = service.getAccountFileUrl(parameters2);
        // Deal with the response header, the second parameter controls whether to print the response header to
        // console
        // or not.
        ResHeader rHeader = ResHeaderUtil.getResHeader(service, true);
        // If status equals zero, there is no error. Otherwise, you need to check the errors in the response header.
        if (rHeader.getStatus() == 0) {
            LOGGER.info("getAccountFileUrl.result\n" + ObjToStringUtil.objToString(ret));
            return ret;
        } else {
            throw new ClientBusinessException(rHeader, ret);
        }
    }
    throw new ClientInternalException(
            "We tried to get file for " + retryNum / 2 + " minites, but file still not ready!");
}

From source file:it.iit.genomics.cru.bridges.liftover.ws.LiftOverRun.java

public static Mapping runLiftOver(String genome, String fromAssembly, String toAssembly, String chromosome,
        int start, int end) {

    String liftOverCommand = RESOURCE_BUNDLE.getString("liftOverCommand");

    String liftOverPath = RESOURCE_BUNDLE.getString("liftOverPath");

    String mapChainDir = RESOURCE_BUNDLE.getString("mapChainDir");

    String tmpDir = RESOURCE_BUNDLE.getString("tmpDir");

    Mapping mapping = null;//ww  w  .ja v  a 2 s .  c om

    Runtime r = Runtime.getRuntime();

    String rootFilename = String.format("%s", RandomStringUtils.randomAlphanumeric(8));

    String inputFilename = rootFilename + "-" + fromAssembly + ".bed";
    String outputFilename = rootFilename + "-" + toAssembly + ".bed";
    String unmappedFilename = rootFilename + "-" + "unmapped.bed";

    String mapChain = fromAssembly.toLowerCase() + "To" + toAssembly.toUpperCase().charAt(0)
            + toAssembly.toLowerCase().substring(1) + ".over.chain.gz";

    try {

        File tmpDirFile = new File(tmpDir);

        // if the directory does not exist, create it
        if (false == tmpDirFile.exists()) {
            System.out.println("creating directory: " + tmpDir);
            boolean result = tmpDirFile.mkdir();

            if (result) {
                System.out.println("DIR created");
            }
        }

        // Write input bed file
        File inputFile = new File(tmpDir + inputFilename);
        // if file doesnt exists, then create it
        if (!inputFile.exists()) {
            inputFile.createNewFile();
        }

        FileWriter fw = new FileWriter(inputFile.getAbsoluteFile());
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write(chromosome + "\t" + start + "\t" + end + "\n");
        bw.close();

        String commandArgs = String.format("%s %s %s %s %s", liftOverPath + "/" + liftOverCommand,
                tmpDir + inputFilename, mapChainDir + mapChain, tmpDir + outputFilename,
                tmpDir + unmappedFilename);
        System.out.println(commandArgs);

        Process p = r.exec(commandArgs);

        p.waitFor();

        BufferedReader b = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line = "";

        while ((line = b.readLine()) != null) {
            System.out.println(line);
        }
        b.close();

        b = new BufferedReader(new FileReader(tmpDir + outputFilename));

        while ((line = b.readLine()) != null) {
            String[] cells = line.split("\t");
            String newChromosome = cells[0];
            int newStart = Integer.parseInt(cells[1]);
            int newEnd = Integer.parseInt(cells[2]);
            mapping = new Mapping(genome, toAssembly, newChromosome, newStart, newEnd);
        }
        b.close();

        // delete
        File delete = new File(tmpDir + inputFilename);
        delete.delete();

        delete = new File(tmpDir + outputFilename);
        delete.delete();

        delete = new File(tmpDir + unmappedFilename);
        delete.delete();

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InterruptedException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    return mapping;
}

From source file:com.mycompany.trader.TradingConnect.java

private static void getPositions(AtomicReference<Throwable> failure) {
    StompSessionHandler handler = new AbstractTestSessionHandler(failure) {

        //this method is called when we get a connection successfully. It will auto- connect to the positions updates 
        @Override// w w  w  .j  a v a2s. c om
        public void afterConnected(final StompSession session, StompHeaders connectedHeaders) {
            System.out.println("got connect");

            session.subscribe("/user/queue/user-position-updates", new StompFrameHandler() {
                @Override
                public Type getPayloadType(StompHeaders headers) {
                    return PortfolioPosition[].class;
                }

                @Override
                public void handleFrame(StompHeaders headers, Object payload) {
                    try {
                        PortfolioPosition[] updates = (PortfolioPosition[]) payload;
                        String[] updateArray = new String[updates.length];
                        int i = 0;
                        for (PortfolioPosition u : updates) {
                            updateArray[i] = u.toString();
                            System.out.println(u.toString());
                        }
                    } catch (Throwable t) {
                        t.printStackTrace();
                    } finally {
                        session.disconnect();
                    }
                }
            });
            System.out.println("got subscribe");
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    };
    WebSocketStompClient stompClient = new WebSocketStompClient(sockJsClient);
    MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
    stompClient.setMessageConverter(converter);
    stompClient.connect("ws://localhost:{port}/blueprint-trading-services/portfolio", headers, handler, port);
    while (true)
        ;
}

From source file:org.openbaton.vnfm.utils.Utils.java

public static boolean isNfvoStarted(String ip, String port) {
    int i = 600;/*  w ww.  j ava 2  s .c o  m*/
    log.info("Testing if NFVO is available...");
    while (!Utils.available(ip, port)) {
        log.warn("NFVO is not available at " + ip + ":" + port + ". Waiting for " + i
                + "s before terminating the VNFM");
        i--;
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        if (i <= 0) {
            return false;
        }
    }
    log.info("NFVO is listening at " + ip + ":" + port);
    return true;
}