Package com.cloudbreakers.runner

Source Code of com.cloudbreakers.runner.Main

package com.cloudbreakers.runner;

import com.cloudbreakers.streamer.stackexchange.StackExchangeStreamer;
import com.cloudbreakers.streamer.stackexchange.StackExchangeStreamerWithSearch;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URLEncoder;
import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
* Created by kalasd on 8/1/2014.
*/
public class Main {
    private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
    private final static ExecutorService executor = Executors.newCachedThreadPool();

    public static void main(String[] args) throws MalformedURLException, UnsupportedEncodingException {
        int intervalSec = 10;

        long initTimestamp = (new Date()).getTime() / 1000;
        if (args.length == 2) {
            String search_query = URLEncoder.encode(args[0], "UTF-8");

            if (!args[1].equalsIgnoreCase("now")) {
                initTimestamp = Long.parseLong(args[1]);
            }
            while (true) {
                if ((new Date()).getTime() / 1000 < initTimestamp + intervalSec) {
                    intervalSec = 10;
                    try {
                        Thread.sleep(intervalSec * 1000);
                        System.err.println("sleep end");
                    } catch (InterruptedException e) {
                        LOGGER.error("sudden interrupt", e);
                    }
                    executor.submit(new StackExchangeStreamerWithSearch(search_query,
                            initTimestamp, initTimestamp + intervalSec));
                } else {
                    intervalSec = 30240;
                    try {
                        new StackExchangeStreamerWithSearch(search_query, initTimestamp,
                                initTimestamp + intervalSec).run();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                initTimestamp += intervalSec;
            }
        } else {
            executor.submit(new StackExchangeStreamer(initTimestamp, initTimestamp + intervalSec));

            while (true) {
                try {
                    Thread.sleep(intervalSec);
                } catch (InterruptedException e) {
                    LOGGER.error("sudden interrupt", e);
                }
                initTimestamp += intervalSec;
                executor.submit(new StackExchangeStreamer(initTimestamp, initTimestamp + intervalSec));
            }
        }

    }
}
TOP

Related Classes of com.cloudbreakers.runner.Main

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.