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;
  
 
Specifies the environment attributes that may be changed after the environment has been opened. EnvironmentMutableConfig is a parameter to Environment.setMutableConfig(com.sleepycat.je.EnvironmentMutableConfig) and is returned by Environment.getMutableConfig().

There are two types of mutable environment properties: per-environment handle properties, and environment wide properties.

Per-Environment Handle Properties

Per-environment handle properties apply only to a single Environment instance. For example, to change the default transaction commit behavior for a single environment handle, do this:

     // Specify no-sync behavior for a given handle.
     EnvironmentMutableConfig mutableConfig = myEnvHandle.getMutableConfig();
     mutableConfig.setTxnNoSync(true);
     myEnvHandle.setMutableConfig(mutableConfig);
 

The per-environment handle properties are listed below. These properties are accessed using the setter and getter methods listed, as shown in the example above.

Environment-Wide Mutable Properties

Environment-wide mutable properties are those that can be changed for an environment as a whole, irrespective of which environment instance (for the same physical environment) is used. For example, to stop the cleaner daemon thread, do this:

     // Stop the cleaner daemon thread for the environment.
     EnvironmentMutableConfig mutableConfig = myEnvHandle.getMutableConfig();
     mutableConfig.setConfigParam("je.env.runCleaner", "false");
     myEnvHandle.setMutableConfig(mutableConfig);
 

The environment-wide mutable properties are listed below. These properties are accessed using the setConfigParam(java.lang.String,java.lang.String) and getConfigParam(java.lang.String) methods, as shown in the example above, using the property names listed below. In some cases setter and getter methods are also available.

Getting the Current Environment Properties

To get the current "live" properties of an environment after constructing it or changing its properties, you must call Environment.getConfig() or Environment.getMutableConfig(). The original EnvironmentConfig or EnvironmentMutableConfig object used to set the properties is not kept up to date as properties are changed, and does not reflect property validation or properties that are computed.

