Example usage for java.lang Thread setDefaultUncaughtExceptionHandler

List of usage examples for java.lang Thread setDefaultUncaughtExceptionHandler

Introduction

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

Prototype

public static void setDefaultUncaughtExceptionHandler(UncaughtExceptionHandler eh) 

Source Link

Document

Set the default handler invoked when a thread abruptly terminates due to an uncaught exception, and no other handler has been defined for that thread.

Usage

From source file:opensource.zeocompanion.ZeoCompanionApplication.java

@Override
public void onCreate() {
    super.onCreate();
    //Log.d(_CTAG + ".onCreate", "=====ON-CREATE=====");
    // activate the global unhandled exception handler in this main thread
    Thread.setDefaultUncaughtExceptionHandler(mMasterAbortHandler);

    // initializations
    mApp = this;//from   w  w w.ja  va 2 s.  co  m
    mOurContext = this;
    ObscuredPrefs.init(this);

    // pre-create empty external storage folders
    mBaseExtStorageDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator
            + "Android" + File.separator + "data" + File.separator + getPackageName());
    createExternalStorageFolders(); // note if there are external storage problems, the Application Object does not have a UI Activity in which to report it; MainActivity will re-detect this

    // startup all the global application handlers; the order of these startups is important
    mDatabaseHandler = new CompanionDatabase(this); // database handler must be first and must be initialized
    String msg = mDatabaseHandler.initialize();
    //if (!msg.isEmpty()) { Utilities.showAlertDialog(this, "Error", msg, "Okay"); }      TODO need end-user error reporting but only Toast is available at this stage
    mZeoAppHandler = new ZeoAppHandler(this);
    mCoordinator = new JournalDataCoordinator(this); // ZeoAppHandler must be instantiated first
    mEmailOutbox = new DirectEmailerOutbox(this); // JournalDataCoordinator must be instantiated first

    // detect whether the App is being run the first time after an install (or a data clear from the App Manager)
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    mFirstTIme = prefs.getBoolean("app_firstTime", true);
    mFirstTimeHintsShown = prefs.getInt("app_firstTime_HintsShown", 0);
    if (mFirstTIme) {
        // these obscured preference default values need to be pre-encrypted
        SharedPreferences.Editor editor = prefs.edit();
        editor.putString("profile_goal_hours_per_night", ObscuredPrefs.encryptString("8"));
        editor.putString("profile_goal_percent_deep", ObscuredPrefs.encryptString("15"));
        editor.putString("profile_goal_percent_REM", ObscuredPrefs.encryptString("20"));
        editor.putBoolean("app_firstTime", false);
        editor.commit();
    }

    // setup to receive preference changes that affect the AlarmManager; then configure the AlarmManager
    PreferenceManager.getDefaultSharedPreferences(this)
            .registerOnSharedPreferenceChangeListener(mPrefsChangeListener);
    configAlarmManagerToPrefs();

    // listen to broadcast messages from the Zeo Android App
    IntentFilter filter = new IntentFilter();
    filter.addAction("com.myzeo.android.headband.action.HEADBAND_UNDOCKED");
    filter.addAction("com.myzeo.android.headband.action.HEADBAND_DOCKED");
    filter.addAction("com.myzeo.android.headband.action.HEADBAND_BATTERY_DEAD");
    filter.addAction("com.myzeo.android.headband.action.HEADBAND_BUTTON_PRESS");
    filter.addAction("com.myzeo.android.headband.action.HEADBAND_DISCONNECTED");
    filter.addAction("com.myzeo.android.headband.action.HEADBAND_CONNECTED");
    registerReceiver(mZeoAppReceiver, filter);
}

From source file:com.google.android.marvin.screenspeak.ScreenSpeakService.java

@Override
public void onCreate() {
    super.onCreate();

    sInstance = this;
    setServiceState(SERVICE_STATE_INACTIVE);

    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);

    mSystemUeh = Thread.getDefaultUncaughtExceptionHandler();
    Thread.setDefaultUncaughtExceptionHandler(this);

    mAccessibilityEventProcessor = new AccessibilityEventProcessor(this);
    initializeInfrastructure();//from www .  j  a v a  2  s .c  o m
}

From source file:org.apache.tajo.master.TajoMaster.java

public static void main(String[] args) throws Exception {
    Thread.setDefaultUncaughtExceptionHandler(new TajoUncaughtExceptionHandler());
    StringUtils.startupShutdownMessage(TajoMaster.class, args, LOG);

    try {//from w ww  .j  av  a2s  .c om
        TajoMaster master = new TajoMaster();
        TajoConf conf = new TajoConf();
        master.init(conf);
        master.start();
    } catch (Throwable t) {
        LOG.fatal("Error starting TajoMaster", t);
        System.exit(-1);
    }
}

From source file:com.google.android.marvin.mytalkback.TalkBackService.java

