Source Code Cross Referenced for ThrowableHandler.java in  » Net » Terracotta » com » tc » lang » 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 » Net » Terracotta » com.tc.lang 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003:         * notice. All rights reserved.
004:         */
005:        package com.tc.lang;
006:
007:        import com.tc.config.schema.setup.ConfigurationSetupException;
008:        import com.tc.exception.DatabaseException;
009:        import com.tc.exception.ExceptionHelperImpl;
010:        import com.tc.exception.MortbayMultiExceptionHelper;
011:        import com.tc.exception.RuntimeExceptionHelper;
012:        import com.tc.logging.TCLogger;
013:        import com.tc.util.TCDataFileLockingException;
014:        import com.tc.util.startuplock.FileNotCreatedException;
015:        import com.tc.util.startuplock.LocationNotCreatedException;
016:
017:        import java.net.BindException;
018:
019:        /**
020:         * Handle throwables appropriately by printing messages to the logger, etc.  Deal with 
021:         * nasty problems that can occur as the VM shuts down. 
022:         */
023:        public class ThrowableHandler {
024:            //XXX: The dispatching in this class is retarded, but I wanted to move as much of the exception handling into a single
025:            //place first, then come up with fancy ways of dealing with them. --Orion 03/20/2006
026:
027:            private final TCLogger logger;
028:            private final ExceptionHelperImpl helper;
029:
030:            /**
031:             * Construct a new ThrowableHandler with a logger
032:             * @param logger Logger
033:             */
034:            public ThrowableHandler(TCLogger logger) {
035:                this .logger = logger;
036:                helper = new ExceptionHelperImpl();
037:                helper.addHelper(new RuntimeExceptionHelper());
038:                helper.addHelper(new MortbayMultiExceptionHelper());
039:            }
040:
041:            /**
042:             * Handle throwable occurring on thread
043:             * @param thread Thread receiving Throwable
044:             * @param t Throwable
045:             */
046:            public void handleThrowable(final Thread thread, final Throwable t) {
047:                final Throwable proximateCause = helper.getProximateCause(t);
048:                final Throwable ultimateCause = helper.getUltimateCause(t);
049:                if (proximateCause instanceof  ConfigurationSetupException) {
050:                    handleStartupException((ConfigurationSetupException) proximateCause);
051:                } else if (ultimateCause instanceof  BindException) {
052:                    logger.error(ultimateCause);
053:                    handleStartupException(
054:                            (Exception) ultimateCause,
055:                            ".  Please make sure the server isn't already running or choose a different port.");
056:                } else if (ultimateCause instanceof  DatabaseException) {
057:                    handleStartupException((Exception) proximateCause);
058:                } else if (ultimateCause instanceof  LocationNotCreatedException) {
059:                    handleStartupException((Exception) ultimateCause);
060:                } else if (ultimateCause instanceof  FileNotCreatedException) {
061:                    handleStartupException((Exception) ultimateCause);
062:                } else if (ultimateCause instanceof  TCDataFileLockingException) {
063:                    handleStartupException((Exception) ultimateCause);
064:                } else {
065:                    handleDefaultException(thread, proximateCause);
066:                }
067:            }
068:
069:            private void handleDefaultException(Thread thread,
070:                    Throwable throwable) {
071:                // We need to make SURE that our stacktrace gets printed, when using just the logger sometimes the VM exits
072:                // before the stacktrace prints
073:                throwable.printStackTrace(System.err);
074:                System.err.flush();
075:                logger
076:                        .error(
077:                                "Thread:"
078:                                        + thread
079:                                        + " got an uncaught exception.  About to sleep then exit.",
080:                                throwable);
081:                try {
082:                    // Give our logger a chance to print the stacktrace before the VM exits
083:                    Thread.sleep(3000);
084:                } catch (InterruptedException ie) {
085:                    // When you suck you just suck and nothing will help you
086:                }
087:                System.exit(1);
088:            }
089:
090:            private void handleStartupException(Exception e) {
091:                handleStartupException(e, "");
092:            }
093:
094:            private void handleStartupException(Exception e, String extraMessage) {
095:                System.err.println("");
096:                System.err.println("");
097:                System.err.println("Fatal Terracotta startup exception:");
098:                System.err.println("");
099:                System.err.println("   " + e.getMessage() + extraMessage);
100:                System.err.println("");
101:                System.err.println("Server startup failed.");
102:                System.exit(2);
103:            }
104:
105:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.