Search in sources :

Example 11 with Service

use of org.opennms.netmgt.config.service.Service in project opennms by OpenNMS.

the class InvokerTest method invokeMethods.

private static void invokeMethods(Invoker invoker) throws Throwable {
    for (InvokerService iservice : invoker.getServices()) {
        Service service = iservice.getService();
        ObjectName name = new ObjectName(service.getName());
        System.err.println("object instance = " + getObjectInstanceString(invoker.getServer().getObjectInstance(name)));
    }
    List<InvokerResult> results = invoker.invokeMethods();
    System.err.println(invoker.getAtType().toString() + ": got " + results.size() + " results");
    for (InvokerResult result : results) {
        System.err.println(invoker.getAtType().toString() + ": result = " + getResultString(result));
        if (result.getThrowable() != null) {
            throw result.getThrowable();
        }
    }
}
Also used : Service(org.opennms.netmgt.config.service.Service) ObjectName(javax.management.ObjectName)

Example 12 with Service

use of org.opennms.netmgt.config.service.Service in project opennms by OpenNMS.

the class Starter method start.

private void start() {
    LOG.debug("Beginning startup");
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    Invoker invoker = new Invoker();
    invoker.setServer(server);
    invoker.setAtType(InvokeAtType.START);
    List<InvokerService> services = InvokerService.createServiceList(new ServiceConfigFactory().getServices());
    invoker.setServices(services);
    invoker.instantiateClasses();
    List<InvokerResult> resultInfo = invoker.invokeMethods();
    for (InvokerResult result : resultInfo) {
        if (result != null && result.getThrowable() != null) {
            Service service = result.getService();
            String name = service.getName();
            String className = service.getClassName();
            String message = "An error occurred while attempting to start the \"" + name + "\" service (class " + className + ").  " + "Shutting down and exiting.";
            LOG.error(message, result.getThrowable());
            System.err.println(message);
            result.getThrowable().printStackTrace();
            Manager manager = new Manager();
            manager.stop();
            manager.doSystemExit();
            // Shouldn't get here
            return;
        }
    }
    LOG.debug("Startup complete");
}
Also used : ServiceConfigFactory(org.opennms.netmgt.config.ServiceConfigFactory) Service(org.opennms.netmgt.config.service.Service) MBeanServer(javax.management.MBeanServer)

Aggregations

Service (org.opennms.netmgt.config.service.Service)12 ServiceConfiguration (org.opennms.netmgt.config.service.ServiceConfiguration)5 FileWriter (java.io.FileWriter)3 IOException (java.io.IOException)3 StringWriter (java.io.StringWriter)3 ArrayList (java.util.ArrayList)3 ObjectName (javax.management.ObjectName)3 ServiceConfigFactory (org.opennms.netmgt.config.ServiceConfigFactory)3 OnmsUpgradeException (org.opennms.upgrade.api.OnmsUpgradeException)3 File (java.io.File)2 MBeanServer (javax.management.MBeanServer)2 Test (org.junit.Test)2 Invoke (org.opennms.netmgt.config.service.Invoke)2 StringReader (java.io.StringReader)1 Attribute (javax.management.Attribute)1 ObjectInstance (javax.management.ObjectInstance)1 CommandLine (org.apache.commons.cli.CommandLine)1 CommandLineParser (org.apache.commons.cli.CommandLineParser)1 GnuParser (org.apache.commons.cli.GnuParser)1 HelpFormatter (org.apache.commons.cli.HelpFormatter)1