Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * See the file LICENSE for redistribution information.
   *
   * Copyright (c) 2002, 2013 Oracle and/or its affiliates.  All rights reserved.
   *
   */
  
  package com.sleepycat.je;
  
Indicates that a failure has occurred that could impact the Environment as a whole. For failures that impact only the current operation and/or transaction, see OperationFailureException). For an overview of all exceptions thrown by JE, see DatabaseException.

Depending on the nature of the failure, this exception may indicate that Environment.close() must be called. The application should catch EnvironmentFailureException and then call Environment.isValid(). If false is returned, all Environment handles (instances) must be closed and re-opened in order to run recovery and continue operating. If true is returned, the Environment can continue operating without being closed and re-opened. Also note that Environment.isValid() may be called at any time, not just during exception handling.

The use of the Environment.isValid() method allows JE to determine dynamically whether the failure requires recovery or not, and allows for this determination to change in future releases. Over time, internal improvements to error handling may allow more error conditions to be handled without invalidating the Environment.

(Although this exception class extends RunRecoveryException, it does not always indicate that recovery is necessary, as described above. RunRecoveryException has been deprecated and EnvironmentFailureException should be used instead.)

If an EnvironmentFailureException consistently occurs soon after opening the Environment, this may indicate a persistent problem. It may indicate a system problem or a persistent storage problem. In this case, human intervention is normally required and restoring from a backup may be necessary.

Note that subclasses of EnvironmentFailureException indicate how to handle the exception in more specific ways.

  • If Thread.interrupt is called for a thread performing JE operations, a ThreadInterruptedException is thrown. Since interrupting a thread is intentional, it does not indicate a persistent problem and human intervention is not normally required.
  • If an IOException occurs while writing to the JE log, a LogWriteException is thrown. Although an IOException can occur for different reasons, it is a hint that the disk may be full and applications may wish to attempt recovery after making more disk space available.
  • For replicated environments, see the subclasses of EnvironmentFailureException in the com.sleepycat.je.rep package for more information. Such exceptions may require special handling.

If Environment.close() is not called after an EnvironmentFailureException invalidates the Environment, all subsequent method calls for the Environment will throw the same exception. This provides more than one opportunity to catch and handle the specific exception subclass that caused the failure.

 
 @SuppressWarnings("deprecation")
 
     private static final long serialVersionUID = 1;
 
     private boolean alreadyThrown;
     private EnvironmentFailureReason reason;

    
Only used by makeJavaErrorWrapper.
 
     private EnvironmentFailureException(String msg) {
         super(msg);
     }

    
Only used by unexpectedState and unexpectedException.
 
                                         String message,
                                         Throwable cause) {
         this(null /*envImpl*/reasonmessagecause);
     }

    
For internal use only.

Hidden:
 
                                       EnvironmentFailureReason reason) {
        this(envImplreasonnull /*message*/null /*cause*/);
    }

    
For internal use only.

Hidden:
                                       EnvironmentFailureReason reason,
                                       Throwable cause) {
        this(envImplreasonnull /*message*/cause);
    }

    
For internal use only.

Hidden:
                                       EnvironmentFailureReason reason,
                                       String message) {
        this(envImplreasonmessagenull /*cause*/);
    }

    
For internal use only.

Hidden:
                                       EnvironmentFailureReason reason,
                                       String message,
                                       Throwable cause) {
        super(makeMsg(envImplreasonmessagecause), cause);
        if (reason.invalidatesEnvironment()) {
            assert envImpl != null;
            envImpl.invalidate(this);
        }
        this. = reason;
    }
    private static String makeMsg(EnvironmentImpl envImpl,
                                  EnvironmentFailureReason reason,
                                  String message,
                                  Throwable cause) {
        StringBuilder s = new StringBuilder(300);
        if (envImpl != null) {
            s.append(envImpl.getName()).append(" ");
        }
        if (message != null) {
            s.append(message);
            s.append(' ');
        } else if (cause != null) {
            s.append(cause.toString());
            s.append(' ');
        }
        assert reason != null;
        s.append(reason);
        /*
         * Use the current environment status for reporting in the exception
         * message.  This is more information than simply whether this
         * exception caused an invalidate, since previous exceptions may have
         * occurred.
         */
        if (reason.invalidatesEnvironment() ||
            (envImpl != null && !envImpl.isValid())) {
            s.append(" Environment is invalid and must be closed.");
        }
        return s.toString();
    }

    
For internal use only.

Hidden:
Only for use by wrapSelf methods.
    protected EnvironmentFailureException(String message,
                                          EnvironmentFailureException cause) {
        super(messagecause);
        assert cause != null;
         = cause.reason
    }

    
For internal use only.

