mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-07 08:39:17 +00:00
Add GameService#shutdown, remove comment on overridden method, rebase some sloppy code.
This commit is contained in:
@@ -25,7 +25,7 @@ public final class GamePulseHandler implements Runnable {
|
|||||||
*
|
*
|
||||||
* @param service The {@link GameService}.
|
* @param service The {@link GameService}.
|
||||||
*/
|
*/
|
||||||
GamePulseHandler(GameService service) {
|
protected GamePulseHandler(GameService service) {
|
||||||
this.service = service;
|
this.service = service;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,10 +33,11 @@ public final class GamePulseHandler implements Runnable {
|
|||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
service.pulse();
|
service.pulse();
|
||||||
} catch (Throwable t) {
|
} catch (Throwable reason) {
|
||||||
logger.log(Level.SEVERE, "Exception during pulse.", t);
|
logger.log(Level.SEVERE, "Exception occured during pulse!", reason);
|
||||||
|
} finally {
|
||||||
|
service.shutdown(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -125,18 +125,11 @@ public final class GameService extends Service {
|
|||||||
*/
|
*/
|
||||||
public void pulse() {
|
public void pulse() {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
LoginService loginService = getContext().getService(LoginService.class);
|
finalizeUnregisters();
|
||||||
|
|
||||||
World world = World.getWorld();
|
World world = World.getWorld();
|
||||||
|
for (Player player : world.getPlayerRepository()) {
|
||||||
int unregistered = 0;
|
GameSession session = player.getSession();
|
||||||
Player old;
|
|
||||||
while (unregistered < UNREGISTERS_PER_CYCLE && (old = oldPlayers.poll()) != null) {
|
|
||||||
loginService.submitSaveRequest(old.getSession(), old);
|
|
||||||
unregistered++;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Player p : world.getPlayerRepository()) {
|
|
||||||
GameSession session = p.getSession();
|
|
||||||
if (session != null) {
|
if (session != null) {
|
||||||
session.handlePendingMessages(chainGroup);
|
session.handlePendingMessages(chainGroup);
|
||||||
}
|
}
|
||||||
@@ -147,6 +140,30 @@ public final class GameService extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finalizes the unregistration of Player's queued to be unregistered.
|
||||||
|
*/
|
||||||
|
private void finalizeUnregisters() {
|
||||||
|
LoginService loginService = getContext().getService(LoginService.class);
|
||||||
|
|
||||||
|
for (int count = 0; count < UNREGISTERS_PER_CYCLE; count++) {
|
||||||
|
Player player = oldPlayers.poll();
|
||||||
|
if (player == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
loginService.submitSaveRequest(player.getSession(), player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shuts down this game service.
|
||||||
|
*/
|
||||||
|
public void shutdown(boolean natural) {
|
||||||
|
scheduledExecutor.shutdownNow();
|
||||||
|
// TODO: Other events that should happen upon natural or unexpected shutdown.
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a {@link Player} (may block!).
|
* Registers a {@link Player} (may block!).
|
||||||
*
|
*
|
||||||
@@ -170,9 +187,6 @@ public final class GameService extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Starts the game service.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void start() {
|
public void start() {
|
||||||
scheduledExecutor.scheduleAtFixedRate(new GamePulseHandler(this), GameConstants.PULSE_DELAY, GameConstants.PULSE_DELAY, TimeUnit.MILLISECONDS);
|
scheduledExecutor.scheduleAtFixedRate(new GamePulseHandler(this), GameConstants.PULSE_DELAY, GameConstants.PULSE_DELAY, TimeUnit.MILLISECONDS);
|
||||||
|
|||||||
Reference in New Issue
Block a user