See also:
EnvironmentConfig
 
 public class EnvironmentMutableConfig implements CloneableSerializable {
     private static final long serialVersionUID = 1L;
 
     /*
      * Change copyHandlePropsTo and Environment.copyToHandleConfig when adding
      * fields here.
      */
     private boolean txnNoSync = false;
     private boolean txnWriteNoSync = false;

    

Hidden:
Cache size is a category of property that is calculated within the environment. It is only supplied when returning the cache size to the application and never used internally; internal code directly checks with the MemoryBudget class;
    protected long cacheSize;

    

Hidden:
Note that in the implementation we choose not to extend Properties in order to keep the configuration type safe.
    protected Properties props;

    
For unit testing, to prevent loading of je.properties.
    private transient boolean loadPropertyFile = true;

    
Internal boolean that says whether or not to validate params. Setting it to false means that parameter value validatation won't be performed during setVal() calls. Only should be set to false by unit tests using DbInternal.
    transient boolean validateParams = true;
    private transient ExceptionListener exceptionListener = null;
    private CacheMode cacheMode;

    

Hidden:
Avoid doc build errors.
    private CacheModeStrategy cacheModeStrategy;

    
An instance created using the default constructor is initialized with the system's default settings.
    public EnvironmentMutableConfig() {
         = new Properties();
    }

    
Used by EnvironmentConfig to construct from properties.
        throws IllegalArgumentException {
        DbConfigManager.validateProperties(properties,
                                           false,  // isRepConfigInstance
                                           getClass().getName());
        /* For safety, copy the passed in properties. */
         = new Properties();
        .putAll(properties);
    }

    
Configures the database environment for asynchronous transactions.

Deprecated:
replaced by setDurability(com.sleepycat.je.Durability)
Parameters:
noSync If true, do not write or synchronously flush the log on transaction commit. This means that transactions exhibit the ACI (Atomicity, Consistency, and Isolation) properties, but not D (Durability); that is, database integrity is maintained, but if the JVM or operating system fails, it is possible some number of the most recently committed transactions may be undone during recovery. The number of transactions at risk is governed by how many updates fit into a log buffer, how often the operating system flushes dirty buffers to disk, and how often the database environment is checkpointed.

This attribute is false by default for this class and for the database environment.

    public EnvironmentMutableConfig setTxnNoSync(boolean noSync) {
        setTxnNoSyncVoid(noSync);
        return this;
    }
    
    

Hidden:
The void return setter for use by Bean editors.
    public void setTxnNoSyncVoid(boolean noSync) {
        TransactionConfig.checkMixedMode
            (falsenoSyncgetDurability());
         = noSync;
    }

    
Returns true if the database environment is configured for asynchronous transactions.

Deprecated:
replaced by getDurability()
Returns:
true if the database environment is configured for asynchronous transactions.
    public boolean getTxnNoSync() {
        return ;
    }

    
Configures the database environment for transactions which write but do not flush the log.

Deprecated:
replaced by setDurability(com.sleepycat.je.Durability)
Parameters:
writeNoSync If true, write but do not synchronously flush the log on transaction commit. This means that transactions exhibit the ACI (Atomicity, Consistency, and Isolation) properties, but not D (Durability); that is, database integrity is maintained, but if the operating system fails, it is possible some number of the most recently committed transactions may be undone during recovery. The number of transactions at risk is governed by how often the operating system flushes dirty buffers to disk, and how often the database environment is checkpointed.

The motivation for this attribute is to provide a transaction that has more durability than asynchronous (nosync) transactions, but has higher performance than synchronous transactions.

This attribute is false by default for this class and for the database environment.

    public EnvironmentMutableConfig setTxnWriteNoSync(boolean writeNoSync) {
        setTxnWriteNoSyncVoid(writeNoSync);
        return this;
    }
    
    

Hidden:
The void return setter for use by Bean editors.
    public void setTxnWriteNoSyncVoid(boolean writeNoSync) {
        TransactionConfig.checkMixedMode
            (falsewriteNoSyncgetDurability());
         = writeNoSync;
    }

    
Returns true if the database environment is configured for transactions which write but do not flush the log.

Deprecated:
replaced by getDurability()
Returns:
true if the database environment is configured for transactions which write but do not flush the log.
    public boolean getTxnWriteNoSync() {
        return ;
    }

    
Configures the durability associated with transactions.

Equivalent to setting the je.txn.durability property in the je.properties file.

Parameters:
durability the new durability definition
Returns:
this
See also:
Durability
    public EnvironmentMutableConfig setDurability(Durability durability) {
        setDurabilityVoid(durability);
        return this;
    }
    
    

Hidden:
The void return setter for use by Bean editors.
    public void setDurabilityVoid(Durability durability) {
        TransactionConfig.checkMixedMode
            (falsedurability);
        if (durability == null) {
        } else {
            DbConfigManager.setVal(.,
                                   durability.toString(),
                                   );
        }
    }

    
Returns the durability associated with the configuration.

Returns:
the durability setting currently associated with this config.
    public Durability getDurability() {
        String value = DbConfigManager.getVal(,
                                              .);
        return Durability.parse(value);
    }

    
Configures the memory available to the database system, in bytes.

Equivalent to setting the je.maxMemory property in the je.properties file. The system will evict database objects when it comes within a prescribed margin of the limit.

By default, JE sets the cache size to:

(je.maxMemoryPercent * JVM maximum memory) / 100

where JVM maximum memory is specified by the JVM -Xmx flag. However, calling setCacheSize() with a non-zero value overrides the percentage based calculation and sets the cache size explicitly.

Note that the log buffer cache may be cleared if the cache size is changed after the environment has been opened.

If setSharedCache(true) is called, setCacheSize and setCachePercent specify the total size of the shared cache, and changing these parameters will change the size of the shared cache.

To take full advantage of JE cache memory, it is strongly recommended that compressed oops (-XX:+UseCompressedOops) is specified when a 64-bit JVM is used and the maximum heap size is less than 32 GB. As described in the referenced documentation, compressed oops is sometimes the default JVM mode even when it is not explicitly specified in the Java command. However, if compressed oops is desired then it must be explicitly specified in the Java command when running DbCacheSize or a JE application. If it is not explicitly specified then JE will not aware of it, even if it is the JVM default setting, and will not take it into account when calculating cache memory sizes.

Parameters:
totalBytes The memory available to the database system, in bytes.
Returns:
this
Throws:
java.lang.IllegalArgumentException if an invalid parameter is specified.
    public EnvironmentMutableConfig setCacheSize(long totalBytes)
        throws IllegalArgumentException {
        setCacheSizeVoid(totalBytes);
        return this;
    }
    
    

Hidden:
The void return setter for use by Bean editors.
    public void setCacheSizeVoid(long totalBytes)
        throws IllegalArgumentException {
        DbConfigManager.setVal(.,
                               Long.toString(totalBytes), );
    }

    
Returns the memory available to the database system, in bytes. A valid value is only available if this EnvironmentConfig object has been returned from Environment.getConfig();

Returns:
The memory available to the database system, in bytes.
    public long getCacheSize() {
        /*
         * CacheSize is filled in from the EnvironmentImpl by way of
         * fillInEnvironmentGeneratedProps.
         */
        return ;
    }

    

By default, JE sets its cache size proportionally to the JVM memory. This formula is used:

         je.maxMemoryPercent *  JVM maximum memory
 

where JVM maximum memory is specified by the JVM -Xmx flag. setCachePercent() specifies the percentage used and is equivalent to setting the je.maxMemoryPercent property in the je.properties file.

Calling setCacheSize() with a non-zero value overrides the percentage based calculation and sets the cache size explicitly.

Note that the log buffer cache may be cleared if the cache size is changed after the environment has been opened.

If setSharedCache(true) is called, setCacheSize and setCachePercent specify the total size of the shared cache, and changing these parameters will change the size of the shared cache.

To take full advantage of JE cache memory, it is strongly recommended that compressed oops (-XX:+UseCompressedOops) is specified when a 64-bit JVM is used and the maximum heap size is less than 32 GB. As described in the referenced documentation, compressed oops is sometimes the default JVM mode even when it is not explicitly specified in the Java command. However, if compressed oops is desired then it must be explicitly specified in the Java command when running DbCacheSize or a JE application. If it is not explicitly specified then JE will not aware of it, even if it is the JVM default setting, and will not take it into account when calculating cache memory sizes.

Parameters:
percent The percent of JVM memory to allocate to the JE cache.
Returns:
this
Throws:
java.lang.IllegalArgumentException if an invalid parameter is specified.
    public EnvironmentMutableConfig setCachePercent(int percent)
        throws IllegalArgumentException {
        setCachePercentVoid(percent);
        return this;
    }
    
    

Hidden:
The void return setter for use by Bean editors.
    public void setCachePercentVoid(int percent)
        throws IllegalArgumentException {
        DbConfigManager.setIntVal(.,
                                  percent);
    }

    
Returns the percentage value used in the JE cache size calculation.

Returns:
the percentage value used in the JE cache size calculation.
    public int getCachePercent() {
        return DbConfigManager.getIntVal(,
                                         .);
    }

    
Sets the exception listener for an Environment. The listener is called when a daemon thread throws an exception, in order to provide a notification mechanism for these otherwise asynchronous exceptions. Daemon thread exceptions are also printed through stderr.

Not all daemon exceptions are fatal, and the application bears responsibility for choosing how to respond to the notification. Since exceptions may repeat, the application should also choose how to handle a spate of exceptions. For example, the application may choose to act upon each notification, or it may choose to batch up its responses by implementing the listener so it stores exceptions, and only acts when a certain number have been received.

Parameters:
exceptionListener the callback to be executed when an exception occurs.
Returns:
this
        setExceptionListener(ExceptionListener exceptionListener) {
        setExceptionListenerVoid(exceptionListener);
        return this;
    }
    
    

Hidden:
The void return setter for use by Bean editors.
    public void setExceptionListenerVoid(ExceptionListener exceptionListener) {
        this. = exceptionListener;
    }

    
Returns the exception listener, if set.
        return ;
    }

    
