⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 threadedtoolagentmanager.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                        throw new BaseException(e);                    }                    AppParameter[] params = null;                    try {                        params = makeParameters(trans, tool, app);                    } catch (Exception e) {                        throw new BaseException(e);                    }                    ToolContext ctx = new ToolContext(tool, app, appMap, packageKey, processKey, activityKey, resource, params);                    toolList.add(ctx);                }            }            return toolList;        }        private AppParameter[] makeParameters(SharkTransaction transaction, Tool tool, Application app) throws Exception {            // build up the parameters            List parameters = new ArrayList();            // the extended attributes are always the first parameter passed to tool agent            String appPStr = app.getExtendedAttributesString();            AppParameter param = new AppParameter("ExtendedAttributes", "ExtendedAttributes", AppParameter.MODE_IN, appPStr, String.class);            parameters.add(param);            ActualParameters aps = (ActualParameters) tool.get("ActualParameters");            FormalParameters fps = (FormalParameters) ((XMLComplexChoice) app.get("Choice")).getChoosen();            Map ctxMap = SharkUtilities.createContextMap(transaction, context, aps, fps, packageKey, packageVer);            Iterator itFps = fps.toCollection().iterator();            Iterator itAps = aps.toCollection().iterator();            while (itFps.hasNext() && itAps.hasNext()) {                FormalParameter fp = (FormalParameter) itFps.next();                ActualParameter ap = (ActualParameter) itAps.next();                String fpMode = fp.get("Mode").toValue().toString();                String fpId = fp.getID();                Object paramVal = ctxMap.get(fpId);                // JAWE's CLASSES DataField and FormalParameter RETURNS ITs                // Id ATTRIBUTE WHEN METHOD toString() is CALLED (when calling                // ap.toValue().toString(), it can be called toString() method of                // these two classes)                param = new AppParameter(ap.toValue().toString(), fpId, fpMode, paramVal, SharkUtilities.getJavaClass(fp));                parameters.add(param);            }            return (AppParameter[]) parameters.toArray(new AppParameter[parameters.size()]);        }        private ApplicationMap getApplicationMap(Application app, String applicationId) throws Exception {            // find mapped procedure - but we can also live without mapping            // manager (but we can't without ToolAgentFactory            ApplicationMappingManager mm = SharkEngineManager.getInstance().getApplicationMapPersistenceManager();            ApplicationMap tad = null;            if (mm != null) {                XMLComplexElement cOwn = app.getCollection().getOwner();                boolean isProcessApp = (cOwn instanceof WorkflowProcess);                ApplicationMappingTransaction t = null;                try {                    t = SharkUtilities.createApplicationMappingTransaction();                    tad = SharkEngineManager.getInstance().getApplicationMapPersistenceManager().                            getApplicationMap(t, app.getPackage().get("Id").toString(),                                    ((isProcessApp) ? cOwn.get("Id").toString() : null), applicationId);                } catch (RootException e) {                    throw e;                } finally {                    SharkUtilities.releaseMappingTransaction(t);                }            }            return tad;        }        public void run() {            this.isRunning = true;            // start the tools            Iterator ti = tools.iterator();            while (ti.hasNext()) {                ToolContext tool = (ToolContext) ti.next();                runners.add(new ToolRunner(tool));            }            // monitor the tools            while (isRunning) {                // check tool status                Iterator ri = runners.iterator();                while (ri.hasNext()) {                    ToolRunner runner = (ToolRunner) ri.next();                    if (!runner.isRunning()) {                        // check for errors                        Throwable toolError = runner.getError();                        if (toolError != null) {                            // handle tool error                        } else {                            // get the results                            Map thisResult = runner.getResults();                            if (thisResult != null) {                                toolResults.putAll(thisResult);                            }                        }                        // remove the runner from the waiting list                        ri.remove();                    }                }                // sleep for a while then run again                try {                    Thread.sleep(5000);                } catch (InterruptedException e) {                }            }            // all tools finished - need a transaction and internal activity object            SharkTransaction trans = null;            WfActivityInternal act = null;            try {                trans = SharkUtilities.createTransaction();                act = SharkUtilities.getActivity(trans, processKey, activityKey);                act.set_process_context(trans, toolResults);                act.finish(trans);            } catch (TransactionException e) {                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.            } catch (BaseException e) {                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.            } catch (UpdateNotAllowed e) {                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.            } catch (InvalidData e) {                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.            } catch (CannotComplete e) {                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.            }            // clear out the reference in parent class            ThreadedToolAgentManager.removeToolMonitor(this);        }        class ToolRunner implements Runnable {            private Thread thread;            private ToolContext tool;            private boolean isRunning = false;            private Throwable error = null;            private Map results = null;            ToolRunner(ToolContext tool) {                this.tool = tool;                // run the tool                thread = new Thread(this);                thread.setDaemon(false);                thread.setName(this.getClass().getName());                thread.start();            }            public void run() {                this.isRunning = true;                try {                    this.results = this.runTool(null);                } catch (Exception e) {                    this.error = e;                }                this.isRunning = false;            }            public boolean isRunning() {                return this.isRunning;            }            public Throwable getError() {                return this.error;            }            public Map getResults() {                return this.results;            }            private Map runTool(SharkTransaction transaction) throws Exception {                // get the application to run                ApplicationMap tad = tool.getApplicationMap();                // connect to the tool                String tacn = (tad != null) ? tad.getToolAgentClassName() : defaultToolAgentClassName;                String uname = (tad != null) ? tad.getUsername() : "";                String pwd = (tad != null) ? tad.getPassword() : "";                String appN = (tad != null) ? tad.getApplicationName() : "";                Integer appM = (tad != null) ? tad.getApplicationMode() : null;                ToolAgent ta = SharkEngineManager.getInstance().getToolAgentFactory().createToolAgent(transaction, tacn);                SessionHandle shandle = null;                // try to connect to the tool agent                try {                    shandle = ta.connect(transaction, uname, pwd, cus.getProperty("enginename", "imaobihostrezube"), "");                } catch (ConnectFailed cf) {                    cus.error("Activity[" + tool.getActivityId() + "] - connection to Tool agent " + tacn + " failed !");                    throw cf;                }                String assId = SharkUtilities.createAssignmentKey(tool.getActivityId(), resource);                // invoke the application                ta.invokeApplication(transaction, shandle.getHandle(), appN, tool.getProcessId(), assId, tool.getParameters(), appM);                // check the status                long appStatus = ta.requestAppStatus(transaction, shandle.getHandle(), tool.getProcessId(), assId, tool.getParameters());                if (appStatus == APP_STATUS_INVALID) {                    ta.disconnect(transaction, shandle);                    throw new Exception();                }                ta.disconnect(transaction, shandle);                // return the result parameters                AppParameter[] returnValues = tool.getParameters();                Map newData = new HashMap();                for (int i = 0; i < returnValues.length; i++) {                    if (returnValues[i].the_mode.equals(AppParameter.MODE_OUT) ||                            returnValues[i].the_mode.equals(AppParameter.MODE_INOUT)) {                        String name = returnValues[i].the_actual_name;                        Object value = returnValues[i].the_value;                        newData.put(name, value);                    }                }                return newData;            }        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -