--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.iapi.services.context.SystemContext\r
+\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to you under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+\r
+ */\r
+\r
+package org.apache.derby.iapi.services.context;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+import org.apache.derby.iapi.services.monitor.Monitor;\r
+import org.apache.derby.iapi.error.ExceptionSeverity;\r
+/**\r
+ A context that shuts the system down if it gets an StandardException\r
+ with a severity greater than or equal to ExceptionSeverity.SYSTEM_SEVERITY\r
+ or an exception that is not a StandardException.\r
+*/\r
+final class SystemContext extends ContextImpl\r
+{\r
+ SystemContext(ContextManager cm) {\r
+ super(cm, "SystemContext");\r
+ }\r
+\r
+ public void cleanupOnError(Throwable t) {\r
+\r
+ boolean doShutdown = false;\r
+ if (t instanceof StandardException) {\r
+ StandardException se = (StandardException) t;\r
+ int severity = se.getSeverity();\r
+ if (severity < ExceptionSeverity.SESSION_SEVERITY)\r
+ return;\r
+ \r
+ popMe();\r
+\r
+ if (severity >= ExceptionSeverity.SYSTEM_SEVERITY)\r
+ doShutdown = true;\r
+ } else if (t instanceof ShutdownException) {\r
+ // system is already shutting down ...\r
+ } else if (t instanceof ThreadDeath) {\r
+ // ignore this too, it means we explicitly told thread to\r
+ // stop. one way this can happen is after monitor\r
+ // shutdown, so we don't need to shut down again\r
+ }\r
+ \r
+ if (!doShutdown) {\r
+ //ContextManager cm = getContextManager();\r
+ // need to remove me from the list of all contexts.\r
+ getContextManager().owningCsf.removeContext(getContextManager());\r
+ return;\r
+ }\r
+\r
+\r
+ try {\r
+ // try to print out that the shutdown is occurring.\r
+ // REVISIT: does this need to be a localizable message?\r
+ System.err.println("Shutting down due to severe error.");\r
+ Monitor.getStream().printlnWithHeader("Shutting down due to severe error." + t.getMessage());\r
+\r
+ } finally {\r
+ // we need this to happen even if we fail to print out a notice\r
+ Monitor.getMonitor().shutdown();\r
+ }\r
+\r
+ }\r
+\r
+}\r
+\r