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.common.Constants;
24 import autohit.universe.Universe;
25
26 /**
27 * WAIT call. Waits for the specified milliseconds.
28 * <pre>
29 * REQURIES: logger, core
30 * IGNORES: uni
31 * PARAMETERS (INPUT):
32 * millis= time in milliseconds. must be a long.
33 * </pre>
34 *
35 * @author Erich P. Gatejen
36 * @version 1.0
37 * <i>Version History</i>
38 * <code>EPG - Initial - 25Apr03</code>
39 */
40 public class Call_WAIT extends Call {
41
42 /**
43 * Implement this to handle load time initialization. The
44 * four main fields will already be set--vmc, sc, log, and u.
45 * You must implement this, but you don't have to do anything.
46 * Remember that calls are cached per VM and reused as often
47 * as possible. There will be no thread-safety issues with the
48 * VMCore or log, but the SystemContecxt and Universe may be shared.
49 * @throws CallException
50 */
51 public void load_chain() throws CallException {
52 // Nothing to do.
53 }
54
55 /**
56 * Implement this to return the name of the CALL
57 * @return name of the CALL
58 */
59 public String name() {
60 return "WAIT";
61 }
62
63 /**
64 * Execute it.
65 * @return the result or null if there is no result
66 */
67 public String call() throws CallException {
68
69 try {
70
71 String millis = this.requiredString("millis");
72
73 try {
74 long val = Long.parseLong(millis);
75 this.debug("Sleeping for milliseconds=" + millis);
76 Thread.sleep(val);
77
78 } catch (InterruptedException ie) {
79 this.info("Sleep interrupted! Resuming.");
80
81 } catch (Exception e) {
82 throw new CallException(
83 this.format(
84 "Bad call. Parameter 'millis' is bad. value="
85 + millis),
86 CallException.CODE_CALL_PROGRAM_ERROR);
87 }
88
89 } catch (CallException ce) {
90 throw ce;
91 } catch (Exception e) {
92 throw new CallException(
93 this.format("General exception. error=" + e.getMessage()),
94 CallException.CODE_CALL_FAULT,
95 e);
96 }
97
98 this.debug("Sleeping done.");
99
100 return Constants.EMPTY_LEFT;
101 }
102
103 /**
104 * Execute using the passed universe, rather than the loaded.
105 * @param uni a universe
106 * @return the result or null if there is no result
107 * @see autohit.universe.Universe
108 */
109 public String call(Universe uni) throws CallException {
110 return this.call();
111 }
112 }
|