1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package zeus.actors.graphs;
27
28 import java.util.*;
29 import zeus.util.*;
30 import zeus.concepts.*;
31 import zeus.actors.*;
32 import zeus.actors.rtn.*;
33 import zeus.actors.rtn.util.*;
34
35 public class s6 extends Node {
36
37
38
39 private String node_desc = "do/find protocol";
40
41
42 public final String getDesc()
43 {return node_desc;}
44
45
46 public final void setDesc(String node_desc)
47 {this.node_desc = node_desc;}
48
49
50
51 public s6() {
52 super("s6");
53 }
54
55
56
57
58
59 protected static final double DELTA_TIME = 0.25;
60 private Graph local_graph = null;
61
62 protected int exec() {
63 Planner planner = context.Planner();
64 ProtocolDb protocolDb = context.ProtocolDb();
65 Engine engine = context.Engine();
66 MsgHandler handler = context.MsgHandler();
67
68 GraphStruct gs = (GraphStruct)input;
69 output = input;
70 gs.goal = planner.bind(gs.goal);
71 debug("1");
72 Goal g = (Goal) gs.goal.elementAt(0);
73 debug("2");
74 timeout = g.getConfirmTime().getTime() + DELTA_TIME;
75 debug("3");
76 msg_wait_key = context.newId("ProtocolRespondent");
77 debug("4");
78 String[] agents = new String[1];
79 agents[0] = gs.agent;
80
81
82 Fact fact = g.getFact();
83 debug("5");
84 Vector info = protocolDb.getProtocols(fact,agents,ProtocolInfo.RESPONDENT);
85 debug("6");
86 if ( info.isEmpty() ) return OK;
87 debug("7");
88 ProtocolDbResult result = (ProtocolDbResult)info.elementAt(0);
89 gs.any = result;
90 debug("8");
91 local_graph = createGraph(result.protocol);
92 if ( local_graph == null ) return OK;
93 debug("9");
94 String[] pattern = { "in-reply-to", gs.key };
95
96 handler.addRule(new MessageRuleImpl(gs.key, pattern, engine, "continue_dialogue"));
97 debug("10");
98 local_graph.run(engine,this,gs,msg_wait_key);
99 debug("11");
100 return WAIT;
101 }
102
103
104 protected int continue_exec() {
105 Core.DEBUG(2,getDescription() + " continue_exec");
106 Planner planner = context.Planner();
107 debug("12");
108 MsgHandler handler = context.MsgHandler();
109 debug("13");
110 GraphStruct gs = (GraphStruct)input;
111 debug("14");
112 output = input;
113 debug("15");
114 switch( local_graph.getState() ) {
115 case Graph.DONE:
116 debug("16");
117 planner.goalConfirmed(gs.goal,gs.confirmed_goal,gs.selection);
118 gs.goal = gs.confirmed_goal;
119 debug("17");
120 gs.confirmed_goal = null;
121 Core.DEBUG(2,getDescription() + " continue_exec OK");
122 return OK;
123 case Graph.FAILED:
124 Core.DEBUG(2,getDescription() + " continue_exec FAILED 1");
125 return OK;
126
127 default:
128 if ( timeout > context.now() ) {
129 Core.DEBUG(2,getDescription() + " continue_exec WAIT");
130 return WAIT;
131 }
132 else {
133 Core.DEBUG(2,getDescription() + " continue_exec FAILED 2");
134 return OK;
135 }
136 }
137 }
138
139
140 private void debug (String str) {
141
142 }
143
144
145 protected void reset() {
146 }
147 }