KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > iapi > services > context > SystemContext


1 /*
2
3    Derby - Class org.apache.derby.iapi.services.context.SystemContext
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.derby.iapi.services.context;
23
24 import org.apache.derby.iapi.error.StandardException;
25 import org.apache.derby.iapi.services.monitor.Monitor;
26 import org.apache.derby.iapi.error.ExceptionSeverity;
27 /**
28     A context that shuts the system down if it gets an StandardException
29     with a severity greater than or equal to ExceptionSeverity.SYSTEM_SEVERITY
30     or an exception that is not a StandardException.
31 */

32 final class SystemContext extends ContextImpl
33 {
34     SystemContext(ContextManager cm) {
35         super(cm, "SystemContext");
36     }
37
38     public void cleanupOnError(Throwable JavaDoc t) {
39
40         boolean doShutdown = false;
41         if (t instanceof StandardException) {
42             StandardException se = (StandardException) t;
43             int severity = se.getSeverity();
44             if (severity < ExceptionSeverity.SESSION_SEVERITY)
45                 return;
46             
47             popMe();
48
49             if (severity >= ExceptionSeverity.SYSTEM_SEVERITY)
50                 doShutdown = true;
51         } else if (t instanceof ShutdownException) {
52             // system is already shutting down ...
53
} else if (t instanceof ThreadDeath JavaDoc) {
54             // ignore this too, it means we explicitly told thread to
55
// stop. one way this can happen is after monitor
56
// shutdown, so we don't need to shut down again
57
}
58         
59         if (!doShutdown) {
60             //ContextManager cm = getContextManager();
61
// need to remove me from the list of all contexts.
62
getContextManager().owningCsf.removeContext(getContextManager());
63             return;
64         }
65
66
67         try {
68             // try to print out that the shutdown is occurring.
69
// REVISIT: does this need to be a localizable message?
70
System.err.println("Shutting down due to severe error.");
71             Monitor.getStream().printlnWithHeader("Shutting down due to severe error." + t.getMessage());
72
73         } finally {
74             // we need this to happen even if we fail to print out a notice
75
Monitor.getMonitor().shutdown();
76         }
77
78     }
79
80 }
81
82
Popular Tags