Sets the default CacheMode used for operations performed in this environment. The default cache mode may be overridden on a per-database basis using DatabaseConfig.setCacheMode(com.sleepycat.je.CacheMode), and on a per-record or per-operation basis using Cursor.setCacheMode(com.sleepycat.je.CacheMode).

Parameters:
cacheMode is the default CacheMode used for operations performed in this environment. If null is specified, CacheMode.DEFAULT will be used.
Since:
4.0.97
See also:
CacheMode for further details.
    public EnvironmentMutableConfig setCacheMode(final CacheMode cacheMode) {
        setCacheModeVoid(cacheMode);
        return this;
    }
    
    

Hidden:
The void return setter for use by Bean editors.
    public void setCacheModeVoid(final CacheMode cacheMode) {
        this. = cacheMode;
    }

    
Returns the default CacheMode used for operations performed in this environment, or null if CacheMode.DEFAULT is used.

Returns:
the default CacheMode used for operations performed on this database, or null if CacheMode.DEFAULT is used.
Since:
4.0.97
See also:
setCacheMode(com.sleepycat.je.CacheMode)
    public CacheMode getCacheMode() {
        return ;
    }

    

Parameters:
strategy is the CacheModeStrategy used for operations performed in this environment. If null is specified, then no environment default will be available.
Since:
4.0.97
See also:
CacheModeStrategy for further details.
Hidden:
For internal use only. Sets the default CacheModeStrategy used for operations performed in this environment.
    public EnvironmentMutableConfig 
        setCacheModeStrategy(final CacheModeStrategy strategy) {
        setCacheModeStrategyVoid(strategy);
        return this;
    }
    
    

