use of com.mysql.cj.jdbc.exceptions.CommunicationsException in project ExciteBot by TheGameCommunity.
the class Main method main.
@SuppressWarnings("rawtypes")
public static void main(String[] args) throws InterruptedException, ClassNotFoundException, IOException, SQLException {
if (args.length % 2 != 0) {
throw new IllegalArgumentException("Must be started with an even number of arguments!");
}
for (int i = 0; i < args.length; i++) {
if (args[i].equals("-owner")) {
botOwner = Long.parseLong(args[++i]);
}
}
wiimmfi = startWiimmfi(args);
discordBot = null;
int bootAttempts = 0;
while (discordBot == null) {
try {
bootAttempts++;
discordBot = startDiscordBot(args, wiimmfi);
discordBot.setLoading();
discordBot.setWiimmfi(wiimmfi);
} catch (LoginException | IOException | ErrorResponseException e) {
LOGGER.log(Level.SEVERE, e, () -> e.getMessage());
if (bootAttempts >= 3) {
System.exit(-2);
}
Thread.sleep(5000);
}
}
while (CONSOLE == null) {
try {
CONSOLE = new ConsoleUser();
} catch (IOError e) {
System.out.println(e);
discordBot.setNoDB();
Thread.sleep(5000);
}
}
do {
try {
DatabaseConnection.INSTANCE = new DatabaseConnection();
} catch (Throwable t) {
System.out.println(t);
discordBot.setNoDB();
Thread.sleep(5000);
}
} while (DatabaseConnection.INSTANCE == null);
Throwable prevError = null;
Instant nextDiscordPing = Instant.now().minusMillis(1);
Instant sendDiscordNotifications = Instant.now().minusMillis(1);
startConsole();
Thread mailThread = startMailThread();
try {
while (true) {
try {
System.gc();
Throwable error = wiimmfi.getError();
wiimmfi.update();
if (error == null) {
if (prevError != null) {
// LOGGER.log(Level.SEVERE, "Error resolved.");
}
} else {
if (prevError == null || !prevError.getClass().equals(error.getClass())) {
System.out.println("Error!");
LOGGER.log(Level.SEVERE, error, () -> error.getMessage());
}
prevError = error;
}
if (discordBot != null) {
if (nextDiscordPing.isBefore(Instant.now())) {
nextDiscordPing = Instant.now().plus(Duration.ofSeconds(5));
updateLists(true, true);
}
if (sendDiscordNotifications.isBefore(Instant.now())) {
sendDiscordNotifications = Instant.now().plus(Duration.ofSeconds(4));
DiscordUser.notifyDiscordUsers();
}
}
while (!consoleCommandsAwaitingProcessing.isEmpty()) {
Commands.DISPATCHER.handleCommand(consoleCommandsAwaitingProcessing.pollFirst());
}
} catch (ErrorResponseException e) {
CONSOLE.sendMessage(StacktraceUtil.getStackTrace(e));
CONSOLE.sendMessage("An ErrorResponseException occurred... waiting 10 seconds");
} catch (Throwable t) {
if (t != null && (t instanceof ConnectionIsClosedException || t instanceof CommunicationsException || t instanceof CJCommunicationsException || t instanceof SQLNonTransientConnectionException || (t.getCause() != null && (t.getCause() instanceof IOException || t.getCause() instanceof SQLException || t.getCause() instanceof IOError)))) {
System.err.println("Attempting to recover from database connection failure...");
DatabaseConnection.INSTANCE.close();
DatabaseConnection.INSTANCE = null;
while (DatabaseConnection.INSTANCE == null) {
discordBot.setNoDB();
try {
DatabaseConnection.INSTANCE = new DatabaseConnection();
} catch (Throwable t2) {
System.err.println("Attempting to recover from database connection failure...");
t2.printStackTrace(System.err);
DatabaseConnection.INSTANCE = null;
}
Thread.sleep(5000);
}
continue;
}
throw t;
}
if (!mailThread.isAlive() && !stopping) {
throw new Error("Mail thread has died");
}
Thread.sleep(1000);
}
} catch (Throwable t) {
t.printStackTrace();
if (discordBot != null) {
discordBot.jda.getPresence().setPresence(OnlineStatus.DO_NOT_DISTURB, Activity.of(ActivityType.DEFAULT, "Bot Crashed"));
if (botOwner != -1) {
try {
DiscordUser user = DiscordUser.getDiscordUserIncludingUnknown(ConsoleContext.INSTANCE, botOwner);
if (!(user instanceof UnknownDiscordUser)) {
user.sendMessage(StacktraceUtil.getStackTrace(t));
} else {
CONSOLE.sendMessage(StacktraceUtil.getStackTrace(t));
}
} catch (Throwable t2) {
CONSOLE.sendMessage(StacktraceUtil.getStackTrace(t));
}
}
while (true) {
Thread.sleep(1000);
}
} else {
CONSOLE.sendMessage(StacktraceUtil.getStackTrace(t));
}
}
System.exit(-1);
}
use of com.mysql.cj.jdbc.exceptions.CommunicationsException in project ABC by RuiPinto96274.
the class ExceptionsTest method testConstructors.
@Test
public void testConstructors() {
new CommunicationsException(TEST_MESSAGE, new Throwable());
new CommunicationsException((JdbcConnection) this.conn, new PacketSentTimeHolder() {
}, new PacketReceivedTimeHolder() {
}, new Exception());
new ConnectionFeatureNotAvailableException(TEST_MESSAGE, new Throwable());
new ConnectionFeatureNotAvailableException((JdbcConnection) this.conn, new PacketSentTimeHolder() {
}, new Exception());
new MysqlDataTruncation(TEST_MESSAGE, 0, false, false, 0, 0, 0);
new MySQLQueryInterruptedException();
new MySQLQueryInterruptedException(TEST_MESSAGE);
new MySQLQueryInterruptedException(TEST_MESSAGE, TEST_SQL_STATE);
new MySQLQueryInterruptedException(TEST_MESSAGE, TEST_SQL_STATE, 0);
new MySQLStatementCancelledException();
new MySQLStatementCancelledException(TEST_MESSAGE);
new MySQLStatementCancelledException(TEST_MESSAGE, TEST_SQL_STATE);
new MySQLStatementCancelledException(TEST_MESSAGE, TEST_SQL_STATE, 0);
new MySQLTimeoutException();
new MySQLTimeoutException(TEST_MESSAGE);
new MySQLTimeoutException(TEST_MESSAGE, TEST_SQL_STATE);
new MySQLTimeoutException(TEST_MESSAGE, TEST_SQL_STATE, 0);
new MySQLTransactionRollbackException();
new MySQLTransactionRollbackException(TEST_MESSAGE);
new MySQLTransactionRollbackException(TEST_MESSAGE, TEST_SQL_STATE);
new MySQLTransactionRollbackException(TEST_MESSAGE, TEST_SQL_STATE, 0);
new NotUpdatable(TEST_MESSAGE);
new OperationNotSupportedException();
new OperationNotSupportedException(TEST_MESSAGE);
new PacketTooBigException(TEST_MESSAGE);
new PacketTooBigException(0, 100);
new SQLError();
}
use of com.mysql.cj.jdbc.exceptions.CommunicationsException in project JavaSegundasQuintas by ecteruel.
the class ExceptionsTest method testConstructors.
@Test
public void testConstructors() {
new CommunicationsException(TEST_MESSAGE, new Throwable());
new CommunicationsException((JdbcConnection) this.conn, new PacketSentTimeHolder() {
}, new PacketReceivedTimeHolder() {
}, new Exception());
new ConnectionFeatureNotAvailableException(TEST_MESSAGE, new Throwable());
new ConnectionFeatureNotAvailableException((JdbcConnection) this.conn, new PacketSentTimeHolder() {
}, new Exception());
new MysqlDataTruncation(TEST_MESSAGE, 0, false, false, 0, 0, 0);
new MySQLQueryInterruptedException();
new MySQLQueryInterruptedException(TEST_MESSAGE);
new MySQLQueryInterruptedException(TEST_MESSAGE, TEST_SQL_STATE);
new MySQLQueryInterruptedException(TEST_MESSAGE, TEST_SQL_STATE, 0);
new MySQLStatementCancelledException();
new MySQLStatementCancelledException(TEST_MESSAGE);
new MySQLStatementCancelledException(TEST_MESSAGE, TEST_SQL_STATE);
new MySQLStatementCancelledException(TEST_MESSAGE, TEST_SQL_STATE, 0);
new MySQLTimeoutException();
new MySQLTimeoutException(TEST_MESSAGE);
new MySQLTimeoutException(TEST_MESSAGE, TEST_SQL_STATE);
new MySQLTimeoutException(TEST_MESSAGE, TEST_SQL_STATE, 0);
new MySQLTransactionRollbackException();
new MySQLTransactionRollbackException(TEST_MESSAGE);
new MySQLTransactionRollbackException(TEST_MESSAGE, TEST_SQL_STATE);
new MySQLTransactionRollbackException(TEST_MESSAGE, TEST_SQL_STATE, 0);
new NotUpdatable(TEST_MESSAGE);
new OperationNotSupportedException();
new OperationNotSupportedException(TEST_MESSAGE);
new PacketTooBigException(TEST_MESSAGE);
new PacketTooBigException(0, 100);
new SQLError();
}
use of com.mysql.cj.jdbc.exceptions.CommunicationsException in project JavaSegundasQuintas by ecteruel.
the class ResultSetRegressionTest method testBug75309.
/**
* Tests fix for BUG#75309 - mysql connector/J driver in streaming mode will in the blocking state.
*
* @throws Exception
*/
@Test
public void testBug75309() throws Exception {
Properties props = new Properties();
props.setProperty(PropertyKey.useSSL.getKeyName(), "false");
props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
props.setProperty(PropertyKey.socketTimeout.getKeyName(), "1000");
Connection testConn = getConnectionWithProps(props);
Statement testStmt = testConn.createStatement();
// turn on streaming results.
testStmt.setFetchSize(Integer.MIN_VALUE);
final ResultSet testRs1 = testStmt.executeQuery("SELECT 1 + 18446744073709551615");
assertThrows(SQLException.class, "Data truncation: BIGINT UNSIGNED value is out of range in '\\(1 \\+ 18446744073709551615\\)'", new Callable<Void>() {
public Void call() throws Exception {
testRs1.next();
return null;
}
});
try {
testRs1.close();
} catch (CJCommunicationsException | CommunicationsException ex) {
fail("ResultSet.close() locked while trying to read remaining, nonexistent, streamed data.");
}
try {
ResultSet testRs2 = testStmt.executeQuery("SELECT 1");
assertTrue(testRs2.next());
assertEquals(1, testRs2.getInt(1));
testRs2.close();
} catch (SQLException ex) {
if (ex.getMessage().startsWith("Streaming result set")) {
fail("There is a Streaming result set still active. No other statements can be issued on this connection.");
} else {
ex.printStackTrace();
fail(ex.getMessage());
}
}
testStmt.close();
testConn.close();
}
use of com.mysql.cj.jdbc.exceptions.CommunicationsException in project ABC by RuiPinto96274.
the class ResultSetRegressionTest method testBug75309.
/**
* Tests fix for BUG#75309 - mysql connector/J driver in streaming mode will in the blocking state.
*
* @throws Exception
*/
@Test
public void testBug75309() throws Exception {
Properties props = new Properties();
props.setProperty(PropertyKey.useSSL.getKeyName(), "false");
props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
props.setProperty(PropertyKey.socketTimeout.getKeyName(), "1000");
Connection testConn = getConnectionWithProps(props);
Statement testStmt = testConn.createStatement();
// turn on streaming results.
testStmt.setFetchSize(Integer.MIN_VALUE);
final ResultSet testRs1 = testStmt.executeQuery("SELECT 1 + 18446744073709551615");
assertThrows(SQLException.class, "Data truncation: BIGINT UNSIGNED value is out of range in '\\(1 \\+ 18446744073709551615\\)'", new Callable<Void>() {
public Void call() throws Exception {
testRs1.next();
return null;
}
});
try {
testRs1.close();
} catch (CJCommunicationsException | CommunicationsException ex) {
fail("ResultSet.close() locked while trying to read remaining, nonexistent, streamed data.");
}
try {
ResultSet testRs2 = testStmt.executeQuery("SELECT 1");
assertTrue(testRs2.next());
assertEquals(1, testRs2.getInt(1));
testRs2.close();
} catch (SQLException ex) {
if (ex.getMessage().startsWith("Streaming result set")) {
fail("There is a Streaming result set still active. No other statements can be issued on this connection.");
} else {
ex.printStackTrace();
fail(ex.getMessage());
}
}
testStmt.close();
testConn.close();
}
Aggregations