01: /*
02:
03: Derby - Class org.apache.derby.iapi.services.context.SystemContext
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.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: /**
29: A context that shuts the system down if it gets an StandardException
30: with a severity greater than or equal to ExceptionSeverity.SYSTEM_SEVERITY
31: or an exception that is not a StandardException.
32: */
33: final class SystemContext extends ContextImpl {
34: SystemContext(ContextManager cm) {
35: super (cm, "SystemContext");
36: }
37:
38: public void cleanupOnError(Throwable 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) {
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
63: .removeContext(getContextManager());
64: return;
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(
72: "Shutting down due to severe error."
73: + t.getMessage());
74:
75: } finally {
76: // we need this to happen even if we fail to print out a notice
77: Monitor.getMonitor().shutdown();
78: }
79:
80: }
81:
82: }
|