@Override
public void onCreate() {
    super.onCreate();

    sInstance = this;
    setServiceState(ServiceState.INACTIVE);

    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);

    mSystemUeh = Thread.getDefaultUncaughtExceptionHandler();
    Thread.setDefaultUncaughtExceptionHandler(this);

    initializeInfrastructure();//from   w ww  .j  a  v  a2  s  .  c o m
}

From source file:org.apache.hadoop.hive.llap.daemon.impl.LlapDaemon.java

public static void main(String[] args) throws Exception {
    Thread.setDefaultUncaughtExceptionHandler(new LlapDaemonUncaughtExceptionHandler());
    LlapDaemon llapDaemon = null;//from ww w. j a  v a 2 s  .com
    try {
        // Cache settings will need to be setup in llap-daemon-site.xml - since the daemons don't read hive-site.xml
        // Ideally, these properties should be part of LlapDameonConf rather than HiveConf
        LlapDaemonConfiguration daemonConf = new LlapDaemonConfiguration();

        String containerIdStr = System.getenv(ApplicationConstants.Environment.CONTAINER_ID.name());

        String appName = null;
        if (containerIdStr != null && !containerIdStr.isEmpty()) {
            daemonConf.set(ConfVars.LLAP_DAEMON_CONTAINER_ID.varname, containerIdStr);
            appName = ConverterUtils.toContainerId(containerIdStr).getApplicationAttemptId().getApplicationId()
                    .toString();
        } else {
            daemonConf.unset(ConfVars.LLAP_DAEMON_CONTAINER_ID.varname);
            // Note, we assume production LLAP always runs under YARN.
            LOG.error("Cannot find " + ApplicationConstants.Environment.CONTAINER_ID.toString()
                    + "; LLAP tokens may grant access to subsequent instances of the cluster with"
                    + " the same name");
            appName = null;
        }

        String nmHost = System.getenv(ApplicationConstants.Environment.NM_HOST.name());
        String nmPort = System.getenv(ApplicationConstants.Environment.NM_PORT.name());
        if (!org.apache.commons.lang3.StringUtils.isBlank(nmHost)
                && !org.apache.commons.lang3.StringUtils.isBlank(nmPort)) {
            String nmAddress = nmHost + ":" + nmPort;
            daemonConf.set(ConfVars.LLAP_DAEMON_NM_ADDRESS.varname, nmAddress);
        } else {
            daemonConf.unset(ConfVars.LLAP_DAEMON_NM_ADDRESS.varname);
            // Unlikely, but log the actual values in case one of the two was empty/null
            LOG.warn("NodeManager host/port not found in environment. Values retrieved: host={}, port={}",
                    nmHost, nmPort);
        }

        String workDirsString = System.getenv(ApplicationConstants.Environment.LOCAL_DIRS.name());

        String localDirList = LlapUtil.getDaemonLocalDirString(daemonConf, workDirsString);
        String[] localDirs = (localDirList == null || localDirList.isEmpty()) ? new String[0]
                : StringUtils.getTrimmedStrings(localDirList);
        int rpcPort = HiveConf.getIntVar(daemonConf, ConfVars.LLAP_DAEMON_RPC_PORT);
        int mngPort = HiveConf.getIntVar(daemonConf, ConfVars.LLAP_MANAGEMENT_RPC_PORT);
        int shufflePort = daemonConf.getInt(ShuffleHandler.SHUFFLE_PORT_CONFIG_KEY,
                ShuffleHandler.DEFAULT_SHUFFLE_PORT);
        int webPort = HiveConf.getIntVar(daemonConf, ConfVars.LLAP_DAEMON_WEB_PORT);

        LlapDaemonInfo.initialize(appName, daemonConf);

        int numExecutors = LlapDaemonInfo.INSTANCE.getNumExecutors();
        long executorMemoryBytes = LlapDaemonInfo.INSTANCE.getExecutorMemory();
        long ioMemoryBytes = LlapDaemonInfo.INSTANCE.getCacheSize();
        boolean isDirectCache = LlapDaemonInfo.INSTANCE.isDirectCache();
        boolean isLlapIo = LlapDaemonInfo.INSTANCE.isLlapIo();

        LlapDaemon.initializeLogging(daemonConf);
        llapDaemon = new LlapDaemon(daemonConf, numExecutors, executorMemoryBytes, isLlapIo, isDirectCache,
                ioMemoryBytes, localDirs, rpcPort, mngPort, shufflePort, webPort, appName);

        LOG.info("Adding shutdown hook for LlapDaemon");
        ShutdownHookManager.addShutdownHook(new CompositeServiceShutdownHook(llapDaemon), 1);

        llapDaemon.init(daemonConf);
        llapDaemon.start();
        LOG.info("Started LlapDaemon with PID: {}", LlapDaemonInfo.INSTANCE.getPID());
        // Relying on the RPC threads to keep the service alive.
    } catch (Throwable t) {
        // TODO Replace this with a ExceptionHandler / ShutdownHook
        LOG.error("Failed to start LLAP Daemon with exception", t);
        if (llapDaemon != null) {
            llapDaemon.shutdown();
        }
        System.exit(-1);
    }
}

