Source Code Cross Referenced for Tracer.java in  » JMX » je » com » sleepycat » je » utilint » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » JMX » je » com.sleepycat.je.utilint 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*-
002:         * See the file LICENSE for redistribution information.
003:         *
004:         * Copyright (c) 2002,2008 Oracle.  All rights reserved.
005:         *
006:         * $Id: Tracer.java,v 1.43.2.3 2008/01/07 15:14:18 cwl Exp $
007:         */
008:
009:        package com.sleepycat.je.utilint;
010:
011:        import java.io.PrintWriter;
012:        import java.io.StringWriter;
013:        import java.nio.ByteBuffer;
014:        import java.sql.Timestamp;
015:        import java.util.Calendar;
016:        import java.util.logging.Level;
017:
018:        import com.sleepycat.je.DatabaseException;
019:        import com.sleepycat.je.config.ConfigParam;
020:        import com.sleepycat.je.dbi.EnvironmentImpl;
021:        import com.sleepycat.je.log.LogEntryType;
022:        import com.sleepycat.je.log.LogManager;
023:        import com.sleepycat.je.log.LogUtils;
024:        import com.sleepycat.je.log.Loggable;
025:        import com.sleepycat.je.log.entry.SingleItemEntry;
026:
027:        /**
028:         * The Tracer generates debug messages that are sent to the java.util.Logging
029:         * facility. There are three log handlers set up for logging -- the database
030:         * log itself, an output file, and stdout (the "console").  By default, only
031:         * the database file is enabled.
032:         */
033:        public class Tracer implements  Loggable {
034:
035:            /*
036:             * Name pattern for tracing output that's been directed into a log file by
037:             * enabling the file handler.
038:             */
039:            public static final String INFO_FILES = "je.info";
040:
041:            /*
042:             * Contents of a debug message.
043:             */
044:            private Timestamp time;
045:            private String msg;
046:
047:            /**
048:             * Create a new debug record.
049:             */
050:            public Tracer(String msg) {
051:                this .time = getCurrentTimestamp();
052:                this .msg = msg;
053:            }
054:
055:            /**
056:             * Create trace record that will be filled in from the log.
057:             */
058:            public Tracer() {
059:            }
060:
061:            /*
062:             * Static utility methods for submitting information for logging in the
063:             * text log file, the database log, and stdout.
064:             */
065:
066:            /**
067:             * Logger method for recording a general message.
068:             */
069:            public static void trace(Level logLevel, EnvironmentImpl envImpl,
070:                    String msg) {
071:                envImpl.getLogger().log(logLevel, msg);
072:            }
073:
074:            /**
075:             * Logger method for recording an exception and stacktrace.
076:             */
077:            public static void trace(EnvironmentImpl envImpl,
078:                    String sourceClass, String sourceMethod, String msg,
079:                    Throwable t) {
080:
081:                /*
082:                 * Give it to the Logger, which will funnel it to stdout and/or the
083:                 * text file and/or the database log file
084:                 */
085:                envImpl.getLogger().logp(Level.SEVERE, sourceClass,
086:                        sourceMethod, msg + "\n" + Tracer.getStackTrace(t));
087:            }
088:
089:            /**
090:             * Parse a logging level config parameter, and return a more explanatory
091:             * error message if it doesn't parse.
092:             */
093:            public static Level parseLevel(EnvironmentImpl envImpl,
094:                    ConfigParam configParam) throws DatabaseException {
095:
096:                Level level = null;
097:                try {
098:                    String levelVal = envImpl.getConfigManager().get(
099:                            configParam);
100:                    level = Level.parse(levelVal);
101:                } catch (IllegalArgumentException e) {
102:                    throw new DatabaseException("Problem parsing parameter "
103:                            + configParam.getName() + ": " + e.getMessage(), e);
104:                }
105:                return level;
106:            }
107:
108:            /*
109:             * Helpers
110:             */
111:            public String getMessage() {
112:                return msg;
113:            }
114:
115:            /**
116:             * @return a timestamp for "now"
117:             */
118:            private Timestamp getCurrentTimestamp() {
119:                Calendar cal = Calendar.getInstance();
120:                return new Timestamp(cal.getTime().getTime());
121:            }
122:
123:            /**
124:             * @return the stacktrace for an exception
125:             */
126:            public static String getStackTrace(Throwable t) {
127:                StringWriter s = new StringWriter();
128:                t.printStackTrace(new PrintWriter(s));
129:                String stackTrace = s.toString();
130:                stackTrace = stackTrace.replaceAll("<", "&lt;");
131:                stackTrace = stackTrace.replaceAll(">", "&gt;");
132:                return stackTrace;
133:            }
134:
135:            /*
136:             * Logging support
137:             */
138:
139:            /**
140:             * Convenience method to create a log entry containing this trace msg.
141:             */
142:            public long log(LogManager logManager) throws DatabaseException {
143:                return logManager.log(new SingleItemEntry(
144:                        LogEntryType.LOG_TRACE, this ));
145:            }
146:
147:            /**
148:             * @see Loggable#getLogSize()
149:             */
150:            public int getLogSize() {
151:                return (LogUtils.getTimestampLogSize() + LogUtils
152:                        .getStringLogSize(msg));
153:            }
154:
155:            /**
156:             * @see Loggable#writeToLog
157:             */
158:            public void writeToLog(ByteBuffer logBuffer) {
159:                /* Load the header. */
160:                LogUtils.writeTimestamp(logBuffer, time);
161:                LogUtils.writeString(logBuffer, msg);
162:            }
163:
164:            /**
165:             * @see Loggable#readFromLog
166:             */
167:            public void readFromLog(ByteBuffer itemBuffer, byte entryTypeVersion) {
168:                /* See how many we want to read direct. */
169:                time = LogUtils.readTimestamp(itemBuffer);
170:                msg = LogUtils.readString(itemBuffer);
171:            }
172:
173:            /**
174:             * @see Loggable#dumpLog
175:             */
176:            public void dumpLog(StringBuffer sb, boolean verbose) {
177:                sb.append("<Dbg time=\"");
178:                sb.append(time);
179:                sb.append("\">");
180:                sb.append("<msg val=\"");
181:                sb.append(msg);
182:                sb.append("\"/>");
183:                sb.append("</Dbg>");
184:            }
185:
186:            /**
187:             * @see Loggable#getTransactionId
188:             */
189:            public long getTransactionId() {
190:                return 0;
191:            }
192:
193:            public String toString() {
194:                return (time + "/" + msg);
195:            }
196:
197:            /**
198:             * For unit tests.
199:             */
200:
201:            /**
202:             *  Just in case it's ever used as a hash key.
203:             */
204:            public int hashCode() {
205:                return toString().hashCode();
206:            }
207:
208:            /**
209:             * Override Object.equals
210:             */
211:            public boolean equals(Object obj) {
212:                /* Same instance? */
213:                if (this  == obj) {
214:                    return true;
215:                }
216:
217:                /* Is it another Tracer? */
218:                if (!(obj instanceof  Tracer)) {
219:                    return false;
220:                }
221:
222:                /*
223:                 * We could compare all the fields individually, but since they're all
224:                 * placed in our toString() method, we can just compare the String
225:                 * version of each offer.
226:                 */
227:                return (toString().equals(obj.toString()));
228:            }
229:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.