Hidden:
The void return setter for use by Bean editors.
    public void setCacheModeStrategyVoid(final CacheModeStrategy strategy) {
         = strategy;
    }

    

Returns:
the default CacheModeStrategy used for operations performed in this environment, or null if the no environment default is available.
Since:
4.0.97
See also:
setCacheModeStrategy(com.sleepycat.je.CacheModeStrategy)
Hidden:
For internal use only. Returns the default CacheModeStrategy used for operations performed in this environment, or null if the no environment default is available.
        return ;
    }

    
Set this configuration parameter. First validate the value specified for the configuration parameter; if it is valid, the value is set in the configuration.

Parameters:
paramName the configuration parameter name, one of the String constants in this class
value The configuration value
Returns:
this
Throws:
java.lang.IllegalArgumentException if the paramName or value is invalid.
                                                   String value)
        throws IllegalArgumentException {
        DbConfigManager.setConfigParam(,
                                       paramName,
                                       value,
                                       true/* require mutability. */
                                       ,
                                       false /* forReplication */,
                                       true  /* verifyForReplication */);
        return this;
    }

    
Returns the value for this configuration parameter.

Parameters:
paramName a valid configuration parameter, one of the String constants in this class.
Returns:
the configuration value.
Throws:
java.lang.IllegalArgumentException if the paramName is invalid.
    public String getConfigParam(String paramName)
        throws IllegalArgumentException {
       return DbConfigManager.getConfigParam(paramName);
    }

    

Hidden:
For internal use only.
    public boolean isConfigParamSet(String paramName) {
        return .containsKey(paramName);
    }
    /*
     * Helpers
     */
    void setValidateParams(boolean validateParams) {
        this. = validateParams;
    }

    

