Example usage for java.lang Throwable printStackTrace

List of usage examples for java.lang Throwable printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

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

Usage

From source file:com.aw.core.business.AWContext.java

public static void initBuildInfo() {
    buildNumber = "<Undefined>";
    java.util.Properties props = new java.util.Properties();
    //        java.net.URL url = ClassLoader.getSystemResource("version.properties");
    Resource r = new ClassPathResource("version.properties");
    try {// ww w .  j  a  v  a 2s.  c o  m
        props.load(r.getInputStream());
        buildNumber = (String) props.get("version");
    } catch (Throwable e) {
        logger.warn("Error loading project version Info", e);
        e.printStackTrace();
    }

}

From source file:com.splout.db.benchmark.TCPTest.java

public static void tcpTest(String file, String table)
        throws UnknownHostException, IOException, InterruptedException, JSONSerDeException {
    final TCPServer server = new TCPServer(8888, file, table);

    Thread t = new Thread() {
        @Override//from w  w w  .jav a 2s.  co m
        public void run() {
            server.serve();
        }
    };
    t.start();

    while (!server.isServing()) {
        Thread.sleep(100);
    }

    Socket clientSocket = new Socket("localhost", 8888);
    DataInputStream inFromServer = new DataInputStream(new BufferedInputStream(clientSocket.getInputStream()));

    try {
        do {
            // Read a record
            inFromServer.readUTF();
            inFromServer.readInt();
            inFromServer.readDouble();
            inFromServer.readUTF();
        } while (true);
    } catch (Throwable th) {
        th.printStackTrace();
    }

    clientSocket.close();
    server.stop();
    t.interrupt();
}

From source file:heigit.ors.util.FileUtility.java

public static String getMd5OfFile(String filePath) {
    String returnVal = "";
    try {//from  www  . j  ava  2  s .c  o m
        InputStream input = new FileInputStream(filePath);
        byte[] buffer = new byte[1024];
        MessageDigest md5Hash = MessageDigest.getInstance("MD5");
        int numRead = 0;
        while (numRead != -1) {
            numRead = input.read(buffer);
            if (numRead > 0) {
                md5Hash.update(buffer, 0, numRead);
            }
        }
        input.close();

        byte[] md5Bytes = md5Hash.digest();
        for (int i = 0; i < md5Bytes.length; i++) {
            returnVal += Integer.toString((md5Bytes[i] & 0xff) + 0x100, 16).substring(1);
        }
    } catch (Throwable t) {
        t.printStackTrace();
    }

    return returnVal.toUpperCase();
}

From source file:io.undertow.server.handlers.form.MultipartFormDataParserTestCase.java

private static HttpHandler createHandler() {
    return new HttpHandler() {
        @Override// w  w  w  .  j  a v  a2  s  .c o m
        public void handleRequest(final HttpServerExchange exchange) throws Exception {
            System.out.println("In handler");
            final FormDataParser parser = FormParserFactory.builder().build().createParser(exchange);
            System.out.println("Created parser");
            try {
                FormData data = parser.parseBlocking();
                System.out.println("done parsing");
                exchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR);
                if (data.getFirst("formValue").getValue().equals("myValue")) {
                    FormData.FormValue file = data.getFirst("file");
                    if (file.isFile()) {
                        if (file.getPath() != null) {
                            if (new String(Files.readAllBytes(file.getPath())).startsWith("file contents")) {
                                exchange.setStatusCode(StatusCodes.OK);
                            }
                        }
                    }
                }
                exchange.endExchange();
            } catch (Throwable e) {
                e.printStackTrace();
                exchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR);
                exchange.endExchange();
            } finally {
                IoUtils.safeClose(parser);
            }
        }
    };
}

From source file:us.colloquy.util.ElasticLoader.java

public static void uploadDiariesToElasticServer(Properties properties, List<DiaryEntry> diaryEntries) {

    try (RestHighLevelClient client = new RestHighLevelClient(RestClient
            .builder(new HttpHost("localhost", 9200, "http"), new HttpHost("localhost", 9201, "http")))) {

        BulkRequest request = new BulkRequest();

        indexDiaries(diaryEntries, client, request);

    } catch (Throwable t) {
        t.printStackTrace();
    }/*from   w w w  . j  a  v a  2s .c om*/
}

From source file:com.newlandframework.rpc.netty.MessageRecvExecutor.java

