Widen & break one thing out so I can avoid copy & paste when I format
a very similar message in the yohoho reboot manager. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5570 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -43,21 +43,17 @@ import static com.threerings.presents.Log.log;
|
|||||||
public abstract class RebootManager
|
public abstract class RebootManager
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* An interface for receiving notifications about pending automated
|
* An interface for receiving notifications about pending automated shutdowns.
|
||||||
* shutdowns.
|
|
||||||
*/
|
*/
|
||||||
public static interface PendingShutdownObserver
|
public static interface PendingShutdownObserver
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Called prior to an automated shutdown. NOTE that the shutdown
|
* Called prior to an automated shutdown. NOTE that the shutdown is not guaranteed to
|
||||||
* is not guaranteed to happen, this interface is merely for
|
* happen, this interface is merely for notification purposes.
|
||||||
* notification purposes.
|
|
||||||
*
|
*
|
||||||
* @param warningsLeft The number of warnings left prior to the
|
* @param warningsLeft The number of warnings left prior to the shutdown. This value will
|
||||||
* shutdown. This value will be 0 on the last warning, usually 1-2
|
* be 0 on the last warning, usually 1-2 minutes prior to the actual shutdown.
|
||||||
* minutes prior to the actual shutdown.
|
* @param msLeft the approximate number of milliseconds left prior to the shutdown.
|
||||||
* @param msLeft the approximate number of milliseconds left prior to
|
|
||||||
* the shutdown.
|
|
||||||
*/
|
*/
|
||||||
void shutdownPlanned (int warningsLeft, long msLeft);
|
void shutdownPlanned (int warningsLeft, long msLeft);
|
||||||
}
|
}
|
||||||
@@ -162,8 +158,7 @@ public abstract class RebootManager
|
|||||||
public int preventReboot (String whereFrom)
|
public int preventReboot (String whereFrom)
|
||||||
{
|
{
|
||||||
if (whereFrom == null) {
|
if (whereFrom == null) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException("whereFrom must be descriptive.");
|
||||||
"whereFrom must be descriptive.");
|
|
||||||
}
|
}
|
||||||
int lockId = _nextRebootLockId++;
|
int lockId = _nextRebootLockId++;
|
||||||
_rebootLocks.put(lockId, whereFrom);
|
_rebootLocks.put(lockId, whereFrom);
|
||||||
@@ -176,8 +171,7 @@ public abstract class RebootManager
|
|||||||
public void allowReboot (int lockId)
|
public void allowReboot (int lockId)
|
||||||
{
|
{
|
||||||
if (null == _rebootLocks.remove(lockId)) {
|
if (null == _rebootLocks.remove(lockId)) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException("no such lockId (" + lockId + ")");
|
||||||
"no such lockId (" + lockId + ")");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,8 +185,7 @@ public abstract class RebootManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Broadcasts a message to everyone on the server. The following
|
* Broadcasts a message to everyone on the server. The following messages will be broadcast:
|
||||||
* messages will be broadcast:
|
|
||||||
* <ul><li> m.rebooting_now
|
* <ul><li> m.rebooting_now
|
||||||
* <li> m.reboot_warning (minutes) (message or m.reboot_msg_standard)
|
* <li> m.reboot_warning (minutes) (message or m.reboot_msg_standard)
|
||||||
* <li> m.reboot_delayed
|
* <li> m.reboot_delayed
|
||||||
@@ -201,8 +194,8 @@ public abstract class RebootManager
|
|||||||
protected abstract void broadcast (String message);
|
protected abstract void broadcast (String message);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the frequency in days of our automatic reboots, or -1 to disable
|
* Returns the frequency in days of our automatic reboots, or -1 to disable automatically
|
||||||
* automatically scheduled reboots.
|
* scheduled reboots.
|
||||||
*/
|
*/
|
||||||
protected abstract int getDayFrequency ();
|
protected abstract int getDayFrequency ();
|
||||||
|
|
||||||
@@ -212,8 +205,8 @@ public abstract class RebootManager
|
|||||||
protected abstract int getRebootHour ();
|
protected abstract int getRebootHour ();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the reboot manager should avoid scheduling automated
|
* Returns true if the reboot manager should avoid scheduling automated reboots on the
|
||||||
* reboots on the weekends.
|
* weekends.
|
||||||
*/
|
*/
|
||||||
protected abstract boolean getSkipWeekends ();
|
protected abstract boolean getSkipWeekends ();
|
||||||
|
|
||||||
@@ -222,6 +215,20 @@ public abstract class RebootManager
|
|||||||
*/
|
*/
|
||||||
protected abstract String getCustomRebootMessage ();
|
protected abstract String getCustomRebootMessage ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Composes the given reboot message with the minutes and either the custom or standard details
|
||||||
|
* about the pending reboot.
|
||||||
|
*/
|
||||||
|
protected String getRebootMessage (String key, int minutes)
|
||||||
|
{
|
||||||
|
String msg = getCustomRebootMessage();
|
||||||
|
if (StringUtil.isBlank(msg)) {
|
||||||
|
msg = "m.reboot_msg_standard";
|
||||||
|
}
|
||||||
|
|
||||||
|
return MessageBundle.compose(key, MessageBundle.taint("" + minutes), msg);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Do a warning, schedule the next.
|
* Do a warning, schedule the next.
|
||||||
*/
|
*/
|
||||||
@@ -253,14 +260,8 @@ public abstract class RebootManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
// issue the warning
|
// issue the warning
|
||||||
String msg = getCustomRebootMessage();
|
|
||||||
if (StringUtil.isBlank(msg)) {
|
|
||||||
msg = "m.reboot_msg_standard";
|
|
||||||
}
|
|
||||||
int minutes = WARNINGS[level];
|
int minutes = WARNINGS[level];
|
||||||
msg = MessageBundle.compose(
|
broadcast(getRebootMessage("m.reboot_warning", minutes));
|
||||||
"m.reboot_warning", MessageBundle.taint("" + minutes), msg);
|
|
||||||
broadcast(msg);
|
|
||||||
if (level < WARNINGS.length - 1) {
|
if (level < WARNINGS.length - 1) {
|
||||||
minutes -= WARNINGS[level + 1];
|
minutes -= WARNINGS[level + 1];
|
||||||
}
|
}
|
||||||
@@ -277,8 +278,8 @@ public abstract class RebootManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check to see if there are outstanding reboot locks that may delay the
|
* Check to see if there are outstanding reboot locks that may delay the reboot, returning
|
||||||
* reboot, returning false if there are none.
|
* false if there are none.
|
||||||
*/
|
*/
|
||||||
protected boolean checkLocks ()
|
protected boolean checkLocks ()
|
||||||
{
|
{
|
||||||
@@ -306,8 +307,7 @@ public abstract class RebootManager
|
|||||||
{
|
{
|
||||||
final int warningsLeft = WARNINGS.length - level - 1;
|
final int warningsLeft = WARNINGS.length - level - 1;
|
||||||
final long msLeft = 1000L * 60L * WARNINGS[level];
|
final long msLeft = 1000L * 60L * WARNINGS[level];
|
||||||
_observers.apply(
|
_observers.apply(new ObserverList.ObserverOp<PendingShutdownObserver>() {
|
||||||
new ObserverList.ObserverOp<PendingShutdownObserver>() {
|
|
||||||
public boolean apply (PendingShutdownObserver observer) {
|
public boolean apply (PendingShutdownObserver observer) {
|
||||||
observer.shutdownPlanned(warningsLeft, msLeft);
|
observer.shutdownPlanned(warningsLeft, msLeft);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user