From source file:org.glite.security.voms.admin.core.VOMSService.java

public static void start(ServletContext ctxt) {

    Thread.setDefaultUncaughtExceptionHandler(new ThreadUncaughtExceptionHandler());

    configureLogging(ctxt);//from   ww w. j a va  2s . c  o m

    VOMSConfiguration conf;

    try {

        conf = VOMSConfiguration.load(ctxt);

    } catch (VOMSConfigurationException e) {
        LOG.error("VOMS-Admin configuration failed!", e);
        throw new VOMSFatalException(e);
    }

    LOG.info("VOMS-Admin starting for VO: " + conf.getVOName());

    bootstrapPersistence(conf);

    setupStrutsDevMode();

    checkDatabaseVersion();

    configureCertificateLookupPolicy(conf);

    configureVelocity();

    configureEventManager();

    startBackgroundTasks();

    startNotificationService();

    bootstrapAttributeAuthorityServices();

    PluginManager.instance().configurePlugins();

    ValidationManager.instance().startMembershipChecker();

    initializeDnValidator();

    configureOrgDbHibernateSessionFitler(ctxt);

    setupGlobalApplicationObjects(ctxt);

    LOG.info("VOMS-Admin started succesfully.");
}

From source file:me.mast3rplan.phantombot.PhantomBot.java

