mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-18 03:01:05 +01:00
implemented restarter to move control over the restart process to the core
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package sonia.scm.lifecycle;
|
||||
|
||||
/**
|
||||
* Exception is thrown if a restart is not supported or a restart strategy is misconfigured.
|
||||
*/
|
||||
public class RestartNotSupportedException extends RuntimeException {
|
||||
RestartNotSupportedException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,8 @@ import sonia.scm.SCMContext;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.io.DefaultFileSystem;
|
||||
import sonia.scm.io.FileSystem;
|
||||
import sonia.scm.lifecycle.DefaultRestarter;
|
||||
import sonia.scm.lifecycle.Restarter;
|
||||
import sonia.scm.plugin.PluginLoader;
|
||||
import sonia.scm.repository.RepositoryLocationResolver;
|
||||
import sonia.scm.repository.xml.MetadataStore;
|
||||
@@ -61,6 +63,8 @@ public class BootstrapModule extends AbstractModule {
|
||||
|
||||
bind(FileSystem.class, DefaultFileSystem.class);
|
||||
|
||||
bind(Restarter.class, DefaultRestarter.class);
|
||||
|
||||
// note CipherUtil uses an other generator
|
||||
bind(CipherHandler.class).toInstance(CipherUtil.getInstance().getCipherHandler());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user