Search in sources :

Example 1 with ProcessInstancePage

use of com.centurylink.mdw.designer.runtime.ProcessInstancePage in project mdw-designer by CenturyLinkCloud.

the class LogWatcher method handleLogMessage.

private synchronized void handleLogMessage(String message) {
    Matcher matcher = pattern.matcher(message);
    if (matcher.matches()) {
        String time = matcher.group(1);
        final Long procId = new Long(matcher.group(2));
        final Long procInstId = new Long(matcher.group(3));
        String subtype = matcher.group(4);
        String id = matcher.group(5);
        String msg = matcher.group(6);
        try {
            ProcessInstanceVO processInstanceInfo = processInstances.get(procInstId);
            if (processInstanceInfo == null) {
                processInstanceInfo = new DesignerDataAccess(dataAccess).getProcessInstanceBase(procInstId, null);
                // only interested in one masterRequestId
                if (processInstanceInfo.getMasterRequestId().equals(masterRequestId))
                    processInstances.put(procInstId, processInstanceInfo);
            }
            if (!processInstanceInfo.getMasterRequestId().equals(masterRequestId))
                return;
            // log the message
            outputStream.println(message);
            if (watchProcess) {
                openInstance(processInstanceInfo);
                synchronized (this) {
                    ProcessInstancePage processInstancePage = processInstancePages.get(processInstanceInfo.getId());
                    accumulated.offer(new ProcessInstanceUpdater(procId, procInstId, processInstancePage, subtype, time, id, msg));
                }
            }
            if (msg.startsWith(WorkStatus.LOGMSG_PROC_COMPLETE) && procId.equals(process.getId()))
                scheduleShutdown = true;
        } catch (Exception ex) {
            PluginMessages.log(ex);
            shutdown();
        }
    }
}
Also used : Matcher(java.util.regex.Matcher) ProcessInstancePage(com.centurylink.mdw.designer.runtime.ProcessInstancePage) DesignerDataAccess(com.centurylink.mdw.designer.DesignerDataAccess) ProcessInstanceVO(com.centurylink.mdw.model.value.process.ProcessInstanceVO) IOException(java.io.IOException)

Example 2 with ProcessInstancePage

use of com.centurylink.mdw.designer.runtime.ProcessInstancePage in project mdw-designer by CenturyLinkCloud.

the class LogWatcher method startup.

public void startup(boolean watchProcess) {
    this.watchProcess = watchProcess;
    if (logListener != null)
        // already started
        return;
    pattern = Pattern.compile(MESSAGE_REG_EX, Pattern.DOTALL);
    processInstancePages = new HashMap<Long, ProcessInstancePage>();
    processInstances = new HashMap<Long, ProcessInstanceVO>();
    accumulated = new LinkedList<ProcessInstanceUpdater>();
    scheduleShutdown = false;
    MessageConsole console = MessageConsole.findConsole("Live View Log", icon, display);
    console.setRunnableEntity(this);
    console.setDefaultShowPref(true);
    console.setStatus(MessageConsole.STATUS_RUNNING);
    console.clearConsole();
    outputStream = console.newMessageStream();
    try {
        dataAccess = new DesignerDataAccess(process.getProject().getDesignerProxy().getDesignerDataAccess());
        logListener = new LogSubscriberSocket(dataAccess, serverSettings.getLogWatcherPort(), process.getProject().isOldNamespaces()) {

            protected void handleMessage(String message) {
                handleLogMessage(message);
            }
        };
        logListener.start(true);
        new Thread(new Runnable() {

            public void run() {
                processQueue();
            }
        }).start();
    } catch (Exception ex) {
        if (outputStream != null)
            ex.printStackTrace(new PrintStream(outputStream));
        if (logListener != null && !logListener.isClosed()) {
            logListener.shutdown();
            logListener = null;
        }
        PluginMessages.uiError(ex, "Monitor Logs", process.getProject());
    }
}
Also used : PrintStream(java.io.PrintStream) MessageConsole(com.centurylink.mdw.plugin.MessageConsole) IOException(java.io.IOException) LogSubscriberSocket(com.centurylink.mdw.designer.runtime.LogSubscriberSocket) ProcessInstancePage(com.centurylink.mdw.designer.runtime.ProcessInstancePage) DesignerDataAccess(com.centurylink.mdw.designer.DesignerDataAccess) ProcessInstanceVO(com.centurylink.mdw.model.value.process.ProcessInstanceVO)

Example 3 with ProcessInstancePage

use of com.centurylink.mdw.designer.runtime.ProcessInstancePage in project mdw-designer by CenturyLinkCloud.

the class LogWatcher method processQueue.