Hidden:
Must be overridden by every concrete subclass to return an instance of its own class, constructed with the given msg and this exception as parameters, e.g.: return new MyClass(msg, this);
        assert EnvironmentFailureException.class == this.getClass() :
               "Missing overriding " + this.getClass().getName() +
               ".wrapSelf() method";
        return new EnvironmentFailureException(msgthis);
    }

    
For internal use only.

Hidden:
Remember that this was already thrown. That way, if we re-throw it because another handle uses the environment after the fatal throw, the message is more clear.
    public void setAlreadyThrown(boolean alreadyThrown) {
        this. = alreadyThrown;
    }
    @Override
    public String getMessage() {
        /*
         * Don't allocate memory after a Java Error occurs.  Note that for
         * a Java Error, addErrorMessage is never called, so super.getMessage
         * will not allocate memory either.
         */
        if ( == . || !) {
            return super.getMessage();
        }
        return "Environment invalid because of previous exception: " +
               super.getMessage();
    }

    
For internal use only.

Hidden:
        return ;
    }

    
For internal use only.

Hidden:
May ONLY be used for EnvironmentImpl.SAVED_EFE.
            (..toString());
        e.reason = .;
        return e;
    }

    
For internal use only.

Returns:
the resulting EnvironmentFailureException.
Hidden:
Promotes the given cause exception and message to an EnvironmentFailureException. If the cause is not an EnvironmentFailureException, wraps the cause exception in an EnvironmentFailureException along with the message. If the cause is an EnvironmentFailureException, adds the message to it.
    public static EnvironmentFailureException
        promote(EnvironmentImpl envImpl,
                EnvironmentFailureReason reason,
                String message,
                Throwable cause) {
        if (cause instanceof EnvironmentFailureException) {
            EnvironmentFailureException e =
                (EnvironmentFailureExceptioncause;
            e.addErrorMessage(message);
            return e;
        }
        return new EnvironmentFailureException
            (envImplreasonmessagecause);
    }

    
For internal use only.

Hidden:
Creates an exception indicating that an unexpected exception was caught internally. Used in place of an assert, when an exception is preferred. Used when the Environment should *not* be invalidated.
    public static EnvironmentFailureException
        unexpectedException(Exception cause) {
        return new EnvironmentFailureException
             null /*message*/cause);
    }

    
For internal use only.

Hidden:
Creates an exception indicating that an unexpected exception was caught internally. Used in place of an assert, when an exception is preferred. Used when the Environment *should* be invalidated.
    public static EnvironmentFailureException
        unexpectedException(EnvironmentImpl envImplException cause) {
        return new EnvironmentFailureException
            (envImpl.,
             null /*message*/cause);
    }

    
For internal use only.

Hidden:
Creates an exception indicating that an unexpected exception was caught internally. Used in place of an assert, when an exception is preferred. Used when the Environment should *not* be invalidated.
    public static EnvironmentFailureException
        unexpectedException(String messageException cause) {
        return new EnvironmentFailureException
            (.message,
             cause);
    }

    
For internal use only.

Hidden:
Creates an exception indicating that an unexpected exception was caught internally. Used in place of an assert, when an exception is preferred. Used when the Environment *should* be invalidated.
    public static EnvironmentFailureException
        unexpectedException(EnvironmentImpl envImpl,
                            String message,
                            Exception cause) {
        return new EnvironmentFailureException
            (envImpl.,
             messagecause);
    }

    
For internal use only.

Hidden:
Creates an exception indicating that unexpected internal state was detected. Used in place of an assert, when an exception is preferred. Used when the Environment should *not* be invalidated.
    public static EnvironmentFailureException unexpectedState() {
        return new EnvironmentFailureException
             null /*message*/null /*cause*/);
    }

    
For internal use only.

Hidden:
Creates an exception indicating that unexpected internal state was detected. Used in place of an assert, when an exception is preferred. Used when the Environment *should* be invalidated.
    public static EnvironmentFailureException
        unexpectedState(EnvironmentImpl envImpl) {
        return new EnvironmentFailureException
            (envImpl.,
             null /*message*/null /*cause*/);
    }

    
For internal use only.

Hidden:
Creates an exception indicating that unexpected internal state was detected. Used in place of an assert, when an exception is preferred. Used when the Environment should *not* be invalidated.
    public static EnvironmentFailureException unexpectedState(String message) {
        return new EnvironmentFailureException
            (.message,
             null /*cause*/);
    }

    
For internal use only.

Hidden:
Creates an exception indicating that unexpected internal state was detected. Used in place of an assert, when an exception is preferred. Used when the Environment *should* be invalidated.
    public static EnvironmentFailureException
        unexpectedState(EnvironmentImpl envImplString message) {
        return new EnvironmentFailureException
            (envImpl.,
             messagenull /*cause*/);
    }
New to GrepCode? Check out our FAQ X