1 /*
2 * The contents of this file are subject to the BT "ZEUS" Open Source
3 * Licence (L77741), Version 1.0 (the "Licence"); you may not use this file
4 * except in compliance with the Licence. You may obtain a copy of the Licence
5 * from $ZEUS_INSTALL/licence.html or alternatively from
6 * http://www.labs.bt.com/projects/agents/zeus/licence.htm
7 *
8 * Except as stated in Clause 7 of the Licence, software distributed under the
9 * Licence is distributed WITHOUT WARRANTY OF ANY KIND, either express or
10 * implied. See the Licence for the specific language governing rights and
11 * limitations under the Licence.
12 *
13 * The Original Code is within the package zeus.*.
14 * The Initial Developer of the Original Code is British Telecommunications
15 * public limited company, whose registered office is at 81 Newgate Street,
16 * London, EC1A 7AJ, England. Portions created by British Telecommunications
17 * public limited company are Copyright 1996-9. All Rights Reserved.
18 *
19 * THIS NOTICE MUST BE INCLUDED ON ANY COPY OF THIS FILE
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 d3R extends Node {
34 public d3R() {
35 super("d3R");
36 }
37
38 // memory useful for backtracking
39 private StrategyEvaluator evaluator = null;
40
41 // private TimeOutActions timeOutActions = new TimeOutActions(this);
42 // private Timer timer = null;
43
44 protected int exec() {
45 Engine engine = context.Engine();
46
47 GraphStruct gs = (GraphStruct)input;
48 ProtocolDbResult info = (ProtocolDbResult)gs.any;
49 Goal g = (Goal)gs.goal.elementAt(0);
50 debug ("1");
51 evaluator = (StrategyEvaluator)createObject(info.strategy);
52 if ( evaluator == null ) return FAIL;
53 evaluator.set(context);
54 gs.evaluators.add(evaluator);
55 evaluator.set(gs.evaluators);
56 debug ("2");
57 switch( evaluator.evaluateFirst(gs.goal,info) ) {
58 case StrategyEvaluator.MESSAGE:
59 engine.continue_dialogue(gs.key,gs.agent,"propose", evaluator.getGoals());
60 break;
61
62 default:
63 //timer.cancel();
64 return FAIL;
65 }
66 debug ("3");
67 timeout = g.getConfirmTime().getTime();
68 //timer = new Timer ();
69 //timer.schedule (timeOutActions,(long)timeout+(long)100);// wait 1/10th sec to sort it.
70 msg_wait_key = gs.key;
71 return WAIT;
72 }
73
74
75 public boolean timeOut(){
76 System.out.println("timeing out...");
77 return (false);
78 }
79
80
81 protected int continue_exec() {
82 Core.DEBUG(2,"d3R continue_exec");
83
84 if (context.now() > timeout) {
85 Core.DEBUG(2,"d3R Fail: " + context.now() + " > " + timeout);
86 debug ("4 :d3R Fail: " + context.now() + " > " + timeout);
87 return FAIL;
88 }
89
90 Engine engine = context.Engine();
91
92 GraphStruct gs = (GraphStruct)input;
93 DelegationStruct ds;
94
95 if ( (ds = engine.replyReceived(gs.key)) != null ) {
96 Core.DEBUG(2,"d3R replyReceived: " + ds);
97 debug ("5");
98 switch( evaluator.evaluateNext(ds) ) {
99 case StrategyEvaluator.MESSAGE:
100 engine.continue_dialogue(gs.key,gs.agent,"propose",
101 evaluator.getGoals());
102 debug ("6a");
103 return WAIT;
104
105 case StrategyEvaluator.FAIL:
106 // timer.cancel();
107 //evaluator = null;
108 debug ("6b");
109 return FAIL;
110
111 case StrategyEvaluator.OK:
112 gs.confirmed = true;
113 gs.confirmed_goal = ds.goals;
114 output = gs;
115 // timer.cancel();
116 // evaluator = null;
117 debug ("6c");
118 return OK;
119
120 case StrategyEvaluator.WAIT:
121 debug ("6d");
122 return WAIT;
123 }
124 }
125
126 debug ("7");
127 Core.DEBUG(2,"d3R - end point?");
128 // timer.cancel();
129 // evaluator = null;
130 return FAIL;
131 }
132
133 protected void reset() {
134 // reset any state changed by exec()
135 }
136
137 private void debug (String str) {
138 //System.out.println("d3R>> " + str);
139 }
140
141 }