public static void submit(Callable<Boolean> task, final ChannelHandlerContext ctx, final MessageRequest request,
        final MessageResponse response) {
    if (threadPoolExecutor == null) {
        synchronized (MessageRecvExecutor.class) {
            if (threadPoolExecutor == null) {
                threadPoolExecutor = MoreExecutors
                        .listeningDecorator((ThreadPoolExecutor) (RpcSystemConfig.isMonitorServerSupport()
                                ? RpcThreadPool.getExecutorWithJmx(threadNums, queueNums)
                                : RpcThreadPool.getExecutor(threadNums, queueNums)));
            }//from  w ww .  j a  v a 2 s .  co m
        }
    }

    ListenableFuture<Boolean> listenableFuture = threadPoolExecutor.submit(task);
    Futures.addCallback(listenableFuture, new FutureCallback<Boolean>() {
        public void onSuccess(Boolean result) {
            ctx.writeAndFlush(response).addListener(new ChannelFutureListener() {
                public void operationComplete(ChannelFuture channelFuture) throws Exception {
                    System.out.println("RPC Server Send message-id respone:" + request.getMessageId());
                }
            });
        }

        public void onFailure(Throwable t) {
            t.printStackTrace();
        }
    }, threadPoolExecutor);
}

From source file:ch.bender.evacuate.RunnerCheckDirectoriesTest.java

/**
 * Executed at the end of all tests.//  ww  w .j a  va2  s  .  c o m
 * <p>
 * 
 * @throws Throwable
 *         On any problem
 */
@AfterClass
public static final void doAfterClass() throws Throwable {
    System.out.println("doAfterClass() entering...");
    try {
        if (Files.exists(Testconstants.ROOT_DIR)) {
            Helper.deleteDirRecursive(Testconstants.ROOT_DIR);
        }

        System.out.println("doAfterClass() leaving...");
    } catch (Throwable e) {
        System.err.println("Throwable caught in doAfterClass()");
        e.printStackTrace();
    }
}

From source file:com.alibaba.rocketmq.namesrv.NamesrvStartup.java

public static NamesrvController main0(String[] args) {
    System.setProperty(RemotingCommand.RemotingVersionKey, Integer.toString(MQVersion.CurrentVersion));

    // Socket???/*from w  w  w  . j a  v a 2s. c  o m*/
    if (null == System.getProperty(NettySystemConfig.SystemPropertySocketSndbufSize)) {
        NettySystemConfig.SocketSndbufSize = 2048;
    }

    // Socket?
    if (null == System.getProperty(NettySystemConfig.SystemPropertySocketRcvbufSize)) {
        NettySystemConfig.SocketRcvbufSize = 1024;
    }

    try {
        // ?
        Options options = ServerUtil.buildCommandlineOptions(new Options());
        commandLine = ServerUtil.parseCmdLine("mqnamesrv", args, buildCommandlineOptions(options),
                new PosixParser());
        if (null == commandLine) {
            System.exit(-1);
            return null;
        }

        // ??
        final NamesrvConfig namesrvConfig = new NamesrvConfig();
        final NettyServerConfig nettyServerConfig = new NettyServerConfig();
        nettyServerConfig.setListenPort(9876);
        if (commandLine.hasOption('c')) {
            String file = commandLine.getOptionValue('c');
            if (file != null) {
                InputStream in = new BufferedInputStream(new FileInputStream(file));
                properties = new Properties();
                properties.load(in);
                MixAll.properties2Object(properties, namesrvConfig);
                MixAll.properties2Object(properties, nettyServerConfig);
                System.out.println("load config properties file OK, " + file);
                in.close();
            }
        }

        // ??
        if (commandLine.hasOption('p')) {
            MixAll.printObjectProperties(null, namesrvConfig);
            MixAll.printObjectProperties(null, nettyServerConfig);
            System.exit(0);
        }

        MixAll.properties2Object(ServerUtil.commandLine2Properties(commandLine), namesrvConfig);

        if (null == namesrvConfig.getRocketmqHome()) {
            System.out.println("Please set the " + MixAll.ROCKETMQ_HOME_ENV
                    + " variable in your environment to match the location of the RocketMQ installation");
            System.exit(-2);
        }

        // ?Logback
        LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
        JoranConfigurator configurator = new JoranConfigurator();
        configurator.setContext(lc);
        lc.reset();
        configurator.doConfigure(namesrvConfig.getRocketmqHome() + "/conf/logback_namesrv.xml");
        final Logger log = LoggerFactory.getLogger(LoggerName.NamesrvLoggerName);

        // ????
        MixAll.printObjectProperties(log, namesrvConfig);
        MixAll.printObjectProperties(log, nettyServerConfig);

        // ??
        final NamesrvController controller = new NamesrvController(namesrvConfig, nettyServerConfig);
        boolean initResult = controller.initialize();
        if (!initResult) {
            controller.shutdown();
            System.exit(-3);
        }

        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
            private volatile boolean hasShutdown = false;
            private AtomicInteger shutdownTimes = new AtomicInteger(0);

            @Override
            public void run() {
                synchronized (this) {
                    log.info("shutdown hook was invoked, " + this.shutdownTimes.incrementAndGet());
                    if (!this.hasShutdown) {
                        this.hasShutdown = true;
                        long begineTime = System.currentTimeMillis();
                        controller.shutdown();
                        long consumingTimeTotal = System.currentTimeMillis() - begineTime;
                        log.info("shutdown hook over, consuming time total(ms): " + consumingTimeTotal);
                    }
                }
            }
        }, "ShutdownHook"));

        // ??
        controller.start();

        String tip = "The Name Server boot success.";
        log.info(tip);
        System.out.println(tip);

        return controller;
    } catch (Throwable e) {
        e.printStackTrace();
        System.exit(-1);
    }

    return null;
}

