Search in sources :

Example 1 with ConnectionIsClosedException

use of com.mysql.cj.exceptions.ConnectionIsClosedException in project aws-mysql-jdbc by awslabs.

the class XProtocol method close.

public void close() throws IOException {
    try {
        send(this.messageBuilder.buildClose(), 0);
        readQueryResult(new OkBuilder());
    } catch (Exception e) {
    // ignore exceptions
    } finally {
        try {
            if (this.managedResource == null) {
                throw new ConnectionIsClosedException();
            }
            this.managedResource.close();
            this.managedResource = null;
        } catch (IOException ex) {
            throw new CJCommunicationsException(ex);
        }
    }
}
Also used : IOException(java.io.IOException) WrongArgumentException(com.mysql.cj.exceptions.WrongArgumentException) CJCommunicationsException(com.mysql.cj.exceptions.CJCommunicationsException) SSLParamsException(com.mysql.cj.exceptions.SSLParamsException) FeatureNotAvailableException(com.mysql.cj.exceptions.FeatureNotAvailableException) ConnectionIsClosedException(com.mysql.cj.exceptions.ConnectionIsClosedException) CJConnectionFeatureNotAvailableException(com.mysql.cj.exceptions.CJConnectionFeatureNotAvailableException) CJOperationNotSupportedException(com.mysql.cj.exceptions.CJOperationNotSupportedException) IOException(java.io.IOException) AssertionFailedException(com.mysql.cj.exceptions.AssertionFailedException) ConnectionIsClosedException(com.mysql.cj.exceptions.ConnectionIsClosedException) CJCommunicationsException(com.mysql.cj.exceptions.CJCommunicationsException)

Example 2 with ConnectionIsClosedException

use of com.mysql.cj.exceptions.ConnectionIsClosedException 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);
}
Also used : DiscordUser(com.gamebuster19901.excite.bot.user.DiscordUser) UnknownDiscordUser(com.gamebuster19901.excite.bot.user.UnknownDiscordUser) SQLException(java.sql.SQLException) UnknownDiscordUser(com.gamebuster19901.excite.bot.user.UnknownDiscordUser) Instant(java.time.Instant) IOError(java.io.IOError) IOException(java.io.IOException) CJCommunicationsException(com.mysql.cj.exceptions.CJCommunicationsException) SQLNonTransientConnectionException(java.sql.SQLNonTransientConnectionException) IOError(java.io.IOError) LoginException(javax.security.auth.login.LoginException) ErrorResponseException(net.dv8tion.jda.api.exceptions.ErrorResponseException) ConsoleUser(com.gamebuster19901.excite.bot.user.ConsoleUser) DatabaseConnection(com.gamebuster19901.excite.bot.database.sql.DatabaseConnection) CommunicationsException(com.mysql.cj.jdbc.exceptions.CommunicationsException) CJCommunicationsException(com.mysql.cj.exceptions.CJCommunicationsException) ConnectionIsClosedException(com.mysql.cj.exceptions.ConnectionIsClosedException)

Example 3 with ConnectionIsClosedException

use of com.mysql.cj.exceptions.ConnectionIsClosedException in project JavaSegundasQuintas by ecteruel.

the class XProtocol method close.

public void close() throws IOException {
    try {
        send(this.messageBuilder.buildClose(), 0);
        readQueryResult(new OkBuilder());
    } catch (Exception e) {
    // ignore exceptions
    } finally {
        try {
            if (this.managedResource == null) {
                throw new ConnectionIsClosedException();
            }
            this.managedResource.close();
            this.managedResource = null;
        } catch (IOException ex) {
            throw new CJCommunicationsException(ex);
        }
    }
}
Also used : IOException(java.io.IOException) WrongArgumentException(com.mysql.cj.exceptions.WrongArgumentException) CJCommunicationsException(com.mysql.cj.exceptions.CJCommunicationsException) SSLParamsException(com.mysql.cj.exceptions.SSLParamsException) FeatureNotAvailableException(com.mysql.cj.exceptions.FeatureNotAvailableException) ConnectionIsClosedException(com.mysql.cj.exceptions.ConnectionIsClosedException) CJConnectionFeatureNotAvailableException(com.mysql.cj.exceptions.CJConnectionFeatureNotAvailableException) CJOperationNotSupportedException(com.mysql.cj.exceptions.CJOperationNotSupportedException) IOException(java.io.IOException) AssertionFailedException(com.mysql.cj.exceptions.AssertionFailedException) ConnectionIsClosedException(com.mysql.cj.exceptions.ConnectionIsClosedException) CJCommunicationsException(com.mysql.cj.exceptions.CJCommunicationsException)