public PhantomBot(Properties pbProperties) {

    /* Set the exeption handler */
    Thread.setDefaultUncaughtExceptionHandler(com.gmt2001.UncaughtExceptionHandler.instance());

    /* Start loading the bot information */
    print("");/*from  w ww .j  av  a  2s .  c om*/
    print(botVersion());
    print(botRevision());
    print(getBotCreator());
    print(botDevelopers());
    print(getWebSite());
    print("");

    /* System interactive */
    interactive = (System.getProperty("interactive") != null);

    /* Assign properties passed in to local instance. */
    this.pbProperties = pbProperties;

    /* Set the default bot variables */
    this.botName = this.pbProperties.getProperty("user").toLowerCase();
    this.channelName = this.pbProperties.getProperty("channel").toLowerCase();
    this.ownerName = this.pbProperties.getProperty("owner").toLowerCase();
    this.apiOAuth = this.pbProperties.getProperty("apioauth", "");
    this.oauth = this.pbProperties.getProperty("oauth");

    /* Set the web variables */
    this.youtubeOAuth = this.pbProperties.getProperty("ytauth");
    this.youtubeOAuthThro = this.pbProperties.getProperty("ytauthro");
    this.youtubeKey = this.pbProperties.getProperty("youtubekey", "");
    this.basePort = Integer.parseInt(this.pbProperties.getProperty("baseport", "25000"));
    this.webOAuth = this.pbProperties.getProperty("webauth");
    this.webOAuthThro = this.pbProperties.getProperty("webauthro");
    this.webEnabled = this.pbProperties.getProperty("webenable", "true").equalsIgnoreCase("true");
    this.musicEnabled = this.pbProperties.getProperty("musicenable", "true").equalsIgnoreCase("true");
    this.useHttps = this.pbProperties.getProperty("usehttps", "false").equalsIgnoreCase("true");

    /* Set the datastore variables */
    this.dataStoreType = this.pbProperties.getProperty("datastore", "");
    this.dataStoreConfig = this.pbProperties.getProperty("datastoreconfig", "");

    /* Set the Twitter variables */
    this.twitterUsername = this.pbProperties.getProperty("twitterUser", "");
    this.twitterConsumerToken = this.pbProperties.getProperty("twitter_consumer_key", "");
    this.twitterConsumerSecret = this.pbProperties.getProperty("twitter_consumer_secret", "");
    this.twitterAccessToken = this.pbProperties.getProperty("twitter_access_token", "");
    this.twitterSecretToken = this.pbProperties.getProperty("twitter_secret_token", "");
    this.twitterAuthenticated = false;

    /* Set the Discord variables */
    this.discordToken = this.pbProperties.getProperty("discord_token", "");

    /* Set the GameWisp variables */
    this.gameWispOAuth = this.pbProperties.getProperty("gamewispauth", "");
    this.gameWispRefresh = this.pbProperties.getProperty("gamewisprefresh", "");

    /* Set the TwitchAlerts variables */
    this.twitchAlertsKey = this.pbProperties.getProperty("twitchalertskey", "");
    this.twitchAlertsLimit = Integer.parseInt(this.pbProperties.getProperty("twitchalertslimit", "5"));

    /* Set the StreamTip variables */
    this.streamTipOAuth = this.pbProperties.getProperty("streamtipkey", "");
    this.streamTipClientId = this.pbProperties.getProperty("streamtipid", "");
    this.streamTipLimit = Integer.parseInt(this.pbProperties.getProperty("streamtiplimit", "5"));

    /* Set the TipeeeStream variables */
    this.tipeeeStreamOAuth = this.pbProperties.getProperty("tipeeestreamkey", "");
    this.tipeeeStreamLimit = Integer.parseInt(this.pbProperties.getProperty("tipeeestreamlimit", "5"));

    /* Set the MySql variables */
    this.mySqlName = this.pbProperties.getProperty("mysqlname", "");
    this.mySqlUser = this.pbProperties.getProperty("mysqluser", "");
    this.mySqlPass = this.pbProperties.getProperty("mysqlpass", "");
    this.mySqlHost = this.pbProperties.getProperty("mysqlhost", "");
    this.mySqlPort = this.pbProperties.getProperty("mysqlport", "");

    /* twitch cache */
    PhantomBot.twitchCacheReady = "false";

    /* Set the SSL info */
    this.httpsFileName = this.pbProperties.getProperty("httpsFileName", "");
    this.httpsPassword = this.pbProperties.getProperty("httpsPassword", "");

    /* Set the timeZone */
    PhantomBot.timeZone = this.pbProperties.getProperty("logtimezone", "GMT");

    /* Set the panel username login for the panel to use */
    this.panelUsername = this.pbProperties.getProperty("paneluser", "panel");

    /* Set the panel password login for the panel to use */
    this.panelPassword = this.pbProperties.getProperty("panelpassword", "panel");

    /* Enable/disable devCommands */
    this.devCommands = this.pbProperties.getProperty("devcommands", "false").equalsIgnoreCase("true");

    /* Toggle for the old servers. */
    this.legacyServers = this.pbProperties.getProperty("legacyservers", "false").equalsIgnoreCase("true");

    /*
     * Set the message limit for session.java to use, note that Twitch rate limits at 100 messages in 30 seconds
     * for moderators.  For non-moderators, the maximum is 20 messages in 30 seconds. While it is not recommended
     * to go above anything higher than 18.75 in case the bot is ever de-modded, the option is available but is
     * capped at 80.0. 
     */
    PhantomBot.messageLimit = Double.parseDouble(this.pbProperties.getProperty("msglimit30", "18.75"));
    if (PhantomBot.messageLimit > 80.0) {
        PhantomBot.messageLimit = 80.0;
    } else if (PhantomBot.messageLimit < 18.75) {
        PhantomBot.messageLimit = 18.75;
    }

    /* Set the whisper limit for session.java to use. -- Currently Not Used -- */
    PhantomBot.whisperLimit = Double.parseDouble(this.pbProperties.getProperty("whisperlimit60", "60.0"));

    /* Set the client id for the twitch api to use */
    this.clientId = this.pbProperties.getProperty("clientid", "7wpchwtqz7pvivc3qbdn1kajz42tdmb");

    /* Set any SQLite backup options. */
    this.backupSQLiteAuto = this.pbProperties.getProperty("backupsqliteauto", "false").equalsIgnoreCase("true");
    this.backupSQLiteHourFrequency = Integer
            .parseInt(this.pbProperties.getProperty("backupsqlitehourfreqency", "24"));
    this.backupSQLiteKeepDays = Integer.parseInt(this.pbProperties.getProperty("backupsqlitekeepdays", "5"));

    /* Load up a new SecureRandom for the scripts to use */
    random = new SecureRandom();

    /* Create a map for multiple channels. */
    channels = new HashMap<>();

    /* Create a map for multiple sessions. */
    sessions = new HashMap<>();

    /* Create a map for multiple oauth tokens. */
    apiOAuths = new HashMap<>();

    /* Load the datastore */
    if (dataStoreType.equalsIgnoreCase("inistore")) {
        dataStore = IniStore.instance();
    } else if (dataStoreType.equalsIgnoreCase("mysqlstore")) {
        dataStore = MySQLStore.instance();
        if (this.mySqlPort.isEmpty()) {
            this.mySqlConn = "jdbc:mysql://" + this.mySqlHost + "/" + this.mySqlName + "?useSSL=false";
        } else {
            this.mySqlConn = "jdbc:mysql://" + this.mySqlHost + ":" + this.mySqlPort + "/" + this.mySqlName
                    + "?useSSL=false";
        }
        /* Check to see if we can create a connection */
        if (dataStore.CreateConnection(this.mySqlConn, this.mySqlUser, this.mySqlPass) == null) {
            print("Could not create a connection with MySql. PhantomBot now shutting down...");
            System.exit(0);
        }
        /* Convert to MySql */
        if (IniStore.instance().GetFileList().length > 0) {
            ini2MySql(true);
        } else if (SqliteStore.instance().GetFileList().length > 0) {
            sqlite2MySql();
        }
    } else {
        dataStoreType = "sqlite3store";
        dataStore = SqliteStore.instance();
        /* Create indexes. */
        if (!dataStore.exists("settings", "tables_indexed")) {
            print("Creating SQLite3 Indexes. This might take time...");
            dataStore.CreateIndexes();
            dataStore.set("settings", "tables_indexed", "true");
            print("Completed Creating SQLite3 Indexes!");
        }
        /* Convert the initstore to sqlite if the inistore exists and the db is empty */
        if (IniStore.instance().GetFileList().length > 0 && SqliteStore.instance().GetFileList().length == 0) {
            ini2Sqlite(true);
        }
    }

    /* Set the client Id in the Twitch api. */
    TwitchAPIv3.instance().SetClientID(this.clientId);

    /* Set the oauth key in the Twitch api. */
    if (!this.apiOAuth.isEmpty()) {
        TwitchAPIv3.instance().SetOAuth(this.apiOAuth);
    }

    /* Set the TwitchAlerts OAuth key and limiter. */
    if (!twitchAlertsKey.isEmpty()) {
        TwitchAlertsAPIv1.instance().SetAccessToken(twitchAlertsKey);
        TwitchAlertsAPIv1.instance().SetDonationPullLimit(twitchAlertsLimit);
    }

    /* Set the YouTube API Key if provided. */
    if (!this.youtubeKey.isEmpty()) {
        YouTubeAPIv3.instance().SetAPIKey(this.youtubeKey);
    }

    /* Set the StreamTip OAuth key, Client ID and limiter. */
    if (!streamTipOAuth.isEmpty() && !streamTipClientId.isEmpty()) {
        StreamTipAPI.instance().SetAccessToken(streamTipOAuth);
        StreamTipAPI.instance().SetDonationPullLimit(streamTipLimit);
        StreamTipAPI.instance().SetClientId(streamTipClientId);
    }

    /* Set the TipeeeStream oauth key. */
    if (!tipeeeStreamOAuth.isEmpty()) {
        TipeeeStreamAPIv1.instance().SetOauth(tipeeeStreamOAuth);
        TipeeeStreamAPIv1.instance().SetLimit(tipeeeStreamLimit);
    }

    /* Start things and start loading the scripts. */
    this.init();

    /* Start a channel instance to create a session, and then connect to WS-IRC @ Twitch. */
    this.channel = Channel.instance(this.channelName, this.botName, this.oauth, EventBus.instance());

    /* Start a host checking instance. */
    if (apiOAuth.length() > 0 && checkModuleEnabled("./handlers/hostHandler.js")) {
        this.wsHostIRC = TwitchWSHostIRC.instance(this.channelName, this.apiOAuth, EventBus.instance());
    }

    /* Start a pubsub instance here. */
    if (this.oauth.length() > 0 && checkDataStore("chatModerator", "moderationLogs")) {
        this.pubSubEdge = TwitchPubSub.instance(this.channelName,
                TwitchAPIv3.instance().getChannelId(this.channelName),
                TwitchAPIv3.instance().getChannelId(this.botName), this.oauth);
    }

    /* Check if the OS is Linux. */
    if (SystemUtils.IS_OS_LINUX && !interactive) {
        try {
            java.lang.management.RuntimeMXBean runtime = java.lang.management.ManagementFactory
                    .getRuntimeMXBean();
            int pid = Integer.parseInt(runtime.getName().split("@")[0]);

            File file = new File("PhantomBot." + this.botName.toLowerCase() + ".pid");

            try (FileOutputStream fs = new FileOutputStream(file, false)) {
                PrintStream ps = new PrintStream(fs);
                ps.print(pid);
            }
            file.deleteOnExit();
        } catch (SecurityException | IllegalArgumentException | IOException ex) {
            com.gmt2001.Console.err.printStackTrace(ex);
        }
    }
}