From source file:com.ict.dtube.namesrv.NamesrvStartup.java

public static NamesrvController main0(String[] args) {
    System.setProperty(RemotingCommand.RemotingVersionKey, Integer.toString(MQVersion.CurrentVersion));

    // Socket???//from ww w. j a va2  s  . co m
    if (null == System.getProperty(NettySystemConfig.SystemPropertySocketSndbufSize)) {
        NettySystemConfig.SocketSndbufSize = 2048;
    }

    // Socket?
    if (null == System.getProperty(NettySystemConfig.SystemPropertySocketRcvbufSize)) {
        NettySystemConfig.SocketRcvbufSize = 1024;
    }

    try {
        // ?
        Options options = ServerUtil.buildCommandlineOptions(new Options());
        commandLine = ServerUtil.parseCmdLine("mqnamesrv", args, buildCommandlineOptions(options),
                new PosixParser());
        if (null == commandLine) {
            System.exit(-1);
            return null;
        }

        // ??
        final NamesrvConfig namesrvConfig = new NamesrvConfig();
        final NettyServerConfig nettyServerConfig = new NettyServerConfig();
        nettyServerConfig.setListenPort(9876);
        if (commandLine.hasOption('c')) {
            String file = commandLine.getOptionValue('c');
            if (file != null) {
                InputStream in = new BufferedInputStream(new FileInputStream(file));
                properties = new Properties();
                properties.load(in);
                MixAll.properties2Object(properties, namesrvConfig);
                MixAll.properties2Object(properties, nettyServerConfig);
                System.out.println("load config properties file OK, " + file);
                in.close();
            }
        }

        // ??
        if (commandLine.hasOption('p')) {
            MixAll.printObjectProperties(null, namesrvConfig);
            MixAll.printObjectProperties(null, nettyServerConfig);
            System.exit(0);
        }

        MixAll.properties2Object(ServerUtil.commandLine2Properties(commandLine), namesrvConfig);

        if (null == namesrvConfig.getDtubeHome()) {
            System.out.println("Please set the " + MixAll.DTUBE_HOME_ENV
                    + " variable in your environment to match the location of the Dtube installation");
            System.exit(-2);
        }

        // ?Logback
        LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
        JoranConfigurator configurator = new JoranConfigurator();
        configurator.setContext(lc);
        lc.reset();
        configurator.doConfigure(namesrvConfig.getDtubeHome() + "/conf/logback_namesrv.xml");
        final Logger log = LoggerFactory.getLogger(LoggerName.NamesrvLoggerName);

        // ????
        MixAll.printObjectProperties(log, namesrvConfig);
        MixAll.printObjectProperties(log, nettyServerConfig);

        // ??
        final NamesrvController controller = new NamesrvController(namesrvConfig, nettyServerConfig);
        boolean initResult = controller.initialize();
        if (!initResult) {
            controller.shutdown();
            System.exit(-3);
        }

        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
            private volatile boolean hasShutdown = false;
            private AtomicInteger shutdownTimes = new AtomicInteger(0);

            @Override
            public void run() {
                synchronized (this) {
                    log.info("shutdown hook was invoked, " + this.shutdownTimes.incrementAndGet());
                    if (!this.hasShutdown) {
                        this.hasShutdown = true;
                        long begineTime = System.currentTimeMillis();
                        controller.shutdown();
                        long consumingTimeTotal = System.currentTimeMillis() - begineTime;
                        log.info("shutdown hook over, consuming time total(ms): " + consumingTimeTotal);
                    }
                }
            }
        }, "ShutdownHook"));

        // ??
        controller.start();

        String tip = "The Name Server boot success.";
        log.info(tip);
        System.out.println(tip);

        return controller;
    } catch (Throwable e) {
        e.printStackTrace();
        System.exit(-1);
    }

    return null;
}

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/*ww w.  j  av a 2  s  .c  o m*/
        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)
        ;
}