KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > dyade > aaa > agent > Debug


1 /*
2  * Copyright (C) 2001 - 2004 ScalAgent Distibuted Technologies
3  * Copyright (C) 1996 - 2000 BULL
4  * Copyright (C) 1996 - 2000 INRIA
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA.
20  */

21 package fr.dyade.aaa.agent;
22
23 /**
24  * This class controls the debug traces printed to the audit file.
25  * <p>
26  * Debug traces are controled in the source code by package specific variables.
27  * Those variables may be dynamically set from a special property file,
28  * or from the environment.
29  * <p>
30  * To set debug variable <code>myvar</code> in class <code>myclass</code>,
31  * the variable must be declared <code>public</code> and <code>static</code>,
32  * and the following property should be defined:
33  * <code>
34  * <br> Debug.var.myclass.myvar=true
35  * </code>.
36  * <br> However this works only when the class garbage collection is disabled.
37  * <p>
38  * The <code>Debug</code> debug variables themselves are special, as they
39  * are statically set in the <code>init</code> function. The debug variables
40  * of the other packages must be dynamically set to ensure this is done after
41  * the debug property file has been read.
42  * <p>
43  * Currently only boolean variables may be dynamically set this way.
44  */

45 public final class Debug extends fr.dyade.aaa.util.Debug {
46   public static final String JavaDoc A3Debug = "fr.dyade.aaa.agent";
47   public static final String JavaDoc A3Agent = A3Debug + ".Agent";
48   public static final String JavaDoc A3Engine = A3Debug + ".Engine";
49   public static final String JavaDoc A3Network = A3Debug + ".Network";
50   public static final String JavaDoc A3Service = A3Debug + ".Service";
51   public static final String JavaDoc A3Proxy = A3Agent + ".ProxyAgent";
52   public static final String JavaDoc JGroups = A3Debug + ".JGroups";
53
54     // sets dynamic debug variables for other packages
55
// final String dynvarMarker = "Debug.var.";
56
// int markerLength = dynvarMarker.length();
57
// for (Enumeration list = properties.propertyNames();
58
// list.hasMoreElements();) {
59
// String key = (String) list.nextElement();
60
// if (key.regionMatches(0, dynvarMarker, 0, markerLength)) {
61
// // finds variable class and name
62
// int pindex = key.lastIndexOf('.');
63
// if (pindex <= markerLength) {
64
// // bad formed property name, ignores
65
// logmon.log(BasicLevel.ERROR,
66
// "AgentServer#" + AgentServer.getServerId() +
67
// ".Debug, bad formed property name: " + key);
68
// continue;
69
// }
70
// String varClassName = key.substring(markerLength, pindex);
71
// String varName = key.substring(pindex + 1);
72
// // finds variable value
73
// String varValue = properties.getProperty(key);
74
// try {
75
// // finds variable
76
// Class varClass = Class.forName(varClassName);
77
// Field var = varClass.getField(varName);
78
// // sets variable according to its type
79
// String varType = var.getType().getName();
80
// if (varType.equals("boolean") ||
81
// varType.equals("java.lang.Boolean")) {
82
// var.set(null, new Boolean(varValue));
83
// } else if (varType.equals("int") ||
84
// varType.equals("java.lang.Integer")) {
85
// var.set(null, new Integer(varValue));
86
// } else if (varType.equals("java.lang.String")) {
87
// var.set(null, varValue);
88
// } else {
89
// logmon.log(BasicLevel.ERROR,
90
// "AgentServer#" + AgentServer.getServerId() +
91
// ".Debug, error setting debug variable " +
92
// varClassName + "." + varName +
93
// ": unexpected type " + varType);
94
// continue;
95
// }
96
// } catch (Exception exc) {
97
// logmon.log(BasicLevel.ERROR,
98
// "AgentServer#" + AgentServer.getServerId() +
99
// ".Debug, error setting debug variable " +
100
// varClassName + "." + varName, exc);
101
// continue;
102
// }
103
}
104
Popular Tags