1 /**
2 * AUTOHIT 2003
3 * Copyright Erich P Gatejen (c) 1989,1997,2003,2004
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Additional license information can be found in the documentation.
19 * @author Erich P Gatejen
20 */
21 package autohit.call;
22
23 import autohit.universe.Universe;
24
25 /**
26 * GLOBAL_UNIQUE_INT call. Returns an integer unique to the whole system (as long as the system hasn't been running for more than 5 months).
27 * <pre>
28 * REQURIES: logger
29 * IGNORES: uni, core
30 * </pre>
31 *
32 * @author Erich P. Gatejen
33 * @version 1.0
34 * <i>Version History</i>
35 * <code>EPG - Initial - 21Apr04
36 * </code>
37 */
38 public class Call_GLOBAL_UNIQUE_INT extends Call {
39
40 /**
41 * Implement this to handle load time initialization. The
42 * four main fields will already be set--vmc, sc, log, and u.
43 * You must implement this, but you don't have to do anything.
44 * Remember that calls are cached per VM and reused as often
45 * as possible. There will be no thread-safety issues with the
46 * VMCore or log, but the SystemContecxt and Universe may be shared.
47 * @throws CallException
48 */
49 public void load_chain() throws CallException {
50 // Nothing to do.
51 }
52
53 /**
54 * Implement this to return the name of the CALL
55 * @return name of the CALL
56 */
57 public String name() {
58 return "GLOBAL_UNIQUE_INT";
59 }
60
61 /**
62 * Execute it.
63 * @return the result or null if there is no result
64 */
65 public String call() throws CallException {
66 String val = Integer.toString(sc.uniqueInteger() + this.numberGenerator());
67 this.debug("returned=" + val);
68 return val;
69 }
70
71 /**
72 * Execute using the passed universe, rather than the loaded.
73 * @param uni a universe
74 * @return the result or null if there is no result
75 * @see autohit.universe.Universe
76 */
77 public String call(Universe uni) throws CallException {
78 return this.call();
79 }
80
81 private synchronized int numberGenerator() {
82 long it = System.currentTimeMillis();
83 return (int)it % 2000000000;
84 }
85 }
|