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  
25  package zeus.util;
26  
27  import zeus.concepts.*;
28  import java.util.*;
29  import java.io.*;
30  
31  
32  public class SystemProps {
33     protected static Properties props = new Properties();
34     protected static final String[] defaults = {
35        "agent.language","java",
36        "install.dir", System.getProperty("user.home"),
37        "version.demo", "false",
38        "version.id", "2.0",
39        "application.gif", "gif_files.txt",
40        "file.separator", ":",
41        "debug.on", "false",
42        "debug.level", "10",
43  
44        "HAP.address", "adastralcity.agentcities.net",
45        "container.name", "defaultContainerCode",
46        
47        "system.protocols.respondent", "zeus.actors.graphs.ContractNetRespondent",
48        "system.protocols.initiator", "zeus.actors.graphs.ContractNetInitiator",
49  //added by simon for test 17/05/01
50      
51        
52  // end add
53  
54        "friendly.name.zeus.actors.graphs.ContractNetRespondent",
55           "Fipa-Contract-Net-Contractor",
56        "friendly.name.zeus.actors.graphs.ContractNetInitiator",
57           "Fipa-Contract-Net-Manager",
58           
59   // added by simon for test 17/5/01
60   
61  //    "friendly.name.zeus.actors.graphs.EnglishAuctionInitiator", "FIPA-English-Auction-Manager", 
62  //    "friendly.name.zeus.actors.graphs.EnglishAuctionRespondent", "FIPA-English-Auction-Respondent",
63  
64        "system.strategy.initiator",
65           "zeus.actors.graphs.LinearInitiatorEvaluator",
66           //:zeus.actors.graphs.ExponentialInitiatorEvaluator",
67        "system.strategy.respondent",
68           "zeus.actors.graphs.LinearRespondentEvaluator",
69           //:zeus.actors.graphs.ExponentialRespondentEvaluator",
70  
71        "system.strategy.initiator.default",
72           "zeus.actors.graphs.DefaultInitiatorEvaluator",
73        "system.strategy.respondent.default",
74           "zeus.actors.graphs.DefaultRespondentEvaluator",
75  
76        "friendly.name.zeus.actors.graphs.DefaultInitiatorEvaluator",
77           "Default-No-Negotiation",
78        "friendly.name.zeus.actors.graphs.DefaultRespondentEvaluator",
79           "Default-Fixed-Margin",
80  
81        "friendly.name.zeus.actors.graphs.LinearInitiatorEvaluator",
82           "Linear-Growth",
83        "friendly.name.zeus.actors.graphs.LinearRespondentEvaluator",
84           "Linear-Decay",
85  
86     /*   "friendly.name.zeus.actors.graphs.ExponentialInitiatorEvaluator",
87           "Exponential-Growth",
88        "friendly.name.zeus.actors.graphs.ExponentialRespondentEvaluator",
89           "Exponential-Decay",*/
90  
91        "share.plan", "true",
92        "execute.earliest", "true",
93  
94        "registration.timeout", "3.0",
95        "facilitator.timeout", "0.5",
96        "address.timeout", "0.5",
97        "accept.timeout", "1.5",
98        "addressbook.refresh", "5.0",
99        "facilitator.refresh", "5.0",
100       "replan.period", "2.0",
101 
102       "facilitator.period.default", "5.0",
103       "nameserver.period.default", "0.5",
104       "nameserver.dns.default", "dns.db",
105       "agent.names.nameserver", "Nameserver",
106       "agent.names.facilitator", "Facilitator",
107       "agent.names.visualiser", "Visualiser",
108       "agent.names.dbProxy", "DbProxy",
109       "agent.names.agent", "Agent",
110 
111 
112       "planner.processors.min", "1",
113       "planner.processors.max", "10",
114       "planner.length.min", "10",
115       "planner.length.max", "1000",
116       "planner.doublebooking.min", "0",
117       "planner.doublebooking.max", "100",
118 
119       "agent.default.name", "DefaultAgentName",
120       "agent.default.class", "ZeusAgent",
121       "agent.default.planner.processors", "1",
122       "agent.default.planner.length", "20",
123       "agent.default.planner.doublebooking", "0",
124 
125       "task.default.name", "DefaultTaskName",
126       "task.default.time", "1",
127       "task.default.cost", "0",
128 
129       "system.organisation.relations.default", "peer",
130       "# Note: the ordering of the relations is important",
131       "# Comment terminator",
132       "system.organisation.relations", "superior:subordinate:peer:coworker",
133       "ior.dir", "IOR_",
134       "num.connections", "20",
135       "http_root","E://webapps//ROOT//",
136       "TradeHouseName","GateAgent",
137       "TradeHousePlatform", "agntcity.barcelona.agentcities.net:2099/JADE",
138       "service_platform", "http://193.113.27.14",
139       "out_log","FIPA_out_log.html",
140       "in_log","FIPA_in_log.html"
141    };
142 
143    static {
144       String home_dir = System.getProperty("user.home");
145       String fsep = File.separator;
146 
147       if ( !home_dir.endsWith(fsep) ) home_dir += fsep;
148  
149       String filename = home_dir + ".zeus.prp";
150 
151       File file = new File(filename);
152       try {
153          props.load(new FileInputStream(file));
154       }
155       catch(Exception e) {
156          e.printStackTrace();
157       }
158 
159       for( int i = 0; i < defaults.length; i += 2 ) {
160          if ( props.get(defaults[i]) == null )
161             props.put(defaults[i], defaults[i+1]);
162       }
163 
164       String zeus_dir = props.getProperty("install.dir");
165       if ( !zeus_dir.endsWith(fsep) ) zeus_dir += fsep;
166 
167       file = new File(zeus_dir);
168       if ( !file.exists() ) {
169          System.err.println("Improper install.dir specified in " +
170                             "'zeus.prp' properties file.\nExiting...");
171          System.exit(0);
172       }
173 
174       props.put("zeus.dir",zeus_dir);
175 
176       String gif_dir = zeus_dir + "gifs" + fsep;
177       props.put("gif.dir",gif_dir);
178    }
179 
180    public static String getProperty(String key) {
181       return props.getProperty(key);
182    }
183    public static String getProperty(String key, String defaultValue) {
184       return props.getProperty(key,defaultValue);
185    }
186    public static boolean getState(String key) {
187       String s = props.getProperty(key);
188       return (s != null) ? (Boolean.valueOf(s)).booleanValue() : false;
189    }
190    public static boolean getState(String key, boolean defaultValue) {
191       String s = props.getProperty(key);
192       return (s != null) ? (Boolean.valueOf(s)).booleanValue() : defaultValue;
193    }
194    public static double getDouble(String key) {
195       String s = props.getProperty(key);
196       try {
197          return (s != null) ? (Double.valueOf(s)).doubleValue() : 0.0;
198       }
199       catch(NumberFormatException e) {
200          System.err.println("Illegal format for " + key + " entry in " +
201                             "properties database -- number format expected");
202       }
203       return 0.0;
204    }
205    public static double getDouble(String key, double defaultValue) {
206       String s = props.getProperty(key);
207       try {
208          return (s != null) ? (Double.valueOf(s)).doubleValue() : defaultValue;
209       }
210       catch(NumberFormatException e) {
211          System.err.println("Illegal format for " + key + " entry in " +
212                             "properties database -- number format expected");
213       }
214       return defaultValue;
215    }
216    public static int getInt(String key) {
217       String s = props.getProperty(key);
218       try {
219          return (s != null) ? (Integer.valueOf(s)).intValue() : 0;
220       }
221       catch(NumberFormatException e) {
222          System.err.println("Illegal format for " + key + " entry in " +
223                             "properties database -- number format expected");
224       }
225       return 0;
226    }
227    public static int getInt(String key, int defaultValue) {
228       String s = props.getProperty(key);
229       try {
230          return (s != null) ? (Integer.valueOf(s)).intValue() : defaultValue;
231       }
232       catch(NumberFormatException e) {
233          System.err.println("Illegal format for " + key + " entry in " +
234                             "properties database -- number format expected");
235       }
236       return defaultValue;
237    }
238    public static long getLong(String key) {
239       String s = props.getProperty(key);
240       try {
241          return (s != null) ? (Long.valueOf(s)).intValue() : 0;
242       }
243       catch(NumberFormatException e) {
244          System.err.println("Illegal format for " + key + " entry in " +
245                             "properties database -- number format expected");
246       }
247       return 0;
248    }
249    public static long getLong(String key, long defaultValue) {
250       String s = props.getProperty(key);
251       try {
252          return (s != null) ? (Long.valueOf(s)).longValue() : defaultValue;
253       }
254       catch(NumberFormatException e) {
255          System.err.println("Illegal format for " + key + " entry in " +
256                             "properties database -- number format expected");
257       }
258       return defaultValue;
259    }
260    public static void list(PrintStream out) {
261       props.list(out);
262    }
263    public static void list(PrintWriter out) {
264       props.list(out);
265    }
266    public static synchronized void load(InputStream in) throws IOException {
267       props.load(in);
268    }
269    public static Enumeration propertyNames() {
270       return props.propertyNames();
271    }
272    public static synchronized void save(OutputStream out, String header) {
273       props.save(out,header);
274    }
275 
276    public static void main(String[] args) {
277       System.out.println(SystemProps.getProperty("application.gif"));
278    }
279     
280     /*** 
281         this is a patent hack. I am very, very sorry, 
282         @author Simon Thompson
283         @since 1.1 (hopefully removed later, in the perfect world...
284         */
285     public static boolean FIPA_IMPLEMENTED_TIGHTLY = false ;
286 
287 
288     /*** 
289         transports is used to allow configuration of transport addresses at 
290         runtime
291         */
292     private static StringHashtable transports = new StringHashtable(); 
293     
294     public static TransportConfig getTransport (String name) {
295         System.out.println("trying to get transport " + name); 
296         
297         TransportConfig retVal = (TransportConfig) transports.getForString(name); 
298         System.out.println(retVal); 
299         return retVal; 
300     }
301     
302     public static void setTransport (String name, TransportConfig conf) { 
303         transports.put (name,conf);    
304     }
305     
306     public static void setTransports (StringHashtable trans) { 
307         transports = trans;
308     }
309     
310 }
311