plugins are only loaded while starting.
This commit is contained in:
parent
147c40166d
commit
0d545811b8
|
@ -80,7 +80,7 @@ public class HomeController {
|
|||
scenario.getUserBehaviors()[2].getParameters()[0].setKey("time");
|
||||
scenario.getUserBehaviors()[2].getParameters()[0].setValue("1000");
|
||||
|
||||
this.getScenarioEngine().runScenario(scenario, 1000);
|
||||
this.getScenarioEngine().runScenario(scenario, 100);
|
||||
return "It works!";
|
||||
}
|
||||
}
|
|
@ -23,12 +23,19 @@ import org.springframework.stereotype.Component;
|
|||
public class PluginManager {
|
||||
private ClassHelper classHelper;
|
||||
private TypeConverter typeConverter;
|
||||
private Map<String, Class<?>> plugins;
|
||||
|
||||
@Autowired
|
||||
public PluginManager(ClassHelper classHelper, TypeConverter typeConverter) {
|
||||
this.setClassHelper(classHelper);
|
||||
this.setTypeConverter(typeConverter);
|
||||
this.setPlugins(this.findPlugins("org.bench4q.agent.plugin"));
|
||||
}
|
||||
|
||||
private ClassHelper getClassHelper() {
|
||||
return classHelper;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setClassHelper(ClassHelper classHelper) {
|
||||
this.classHelper = classHelper;
|
||||
}
|
||||
|
@ -37,11 +44,18 @@ public class PluginManager {
|
|||
return typeConverter;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setTypeConverter(TypeConverter typeConverter) {
|
||||
this.typeConverter = typeConverter;
|
||||
}
|
||||
|
||||
public Map<String, Class<?>> getPlugins() {
|
||||
return plugins;
|
||||
}
|
||||
|
||||
private void setPlugins(Map<String, Class<?>> plugins) {
|
||||
this.plugins = plugins;
|
||||
}
|
||||
|
||||
private Map<String, Class<?>> findPlugins(String packageName) {
|
||||
try {
|
||||
List<String> classNames = this.getClassHelper().getClassNames(
|
||||
|
@ -60,10 +74,6 @@ public class PluginManager {
|
|||
}
|
||||
}
|
||||
|
||||
public Class<?> getPlugin(String name) {
|
||||
return this.findPlugins("org.bench4q.agent.plugin").get(name);
|
||||
}
|
||||
|
||||
public Object initializePlugin(Class<?> plugin,
|
||||
Map<String, String> parameters) {
|
||||
try {
|
||||
|
|
|
@ -5,7 +5,7 @@ import org.bench4q.agent.plugin.Plugin;
|
|||
|
||||
@Plugin("ConstantTimer")
|
||||
public class ConstantTimerPlugin {
|
||||
public ConstantTimerPlugin(int time) {
|
||||
public ConstantTimerPlugin() {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.bench4q.agent.scenario;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
@ -24,7 +23,6 @@ public class ScenarioEngine {
|
|||
}
|
||||
|
||||
public void runScenario(final Scenario scenario, int threadCount) {
|
||||
System.out.println("Start at:" + new Date(System.currentTimeMillis()));
|
||||
ExecutorService executorService = Executors
|
||||
.newFixedThreadPool(threadCount);
|
||||
int i;
|
||||
|
@ -37,7 +35,6 @@ public class ScenarioEngine {
|
|||
executorService.execute(runnable);
|
||||
}
|
||||
executorService.shutdown();
|
||||
System.out.println("End at:" + new Date(System.currentTimeMillis()));
|
||||
}
|
||||
|
||||
public void runScenario(Scenario scenario) {
|
||||
|
@ -45,12 +42,13 @@ public class ScenarioEngine {
|
|||
}
|
||||
|
||||
private void doRunScenario(Scenario scenario) {
|
||||
System.out.println("Running");
|
||||
ScenarioContext scenarioContext = new ScenarioContext();
|
||||
scenarioContext.setPlugins(new HashMap<String, Object>());
|
||||
for (UsePlugin usePlugin : scenario.getUsePlugins()) {
|
||||
String pluginId = usePlugin.getId();
|
||||
Class<?> pluginClass = this.getPluginManager().getPlugin(
|
||||
usePlugin.getName());
|
||||
Class<?> pluginClass = this.getPluginManager().getPlugins()
|
||||
.get(usePlugin.getName());
|
||||
Map<String, String> initParameters = new HashMap<String, String>();
|
||||
for (Parameter parameter : usePlugin.getParameters()) {
|
||||
initParameters.put(parameter.getKey(), parameter.getValue());
|
||||
|
@ -71,5 +69,6 @@ public class ScenarioEngine {
|
|||
this.getPluginManager().doBehavior(plugin, behaviorName,
|
||||
behaviorParameters);
|
||||
}
|
||||
System.out.println("Finished");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue