mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-11-28 05:05:21 +01:00
Rework shutdown sequence to close #391
This commit is contained in:
parent
0cd4c9030c
commit
0578f94522
@ -85,6 +85,7 @@ public class BungeeCord extends ProxyServer
|
|||||||
* locations.yml save thread.
|
* locations.yml save thread.
|
||||||
*/
|
*/
|
||||||
private final Timer saveThread = new Timer( "Reconnect Saver" );
|
private final Timer saveThread = new Timer( "Reconnect Saver" );
|
||||||
|
private final Timer metricsThread = new Timer( "Metrics Thread" );
|
||||||
/**
|
/**
|
||||||
* Server socket listener.
|
* Server socket listener.
|
||||||
*/
|
*/
|
||||||
@ -213,8 +214,7 @@ public class BungeeCord extends ProxyServer
|
|||||||
getReconnectHandler().save();
|
getReconnectHandler().save();
|
||||||
}
|
}
|
||||||
}, 0, TimeUnit.MINUTES.toMillis( 5 ) );
|
}, 0, TimeUnit.MINUTES.toMillis( 5 ) );
|
||||||
|
metricsThread.scheduleAtFixedRate( new Metrics(), 0, TimeUnit.MINUTES.toMillis( Metrics.PING_INTERVAL ) );
|
||||||
new Metrics().start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startListeners()
|
public void startListeners()
|
||||||
@ -265,7 +265,12 @@ public class BungeeCord extends ProxyServer
|
|||||||
@Override
|
@Override
|
||||||
public void stop()
|
public void stop()
|
||||||
{
|
{
|
||||||
this.isRunning = false;
|
new Thread( "Shutdown Thread" )
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
BungeeCord.this.isRunning = false;
|
||||||
|
|
||||||
httpClient.close();
|
httpClient.close();
|
||||||
executors.shutdown();
|
executors.shutdown();
|
||||||
@ -288,10 +293,17 @@ public class BungeeCord extends ProxyServer
|
|||||||
|
|
||||||
getLogger().info( "Closing IO threads" );
|
getLogger().info( "Closing IO threads" );
|
||||||
eventLoops.shutdownGracefully();
|
eventLoops.shutdownGracefully();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
eventLoops.awaitTermination( Long.MAX_VALUE, TimeUnit.NANOSECONDS );
|
||||||
|
} catch ( InterruptedException ex )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
getLogger().info( "Saving reconnect locations" );
|
getLogger().info( "Saving reconnect locations" );
|
||||||
reconnectHandler.save();
|
reconnectHandler.save();
|
||||||
saveThread.cancel();
|
saveThread.cancel();
|
||||||
|
metricsThread.cancel();
|
||||||
|
|
||||||
// TODO: Fix this shit
|
// TODO: Fix this shit
|
||||||
getLogger().info( "Disabling plugins" );
|
getLogger().info( "Disabling plugins" );
|
||||||
@ -304,6 +316,8 @@ public class BungeeCord extends ProxyServer
|
|||||||
getLogger().info( "Thankyou and goodbye" );
|
getLogger().info( "Thankyou and goodbye" );
|
||||||
System.exit( 0 );
|
System.exit( 0 );
|
||||||
}
|
}
|
||||||
|
}.start();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Broadcasts a packet to all clients that is connected to this instance.
|
* Broadcasts a packet to all clients that is connected to this instance.
|
||||||
|
@ -8,9 +8,10 @@ import java.io.UnsupportedEncodingException;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.util.TimerTask;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
|
||||||
public class Metrics extends Thread
|
public class Metrics extends TimerTask
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,19 +29,11 @@ public class Metrics extends Thread
|
|||||||
/**
|
/**
|
||||||
* Interval of time to ping (in minutes)
|
* Interval of time to ping (in minutes)
|
||||||
*/
|
*/
|
||||||
private final static int PING_INTERVAL = 10;
|
final static int PING_INTERVAL = 10;
|
||||||
|
boolean firstPost = true;
|
||||||
public Metrics()
|
|
||||||
{
|
|
||||||
super( "Metrics Gathering Thread" );
|
|
||||||
setDaemon( true );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
|
||||||
boolean firstPost = true;
|
|
||||||
while ( true )
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -56,14 +49,6 @@ public class Metrics extends Thread
|
|||||||
{
|
{
|
||||||
ProxyServer.getInstance().getLogger().info( "[Metrics] " + ex.getMessage() );
|
ProxyServer.getInstance().getLogger().info( "[Metrics] " + ex.getMessage() );
|
||||||
}
|
}
|
||||||
try
|
|
||||||
{
|
|
||||||
sleep( PING_INTERVAL * 1000 * 60 );
|
|
||||||
} catch ( InterruptedException ex )
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user