Plugin Help MySQL offline

Discussion in 'Plugin Help/Development/Requests' started by metmad22, Apr 29, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    metmad22

    Hello all, I've made a custom plugin that looks for data from the server and sends it to a MySQL database. Some of these data types are related to player events. Because of this, I noticed if the MySQL database crashes or goes offline, the server crashes too since it can no longer complete the player's function.

    What my question is, how can I add some code to check if the database is offline, to close the connection and continue logging what's needed to a file instead?

    Thanks for the help! :)
     
  2. Offline

    timtower Administrator Administrator Moderator

    @metmad22 try catch around the connection
     
  3. Offline

    metmad22

    @timtower
    I already have one. But in the console, it says "last packet sent blablabla" and since I'm sending player chat related things to the database, it stops the whole chat and crashes players.

    Any other way around this?
     
  4. Offline

    timtower Administrator Administrator Moderator

    @metmad22 Store the messages to be send in a list, send them async.
     
  5. Offline

    metmad22

    @timtower

    I already had it like that. Maybe I should surround this with a try and catch and close the connection in a finally {} ?

    Code:
        public void content(final Player player, final String text, final Integer type, final String xyz)
        {
            Bukkit.getScheduler().runTaskAsynchronously(this, new Runnable() {
                @Override
                public void run() {
                    mysqlMethod(player, text, type, xyz);
                }
            });
        }
     
  6. Offline

    timtower Administrator Administrator Moderator

    @metmad22 Depends on what your mysqlmethod is.
    But my suggestion is creating a list of tasks to complete. And run those tasks every 5 min or so.
     
  7. Offline

    metmad22

    @timtower

    So just create a list, add the content to it, make a delayed task inside the async thread task and call it every x minutes?
    What happens if the database is still offline and it tries connecting to it 5 minutes later? Would that not timeout the server again?
     
  8. Offline

    timtower Administrator Administrator Moderator

    @metmad22 It would, but you would catch that error and your list would still exist, so the data is still safe.
     
  9. Offline

    metmad22

    @timtower
    Hmmm. Fair enough. Is there a way I could check if it's back online though so I can dump the saved and delayed data from the list once it finds a connection again?
     
  10. Offline

    timtower Administrator Administrator Moderator

Thread Status:
Not open for further replies.

Share This Page