From source file:tv.phantombot.PhantomBot.java

public PhantomBot(Properties pbProperties) {

    /* Set the exeption handler */
    Thread.setDefaultUncaughtExceptionHandler(com.gmt2001.UncaughtExceptionHandler.instance());

    /* Start loading the bot information */
    print("");/*  ww w. j  a v  a 2  s . c o m*/
    print(botVersion());
    print(botRevision());
    print(getBotCreator());
    print(botDevelopers());
    print(getWebSite());
    print("");

    /* System interactive */
    interactive = (System.getProperty("interactive") != null);

    /* Assign properties passed in to local instance. */
    this.pbProperties = pbProperties;

    /* Set the default bot variables */
    this.botName = this.pbProperties.getProperty("user").toLowerCase();
    this.channelName = this.pbProperties.getProperty("channel").toLowerCase();
    this.ownerName = this.pbProperties.getProperty("owner").toLowerCase();
    this.apiOAuth = this.pbProperties.getProperty("apioauth", "");
    this.oauth = this.pbProperties.getProperty("oauth");

    /* Set the web variables */
    this.youtubeOAuth = this.pbProperties.getProperty("ytauth");
    this.youtubeOAuthThro = this.pbProperties.getProperty("ytauthro");
    this.youtubeKey = this.pbProperties.getProperty("youtubekey", "");
    this.basePort = Integer.parseInt(this.pbProperties.getProperty("baseport", "25000"));
    this.bindIP = this.pbProperties.getProperty("bindIP", "");
    this.ytSocketPort = Integer
            .parseInt(this.pbProperties.getProperty("ytsocketport", String.valueOf((this.basePort + 3))));
    this.panelSocketPort = Integer
            .parseInt(this.pbProperties.getProperty("panelsocketport", String.valueOf((this.basePort + 4))));
    this.webOAuth = this.pbProperties.getProperty("webauth");
    this.webOAuthThro = this.pbProperties.getProperty("webauthro");
    this.webEnabled = this.pbProperties.getProperty("webenable", "true").equalsIgnoreCase("true");
    this.musicEnabled = this.pbProperties.getProperty("musicenable", "true").equalsIgnoreCase("true");
    this.useHttps = this.pbProperties.getProperty("usehttps", "false").equalsIgnoreCase("true");
    this.socketServerTasksSize = Integer.parseInt(this.pbProperties.getProperty("wstasksize", "200"));
    this.testPanelServer = this.pbProperties.getProperty("testpanelserver", "false").equalsIgnoreCase("true");

    /* Set the datastore variables */
    this.dataStoreType = this.pbProperties.getProperty("datastore", "");
    this.dataStoreConfig = this.pbProperties.getProperty("datastoreconfig", "");

    /* Set the Twitter variables */
    this.twitterUsername = this.pbProperties.getProperty("twitterUser", "");
    this.twitterConsumerToken = this.pbProperties.getProperty("twitter_consumer_key", "");
    this.twitterConsumerSecret = this.pbProperties.getProperty("twitter_consumer_secret", "");
    this.twitterAccessToken = this.pbProperties.getProperty("twitter_access_token", "");
    this.twitterSecretToken = this.pbProperties.getProperty("twitter_secret_token", "");
    this.twitterAuthenticated = false;

    /* Set the Discord variables */
    this.discordToken = this.pbProperties.getProperty("discord_token", "");

    /* Set the GameWisp variables */
    this.gameWispOAuth = this.pbProperties.getProperty("gamewispauth", "");
    this.gameWispRefresh = this.pbProperties.getProperty("gamewisprefresh", "");

    /* Set the TwitchAlerts variables */
    this.twitchAlertsKey = this.pbProperties.getProperty("twitchalertskey", "");
    this.twitchAlertsLimit = Integer.parseInt(this.pbProperties.getProperty("twitchalertslimit", "5"));

    /* Set the TipeeeStream variables */
    this.tipeeeStreamOAuth = this.pbProperties.getProperty("tipeeestreamkey", "");
    this.tipeeeStreamLimit = Integer.parseInt(this.pbProperties.getProperty("tipeeestreamlimit", "5"));

    /* Set the StreamElements variables */
    this.streamElementsJWT = this.pbProperties.getProperty("streamelementsjwt", "");
    this.streamElementsID = this.pbProperties.getProperty("streamelementsid", "");
    this.streamElementsLimit = Integer.parseInt(this.pbProperties.getProperty("streamelementslimit", "5"));

    /* Set the PhantomBot Commands API variables */
    this.dataRenderServiceAPIToken = this.pbProperties.getProperty("datarenderservicetoken", "");
    this.dataRenderServiceAPIURL = this.pbProperties.getProperty("datarenderserviceurl",
            "https://drs.phantombot.tv");

    /* Set the MySql variables */
    this.mySqlName = this.pbProperties.getProperty("mysqlname", "");
    this.mySqlUser = this.pbProperties.getProperty("mysqluser", "");
    this.mySqlPass = this.pbProperties.getProperty("mysqlpass", "");
    this.mySqlHost = this.pbProperties.getProperty("mysqlhost", "");
    this.mySqlPort = this.pbProperties.getProperty("mysqlport", "");

    /* twitch cache */
    PhantomBot.twitchCacheReady = "false";

    /* Set the SSL info */
    this.httpsFileName = this.pbProperties.getProperty("httpsFileName", "");
    this.httpsPassword = this.pbProperties.getProperty("httpsPassword", "");

    /* Verify SSL file if useHttps is enabled. */
    if (this.useHttps) {
        if (this.httpsFileName.equals("")) {
            com.gmt2001.Console.err
                    .println("HTTPS is enabled but the Java Keystore (httpsFileName) is not defined.");
            com.gmt2001.Console.err.println("Terminating PhantomBot");
            System.exit(1);
        }

        if (!new File(httpsFileName).exists()) {
            com.gmt2001.Console.err.println(
                    "HTTPS is enabled but the Java Keystore (httpsFileName) is not present: " + httpsFileName);
            com.gmt2001.Console.err.println("Terminating PhantomBot");
            System.exit(1);
        }
    }

    /* Set the timeZone */
    PhantomBot.timeZone = this.pbProperties.getProperty("logtimezone", "GMT");

    /* Set the panel username login for the panel to use */
    this.panelUsername = this.pbProperties.getProperty("paneluser", "panel");

    /* Set the panel password login for the panel to use */
    this.panelPassword = this.pbProperties.getProperty("panelpassword", "panel");

    /* Toggle for the old servers. */
    this.legacyServers = this.pbProperties.getProperty("legacyservers", "false").equalsIgnoreCase("true");

    /* Set the tcp delay toggle. Having this set to true uses a bit more bandwidth but sends messages to Twitch faster. */
    PhantomBot.twitch_tcp_nodelay = this.pbProperties.getProperty("twitch_tcp_nodelay", "true")
            .equalsIgnoreCase("true");

    /* Setting for scania */
    PhantomBot.betap = this.pbProperties.getProperty("betap", "false").equalsIgnoreCase("true");

    /*
     * Set the message limit for session.java to use, note that Twitch rate limits at 100 messages in 30 seconds
     * for moderators.  For non-moderators, the maximum is 20 messages in 30 seconds. While it is not recommended
     * to go above anything higher than 19 in case the bot is ever de-modded, the option is available but is
     * capped at 100.0.
     */
    PhantomBot.messageLimit = Math
            .floor(Double.parseDouble(this.pbProperties.getProperty("msglimit30", "19.0")));
    if (PhantomBot.messageLimit > 99.0) {
        PhantomBot.messageLimit = 99.0;
    } else if (PhantomBot.messageLimit < 19.0) {
        PhantomBot.messageLimit = 19.0;
    }

    // *Not currently being used.*
    // If this is false the bot won't limit the bot to 1 message every 1.5 second. It will still limit to 19/30 though.
    PhantomBot.useMessageQueue = this.pbProperties.getProperty("usemessagequeue", "true").equals("true");

    /* Set the whisper limit for session.java to use. -- Currently Not Used -- */
    PhantomBot.whisperLimit = Double.parseDouble(this.pbProperties.getProperty("whisperlimit60", "60.0"));

    /* Set the client id for the twitch api to use */
    this.clientId = this.pbProperties.getProperty("clientid", "7wpchwtqz7pvivc3qbdn1kajz42tdmb");

    /* Set any SQLite backup options. */
    this.backupSQLiteAuto = this.pbProperties.getProperty("backupsqliteauto", "true").equalsIgnoreCase("true");
    this.backupSQLiteHourFrequency = Integer
            .parseInt(this.pbProperties.getProperty("backupsqlitehourfrequency", "24"));
    this.backupSQLiteKeepDays = Integer.parseInt(this.pbProperties.getProperty("backupsqlitekeepdays", "5"));

    /* Load up a new SecureRandom for the scripts to use */
    random = new SecureRandom();

    /* Load the datastore */
    if (dataStoreType.equalsIgnoreCase("inistore")) {
        dataStore = IniStore.instance();
    } else if (dataStoreType.equalsIgnoreCase("mysqlstore")) {
        dataStore = MySQLStore.instance();
        if (this.mySqlPort.isEmpty()) {
            this.mySqlConn = "jdbc:mysql://" + this.mySqlHost + "/" + this.mySqlName + "?useSSL=false";
        } else {
            this.mySqlConn = "jdbc:mysql://" + this.mySqlHost + ":" + this.mySqlPort + "/" + this.mySqlName
                    + "?useSSL=false";
        }
        /* Check to see if we can create a connection */
        if (dataStore.CreateConnection(this.mySqlConn, this.mySqlUser, this.mySqlPass) == null) {
            print("Could not create a connection with MySQL Server. PhantomBot now shutting down...");
            System.exit(0);
        }
        /* Convert to MySql */
        if (IniStore.instance().GetFileList().length > 0 && MySQLStore.instance().GetFileList().length == 0) {
            DataStoreConverter.convertDataStore(MySQLStore.instance(), IniStore.instance());
        } else if (SqliteStore.instance().GetFileList().length > 0
                && MySQLStore.instance().GetFileList().length == 0) {
            DataStoreConverter.convertDataStore(MySQLStore.instance(), SqliteStore.instance());
        }
    } else if (dataStoreType.equalsIgnoreCase("h2store")) {
        dataStore = H2Store.instance();

        if (dataStore.CreateConnection("", "", "") == null) {
            print("Could not create a connection with H2 Database. PhantomBot now shutting down...");
            System.exit(0);
        }

        if (SqliteStore.instance().GetFileList().length > 0 && H2Store.instance().GetFileList().length == 0) {
            DataStoreConverter.convertDataStore(H2Store.instance(), SqliteStore.instance());
        }
    } else {
        dataStoreType = "sqlite3store";
        dataStore = SqliteStore.instance();

        /* Convert the inistore to sqlite if the inistore exists and the db is empty */
        if (IniStore.instance().GetFileList().length > 0 && SqliteStore.instance().GetFileList().length == 0) {
            DataStoreConverter.convertDataStore(SqliteStore.instance(), IniStore.instance());
        }

        /* Handle index operations. */
        com.gmt2001.Console.debug.println("Checking database indexes, please wait...");
        if (SqliteStore.instance().getUseIndexes()) {
            dataStore.CreateIndexes();
        } else {
            dataStore.DropIndexes();
        }
    }

    /* Set the client Id in the Twitch api. */
    TwitchAPIv5.instance().SetClientID(this.clientId);

    /* Set the oauth key in the Twitch api. */
    if (!this.apiOAuth.isEmpty()) {
        TwitchAPIv5.instance().SetOAuth(this.apiOAuth);
    }

    /* Set the TwitchAlerts OAuth key and limiter. */
    if (!twitchAlertsKey.isEmpty()) {
        TwitchAlertsAPIv1.instance().SetAccessToken(twitchAlertsKey);
        TwitchAlertsAPIv1.instance().SetDonationPullLimit(twitchAlertsLimit);
    }

    /* Set the YouTube API Key if provided. */
    if (!this.youtubeKey.isEmpty()) {
        YouTubeAPIv3.instance().SetAPIKey(this.youtubeKey);
    }

    /* Set the TipeeeStream oauth key. */
    if (!tipeeeStreamOAuth.isEmpty()) {
        TipeeeStreamAPIv1.instance().SetOauth(tipeeeStreamOAuth);
        TipeeeStreamAPIv1.instance().SetLimit(tipeeeStreamLimit);
    }

    /* Set the StreamElements JWT token. */
    if (!streamElementsJWT.isEmpty() && !streamElementsID.isEmpty()) {
        StreamElementsAPIv2.instance().SetJWT(streamElementsJWT);
        StreamElementsAPIv2.instance().SetID(streamElementsID);
        StreamElementsAPIv2.instance().SetLimit(streamElementsLimit);
    }

    /* Set the PhantomBot Commands authentication key. */
    if (!dataRenderServiceAPIToken.isEmpty()) {
        DataRenderServiceAPIv1.instance().setAPIURL(dataRenderServiceAPIURL);
        DataRenderServiceAPIv1.instance().setAPIKey(dataRenderServiceAPIToken);
    }

    /* Start things and start loading the scripts. */
    this.init();

    /* Start a session instance and then connect to WS-IRC @ Twitch. */
    this.session = TwitchSession.instance(this.channelName, this.botName, this.oauth).connect();

    /* Start a host checking instance. */
    if (apiOAuth.length() > 0 && checkModuleEnabled("./handlers/hostHandler.js")) {
        this.wsHostIRC = TwitchWSHostIRC.instance(this.channelName, this.apiOAuth, EventBus.instance());
    }

    /* Check if the OS is Linux. */
    if (SystemUtils.IS_OS_LINUX && !interactive) {
        try {
            java.lang.management.RuntimeMXBean runtime = java.lang.management.ManagementFactory
                    .getRuntimeMXBean();
            int pid = Integer.parseInt(runtime.getName().split("@")[0]);

            File file = new File("PhantomBot." + this.botName + ".pid");

            try (FileOutputStream fs = new FileOutputStream(file, false)) {
                PrintStream ps = new PrintStream(fs);
                ps.print(pid);
            }
            file.deleteOnExit();
        } catch (SecurityException | IllegalArgumentException | IOException ex) {
            com.gmt2001.Console.err.printStackTrace(ex);
        }
    }
}

From source file:com.facebook.infrastructure.service.CassandraServer.java

public static void main(String[] args) throws Throwable {
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        public void uncaughtException(Thread t, Throwable e) {
            logger_.error("Fatal exception in thread " + t, e);
        }//  ww  w . j a  v  a2  s .co  m
    });

    try {
        CassandraServer server = new CassandraServer();
        server.start();
        TThreadPoolServer threadPoolServer = thriftEngine(server);
        threadPoolServer.serve();
    } catch (Throwable x) {
        logger_.error("Fatal error; exiting", x);
        System.exit(1);
    }

}

From source file:com.twitter.heron.instance.HeronInstance.java

public void start() {
    // Add exception handler for any uncaught exception here.
    Thread.setDefaultUncaughtExceptionHandler(new DefaultExceptionHandler());

    // Get the Thread Pool and run it
    threadsPool.execute(gateway);/*from   w  ww . j ava 2  s.  c o  m*/
    threadsPool.execute(slave);
}