1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package zeus.actors.graphs;
25
26 import java.util.*;
27 import zeus.util.*;
28 import zeus.concepts.*;
29 import zeus.actors.*;
30 import zeus.actors.rtn.*;
31 import zeus.actors.rtn.util.*;
32
33 public class d3I extends Node {
34 protected static final double DELTA_TIME = 0.25;
35
36 public d3I() {
37 super("d3I");
38 }
39
40
41 private StrategyEvaluator evaluator = null;
42
43 protected int exec() {
44 Engine engine = context.Engine();
45
46 LocalDStruct ls = (LocalDStruct)input;
47 ProtocolDbResult info = (ProtocolDbResult)ls.any;
48
49 Goal g = (Goal) ls.goal.elementAt(0);
50 double ct = g.getConfirmTime().getTime();
51 timeout = ct-1.5*DELTA_TIME;
52
53 Core.DEBUG(3,getDescription() + " Pre-timeout = " + timeout);
54 Core.DEBUG(3,getDescription() + " ls.gs.timeout = " + ls.gs.timeout);
55
56 if ( !Misc.isZero(ls.gs.timeout) )
57 timeout = Math.min(timeout,context.now() + ls.gs.timeout);
58
59 Core.DEBUG(3,getDescription() + " Post-timeout = " + timeout);
60
61 Time t = new Time(timeout);
62 for(int i = 0; i < ls.goal.size(); i++ ) {
63 g = (Goal)ls.goal.elementAt(i);
64 g.setReplyTime(t);
65 }
66 msg_wait_key = ls.key;
67
68 evaluator = (StrategyEvaluator)createObject(info.strategy);
69 if ( evaluator == null ) return FAIL;
70 evaluator.set(context);
71 ls.gs.evaluators.add(evaluator);
72 evaluator.set(ls.gs.evaluators);
73
74 switch( evaluator.evaluateFirst(ls.goal,info) ) {
75 case StrategyEvaluator.MESSAGE:
76 engine.new_dialogue(ls.key,ls.agent,"cfp",evaluator.getGoals());
77 return WAIT;
78
79 default:
80 return FAIL;
81 }
82 }
83
84 protected int continue_exec() {
85
86 if (context.now() > timeout) return FAIL;
87
88 Engine engine = context.Engine();
89
90 LocalDStruct ls = (LocalDStruct)input;
91 ProtocolDbResult info = (ProtocolDbResult)ls.any;
92 DelegationStruct ds;
93
94 if ( (ds = engine.replyReceived(ls.key)) != null ) {
95 Core.DEBUG(2,"d3I replyReceived: " + ds);
96 switch( evaluator.evaluateNext(ds) ) {
97 case StrategyEvaluator.MESSAGE:
98 engine.continue_dialogue(ls.key,ls.agent,"cfp",
99 evaluator.getGoals());
100 return WAIT;
101
102 case StrategyEvaluator.FAIL:
103 return FAIL;
104
105 case StrategyEvaluator.OK:
106 ls.result = ds;
107 output = ls;
108 return OK;
109
110 case StrategyEvaluator.WAIT:
111 return WAIT;
112
113 }
114 }
115 return FAIL;
116 }
117
118 protected void reset() {
119
120 LocalDStruct ls = (LocalDStruct)input;
121 ls.result = null;
122 }
123 }