use of org.opennms.netmgt.config.service.Invoke in project opennms by OpenNMS.
the class Invoker method getLastPass.
/**
* Get the last pass for a set of InvokerServices.
*
* @param invokerServices list to look at
* @return highest pass value found for all Invoke objects in the
* invokerServices list
*/
private int getLastPass() {
List<InvokerService> invokerServices = getServices();
int end = 0;
for (final InvokerService invokerService : invokerServices) {
final List<Invoke> invokes = invokerService.getService().getInvokes();
if (invokes == null) {
continue;
}
for (final Invoke invoke : invokes) {
if (invoke.getPass() > end) {
end = invoke.getPass();
}
}
}
return end;
}
use of org.opennms.netmgt.config.service.Invoke in project opennms by OpenNMS.
the class Invoker method invokeMethods.
/**
* <p>invokeMethods</p>
*
* @return a {@link java.util.List} object.
*/
public List<InvokerResult> invokeMethods() {
List<InvokerService> invokerServicesOrdered;
if (isReverse()) {
invokerServicesOrdered = new ArrayList<InvokerService>(getServices());
Collections.reverse(invokerServicesOrdered);
} else {
// We can use the original list
invokerServicesOrdered = getServices();
}
List<InvokerResult> resultInfo = new ArrayList<InvokerResult>(invokerServicesOrdered.size());
for (int pass = 0, end = getLastPass(); pass <= end; pass++) {
LOG.debug("starting pass {}", pass);
for (InvokerService invokerService : invokerServicesOrdered) {
Service service = invokerService.getService();
String name = invokerService.getService().getName();
ObjectInstance mbean = invokerService.getMbean();
if (invokerService.isBadService()) {
resultInfo.add(new InvokerResult(service, mbean, null, invokerService.getBadThrowable()));
if (isFailFast()) {
return resultInfo;
}
}
for (final Invoke invoke : invokerService.getService().getInvokes()) {
if (invoke.getPass() != pass || !getAtType().equals(invoke.getAt())) {
continue;
}
LOG.debug("pass {} on service {} will invoke method \"{}\"", pass, name, invoke.getMethod());
try {
Object result = invoke(invoke, mbean);
resultInfo.add(new InvokerResult(service, mbean, result, null));
} catch (Throwable t) {
resultInfo.add(new InvokerResult(service, mbean, null, t));
if (isFailFast()) {
return resultInfo;
}
}
}
}
LOG.debug("completed pass {}", pass);
}
return resultInfo;
}
use of org.opennms.netmgt.config.service.Invoke in project opennms by OpenNMS.
the class Main method main.
@SuppressWarnings({ "static-access", "deprecation" })
public static void main(final String... args) throws Exception {
final Options options = new Options();
options.addOption(OptionBuilder.withDescription("this help").withLongOpt("help").create("h"));
options.addOption(OptionBuilder.hasArg().withArgName("DIRECTORY").withDescription("OpenNMS home directory").withLongOpt("opennms-home").create("o"));
final CommandLineParser parser = new GnuParser();
try {
final CommandLine line = parser.parse(options, args);
if (line.hasOption("help")) {
final HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("syslog-profiler", options, true);
System.exit(1);
}
if (line.hasOption("opennms-home")) {
OPENNMS_HOME = line.getOptionValue("opennms-home");
} else {
final HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("syslog-profiler", "You must specify your OpenNMS home.", options, null);
System.exit(1);
}
} catch (Throwable e) {
LOG.warn("An error occurred trying to parse the command-line.", e);
}
System.out.println("- using " + OPENNMS_HOME + "/etc for configuration files");
System.setProperty("opennms.home", OPENNMS_HOME);
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
List<Invoke> invokes = new ArrayList<Invoke>();
invokes.add((Invoke) CastorUtils.unmarshal(Invoke.class, new StringReader("<invoke at=\"start\" pass=\"0\" method=\"init\"/>")));
invokes.add((Invoke) CastorUtils.unmarshal(Invoke.class, new StringReader("<invoke at=\"start\" pass=\"1\" method=\"start\"/>")));
invokes.add((Invoke) CastorUtils.unmarshal(Invoke.class, new StringReader("<invoke at=\"status\" pass=\"0\" method=\"status\"/>")));
invokes.add((Invoke) CastorUtils.unmarshal(Invoke.class, new StringReader("<invoke at=\"stop\" pass=\"0\" method=\"stop\"/>")));
List<Service> services = new ArrayList<Service>();
Invoker invoker = new Invoker();
invoker.setServer(server);
invoker.setAtType(InvokeAtType.START);
for (final Service s : Invoker.getDefaultServiceConfigFactory().getServices()) {
if (s.getName().contains("Eventd") || s.getName().contains("Syslogd")) {
services.add(s);
}
}
List<InvokerService> invokerServices = InvokerService.createServiceList(services.toArray(new Service[0]));
System.err.println(invokerServices);
invoker.setServices(invokerServices);
invoker.instantiateClasses();
Thread.sleep(10000);
}
Aggregations