📄 monitor.java
字号:
package name.lxm.robot.arch.module;import name.lxm.robot.arch.*;import java.io.*;public class Monitor implements Module, Runnable{ private ModuleDoc m_conf = null; private String module_name = "monitor"; private SimpleInPort port = null; private static String DATA_PORT_NAME = "data"; private Thread t_this = null; private boolean bRun = false; private String lf = null; public String getName() { return module_name; } public Port getPort(String name) { if(DATA_PORT_NAME.equals(name)) { return port; } return null; } public ModuleDoc getModuleDoc() { return m_conf; } public int getLayer() { return m_conf.getLayer(); } public Monitor() { } public void init(ModuleDoc conf) { m_conf = conf; module_name = conf.getName(); port = new SimpleInPort(this, DATA_PORT_NAME); lf = conf.getParamValue("logfile"); } public void start() { bRun = true; t_this = new Thread(this); t_this.start(); } public void stop() throws Exception { bRun = false; int c = 0; while(t_this.isAlive()) { try{ Thread.sleep(10); }catch(InterruptedException e) {} if(c > 5) { throw new Exception("Can not Stop this thread: "+ t_this.toString()); } c++; } } public void destroy() { } public void run() { try{ FileWriter fw = new FileWriter(lf); while(bRun) { //check if there's any data in Object o = port.getValue(); //print it to a writer if(o != null) { System.out.println(o.toString()); fw.write(o.toString()+"\n\n"); } else System.out.println("No data has been received."); try{ Thread.sleep(50); }catch(InterruptedException e) {} } fw.close(); }catch(IOException e) { e.printStackTrace(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -