📄 stafdemocontroller.java
字号:
{ case 0: fMachineNickname = (String)varInfo.get( "result"); case 1: sepPath = (String)varInfo.get("result"); case 2: sepFile = (String)varInfo.get("result"); case 3: { String osName = (String)varInfo.get("result"); if (osName.startsWith("Win")) { targetJavacmd = "javaw"; jstafDir = "bin"; } else { targetJavacmd = "java"; jstafDir = "lib"; } } default: break; } } stafResult = handle.submit2( machineName, "FS", "QUERY ENTRY {STAF/Config/STAFRoot}/samples/demo/" + "STAFDemo.jar"); if (stafResult.rc == STAFResult.DoesNotExist) { // copy the STAFDemo.jar file stafResult = handle.submit2( "local", "FS", "COPY FILE {STAF/Config/STAFRoot}/samples/demo/" + "STAFDemo.jar TOMACHINE " + machineName); if (stafResult.rc != 0) { System.out.println("Copy file RC: " + stafResult.rc + " Result: " + stafResult.result); } } String stafDemoJarFile = "{STAF/Config/STAFRoot}" + sepFile + "samples" + sepFile + "demo" + sepFile + "STAFDemo.jar"; String jStafJarFile = "{STAF/Config/STAFRoot}" + sepFile + jstafDir + sepFile + "JSTAF.jar"; targetClasspath = "{STAF/Env/CLASSPATH}" + sepPath + stafDemoJarFile + sepPath + jStafJarFile; stafResult = handle.submit2( machineName, "PROCESS", "START COMMAND " + targetJavacmd + " " + "PARMS STAFProcess " + "VAR STAFDemo/ResourcePoolMachine=" + stafMachineName + " VAR STAF/Service/Log/Mask=Error" + " ENV CLASSPATH=" + targetClasspath + " NOTIFY ONEND"); if (stafResult.rc != 0) { String errMsg = "Error starting process. RC:" + stafResult.rc + " Result:" + stafResult.result; if (stafResult.rc == STAFResult.AccessDenied) { errMsg += "\nThis error code indicates that " + "machine " + machineName + " has not given" + " this machine a TRUST level of 5"; } else if (stafResult.rc == STAFResult.NoPathToMachine) { errMsg += "\nThis error code indicates that this" + " machine could not communication with " + "machine " + machineName; } JOptionPane.showMessageDialog(stafStartPanel, errMsg, "Error starting process", JOptionPane.ERROR_MESSAGE); return; } String theHandle = stafResult.result; stafResult = handle.submit2( machineName, "LOG", "DELETE MACHINE " + fMachineNickname + " HANDLE " + theHandle + " LOGNAME STAFDemo CONFIRM"); stafResult = handle.submit2( machineName, "SEM", "POST EVENT STAFDemo/Handle/" + theHandle + "/Continue"); STAFProcessFrame frame = new STAFProcessFrame(machineName, fMachineNickname, theHandle); frame.setSize(425, 270); frame.show(); } }); fConnect.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { STAFProcessFrame frame = new STAFProcessFrame(fMachine.getText(), fMachineNickname, fHandle.getText()); frame.setSize(425, 270); frame.show(); } }); fAddResource.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { STAFResult stafResult = handle.submit2( "local", "RESPOOL", "ADD POOL STAFDemo ENTRY Resource" + String.valueOf(STAFDemoController.numResources + 1)); if (stafResult.rc != 0) System.out.println("Error adding resource RC: " + stafResult.rc + " Result: " + stafResult.result); fNumResourcesLabel.setText( String.valueOf(++STAFDemoController.numResources)); } }); fDeleteResource.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { STAFResult stafResult = handle.submit2( "local", "RESPOOL", "REMOVE POOL STAFDemo " + "ENTRY Resource" + String.valueOf(STAFDemoController.numResources) + " CONFIRM FORCE"); if (stafResult.rc != 0) System.out.println("Error removing resource RC: " + stafResult.rc + " Result: " + stafResult.result); fNumResourcesLabel.setText( String.valueOf(--STAFDemoController.numResources)); } }); } } public class STAFProcessFrame extends JFrame { public STAFProcessFrame(String machine, String machineNickname, String handle) { super("Machine: " + machine + " Handle: " + handle); getContentPane().add(new STAFProcessPanel(this, machine, machineNickname, handle)); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent event) { dispose(); } }); } } public class STAFProcessPanel extends JPanel { String fMachine; String fHandle; String fMachineNickname; JButton fStop = new JButton("Stop"); JButton fPause = new JButton("Pause"); JButton fContinue = new JButton("Continue"); JTextField fMonitorRefreshRate = new JTextField(25); JLabel fMonitorDate = new JLabel("Unknown"); JLabel fMonitorStatus = new JLabel("Unknown"); JButton fSetBackground = new JButton("Set"); JComboBox fColorList = new JComboBox(); MonitorThread fMonitorThread; STAFProcessFrame fProcessFrame; JCheckBox fErrorLog = new JCheckBox("Error"); JLabel fErrorCount = new JLabel("0"); JCheckBox fWarningLog = new JCheckBox("Warning"); JLabel fWarningCount = new JLabel("0"); JCheckBox fInfoLog = new JCheckBox("Info"); JLabel fInfoCount = new JLabel("0"); JCheckBox fDebugLog = new JCheckBox("Debug"); JLabel fDebugCount = new JLabel("0"); JList fLogList = new JList(); JButton fSetLogMask = new JButton("Set Log Mask"); JButton fRefreshLog = new JButton("Refresh Totals"); JButton fClearLog = new JButton("Clear Log"); JButton fDisplayLog = new JButton("Display Log"); public STAFProcessPanel(STAFProcessFrame frame, String machine, String machineNickname, String handle) { fProcessFrame = frame; fMachine = machine; fMachineNickname = machineNickname; fHandle = handle; // Setup display GridBagLayout gbl = new GridBagLayout(); GridBagConstraints gbc = new GridBagConstraints(); setLayout(gbl); gbc.anchor = GridBagConstraints.WEST; // gbc.fill = GridBagConstraints.HORIZONTAL; gbc.fill = GridBagConstraints.BOTH; gbc.gridwidth = 1; gbc.gridx = 1; gbc.gridy = 1; // Setup Process/Semaphore panel JPanel processSemPanel = new JPanel(); processSemPanel.setBorder(new TitledBorder("Queue / Semaphore")); processSemPanel.add(fStop); processSemPanel.add(fPause); processSemPanel.add(fContinue); add(processSemPanel, gbc); // Setup variable panel JPanel varPanel = new JPanel(); varPanel.setBorder(new TitledBorder("Variable")); varPanel.add(fSetBackground); varPanel.add(new JLabel("background color to")); fColorList.addItem("Blue"); fColorList.addItem("Green"); fColorList.addItem("Red"); fColorList.addItem("Yellow"); varPanel.add(fColorList); // gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.gridy = 2; add(varPanel, gbc); // Setup monitor panel JPanel monPanel = new JPanel(); monPanel.setLayout(new GridBagLayout()); GridBagConstraints monGBC = new GridBagConstraints(); monGBC.anchor = GridBagConstraints.WEST; monGBC.fill = GridBagConstraints.HORIZONTAL; monGBC.gridwidth = 1; monPanel.setBorder(new TitledBorder("Monitor")); monGBC.fill = GridBagConstraints.NONE; monGBC.gridwidth = 3; monPanel.add(new JLabel("Refresh rate (sec.):"), monGBC); monPanel.add(Box.createHorizontalStrut(5)); monGBC.fill = GridBagConstraints.HORIZONTAL; monGBC.gridwidth = 1; fMonitorRefreshRate.setColumns(3); fMonitorRefreshRate.setText("2"); monPanel.add(fMonitorRefreshRate, monGBC); monPanel.add(Box.createGlue(), monGBC); monGBC.gridwidth = GridBagConstraints.REMAINDER; monPanel.add(Box.createHorizontalStrut(80), monGBC); monGBC.gridwidth = 1; monGBC.fill = GridBagConstraints.NONE; monPanel.add(new JLabel("Timestamp:"), monGBC); monGBC.fill = GridBagConstraints.HORIZONTAL; monPanel.add(Box.createHorizontalStrut(5)); monGBC.gridwidth = GridBagConstraints.REMAINDER;; monPanel.add(fMonitorDate, monGBC); monGBC.gridwidth = 1; monGBC.fill = GridBagConstraints.NONE; monPanel.add(new JLabel("Status:"), monGBC); monGBC.fill = GridBagConstraints.HORIZONTAL; monPanel.add(Box.createHorizontalStrut(5)); monGBC.gridwidth = GridBagConstraints.REMAINDER;; monPanel.add(fMonitorStatus, monGBC); gbc.gridy = 3; add(monPanel, gbc); // Setup log panel JPanel logPanel = new JPanel(); logPanel.setLayout(new GridBagLayout()); GridBagConstraints logGBC = new GridBagConstraints(); logGBC.anchor = GridBagConstraints.WEST; logGBC.fill = GridBagConstraints.HORIZONTAL; logGBC.gridwidth = 1; logPanel.setBorder(new TitledBorder("Log / Variable")); fErrorLog.setSelected(true); logPanel.add(fErrorLog, logGBC); logGBC.gridwidth = GridBagConstraints.REMAINDER; logPanel.add(fErrorCount, logGBC); logGBC.gridwidth = 1; logPanel.add(fWarningLog, logGBC); logGBC.gridwidth = GridBagConstraints.REMAINDER; logPanel.add(fWarningCount, logGBC); logGBC.gridwidth = 1; logPanel.add(fInfoLog, logGBC); logGBC.gridwidth = GridBagConstraints.REMAINDER; logPanel.add(fInfoCount, logGBC); logGBC.gridwidth = 1; logPanel.add(fDebugLog, logGBC); logGBC.gridwidth = GridBagConstraints.REMAINDER; logPanel.add(fDebugCount, logGBC); logPanel.add(fSetLogMask, logGBC); logPanel.add(fRefreshLog, logGBC); logPanel.add(fClearLog, logGBC); logPanel.add(fDisplayLog, logGBC); // gbc.fill = GridBagConstraints.BOTH; gbc.gridx = 2; gbc.gridy = 1; gbc.gridheight = 3; add(logPanel, gbc); // Add button commands fStop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { STAFResult stafResult = STAFDemoController.handle.submit2( fMachine, "QUEUE", "QUEUE HANDLE " + fHandle + " TYPE STAF/STAFDemo/Stop MESSAGE " + STAFUtil.wrapData("")); if (stafResult.rc != 0) System.out.println("Error queueing message RC: " + stafResult.rc + " Result: " + stafResult.result); } }); fPause.addActionListener(new ActionListener() {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -