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   * @(#)s2.java 1.03b
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 s2 extends Node {
36     public s2() {
37        super("s2");
38     }
39    
40  // ST 050500 1.03bB node description due to CVB
41     private String node_desc = "entry/COMMIT scheduled task";
42     
43     
44     public final String getDesc()
45        {return node_desc;}
46     
47     
48     public final void setDesc(String node_desc) 
49        {this.node_desc = node_desc;}
50     // ST 050500 1.03bE
51  
52     // memory for backtracking
53     protected PlannerQueryStruct bind_data = null;
54  
55     protected int exec() {
56      try {
57        Planner table = context.Planner();
58        Engine engine = context.Engine();
59        AuditTable audit = engine.getAuditTable();
60  
61        GraphStruct gs = (GraphStruct) input;
62  
63        Vector bound_goals = table.bind(gs.goal);
64        bind_data = table.clear_bind(gs.goal);
65  
66        // for now assume gs.goal & ds.goals have one element only
67        Goal g0, g1;
68        Vector records;
69        DelegationStruct ds;
70  
71        for(int i = 0; i < gs.goal.size(); i++ ) {
72           // Original goal statement
73           g0 = (Goal)bind_data.goals.elementAt(i);
74           // Goal statement with new info, e.g. cost, routing, etc.
75           g1 = (Goal)bound_goals.elementAt(i);
76  
77           audit.addProducerRecords(g1.getProducerRecords());
78           audit.addConsumerRecords(g1.getConsumerRecords());
79  
80           audit.add(g0,gs.key,g1.getCost(),false,false,context.whoami(),
81                     gs.agent,g0.getEndTime());
82        }
83        for(int i = 0; i < gs.selection.size(); i++ ) {
84           ds = (DelegationStruct)gs.selection.elementAt(i);
85           g0 = (Goal)ds.goals.elementAt(0);
86  
87           audit.addProducerRecords(g0.getProducerRecords());
88           audit.addConsumerRecords(g0.getConsumerRecords());
89  
90           audit.add(g0,ds.key,g0.getCost(),false,false,ds.agent,
91                     context.whoami(),g0.getEndTime());
92        }
93  
94        if ( !gs.internal.isEmpty() ){
95           table.book(PlanRecord.FIRM,gs.goal,gs.internal);
96         }
97        
98        Core.DEBUG(2,"*** S2 AuditTable State ***");
99        Core.DEBUG(2,audit);
100 
101       output = gs;
102       
103       return OK;} 
104       catch (Exception e) { 
105         return FAIL; 
106       }
107    }
108 
109    protected void reset() {
110       // reset any state changed by exec()
111       Planner table = context.Planner();
112       Engine engine = context.Engine();
113       AuditTable audit = engine.getAuditTable();
114 
115       GraphStruct gs = (GraphStruct) input;
116       if ( !gs.internal.isEmpty() )
117          table.book(PlanRecord.TENTATIVE,gs.goal,gs.internal);
118 
119       table.reset_bind(gs.goal,bind_data);
120 
121       bind_data = null; // gc
122 
123       // for now assume gs.goal & ds.goals have one element only
124       Goal g;
125 
126       for(int i = 0; i < gs.goal.size(); i++ ) {
127          g = (Goal)gs.goal.elementAt(i);
128          audit.del(g);
129       }
130       DelegationStruct ds;
131       for(int i = 0; i < gs.selection.size(); i++ ) {
132          ds = (DelegationStruct)gs.selection.elementAt(i);
133          g = (Goal)ds.goals.elementAt(0);
134          audit.del(g);
135       }
136       this.finals();
137    }
138 }