Expose USR1 and USR2 signals to users of AbstractSignalHandler if they bind instances of a
SignalReceiver class for those signals. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5979 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
package com.threerings.presents.server;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.name.Named;
|
||||
|
||||
import static com.threerings.presents.Log.log;
|
||||
|
||||
@@ -72,6 +73,23 @@ public abstract class AbstractSignalHandler
|
||||
log.info(_repmgr.generateReport(ReportManager.DEFAULT_TYPE));
|
||||
}
|
||||
|
||||
protected void usr1Received ()
|
||||
{
|
||||
if (_usr1receiver != null) {
|
||||
_usr1receiver.received();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void usr2Received ()
|
||||
{
|
||||
if (_usr2receiver != null) {
|
||||
_usr2receiver.received();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(optional=true) @Named(SignalReceiver.USR1) protected SignalReceiver _usr1receiver;
|
||||
@Inject(optional=true) @Named(SignalReceiver.USR2) protected SignalReceiver _usr2receiver;
|
||||
@Inject protected PresentsServer _server;
|
||||
@Inject protected ReportManager _repmgr;
|
||||
}
|
||||
|
||||
@@ -44,6 +44,12 @@ public class NativeSignalHandler extends AbstractSignalHandler
|
||||
case SignalManager.SIGHUP:
|
||||
hupReceived();
|
||||
break;
|
||||
case SignalManager.SIGUSR1:
|
||||
usr1Received();
|
||||
break;
|
||||
case SignalManager.SIGUSR2:
|
||||
usr2Received();
|
||||
break;
|
||||
default:
|
||||
log.warning("Received unknown signal", "signo", signo);
|
||||
break;
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.threerings.presents.server;
|
||||
|
||||
/**
|
||||
* Listens for Unix signals captured by {@link AbstractSignalHandler}.
|
||||
*/
|
||||
public interface SignalReceiver
|
||||
{
|
||||
|
||||
/**
|
||||
* Used to mark the receiver for the USR1 signal in guice injection. Bind implementations that
|
||||
* should receive this signal with
|
||||
* <code>annotatedWith(Names.named(SignalReceiver.USR1))</code>.
|
||||
*/
|
||||
public static final String USR1 = "usr1";
|
||||
/**
|
||||
* Used to mark the receiver for the USR2 signal in guice injection. Bind implementations that
|
||||
* should receive this signal with
|
||||
* <code>annotatedWith(Names.named(SignalReceiver.USR2))</code>.
|
||||
*/
|
||||
public static final String USR2 = "usr2";
|
||||
|
||||
void received();
|
||||
}
|
||||
@@ -42,6 +42,16 @@ public class SunSignalHandler extends AbstractSignalHandler
|
||||
intReceived();
|
||||
}
|
||||
});
|
||||
SignalUtil.register(SignalUtil.Number.USR1, new SignalUtil.Handler() {
|
||||
public void signalReceived (SignalUtil.Number sig) {
|
||||
usr1Received();
|
||||
}
|
||||
});
|
||||
SignalUtil.register(SignalUtil.Number.USR2, new SignalUtil.Handler() {
|
||||
public void signalReceived (SignalUtil.Number sig) {
|
||||
usr2Received();
|
||||
}
|
||||
});
|
||||
if (!RunAnywhere.isWindows()) {
|
||||
SignalUtil.register(SignalUtil.Number.HUP, new SignalUtil.Handler() {
|
||||
public void signalReceived (SignalUtil.Number sig) {
|
||||
|
||||
Reference in New Issue
Block a user