01: /*
02:
03: Derby - Class org.apache.derbyTesting.unitTests.util.MsgTrace
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to You under the Apache License, Version 2.0
09: (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 {
38: //
39: // Number of seconds the memory trace waits before
40: // dumping its output.
41: public static final String DELAY_PARAM_NAME = "derby.memoryTrace.bombDelay";
42:
43: public static final String RING_BUFFER_SIZE_PARAM_NAME = "derby.memoryTrace.ringBufferSize";
44:
45: private static MsgTrace singleton = null;
46: long bombDelay; // 30 minutes
47: int ringBufferSize;
48: // InMemoryTrace recorder;
49: HeaderPrintWriter output;
50:
51: private MsgTrace() {
52:
53: output = Monitor.getMonitor().getSystemStreams().stream();
54:
55: bombDelay = PropertyUtil
56: .getSystemInt(DELAY_PARAM_NAME, 30 * 60); // 30 minutes default
57: bombDelay *= 1000;
58:
59: ringBufferSize = PropertyUtil
60: .getSystemInt(RING_BUFFER_SIZE_PARAM_NAME, 99/*InMemoryTrace.DEFAULT_RING_BUFFER_SIZE*/);
61:
62: // recorder = new InMemoryTrace(ringBufferSize);
63:
64: Thread t = new Thread(this );
65: t.setDaemon(true);
66: t.start();
67: }
68:
69: public static void traceString(String msg) {
70: if (singleton == null)
71: singleton = new MsgTrace();
72: singleton.trace(msg);
73: }
74:
75: private void trace(String 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 {
85: Thread.sleep(bombDelay);
86: } catch (InterruptedException ie) {
87: }
88:
89: // recorder.dump(output);
90:
91: System.exit(1);
92: }
93: }
|