01: package org.jacorb.util.tracing;
02:
03: /*
04: * JacORB - a free Java ORB
05: *
06: * Copyright (C) 1999-2004 Gerald Brose
07: *
08: * This library is free software; you can redistribute it and/or
09: * modify it under the terms of the GNU Library General Public
10: * License as published by the Free Software Foundation; either
11: * version 2 of the License, or (at your option) any later version.
12: *
13: * This library is distributed in the hope that it will be useful,
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16: * Library General Public License for more details.
17: *
18: * You should have received a copy of the GNU Library General Public
19: * License along with this library; if not, write to the Free
20: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21: *
22: */
23:
24: import java.util.Hashtable;
25:
26: public class Timer {
27: private final Hashtable tableTable;
28:
29: public Timer() {
30: tableTable = new Hashtable();
31: }
32:
33: public void start(int rid, Object target) {
34: try {
35: Integer id = new Integer(rid);
36:
37: Hashtable table = (Hashtable) tableTable.get(target);
38: if (table == null) {
39: table = new Hashtable();
40: tableTable.put(target, table);
41: }
42: table.put(id, new Long(System.currentTimeMillis()));
43: } catch (Exception e) {
44: e.printStackTrace();
45: }
46: }
47:
48: /**
49: * @return difference between start and stop time for
50: * request rif `
51: */
52:
53: public long stop(int rid, Object target) {
54: long t = System.currentTimeMillis();
55:
56: Hashtable table = (Hashtable) tableTable.get(target);
57: if (table == null) {
58: System.err
59: .println("errorin timer: no request table for object");
60: }
61:
62: Long startTime = (Long) table.remove(new Integer(rid));
63:
64: if (startTime != null) {
65: return t - startTime.longValue();
66: }
67:
68: return -1;
69: }
70: }
|