KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > unitTests > util > MsgTrace


1 /*
2
3    Derby - Class org.apache.derbyTesting.unitTests.util.MsgTrace
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derbyTesting.unitTests.util;
23
24 import org.apache.derby.iapi.services.monitor.Monitor;
25 import org.apache.derby.iapi.services.sanity.SanityManager;
26 import org.apache.derby.iapi.services.stream.HeaderPrintWriter;
27 import org.apache.derby.iapi.services.property.PropertyUtil;
28
29 import org.apache.derby.iapi.services.stream.InfoStreams;
30
31 // static methods
32
// set up automatically first time it's used
33
// default trigger is time-bomb, but refer to config for other
34
// possibilities
35
// add timestamps, thread ID's, (stack location info?)
36

37 public class MsgTrace implements Runnable JavaDoc {
38     //
39
// Number of seconds the memory trace waits before
40
// dumping its output.
41
public static final String JavaDoc
42     DELAY_PARAM_NAME = "derby.memoryTrace.bombDelay";
43
44     public static final String JavaDoc
45     RING_BUFFER_SIZE_PARAM_NAME = "derby.memoryTrace.ringBufferSize";
46
47     private static MsgTrace singleton = null;
48     long bombDelay; // 30 minutes
49
int ringBufferSize;
50     // InMemoryTrace recorder;
51
HeaderPrintWriter output;
52
53     private MsgTrace() {
54
55         output = Monitor.getMonitor().getSystemStreams().stream();
56
57         bombDelay = PropertyUtil.getSystemInt(DELAY_PARAM_NAME, 30 * 60); // 30 minutes default
58
bombDelay *= 1000;
59
60         ringBufferSize = PropertyUtil.getSystemInt(RING_BUFFER_SIZE_PARAM_NAME, 99/*InMemoryTrace.DEFAULT_RING_BUFFER_SIZE*/);
61
62         // recorder = new InMemoryTrace(ringBufferSize);
63

64         Thread JavaDoc t = new Thread JavaDoc(this);
65         t.setDaemon(true);
66         t.start();
67     }
68     
69     public static void traceString(String JavaDoc msg) {
70         if (singleton == null)
71             singleton = new MsgTrace();
72         singleton.trace(msg);
73     }
74
75     private void trace(String JavaDoc msg) {
76 // // wrap msg in a Dumpable
77
// d.timestamp = System.currentTimeMillis();
78
// d.threadId = Thread.currentThread().getName();
79
// d.msg = msg;
80
// recorder.traceString(msg);
81
}
82
83     public void run() {
84         try { Thread.sleep(bombDelay); } catch (InterruptedException JavaDoc ie) {}
85
86         // recorder.dump(output);
87

88         System.exit(1);
89     }
90 }
91
Popular Tags