View Javadoc

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 d3I extends Node {
34     protected static final double DELTA_TIME = 0.25;
35  
36     public d3I() {
37        super("d3I");
38     }
39  
40     // memory useful for backtracking
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; // should not get here
116    }
117 
118    protected void reset() {
119       // reset any state changed by exec()
120       LocalDStruct ls = (LocalDStruct)input;
121       ls.result = null;
122    }
123 }