abstractmodule.java
来自「j2me实现的移动机器人代码(Java实现)」· Java 代码 · 共 71 行
JAVA
71 行
package name.lxm.robot.arch;
public abstract class AbstractModule implements Runnable, Module, ValueUpdateListener
{
protected String module_name;
protected ModuleDoc doc;
protected Thread t_this;
protected boolean bRun = false;
public String getName()
{
return module_name;
}
public abstract Port getPort(String name);
public ModuleDoc getModuleDoc()
{
return doc;
}
public void init(ModuleDoc cfg) throws Exception
{
doc = cfg;
module_name = doc.getName();
}
public void start() throws Exception
{
t_this = new Thread(this);
bRun = true;
t_this.start();
}
public void stop() throws Exception
{
bRun = false;
int i = 0;
while(t_this.isAlive() && i < 5)
{
t_this.interrupt();
sleep(50);
i++;
}
if(t_this.isAlive())
throw new Exception("Cannot stop the module: " + module_name);
}
protected void sleep(long milli)
{
try{
Thread.sleep(milli);
}catch(InterruptedException e){}
}
public void destroy() throws Exception
{
}
public int getLayer()
{
return doc.getLayer();
}
public abstract void run();
public abstract void valueUpdated();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?