1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package nl.toolforge.karma.core.cmd.event;
20
21 import nl.toolforge.karma.core.cmd.Command;
22
23 /***
24 * Generated when a command was finished (without an exception).
25 *
26 * @author D.A. Smedes
27 * @version $Id: CommandFinishedEvent.java,v 1.2 2004/10/26 22:47:58 hippe Exp $
28 */
29 public final class CommandFinishedEvent extends CommandResponseEvent {
30
31 private long start = 0L;
32 private long duration = 0L;
33
34 /***
35 * Creates the event for <code>command</code>.
36 *
37 * @param command The command that has started.
38 */
39 public CommandFinishedEvent(Command command, long startTime) {
40
41 super(command);
42
43 start = startTime;
44 duration = System.currentTimeMillis() - start;
45 }
46
47 /***
48 * Returns the time this event was generated, effectively, the time the command was finished.
49 *
50 * @return Finish time of the command.
51 */
52 public long getTime() {
53 return duration;
54 }
55
56 /***
57 * Returns a SimpleMessage formatted as <code>[ <command-name> ] Started.</code>.
58 */
59 public Message getEventMessage() {
60
61 if (duration < 1000) {
62 return new SimpleMessage(MessageHelper.format(getCommand().getName(), "Finished in " + duration + " milliseconds."));
63 } else {
64 if (duration/1000 <= 1) {
65 return new SimpleMessage(MessageHelper.format(getCommand().getName(), "Finished in " + duration/1000 + " second."));
66 } else {
67 return new SimpleMessage(MessageHelper.format(getCommand().getName(), "Finished in " + duration/1000 + " seconds."));
68 }
69 }
70 }
71 }