mirror of
https://github.com/theonedev/onedev.git
synced 2025-12-08 18:26:30 +00:00
Refactor plugin start/stop to use Lifecycle interface.
This commit is contained in:
parent
65473b2720
commit
5242e0554a
@ -40,7 +40,7 @@ public class JettyPlugin extends AbstractPlugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preStartDependents() {
|
||||
public void start() {
|
||||
server = createServer();
|
||||
|
||||
try {
|
||||
@ -51,7 +51,7 @@ public class JettyPlugin extends AbstractPlugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postStopDependents() {
|
||||
public void stop() {
|
||||
try {
|
||||
server.stop();
|
||||
} catch (Exception e) {
|
||||
|
||||
@ -5,9 +5,10 @@ import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.pmease.commons.bootstrap.Lifecycle;
|
||||
import com.pmease.commons.util.dependency.Dependency;
|
||||
|
||||
public abstract class AbstractPlugin implements Dependency {
|
||||
public abstract class AbstractPlugin implements Dependency, Lifecycle {
|
||||
|
||||
private String id;
|
||||
|
||||
@ -77,25 +78,25 @@ public abstract class AbstractPlugin implements Dependency {
|
||||
/**
|
||||
* This function will be called before starting other plugins depending on this plugin.
|
||||
*/
|
||||
public void preStartDependents() {
|
||||
public void start() {
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will be called after other plugins depending on this plugin have been started.
|
||||
*/
|
||||
public void postStartDependents() {
|
||||
public void postStart() {
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will be called before stopping other plugins depending on this plugin.
|
||||
*/
|
||||
public void preStopDependents() {
|
||||
public void preStop() {
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will be called after other plugins depending on this plugin have been stopped.
|
||||
*/
|
||||
public void postStopDependents() {
|
||||
public void stop() {
|
||||
}
|
||||
|
||||
public abstract Collection<?> getExtensions();
|
||||
|
||||
@ -38,20 +38,20 @@ public class DefaultPluginManager implements PluginManager {
|
||||
|
||||
public void start() {
|
||||
for (AbstractPlugin plugin: pluginMap.values())
|
||||
plugin.preStartDependents();
|
||||
plugin.start();
|
||||
List<AbstractPlugin> reversed = new ArrayList<AbstractPlugin>(pluginMap.values());
|
||||
Collections.reverse(reversed);
|
||||
for (AbstractPlugin plugin: reversed)
|
||||
plugin.postStartDependents();
|
||||
plugin.postStart();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
for (AbstractPlugin plugin: pluginMap.values())
|
||||
plugin.preStopDependents();
|
||||
plugin.preStop();
|
||||
List<AbstractPlugin> reversed = new ArrayList<AbstractPlugin>(pluginMap.values());
|
||||
Collections.reverse(reversed);
|
||||
for (AbstractPlugin plugin: reversed)
|
||||
plugin.postStopDependents();
|
||||
plugin.stop();
|
||||
}
|
||||
|
||||
public <T> Collection<T> getExtensions(Class<T> extensionPoint) {
|
||||
|
||||
@ -65,13 +65,13 @@ public class AbstractPluginTest {
|
||||
|
||||
InOrder inOrder = inOrder(plugin1, plugin2, plugin3);
|
||||
|
||||
inOrder.verify(plugin3).preStartDependents();
|
||||
inOrder.verify(plugin2).preStartDependents();
|
||||
inOrder.verify(plugin1).preStartDependents();
|
||||
inOrder.verify(plugin3).start();
|
||||
inOrder.verify(plugin2).start();
|
||||
inOrder.verify(plugin1).start();
|
||||
|
||||
inOrder.verify(plugin1).postStartDependents();
|
||||
inOrder.verify(plugin2).postStartDependents();
|
||||
inOrder.verify(plugin3).postStartDependents();
|
||||
inOrder.verify(plugin1).postStart();
|
||||
inOrder.verify(plugin2).postStart();
|
||||
inOrder.verify(plugin3).postStart();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -80,12 +80,12 @@ public class AbstractPluginTest {
|
||||
|
||||
InOrder inOrder = inOrder(plugin1, plugin2, plugin3);
|
||||
|
||||
inOrder.verify(plugin3).preStopDependents();
|
||||
inOrder.verify(plugin2).preStopDependents();
|
||||
inOrder.verify(plugin1).preStopDependents();
|
||||
inOrder.verify(plugin3).preStop();
|
||||
inOrder.verify(plugin2).preStop();
|
||||
inOrder.verify(plugin1).preStop();
|
||||
|
||||
inOrder.verify(plugin1).postStopDependents();
|
||||
inOrder.verify(plugin2).postStopDependents();
|
||||
inOrder.verify(plugin3).postStopDependents();
|
||||
inOrder.verify(plugin1).stop();
|
||||
inOrder.verify(plugin2).stop();
|
||||
inOrder.verify(plugin3).stop();
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,12 +26,12 @@ public class PersistencePlugin extends AbstractPlugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preStartDependents() {
|
||||
public void start() {
|
||||
persistService.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postStopDependents() {
|
||||
public void stop() {
|
||||
persistService.stop();
|
||||
}
|
||||
|
||||
|
||||
@ -4,7 +4,6 @@ import org.hibernate.cfg.NamingStrategy;
|
||||
|
||||
import com.pmease.commons.loader.AbstractPlugin;
|
||||
import com.pmease.commons.loader.AbstractPluginModule;
|
||||
import com.pmease.commons.loader.AppName;
|
||||
import com.pmease.commons.persistence.PrefixedNamingStrategy;
|
||||
import com.pmease.commons.security.AbstractRealm;
|
||||
import com.pmease.commons.web.AbstractWicketConfig;
|
||||
@ -16,8 +15,6 @@ import com.pmease.gitop.core.permission.UserRealm;
|
||||
*/
|
||||
public class CoreModule extends AbstractPluginModule {
|
||||
|
||||
public static final String PRODUCT_NAME = "Gitop";
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
super.configure();
|
||||
@ -25,7 +22,6 @@ public class CoreModule extends AbstractPluginModule {
|
||||
bind(AbstractWicketConfig.class).to(WicketConfig.class);
|
||||
bind(AbstractRealm.class).to(UserRealm.class);
|
||||
|
||||
bindConstant().annotatedWith(AppName.class).to(PRODUCT_NAME);
|
||||
bind(NamingStrategy.class).toInstance(new PrefixedNamingStrategy("G"));
|
||||
|
||||
bind(Gitop.class);
|
||||
|
||||
@ -50,7 +50,7 @@ public class CorePlugin extends AbstractPlugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postStartDependents() {
|
||||
public void postStart() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ public class Product extends AbstractPlugin {
|
||||
|
||||
private final Properties serverProps;
|
||||
|
||||
public static final String PRODUCT_NAME = "Gitop";
|
||||
public static final String NAME = "Gitop";
|
||||
|
||||
@Inject
|
||||
public Product() {
|
||||
@ -103,8 +103,8 @@ public class Product extends AbstractPlugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postStartDependents() {
|
||||
logger.info(PRODUCT_NAME + " has been started successfully.");
|
||||
public void postStart() {
|
||||
logger.info(NAME + " has been started successfully.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ import java.util.Properties;
|
||||
import com.pmease.commons.bootstrap.Bootstrap;
|
||||
import com.pmease.commons.loader.AbstractPlugin;
|
||||
import com.pmease.commons.loader.AbstractPluginModule;
|
||||
import com.pmease.commons.loader.AppName;
|
||||
import com.pmease.commons.persistence.Hibernate;
|
||||
import com.pmease.commons.util.FileUtils;
|
||||
|
||||
@ -15,6 +16,8 @@ public class ProductModule extends AbstractPluginModule {
|
||||
protected void configure() {
|
||||
super.configure();
|
||||
|
||||
bindConstant().annotatedWith(AppName.class).to(Product.NAME);
|
||||
|
||||
Properties hibernateProps = FileUtils.loadProperties(
|
||||
new File(Bootstrap.installDir, "conf/hibernate.properties"));
|
||||
bind(Properties.class).annotatedWith(Hibernate.class).toInstance(hibernateProps);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user