Hidden:
Used by unit tests.
    boolean getValidateParams() {
        return ;
    }

    
Checks that the immutable values in the environment config used to open an environment match those in the config object saved by the underlying shared EnvironmentImpl.

Parameters:
handleConfigProps are the config property values that were specified by configuration object from the Environment.
    void checkImmutablePropsForEquality(Properties handleConfigProps)
        throws IllegalArgumentException {
        Iterator<Stringiter =
        while (iter.hasNext()) {
            String paramName = iter.next();
            ConfigParam param =
                ..get(paramName);
            assert param != null;
            if (!param.isMutable() && !param.isForReplication()) {
                String paramVal = .getProperty(paramName);
                String useParamVal = handleConfigProps.getProperty(paramName);
                if ((paramVal != null) ?
                    (!paramVal.equals(useParamVal)) :
                    (useParamVal != null)) {
                    throw new IllegalArgumentException
                        (paramName + " is set to " +
                         useParamVal +
                         " in the config parameter" +
                         " which is incompatible" +
                         " with the value of " +
                         paramVal + " in the" +
                         " underlying environment");
                }
            }
        }
    }

    

Hidden:
For internal use only. Overrides Object.clone() to clone all properties, used by this class and EnvironmentConfig.
    @Override
    protected EnvironmentMutableConfig clone() {
        try {
            EnvironmentMutableConfig copy =
                (EnvironmentMutableConfigsuper.clone();
            copy.props = (Properties.clone();
            return copy;
        } catch (CloneNotSupportedException willNeverOccur) {
            return null;
        }
    }

    
Used by Environment to create a copy of the application supplied configuration. Done this way to provide non-public cloning.
        /* Remove all immutable properties. */
        copy.clearImmutableProps();
        return copy;
    }

    
Copies the per-handle properties of this object to the given config object.
        other.txnNoSync = ;
        other.txnWriteNoSync = ;
        other.setDurability(getDurability());
    }

    
Copies all mutable props to the given config object. Unchecked suppress here because Properties don't play well with generics in Java 1.5
    @SuppressWarnings("unchecked")
        Properties toProps = toConfig.props;
        Enumeration propNames = .propertyNames();
        while (propNames.hasMoreElements()) {
            String paramName = (StringpropNames.nextElement();
            ConfigParam param =
                ..get(paramName);
            assert param != null;
            if (param.isMutable()) {
                String newVal = .getProperty(paramName);
                toProps.setProperty(paramNamenewVal);
            }
        }
        toConfig.exceptionListener = this.;
        toConfig.cacheMode = this.;
        toConfig.cacheModeStrategy = this.;
    }

    
Fills in the properties calculated by the environment to the given config object.
         = envImpl.getMemoryBudget().getMaxMemory();
    }

   
Removes all immutable props. Unchecked suppress here because Properties don't play well with generics in Java 1.5
    @SuppressWarnings("unchecked")
    private void clearImmutableProps() {
        Enumeration propNames = .propertyNames();
        while (propNames.hasMoreElements()) {
            String paramName = (StringpropNames.nextElement();
            ConfigParam param =
                ..get(paramName);
            assert param != null;
            if (!param.isMutable()) {
                .remove(paramName);
            }
        }
    }
    Properties getProps() {
        return ;
    }

    
For unit testing, to prevent loading of je.properties.
    void setLoadPropertyFile(boolean loadPropertyFile) {
        this. = loadPropertyFile;
    }

    
For unit testing, to prevent loading of je.properties.
    boolean getLoadPropertyFile() {
        return ;
    }

    
Testing support

Hidden:
    public int getNumExplicitlySetParams() {
        return .size();
    }

    
Display configuration values.
    @Override
    public String toString() {
        return ("cacheSize=" +  + "\n" +
                "txnNoSync=" +  + "\n" +
                "txnWriteNoSync=" +  + "\n" +
                .toString() + "\n");
    }
New to GrepCode? Check out our FAQ X