📄 audittable.java
字号:
Core.DEBUG(2,"GoodsReceived - post\n" + this);
}
//synchronized
public void invoiceReceived(DelegationStruct ds) {
Core.DEBUG(2,"AuditTable invoiceReceived:\n" + ds);
Core.DEBUG(2,this);
ResourceDb db = engine.getAgentContext().ResourceDb();
MsgHandler handler = engine.getAgentContext().MsgHandler();
String myself = engine.getAgentContext().whoami();
Contract entry = (Contract)contracts.remove(ds.key);
Core.DEBUG(3,"InvoiceReceived: contract\n\t" + entry);
Assert.notFalse(entry.agent.equals(ds.agent));
Assert.notFalse(entry.owner.equals(myself));
entry.paid = true;
Core.DEBUG(3,"InvoiceReceived: about to debit");
Fact money = db.debit(entry.cost);
Core.DEBUG(3,"InvoiceReceived: debit = " + money);
Vector data = new Vector();
data.addElement(money);
engine.continue_dialogue(entry.key,entry.agent,"inform",
"payment", ds.key, data);
handler.removeRule(entry.key);
Core.DEBUG(2,"AuditTable invoiceReceived - post:\n" + this);
}
public synchronized void paymentReceived(DelegationStruct ds) {
Core.DEBUG(2,"AuditTable paymentReceived:\n" + ds);
Core.DEBUG(2,this);
ResourceDb db = engine.getAgentContext().ResourceDb();
String myself = engine.getAgentContext().whoami();
Contract entry = (Contract)contracts.remove(ds.key);
Assert.notFalse(entry.owner.equals(ds.agent));
Assert.notFalse(entry.agent.equals(myself));
entry.paid = true;
// Payment for a job I did
Fact money = (Fact)ds.goals.elementAt(0);
db.add(money);
Core.DEBUG(2,"AuditTable paymentReceived - post\n" + this);
}
public synchronized int exception(DelegationStruct ds) {
Core.DEBUG(2,"AuditTable exception:\n" + ds);
/*
Core.DEBUG(2,this);
Contract entry = getEntry(KEY,ds.key);
this.remove(entry.goal.getId());
Planner table = engine.getAgentContext().Planner();
Goal g = table.recreateSubgoal(entry.goal);
ds.goals.removeAllElements();
ds.goals.addElement(g);
String myself = engine.getAgentContext().whoami();
if ( ds.agent.equals(myself) ) {
auxiliary.put(g.getId(),entry);
if ( entry.owner.equals(myself) )
entry.cost = 0;
return ROOT;
}
else {
Contract aux;
aux = (Contract)auxiliary.get(entry.goal.getId());
if ( aux != null ) {
auxiliary.remove(entry.goal.getId());
Assert.notFalse(auxiliary.put(g.getId(),aux) == null);
return ROOT;
}
return CHILD;
}
*/
return CHILD;
}
public synchronized void cancel(DelegationStruct ds) {
Core.DEBUG(2,"AuditTable cancel:\n" + ds);
/*
Core.DEBUG(2,this);
String myself = engine.getAgentContext().whoami();
Contract entry = getEntry(KEY,ds.key);
Assert.notFalse(entry.agent.equals(myself));
Assert.notFalse(ds.agent.equals(entry.owner));
this.remove(entry.goal.getId()); // remove entry
auxiliary.remove(entry.goal.getId()); // remove entry
redirection.remove(entry.goal.getId()); // remove entry
engine.getAgentContext().Planner().reject(ds.goals, new Vector());
*/
}
public synchronized void cancel(String goal_id) {
Core.DEBUG(2,"AuditTable cancel: " + goal_id);
/*
MsgHandler handler = engine.getAgentContext().MsgHandler();
String myself = engine.getAgentContext().whoami();
Core.DEBUG(2,this);
if ( entry == null ) return;
this.remove(goal_id);
redirection.remove(goal_id);
if ( !entry.agent.equals(myself) ) {
Vector goals = new Vector();
goals.addElement(entry.goal);
handler.send_message(entry.agent,entry.key,"cancel",goals);
}
*/
}
public synchronized void enact(DelegationStruct ds) {
Core.DEBUG(2,"AuditTable enact:\n" + ds);
/*
Planner table = engine.getAgentContext().Planner();
MsgHandler handler = engine.getAgentContext().MsgHandler();
String myself = engine.getAgentContext().whoami();
Core.DEBUG(2,this);
Contract entry = contracts.get(KEY,ds.key);
Assert.notFalse(entry.owner.equals(ds.agent));
Assert.notFalse(entry.agent.equals(myself));
Goal g = (Goal)ds.goals.elementAt(0);
PlannerEnactStruct es = table.enact(g,entry.goal);
if ( !es.ok ) return;
// add entries referring to self
add(g, g.getId(), entry.cost, false, false, entry.agent,
entry.owner, g.getEndTime());
if ( !entry.owner.equals(entry.agent) )
router.add(g.getId(),"coordination_dialog");
// add entries for children
String goal_id;
Vector goals;
for(int i = 0; i < es.external.size(); i++ ) {
g = (Goal)es.external.elementAt(i);
goal_id = (String)es.table.get(g.getId());
entry = getEntry(GOAL,goal_id);
Assert.notFalse(entry.owner.equals(myself));
add(g, g.getId(), entry.cost, false, false, entry.agent,
entry.owner, g.getEndTime());
router.add(g.getId(),"coordination_dialog");
goals = new Vector();
goals.addElement(g);
handler.send_message(entry.agent,entry.key,"enact",goals);
}
*/
}
protected synchronized boolean cleanup(Contract entry) {
/*
if ( entry.delivered && entry.paid ) {
if ( entry.goal != null )
this.remove(entry.goal.getId());
else
this.remove(entry.key);
return true;
}
else
return false;
*/
return false;
}
public Object remove(Object key) {
/*
Contract entry = (Contract)super.remove(key);
if ( entry != null ) {
MContext msgContext = engine.getAgentContext().MsgContext();
msgContext.del(entry.key);
}
return entry;
*/
return null;
}
public String toString() {
String output = "Audit Table Entries\n";
String key;
Enumeration keys = contracts.keys();
Contract entry;
RoutingRecord record;
output += "...Contracts...\n";
while( keys.hasMoreElements() ) {
key = (String)keys.nextElement();
entry = (Contract)contracts.get(key);
output += "Table-key = " + key + "\n" + entry + "\n";
}
output += "...Routing...\n";
keys = router.keys();
while( keys.hasMoreElements() ) {
key = (String)keys.nextElement();
record = (RoutingRecord)router.get(key);
output += "Table-key = " + key + "\n" + record + "\n";
}
output += "\n**************\n";
return output;
}
public void debug (String str) {
//System.out.println("audittable >> " + str);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -