mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 08:55:44 +01:00
42 lines
967 B
Java
42 lines
967 B
Java
|
|
package sonia.scm.lifecycle;
|
||
|
|
|
||
|
|
import com.google.common.annotations.VisibleForTesting;
|
||
|
|
import sonia.scm.event.ScmEventBus;
|
||
|
|
|
||
|
|
import javax.inject.Inject;
|
||
|
|
import javax.inject.Singleton;
|
||
|
|
|
||
|
|
@Singleton
|
||
|
|
public class DefaultRestarter implements Restarter {
|
||
|
|
|
||
|
|
private ScmEventBus eventBus;
|
||
|
|
private RestartStrategy strategy;
|
||
|
|
|
||
|
|
@Inject
|
||
|
|
public DefaultRestarter() {
|
||
|
|
this(
|
||
|
|
ScmEventBus.getInstance(),
|
||
|
|
RestartStrategy.get(Thread.currentThread().getContextClassLoader()).orElse(null)
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
@VisibleForTesting
|
||
|
|
DefaultRestarter(ScmEventBus eventBus, RestartStrategy strategy) {
|
||
|
|
this.eventBus = eventBus;
|
||
|
|
this.strategy = strategy;
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public boolean isSupported() {
|
||
|
|
return strategy != null;
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public void restart(Class<?> cause, String reason) {
|
||
|
|
if (!isSupported()) {
|
||
|
|
throw new RestartNotSupportedException("restarting is not supported");
|
||
|
|
}
|
||
|
|
eventBus.post(new RestartEvent(cause, reason));
|
||
|
|
}
|
||
|
|
}
|