com.threerings.presents.server
Class RebootManager

java.lang.Object
  extended by com.threerings.presents.server.RebootManager

public abstract class RebootManager
extends Object

Handles scheduling and execution of automated server reboots. Note that this service simply shuts down the server and assumes it will be automatically restarted by some external entity. It is generally useful to run a server from a script that automatically restarts it when it terminates.


Nested Class Summary
static interface RebootManager.PendingShutdownObserver
          An interface for receiving notifications about pending automated shutdowns.
 
Field Summary
protected  String _initiator
          The entity that scheduled the reboot.
protected  Interval _interval
          The interval scheduled to perform the next step the reboot process.
protected  long _nextReboot
          The time at which our next reboot is scheduled or 0L.
protected  int _nextRebootLockId
          The next reboot lock id.
protected  ObserverList<RebootManager.PendingShutdownObserver> _observers
          A list of PendingShutdownObservers.
protected  RootDObjectManager _omgr
          Our distributed object manager.
protected  HashIntMap<String> _rebootLocks
          Things that can delay the reboot.
protected  boolean _rebootSoon
          True if the reboot is coming soon, within the earliest warning.
protected  PresentsServer _server
          The server that we're going to reboot.
protected static String AUTOMATIC_INITIATOR
           
static int[] DEFAULT_WARNINGS
          The default warning times.
 
Constructor Summary
protected RebootManager(PresentsServer server, RootDObjectManager omgr)
          Provides us with our dependencies.
 
Method Summary
 void addObserver(RebootManager.PendingShutdownObserver observer)
          Add an observer to the observer list.
 void allowReboot(int lockId)
          Release a reboot lock.
protected abstract  void broadcast(String message)
          Broadcasts a message to everyone on the server.
protected  boolean checkLocks()
          Check to see if there are outstanding reboot locks that may delay the reboot, returning false if there are none.
protected  void doWarning(int level)
          Do a warning, schedule the next.
protected abstract  String getCustomRebootMessage()
          Returns a custom message to be used when broadcasting a pending reboot.
protected abstract  int getDayFrequency()
          Returns the frequency in days of our automatic reboots, or -1 to disable automatically scheduled reboots.
protected abstract  int getRebootHour()
          Returns the desired hour at which to perform our reboot.
protected  String getRebootMessage(String key, int minutes)
          Composes the given reboot message with the minutes and either the custom or standard details about the pending reboot.
protected abstract  boolean getSkipWeekends()
          Returns true if the reboot manager should avoid scheduling automated reboots on the weekends.
 int[] getWarnings()
          Returns the minutes at which we give warnings.
 void init()
          Finishes initialization of the manager.
protected  void notifyObservers(int level)
          Notify all PendingShutdownObservers of the pending shutdown!
 int preventReboot(String whereFrom)
          Called by an entity that would like to prevent a reboot.
 void scheduleReboot(long rebootTime, String initiator)
          Schedules a reboot for the specified time.
 boolean scheduleRegularReboot()
          Schedules our next regularly scheduled reboot.
 boolean willShutdownSoon()
          Is the manager planning a shutdown in the near future?
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_WARNINGS

public static final int[] DEFAULT_WARNINGS
The default warning times.


_server

protected PresentsServer _server
The server that we're going to reboot.


_omgr

protected RootDObjectManager _omgr
Our distributed object manager.


_nextReboot

protected long _nextReboot
The time at which our next reboot is scheduled or 0L.


_initiator

protected String _initiator
The entity that scheduled the reboot.


_rebootSoon

protected boolean _rebootSoon
True if the reboot is coming soon, within the earliest warning.


_interval

protected Interval _interval
The interval scheduled to perform the next step the reboot process.


_observers

protected ObserverList<RebootManager.PendingShutdownObserver> _observers
A list of PendingShutdownObservers.


_nextRebootLockId

protected int _nextRebootLockId
The next reboot lock id.


_rebootLocks

protected HashIntMap<String> _rebootLocks
Things that can delay the reboot.


AUTOMATIC_INITIATOR

protected static final String AUTOMATIC_INITIATOR
See Also:
Constant Field Values
Constructor Detail

RebootManager

protected RebootManager(PresentsServer server,
                        RootDObjectManager omgr)
Provides us with our dependencies.

Method Detail

init

public void init()
Finishes initialization of the manager.


scheduleRegularReboot

public boolean scheduleRegularReboot()
Schedules our next regularly scheduled reboot.

Returns:
true if a reboot was scheduled, false if regularly scheduled reboots are disabled.

willShutdownSoon

public boolean willShutdownSoon()
Is the manager planning a shutdown in the near future?


addObserver

public void addObserver(RebootManager.PendingShutdownObserver observer)
Add an observer to the observer list.


scheduleReboot

public void scheduleReboot(long rebootTime,
                           String initiator)
Schedules a reboot for the specified time.


preventReboot

public int preventReboot(String whereFrom)
Called by an entity that would like to prevent a reboot.


allowReboot

public void allowReboot(int lockId)
Release a reboot lock.


getWarnings

public int[] getWarnings()
Returns the minutes at which we give warnings. The last value is also the minimum time at which we can possibly reboot after the value of the nextReboot field is changed, to prevent accidentally causing instant server reboots.


broadcast

protected abstract void broadcast(String message)
Broadcasts a message to everyone on the server. The following messages will be broadcast:


getDayFrequency

protected abstract int getDayFrequency()
Returns the frequency in days of our automatic reboots, or -1 to disable automatically scheduled reboots.


getRebootHour

protected abstract int getRebootHour()
Returns the desired hour at which to perform our reboot.


getSkipWeekends

protected abstract boolean getSkipWeekends()
Returns true if the reboot manager should avoid scheduling automated reboots on the weekends.


getCustomRebootMessage

protected abstract String getCustomRebootMessage()
Returns a custom message to be used when broadcasting a pending reboot.


getRebootMessage

protected String getRebootMessage(String key,
                                  int minutes)
Composes the given reboot message with the minutes and either the custom or standard details about the pending reboot.


doWarning

protected void doWarning(int level)
Do a warning, schedule the next.


checkLocks

protected boolean checkLocks()
Check to see if there are outstanding reboot locks that may delay the reboot, returning false if there are none.


notifyObservers

protected void notifyObservers(int level)
Notify all PendingShutdownObservers of the pending shutdown!