private void startProcess(Target target, Parameters configuration, Pair<Target, Parameters> key) { ProgramRunner runner = new DefaultProgramRunner() { @NotNull public String getRunnerId() { return "MyRunner"; } public boolean canRun(@NotNull String executorId, @NotNull RunProfile profile) { return true; } }; Executor executor = DefaultRunExecutor.getRunExecutorInstance(); ProcessHandler processHandler = null; try { RunProfileState state = getRunProfileState(target, configuration, executor); ExecutionResult result = state.execute(executor, runner); //noinspection ConstantConditions processHandler = result.getProcessHandler(); } catch (Exception e) { dropProcessInfo(key, ExceptionUtil.getUserStackTrace(e, LOG), processHandler); return; } processHandler.addProcessListener(getProcessListener(key)); processHandler.startNotify(); }
@SuppressWarnings("unchecked") protected void handleForEachNode( final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException { super.handleNode(node, element, uri, localName, parser); ForEachNode forEachNode = (ForEachNode) node; org.w3c.dom.Node xmlNode = element.getFirstChild(); while (xmlNode != null) { String nodeName = xmlNode.getNodeName(); if ("ioSpecification".equals(nodeName)) { readIoSpecification(xmlNode, dataInputs, dataOutputs); } else if ("dataInputAssociation".equals(nodeName)) { readDataInputAssociation(xmlNode, forEachNode); } else if ("multiInstanceLoopCharacteristics".equals(nodeName)) { readMultiInstanceLoopCharacteristics(xmlNode, forEachNode, parser); } xmlNode = xmlNode.getNextSibling(); } List<SequenceFlow> connections = (List<SequenceFlow>) forEachNode.getMetaData(ProcessHandler.CONNECTIONS); ProcessHandler.linkConnections(forEachNode, connections); ProcessHandler.linkBoundaryEvents(forEachNode); }
private void initConsoleUI(Process process) { // Init console view myConsoleView = createConsoleView(); myConsoleView.setBorder(new SideBorder(UIUtil.getBorderColor(), SideBorder.LEFT)); myProcessHandler = createProcessHandler(process, myProvider.getCommandLineString()); myConsoleExecuteActionHandler = createConsoleExecuteActionHandler(); ProcessTerminatedListener.attach(myProcessHandler); myProcessHandler.addProcessListener( new ProcessAdapter() { @Override public void processTerminated(ProcessEvent event) { finishConsole(); } }); // Attach to process myConsoleView.attachToProcess(myProcessHandler); // Runner creating final Executor defaultExecutor = ExecutorRegistry.getInstance().getExecutorById(DefaultRunExecutor.EXECUTOR_ID); final DefaultActionGroup toolbarActions = new DefaultActionGroup(); final ActionToolbar actionToolbar = ActionManager.getInstance() .createActionToolbar(ActionPlaces.UNKNOWN, toolbarActions, false); // Runner creating final JPanel panel = new JPanel(new BorderLayout()); panel.add(actionToolbar.getComponent(), BorderLayout.WEST); panel.add(myConsoleView.getComponent(), BorderLayout.CENTER); actionToolbar.setTargetComponent(panel); final RunContentDescriptor contentDescriptor = new RunContentDescriptor( myConsoleView, myProcessHandler, panel, constructConsoleTitle(myConsoleTitle)); // tool bar actions final List<AnAction> actions = fillToolBarActions(toolbarActions, defaultExecutor, contentDescriptor); registerActionShortcuts(actions, getLanguageConsole().getConsoleEditor().getComponent()); registerActionShortcuts(actions, panel); panel.updateUI(); showConsole(defaultExecutor, contentDescriptor); // Run myProcessHandler.startNotify(); }
public void release(@NotNull Target target, @Nullable Parameters configuration) { ArrayList<ProcessHandler> handlers = new ArrayList<ProcessHandler>(); synchronized (myProcMap) { for (Pair<Target, Parameters> pair : myProcMap.keySet()) { if (pair.first == target && (configuration == null || pair.second == configuration)) { ContainerUtil.addIfNotNull(myProcMap.get(pair).handler, handlers); } } } for (ProcessHandler handler : handlers) { handler.destroyProcess(); } fireModificationCountChanged(); }
public void stopAll(boolean wait) { ArrayList<ProcessHandler> allHandlers = new ArrayList<ProcessHandler>(); synchronized (myProcMap) { for (Info o : myProcMap.values()) { ContainerUtil.addIfNotNull(o.handler, allHandlers); } } for (ProcessHandler handler : allHandlers) { handler.destroyProcess(); } if (wait) { for (ProcessHandler handler : allHandlers) { handler.waitFor(); } } }
@Override public void receiveStdout(char ch) { try { processHandler.write(ch); } catch (IOException exc) { handleError(exc); } }
public void update(final AnActionEvent e) { final EditorEx editor = myLanguageConsole.getConsoleEditor(); final Lookup lookup = LookupManager.getActiveLookup(editor); e.getPresentation() .setEnabled( !editor.isRendererMode() && !myProcessHandler.isProcessTerminated() && (lookup == null || !(lookup.isCompletion() && lookup.isFocused()))); }
@SuppressWarnings("unchecked") protected void handleCompositeContextNode( final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException { super.handleNode(node, element, uri, localName, parser); CompositeContextNode compositeNode = (CompositeContextNode) node; List<SequenceFlow> connections = (List<SequenceFlow>) compositeNode.getMetaData(ProcessHandler.CONNECTIONS); ProcessHandler.linkConnections(compositeNode, connections); List<IntermediateLink> throwLinks = (List<IntermediateLink>) compositeNode.getMetaData(ProcessHandler.LINKS); ProcessHandler.linkIntermediateLinks(compositeNode, throwLinks); ProcessHandler.linkBoundaryEvents(compositeNode); }
protected void assertOutput(String className, String expected, final Module module) throws ExecutionException { final StringBuffer sb = new StringBuffer(); ProcessHandler process = runProcess( className, module, DefaultRunExecutor.class, new ProcessAdapter() { @Override public void onTextAvailable(ProcessEvent event, Key outputType) { if (ProcessOutputTypes.SYSTEM != outputType) { sb.append(event.getText()); } } }, ProgramRunner.PROGRAM_RUNNER_EP.findExtension(DefaultJavaProgramRunner.class)); process.waitFor(); assertEquals(expected.trim(), StringUtil.convertLineSeparators(sb.toString().trim())); }
/** * See lego ev3 firmware developer kit, Folder structure within firmware, page 102; * * <p>See lego ev3 communication developer kit, Downloading data to the EV3 programmable brick, * page 7; * * @param data byte[] body of local file * @param outputFileName brick full filename e.g. "../prjs/SD_Card/test/1.jpg" * @param timeout between each iteration of transmission, msec * @param part portion of bytes in each iteration of transmission. default 10000, must be between * 1 and SystemCommand.MAX_FILE_CHUNK * @param sh sh is handler which counts progress in transmission, may be null * @throws IOException */ public void sendFile(byte[] data, String outputFileName, int timeout, int part, ProcessHandler sh) throws IOException { int fileSize = data.length; if (sh != null) { sh.setTotal(fileSize); } int chunk = 10000; // SystemCommand.MAX_FILE_CHUNK if (part > 0 && part <= SystemCommand.MAX_FILE_CHUNK) { chunk = part; } SystemFormatter sf = new SystemFormatter(SystemCommand.Command.BEGIN_DOWNLOAD, SystemCommand.REPLY); sf.addSize(fileSize); sf.addString(outputFileName); byte[] bytecode = sf.toByteArray(); connector.write(bytecode, timeout); bytecode = connector.read(0, 0); if (bytecode[6] != SystemCommand.SUCCESS) { throw new IOException("Could not begin file save: " + bytecode[6]); } byte handler = bytecode[7]; int sizeSent = 0; while (sizeSent < data.length) { sf = new SystemFormatter(SystemCommand.Command.CONTINUE_DOWNLOAD, SystemCommand.REPLY); sf.addByteCode(handler); int sizeToSend = Math.min(chunk, data.length - sizeSent); sf.addBytes(data, sizeSent, sizeToSend); bytecode = sf.toByteArray(); connector.write(bytecode, timeout); bytecode = connector.read(0, 0); handler = bytecode[7]; sizeSent += sizeToSend; if (sh != null) { sh.setCurrent(sizeSent); } if (bytecode[6] != SystemCommand.SUCCESS && bytecode[6] != SystemCommand.END_OF_FILE) { throw new IOException("Error saving file: " + bytecode[6]); } } }
private String constructConsoleTitle(final @NotNull String consoleTitle) { if (shouldAddNumberToTitle()) { List<RunContentDescriptor> consoles = ExecutionHelper.collectConsolesByDisplayName( myProject, new NotNullFunction<String, Boolean>() { @NotNull @Override public Boolean fun(String dom) { return dom.contains(consoleTitle); } }); int max = 0; for (RunContentDescriptor dsc : consoles) { ProcessHandler handler = dsc.getProcessHandler(); if (handler != null && !handler.isProcessTerminated()) { if (max == 0) { max = 1; } try { int num = Integer.parseInt( dsc.getDisplayName() .substring(consoleTitle.length() + 1, dsc.getDisplayName().length() - 1)); if (num > max) { max = num; } } catch (Exception e) { // skip } } } if (max >= 1) { return consoleTitle + "(" + (max + 1) + ")"; } } return consoleTitle; }
@Override public synchronized void process(ApduType apdu) { if (apdu.isPrstSelected()) { process.processPrstApdu(apdu.getPrst()); } else if (apdu.isRlrqSelected()) { state_handler.send(MessageFactory.RlreApdu_NORMAL()); state_handler.changeState(new MUnassociated(state_handler)); } else if (apdu.isAarqSelected() || apdu.isAareSelected() || apdu.isRlreSelected()) { state_handler.send(MessageFactory.AbrtApdu_UNDEFINED()); state_handler.changeState(new MUnassociated(state_handler)); } else if (apdu.isAbrtSelected()) { state_handler.changeState(new MUnassociated(state_handler)); } }
@Override public void startNotify() { addProcessListener( new ProcessAdapter() { @Override public void startNotified(ProcessEvent event) { try { myWaitFor.setTerminationCallback( new Consumer<Integer>() { @Override public void consume(Integer integer) { notifyProcessTerminated(integer); } }); } finally { removeProcessListener(this); } } }); super.startNotify(); }
@Override public void signalTerminated(int code) { processHandler.close(); }