Search in sources :

Example 1 with ProcessHandler

use of org.eclipse.che.plugin.maven.server.execution.ProcessHandler in project che by eclipse.

the class RmiClient method getProcessListener.

private ProcessListener getProcessListener(Pair<Object, Object> key) {
    return new ProcessListener() {

        @Override
        public void onStart(ProcessEvent event) {
            ProcessHandler processHandler = event.getProcessHandler();
            synchronized (infoMap) {
                ProcessInfo info = infoMap.get(key);
                if (info instanceof PendingInfo) {
                    infoMap.put(key, new PendingInfo(processHandler, ((PendingInfo) info).ref));
                }
            }
        }

        @Override
        public void onText(ProcessEvent event, ProcessOutputType outputType) {
            String text = event.getText();
            if (text == null) {
                text = "";
            }
            if (outputType == ProcessOutputType.STDERR) {
                LOG.error(text);
            } else {
                LOG.info(text);
            }
            RunningInfo runningInfo = null;
            PendingInfo pendingInfo = null;
            synchronized (infoMap) {
                ProcessInfo info = infoMap.get(key);
                if (info instanceof PendingInfo) {
                    pendingInfo = (PendingInfo) info;
                    if (outputType == ProcessOutputType.STDOUT) {
                        String prefix = "Port/Name:";
                        if (text.startsWith(prefix)) {
                            String portName = text.substring(prefix.length()).trim();
                            int i = portName.indexOf('/');
                            runningInfo = new RunningInfo(pendingInfo.processHandler, Integer.parseInt(portName.substring(0, i)), portName.substring(i + 1));
                            infoMap.put(key, runningInfo);
                            infoMap.notifyAll();
                        }
                    } else if (outputType == ProcessOutputType.STDERR) {
                        pendingInfo.stderr.append(text);
                    }
                }
            }
            if (runningInfo != null) {
                synchronized (pendingInfo.ref) {
                    pendingInfo.ref.setValue(runningInfo);
                    pendingInfo.ref.notifyAll();
                }
            // todo add ping there
            }
        }

        @Override
        public void onProcessTerminated(ProcessEvent event) {
            removeProcessInfo(key, event.getProcessHandler(), null);
        }

        @Override
        public void onProcessWillTerminate(ProcessEvent event) {
            removeProcessInfo(key, event.getProcessHandler(), null);
        }
    };
}
Also used : ProcessEvent(org.eclipse.che.plugin.maven.server.execution.ProcessEvent) ProcessListener(org.eclipse.che.plugin.maven.server.execution.ProcessListener) ProcessHandler(org.eclipse.che.plugin.maven.server.execution.ProcessHandler) ProcessOutputType(org.eclipse.che.plugin.maven.server.execution.ProcessOutputType)

Example 2 with ProcessHandler

use of org.eclipse.che.plugin.maven.server.execution.ProcessHandler in project che by eclipse.

the class RmiClient method startProcess.

private void startProcess(Pair<Object, Object> key) {
    ProcessHandler handler;
    try {
        ProcessExecutor executor = getExecutor();
        handler = executor.execute();
    } catch (ExecutionException e) {
        removeProcessInfo(key, null, e.getMessage());
        return;
    }
    handler.addProcessListener(getProcessListener(key));
    handler.startNotify();
}
Also used : ProcessHandler(org.eclipse.che.plugin.maven.server.execution.ProcessHandler) ProcessExecutor(org.eclipse.che.plugin.maven.server.execution.ProcessExecutor) ExecutionException(org.eclipse.che.plugin.maven.server.execution.ExecutionException)

Aggregations

ProcessHandler (org.eclipse.che.plugin.maven.server.execution.ProcessHandler)2 ExecutionException (org.eclipse.che.plugin.maven.server.execution.ExecutionException)1 ProcessEvent (org.eclipse.che.plugin.maven.server.execution.ProcessEvent)1 ProcessExecutor (org.eclipse.che.plugin.maven.server.execution.ProcessExecutor)1 ProcessListener (org.eclipse.che.plugin.maven.server.execution.ProcessListener)1 ProcessOutputType (org.eclipse.che.plugin.maven.server.execution.ProcessOutputType)1