日期:2014-05-20 浏览次数:20778 次
public class Unit {
private String name;
private Map<String, TT> tts = new HashMap<String, TT>();
// set and get
}
public class TT {
private String name;
// set and get
}
// package and import
rule "test"
when
$t: T ( $name: name == "test")
$u: Unit ( name == "name", tts contains $name)
then
System.out.println("OK");
end
// 创建session
Unit unit = new Unit();
unit.setName("name");
TT tt = new TT();
tt.setName("test");
unit.getTts().put(tt.getName(), tt);
FactHandle f = session.insert(unit);
session.insert(unit.getTts());
session.insert(tt);
// 开启线程
// 在新线程中,每秒执行一次session.update(f, unit);
// fire
s.fireUnitHalt();
package test;
import java.util.HashMap;
import java.util.Map;
public class Unit {
private String name;
private Map<String, TT> tts = new HashMap<String, TT>();
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Map<String, TT> getTts() {
return tts;
}
public void setTts(Map<String, TT> tts) {
this.tts = tts;
}
}
package test;
public class TT {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
package test;
import java.util.Collection;
import org.drools.KnowledgeBase;