List of usage examples for java.lang.management RuntimeMXBean getName
public String getName();
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("");//w w w .j a v a 2 s. co 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); } } }