source: trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDshowTimer.java @ 277

Last change on this file since 277 was 242, checked in by sherbold, 13 years ago
  • command showTimer writes now writes to trace stream instead of output stream.
  • Property svn:mime-type set to text/plain
File size: 1.4 KB
Line 
1package de.ugoe.cs.eventbench.commands;
2
3import java.security.InvalidParameterException;
4import java.util.List;
5
6import de.ugoe.cs.eventbench.CommandHelpers;
7import de.ugoe.cs.eventbench.data.GlobalDataContainer;
8import de.ugoe.cs.util.console.Command;
9import de.ugoe.cs.util.console.Console;
10
11/**
12 * <p>
13 * Command to show the time elapsed since a timer has been started.
14 * </p>
15 *
16 * @author Steffen Herbold
17 * @version 1.0
18 */
19public class CMDshowTimer implements Command {
20
21        /*
22         * (non-Javadoc)
23         *
24         * @see de.ugoe.cs.util.console.Command#run(java.util.List)
25         */
26        @Override
27        public void run(List<Object> parameters) {
28                String timerName;
29                try {
30                        timerName = (String) parameters.get(0);
31                } catch (Exception e) {
32                        throw new InvalidParameterException();
33                }
34
35                Object dataObject = (Long) GlobalDataContainer.getInstance().getData(
36                                timerName);
37                if (dataObject == null) {
38                        CommandHelpers.objectNotFoundMessage(timerName);
39                        return;
40                }
41                if (!(dataObject instanceof Long)) {
42                        CommandHelpers.objectNotType(timerName, "Long");
43                        return;
44                }
45
46                long startTime = (Long) dataObject;
47                long currentTime = System.currentTimeMillis();
48                Console.traceln("" + (currentTime - startTime) + " milliseconds");
49        }
50
51        /*
52         * (non-Javadoc)
53         *
54         * @see de.ugoe.cs.util.console.Command#help()
55         */
56        @Override
57        public void help() {
58                Console.println("Usage: showTimer <timerName>");
59        }
60
61}
Note: See TracBrowser for help on using the repository browser.