Search in sources :

Example 6 with ShutdownException

use of org.apache.derby.shared.common.error.ShutdownException in project derby by apache.

the class InterruptStatus method restoreIntrFlagIfSeen.

/**
 * Check if the we ever noticed and reset the thread's interrupt status
 * flag to allow safe operation during execution.  Called from JDBC API
 * methods before returning control to user application. Typically, this
 * happens just prior to return in methods that catch {@code Throwable} and
 * invoke
 * {@code handleException} (directly or indirectly) on it, e.g.
 * <pre>
 *       :
 *       InterruptStatus.restoreIntrFlagIfSeen();
 *       return ...;
 *    } catch (Throwable t) {
 *       throw handleException(t);
 *    }
 * </pre>
 * {@code handleException} does its own calls to {@code
 * restoreIntrFlagIfSeen}. If {@code setupContextStack} has been called
 * consider using the overloaded variant of {@code restoreIntrFlagIfSeen}
 * with an lcc argument.
 * <p/>
 * If an interrupt status flag was seen, we set it back <em>on</em> here.
 */
public static void restoreIntrFlagIfSeen() {
    LanguageConnectionContext lcc = null;
    try {
        lcc = (LanguageConnectionContext) getContextOrNull(LanguageConnectionContext.CONTEXT_ID);
    } catch (ShutdownException e) {
    // Ignore. DERBY-4911 Restoring interrupt flag is moot anyway if we
    // are closing down.
    }
    if (lcc == null) {
        // no lcc available for this thread, use thread local flag
        if (exception.get() != null) {
            exception.set(null);
            // Set thread's interrupt status flag back on before returning
            // control to user application
            Thread.currentThread().interrupt();
        }
    } else if (lcc.getInterruptedException() != null) {
        lcc.setInterruptedException(null);
        // Set thread's interrupt status flag back on before returning
        // control to user application
        Thread.currentThread().interrupt();
    }
}
Also used : LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) ShutdownException(org.apache.derby.shared.common.error.ShutdownException)

Example 7 with ShutdownException

use of org.apache.derby.shared.common.error.ShutdownException in project derby by apache.

the class SystemContext method cleanupOnError.

public void cleanupOnError(Throwable t) {
    boolean doShutdown = false;
    if (t instanceof StandardException) {
        StandardException se = (StandardException) t;
        int severity = se.getSeverity();
        if (severity < ExceptionSeverity.SESSION_SEVERITY)
            return;
        popMe();
        if (severity >= ExceptionSeverity.SYSTEM_SEVERITY)
            doShutdown = true;
    } else if (t instanceof ShutdownException) {
    // system is already shutting down ...
    } else if (t instanceof ThreadDeath) {
    // ignore this too, it means we explicitly told thread to
    // stop.  one way this can happen is after monitor
    // shutdown, so we don't need to shut down again
    }
    if (!doShutdown) {
        // ContextManager cm = getContextManager();
        // need to remove me from the list of all contexts.
        getContextManager().owningCsf.removeContext(getContextManager());
        return;
    }
    try {
        // try to print out that the shutdown is occurring.
        // REVISIT: does this need to be a localizable message?
        System.err.println("Shutting down due to severe error.");
        Monitor.getStream().printlnWithHeader("Shutting down due to severe error." + t.getMessage());
    } finally {
        // we need this to happen even if we fail to print out a notice
        getMonitor().shutdown();
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) ShutdownException(org.apache.derby.shared.common.error.ShutdownException)

Example 8 with ShutdownException

use of org.apache.derby.shared.common.error.ShutdownException in project derby by apache.

the class IndexStatisticsDaemonImpl method run.

/**
 * Drives the statistics generation.
 * <p>
 * This method will be run in a separate thread, and it will keep working
 * as long as there is work to do. When the queue is exhausted, the method
 * will exit (the thread dies).
 */
public void run() {
    final long runStart = System.currentTimeMillis();
    ContextService ctxService = null;
    // Implement the outer-level exception handling here.
    try {
        // DERBY-5088: Factory-call may fail.
        ctxService = getContextService();
        ctxService.setCurrentContextManager(ctxMgr);
        processingLoop();
    } catch (ShutdownException se) {
        // The database is/has been shut down.
        // Log processing statistics and exit.
        trace(1, "swallowed shutdown exception: " + extractIstatInfo(se));
        stop();
        ctxMgr.cleanupOnError(se, db.isActive());
    } catch (RuntimeException re) {
        // on a lower level
        if (!isShuttingDown()) {
            log(AS_BACKGROUND_TASK, null, re, "runtime exception during normal operation");
            throw re;
        }
        trace(1, "swallowed runtime exception during shutdown: " + extractIstatInfo(re));
    } finally {
        if (ctxService != null) {
            ctxService.resetCurrentContextManager(ctxMgr);
        }
        runTime += (System.currentTimeMillis() - runStart);
        trace(0, "worker thread exit");
    }
}
Also used : ContextService(org.apache.derby.iapi.services.context.ContextService) ShutdownException(org.apache.derby.shared.common.error.ShutdownException)

Aggregations

ShutdownException (org.apache.derby.shared.common.error.ShutdownException)8 StandardException (org.apache.derby.shared.common.error.StandardException)4 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)3 TransactionController (org.apache.derby.iapi.store.access.TransactionController)2 ContextService (org.apache.derby.iapi.services.context.ContextService)1 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)1 AccessFactory (org.apache.derby.iapi.store.access.AccessFactory)1