Fix disconnection issues. Push 1.3.3.7
This commit is contained in:
parent
e3cfc79055
commit
6a4feca615
4 changed files with 46 additions and 4 deletions
|
@ -79,7 +79,7 @@ public class OTEMod
|
|||
public static Map<String,Profile> PROFILES = new HashMap<String,Profile>();
|
||||
public static List<TeleportContainer> TeleportRegistry = new ArrayList<>();
|
||||
public static MinecraftServer THE_SERVER;
|
||||
private static boolean ALIVE;
|
||||
public static boolean ALIVE;
|
||||
|
||||
public static boolean DEVELOPER=false;
|
||||
private static Thread MasterThread;
|
||||
|
|
|
@ -12,7 +12,7 @@ public class Database {
|
|||
private Connection connection;
|
||||
|
||||
|
||||
public Database (OTEMod instance) throws DatabaseConnectionException
|
||||
public Database (OTEMod instance) throws DatabaseConnectionException, SQLException
|
||||
{
|
||||
mod=instance;
|
||||
try{
|
||||
|
@ -20,6 +20,48 @@ public class Database {
|
|||
}catch(Exception e){
|
||||
throw new DatabaseConnectionException(e.getMessage());
|
||||
}
|
||||
|
||||
Thread tx = new Thread(new Runnable(){
|
||||
public void run()
|
||||
{
|
||||
while(true){
|
||||
|
||||
// Watch the connection for disconnections
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(!OTEMod.ALIVE)return;// Exit now. We are being torn down/server is going down
|
||||
try {
|
||||
if(!OTEMod.DB.isConnected())
|
||||
{
|
||||
OTEMod.LOGGER.info("/!\\ Lost connection to data provider. Reconnecting...");
|
||||
// Refresh
|
||||
try {
|
||||
OTEMod.DB.connect();
|
||||
|
||||
if(OTEMod.DB.isConnected())
|
||||
{
|
||||
OTEMod.LOGGER.info("/!\\ Reconnected!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if(isConnected()){
|
||||
tx.start();
|
||||
}
|
||||
}
|
||||
|
||||
public void connect() throws Exception
|
||||
|
|
Reference in a new issue