Example 4 with ConnectionIsClosedException

use of com.mysql.cj.exceptions.ConnectionIsClosedException in project ABC by RuiPinto96274.

the class XProtocol method close.

public void close() throws IOException {
    try {
        send(this.messageBuilder.buildClose(), 0);
        readQueryResult(new OkBuilder());
    } catch (Exception e) {
    // ignore exceptions
    } finally {
        try {
            if (this.managedResource == null) {
                throw new ConnectionIsClosedException();
            }
            this.managedResource.close();
            this.managedResource = null;
        } catch (IOException ex) {
            throw new CJCommunicationsException(ex);
        }
    }
}
Also used : IOException(java.io.IOException) WrongArgumentException(com.mysql.cj.exceptions.WrongArgumentException) CJCommunicationsException(com.mysql.cj.exceptions.CJCommunicationsException) SSLParamsException(com.mysql.cj.exceptions.SSLParamsException) FeatureNotAvailableException(com.mysql.cj.exceptions.FeatureNotAvailableException) ConnectionIsClosedException(com.mysql.cj.exceptions.ConnectionIsClosedException) CJConnectionFeatureNotAvailableException(com.mysql.cj.exceptions.CJConnectionFeatureNotAvailableException) CJOperationNotSupportedException(com.mysql.cj.exceptions.CJOperationNotSupportedException) IOException(java.io.IOException) AssertionFailedException(com.mysql.cj.exceptions.AssertionFailedException) ConnectionIsClosedException(com.mysql.cj.exceptions.ConnectionIsClosedException) CJCommunicationsException(com.mysql.cj.exceptions.CJCommunicationsException)

Aggregations

CJCommunicationsException (com.mysql.cj.exceptions.CJCommunicationsException)4 ConnectionIsClosedException (com.mysql.cj.exceptions.ConnectionIsClosedException)4 IOException (java.io.IOException)4 AssertionFailedException (com.mysql.cj.exceptions.AssertionFailedException)3 CJConnectionFeatureNotAvailableException (com.mysql.cj.exceptions.CJConnectionFeatureNotAvailableException)3 CJOperationNotSupportedException (com.mysql.cj.exceptions.CJOperationNotSupportedException)3 FeatureNotAvailableException (com.mysql.cj.exceptions.FeatureNotAvailableException)3 SSLParamsException (com.mysql.cj.exceptions.SSLParamsException)3 WrongArgumentException (com.mysql.cj.exceptions.WrongArgumentException)3 DatabaseConnection (com.gamebuster19901.excite.bot.database.sql.DatabaseConnection)1 ConsoleUser (com.gamebuster19901.excite.bot.user.ConsoleUser)1 DiscordUser (com.gamebuster19901.excite.bot.user.DiscordUser)1 UnknownDiscordUser (com.gamebuster19901.excite.bot.user.UnknownDiscordUser)1 CommunicationsException (com.mysql.cj.jdbc.exceptions.CommunicationsException)1 IOError (java.io.IOError)1 SQLException (java.sql.SQLException)1 SQLNonTransientConnectionException (java.sql.SQLNonTransientConnectionException)1 Instant (java.time.Instant)1 LoginException (javax.security.auth.login.LoginException)1 ErrorResponseException (net.dv8tion.jda.api.exceptions.ErrorResponseException)1