Package org.rioproject.exec

Examples of org.rioproject.exec.ExecDescriptor


    public boolean verify() {
        if(context==null) {
            logger.error("Cannot verify with a null ServiceBeanContext");
            return false;
        }
        ExecDescriptor exDesc = context.getServiceElement().getExecDescriptor();
        if(exDesc==null) {
            logger.error("Cannot verify with a null ExecDescriptor");
            return false;
        }       
        String[] declaredArgs = toArray(exDesc.getInputArgs());
        RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
        List<String> jvmArgs = runtime.getInputArguments();
        logger.info("Runtime JVM Args [" + flatten(jvmArgs) + "]");
        for (String arg : declaredArgs) {
            boolean matched = false;
View Full Code Here


            StagedData dAttrs = postInstall.getStagedData();
            if(dAttrs != null) {
                postInstallRecord = doDownload(dAttrs, true);
                path = postInstallRecord.getPath();
            }
            ExecDescriptor execDesc = postInstall.getExecDescriptor();
            if(execDesc != null) {
                if(!execDesc.getCommandLine().startsWith(File.separator))
                    execDesc = Util.extendCommandLine(path, execDesc);
                ServiceExecutor svcExecutor = new ServiceExecutor();
                ProcessManager manager = svcExecutor.exec(execDesc);
                manager.manage();
                //manager.waitFor();
View Full Code Here

        }
        return pid;
    }

    public static void main(String[] args) {
        ExecDescriptor exDesc;
        try {
            if(args.length>0 && args[0].endsWith("config")) {
                Configuration config = ConfigurationProvider.getInstance(args);
                exDesc = (ExecDescriptor) config.getEntry(COMPONENT,
                                                          "descriptor",
                                                          ExecDescriptor.class,
                                                          null);
            } else {
                exDesc = new ExecDescriptor();
                exDesc.setCommandLine("${RIO_HOME}/bin/cybernode");
                exDesc.setWorkingDirectory("${RIO_HOME}/bin");
                exDesc.setStdErrFileName("${RIO_HOME}/logs/cybernode.log");
                exDesc.setStdOutFileName("${RIO_HOME}/logs/cybernode.log");
            }
            final ServiceExecutor svcExecutor = new ServiceExecutor();
            try {
                ProcessManager manager = svcExecutor.exec(exDesc);
                manager.manage();
View Full Code Here

    public ServiceBeanInstance exec(final OperationalStringManager opStringMgr,
                                    final DiscardManager discardManager,
                                    final PlatformCapability[] installedPlatformCapabilities,
                                    final String classPath) throws Exception {
        ExecDescriptor exDesc = new ExecDescriptor();

        String rioHome = System.getProperty("RIO_HOME");
        if(rioHome==null)
            throw new ServiceBeanInstantiationException(String.format("Cannot exec service [%s], unknown RIO_HOME system property",
                                                                      sElem.getName()));
        String classPathToUse;
        if(classPath==null)
            classPathToUse = CommandLineHelper.generateRioStarterClassPath();
        else
            classPathToUse = classPath;

        /* Create a normalized service name, translating " " to "_" and
         * appending the instance ID to the name. This will be used for the
         * log name and the registry bind name */
        String normalizedServiceName = RMIServiceNameHelper.createNormalizedServiceName(sElem);
        String serviceBindName = RMIServiceNameHelper.createBindName(sElem);

        /* Get the Cybernode's RMI Registry */
        int regPort = RegistryUtil.checkRegistry();
        String sPort = Integer.toString(regPort);

        String logDir = getLogDirectory(config, sElem.getOperationalStringName());
        if(!logDir.endsWith(File.separator))
            logDir = logDir+File.separator;
        logger.info("Logging for {} will be sent to {}", sElem.getName(), logDir);

        /* Create command line */
        exDesc.setCommandLine(CommandLineHelper.getJava());

        /* Create input args */
        StringBuilder inputArgsBuilder = new StringBuilder();
        inputArgsBuilder.append(CommandLineHelper.getClassPath(classPathToUse));
        String jvmOptions = (sElem.getExecDescriptor()==null? null: sElem.getExecDescriptor().getInputArgs());
        inputArgsBuilder.append(CommandLineHelper.createInputArgs(normalizedServiceName,
                                                                  serviceBindName,
                                                                  sPort,
                                                                  jvmOptions,
                                                                  logDir));
        inputArgsBuilder.append(CommandLineHelper.getStarterClass()).append(" ");
        String serviceBeanExecStarter = CommandLineHelper.getStarterConfig(rioHome);
        logger.trace("Using service bean exec starter: {}", serviceBeanExecStarter);
        inputArgsBuilder.append(serviceBeanExecStarter);

        exDesc.setInputArgs(inputArgsBuilder.toString());
        exDesc.setWorkingDirectory(System.getProperty("user.dir"));

        /* If we have an exec descriptor, make add any environment settings the
         * service has declared */
        if(sElem.getExecDescriptor()!=null) {
            Map<String, String> env = sElem.getExecDescriptor().getEnvironment();
            for(Map.Entry<String, String> entry : env.entrySet()) {
                env.put(entry.getKey(), PropertyHelper.expandProperties(entry.getValue()));
            }
            exDesc.setEnvironment(env);
        }

        String serviceOut = logDir+normalizedServiceName+".out";
        exDesc.setStdErrFileName(serviceOut);
        exDesc.setStdOutFileName(serviceOut);

        try {
            Registry registry = LocateRegistry.getRegistry(regPort);
            ForkedServiceBeanListener forkedServiceListener = new ForkedServiceBeanListener(discardManager);
            ServiceBeanExecListener listener = forkedServiceListener.getServiceBeanExecListener();
            long start = System.currentTimeMillis();

            Shell shell = ShellFactory.createShell();
            try {
                String shellTemplate = (String)config.getEntry(COMPONENT,
                                                               "serviceBeanExecShellTemplate",
                                                               String.class,
                                                               null);
                if(shellTemplate!=null)
                    shell.setShellTemplate(shellTemplate);
            } catch (ConfigurationException e) {
                logger.warn("Cannot get shell template from configuration, continue with default");
            }
            logger.info("Invoke {}.exec for {}, working directory {}",
                        shell.getClass().getName(), ServiceLogUtil.logName(sElem), exDesc.getWorkingDirectory());
            manager = shell.exec(exDesc);
            forkedServiceListener.setName(serviceBindName);
            forkedServiceListener.setRegistryPort(regPort);

            long wait = 0;
View Full Code Here

TOP

Related Classes of org.rioproject.exec.ExecDescriptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.