private void processQueue() {
    while (isRunning()) {
        ProcessInstanceUpdater pid = null;
        final ProcessInstancePage pip;
        // boolean isEmbedded = false;
        synchronized (this) {
            pid = accumulated.peek();
            // isEmbedded = pid == null ? false :
            // isEmbeddedProcess(processInstanceInfos.get(pid.getProcessInstanceId()));
            pip = pid == null ? null : processInstancePages.get(pid.getProcessInstanceId());
            if (pid != null) {
                if (pip != null)
                    accumulated.remove();
            }
        }
        if (pid != null && pip != null) {
            pid.setProcessInstancePage(pip);
            pid.handleMessage();
            if (scheduleShutdown && accumulated.isEmpty())
                shutdown();
            EventQueue.invokeLater(new Runnable() {

                public void run() {
                    pip.canvas.repaint();
                }
            });
        }
        try {
            Thread.sleep(250);
        } catch (InterruptedException ex) {
        }
    }
    refresh();
}
Also used : ProcessInstancePage(com.centurylink.mdw.designer.runtime.ProcessInstancePage)

Example 4 with ProcessInstancePage

use of com.centurylink.mdw.designer.runtime.ProcessInstancePage in project mdw-designer by CenturyLinkCloud.

the class LogWatcher method openInstance.

private synchronized void openInstance(final ProcessInstanceVO processInstanceInfo) {
    final WorkflowProcess newProcess = new WorkflowProcess(process);
    if (!processInstanceInfo.getProcessId().equals(process.getId())) {
        // must be a subprocess
        ProcessVO subprocVO = new ProcessVO();
        subprocVO.setProcessId(processInstanceInfo.getProcessId());
        subprocVO.setProcessName(processInstanceInfo.getProcessName());
        newProcess.setProcessVO(subprocVO);
    }
    final boolean isEmbedded = isEmbeddedProcess(processInstanceInfo);
    final ProcessInstanceVO pageInfo = isEmbedded ? processInstances.get(processInstanceInfo.getOwnerId()) : processInstanceInfo;
    newProcess.setProcessInstance(pageInfo);
    display.syncExec(new Runnable() {

        public void run() {
            ProcessInstancePage procInstPage = null;
            try {
                IWorkbenchPage page = MdwPlugin.getActivePage();
                ProcessEditor editor = null;
                if (processInstancePages.get(pageInfo.getId()) == null) {
                    newProcess.setDesignerDataAccess(dataAccess);
                    editor = (ProcessEditor) page.openEditor(newProcess, "mdw.editors.process");
                    procInstPage = editor.getProcessCanvasWrapper().getProcessInstancePage();
                    if (procInstPage != null) {
                        processInstancePages.put(pageInfo.getId(), procInstPage);
                    }
                } else if (isEmbedded && processInstancePages.get(processInstanceInfo.getId()) == null) {
                    newProcess.getProject().getDesignerProxy().loadProcessInstance(newProcess, processInstancePages.get(pageInfo.getId()));
                    processInstancePages.put(processInstanceInfo.getId(), processInstancePages.get(pageInfo.getId()));
                } else {
                    editor = (ProcessEditor) page.findEditor(newProcess);
                    if (editor != null)
                        page.activate(editor);
                }
            } catch (Exception ex) {
                PluginMessages.log(ex);
                processInstancePages.remove(processInstanceInfo.getId());
            }
        }
    });
}
Also used : ProcessInstancePage(com.centurylink.mdw.designer.runtime.ProcessInstancePage) ProcessVO(com.centurylink.mdw.model.value.process.ProcessVO) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) WorkflowProcess(com.centurylink.mdw.plugin.designer.model.WorkflowProcess) ProcessInstanceVO(com.centurylink.mdw.model.value.process.ProcessInstanceVO) ProcessEditor(com.centurylink.mdw.plugin.designer.editors.ProcessEditor) IOException(java.io.IOException)

Aggregations

ProcessInstancePage (com.centurylink.mdw.designer.runtime.ProcessInstancePage)4 ProcessInstanceVO (com.centurylink.mdw.model.value.process.ProcessInstanceVO)3 IOException (java.io.IOException)3 DesignerDataAccess (com.centurylink.mdw.designer.DesignerDataAccess)2 LogSubscriberSocket (com.centurylink.mdw.designer.runtime.LogSubscriberSocket)1 ProcessVO (com.centurylink.mdw.model.value.process.ProcessVO)1 MessageConsole (com.centurylink.mdw.plugin.MessageConsole)1 ProcessEditor (com.centurylink.mdw.plugin.designer.editors.ProcessEditor)1 WorkflowProcess (com.centurylink.mdw.plugin.designer.model.WorkflowProcess)1 PrintStream (java.io.PrintStream)1 Matcher (java.util.regex.Matcher)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1