01: /*
02: * RDMProgress.java
03: *
04: * Created on February 14, 2003, 12:03 PM
05: */
06:
07: package com.sun.portal.search.rdmgr;
08:
09: import java.io.*;
10: import java.util.*;
11:
12: /**
13: * Reports progress of an RDM query, persistent search, etc
14: */
15: public class RDMProgress {
16:
17: // XXX this should be a general RDM interface (persistent search, etc)
18:
19: boolean started = false;
20: long start_time = 0;
21: PrintWriter progressWriter = null; // XXX shouldn't be here
22: public boolean closeProgressWriter = false; // XXX
23:
24: public RDMProgress() {
25: }
26:
27: public void reportProgress(String key) {
28: reportProgress(key, (Object[]) null);
29: }
30:
31: public void reportProgress(String key, String msg) {
32: reportProgress(key, new Object[] { msg });
33: }
34:
35: public void reportProgress(String key, int num) {
36: reportProgress(key, new Object[] { new Long(num) });
37: }
38:
39: public void reportProgress(String key, Date date) {
40: reportProgress(key, new Object[] { date });
41: }
42:
43: public void reportProgress(String key, Object[] params) {
44: if (progressWriter != null) {
45: long t = new Date().getTime();
46: progressWriter.println(RDMgrUtil
47: .getLocalizedString("progress")
48: + ": +"
49: + (t - start_time)
50: / 1000
51: + " "
52: + RDMgrUtil.getLocalizedString(key, params));
53: }
54: }
55:
56: protected void init() {
57: if (progressWriter != null) {
58: Date start = new Date();
59: start_time = start.getTime();
60: progressWriter.println(RDMgrUtil
61: .getLocalizedString("progress")
62: + ": +0 "
63: + RDMgrUtil.getLocalizedString("progressStart"));
64: started = true;
65: }
66: }
67:
68: protected void finish() {
69: if (started && progressWriter != null) {
70: Date finish = new Date();
71: long t = finish.getTime();
72: reportProgress("progressFinished", finish);
73: if (closeProgressWriter)
74: progressWriter.close();
75: }
76: }
77:
78: }
|