当前位置: 首页>>代码示例>>Java>>正文


Java Environment.close方法代码示例

本文整理汇总了Java中com.sleepycat.je.Environment.close方法的典型用法代码示例。如果您正苦于以下问题:Java Environment.close方法的具体用法?Java Environment.close怎么用?Java Environment.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sleepycat.je.Environment的用法示例。


在下文中一共展示了Environment.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: UpdateGroundhogScript

import com.sleepycat.je.Environment; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public UpdateGroundhogScript(File datadir) throws DatabaseException {
  environmentConfig = new EnvironmentConfig();
  environmentConfig.setAllowCreate(true);
  environmentConfig.setTransactional(true);
  environmentConfig.setCacheSize(302400000);

  // perform other environment configurations

  environment = new Environment(datadir, environmentConfig);
  List<String> names = environment.getDatabaseNames();
  if (names.contains(datadir.getName())) {
    environment.renameDatabase(null, datadir.getName(), databaseName);
  }
  environment.close();
}
 
开发者ID:BiosemanticsDotOrg,项目名称:GeneDiseasePaper,代码行数:17,代码来源:UpdateGroundhogScript.java

示例2: testLesserVersionNotUpdated

import com.sleepycat.je.Environment; //导入方法依赖的package包/类
/**
 * Tests that when a file is opened with a lesser version than the current
 * version, a new log file is started for writing new log entries.  This is
 * important so that the new header version is written even if no new log
 * file is needed.  If the new version were not written, an older version
 * of JE would not recognize that there had been a version change.
 */
public void testLesserVersionNotUpdated()
    throws DatabaseException, IOException {

    TestUtils.loadLog(getClass(), Utils.MIN_VERSION_NAME, envHome);
    File logFile = new File(envHome, TestUtils.LOG_FILE_NAME);
    long origFileSize = logFile.length();

    EnvironmentConfig envConfig = TestUtils.initEnvConfig();
    envConfig.setAllowCreate(false);
    envConfig.setTransactional(true);

    Environment env = new Environment(envHome, envConfig);
    env.sync();
    env.close();

    assertEquals(origFileSize, logFile.length());
}
 
开发者ID:nologic,项目名称:nabs,代码行数:25,代码来源:LogHeaderVersionTest.java

示例3: testEmptyDatabaseSR14744

import com.sleepycat.je.Environment; //导入方法依赖的package包/类
public void testEmptyDatabaseSR14744()
throws Throwable {

Database db = null;
try {
    EnvironmentConfig envConfig = getEnvConfig(true);
    env = new Environment(envHome, envConfig);
    db = createDb(true);
    db.sync();
       } finally {
           if (db != null) {
               db.close();
           }

           env.sync();
           env.close();
           env = null;
       }
   }
 
开发者ID:nologic,项目名称:nabs,代码行数:20,代码来源:DeferredWriteTest.java

示例4: testGreaterVersionNotAllowed

import com.sleepycat.je.Environment; //导入方法依赖的package包/类
/**
 * Tests that an exception is thrown when a log header is read with a newer
 * version than the current version.  The maxversion.jdb log file is loaded
 * as a resource by this test and written as a regular log file.  When the
 * environment is opened, we expect a LogException.
 */
public void testGreaterVersionNotAllowed()
    throws DatabaseException, IOException {

    TestUtils.loadLog(getClass(), Utils.MAX_VERSION_NAME, envHome);

    EnvironmentConfig envConfig = TestUtils.initEnvConfig();
    envConfig.setAllowCreate(false);
    envConfig.setTransactional(true);

    try {
        Environment env = new Environment(envHome, envConfig);
        try {
            env.close();
        } catch (Exception ignore) {}
    } catch (DatabaseException e) {
        if (e.getCause() instanceof LogException) {
            /* Got LogException as expected. */
            return;
        }
    }
    fail("Expected LogException");
}
 
开发者ID:nologic,项目名称:nabs,代码行数:29,代码来源:LogHeaderVersionTest.java

示例5: testBadLog

import com.sleepycat.je.Environment; //导入方法依赖的package包/类
/**
 * Tests that we can load a log file containing offsets that correspond to
 * non-obsolete LNs.  The bad log file was created using testBasic run
 * against JE 2.0.54.  It contains version 1 FSLNs, one of which has an
 * offset which is not obsolete.
 */
public void testBadLog()
    throws DatabaseException, IOException {

    /* Copy a log file with bad offsets to log file zero. */
    String resName = "rmw_bad_offsets.jdb";
    TestUtils.loadLog(getClass(), resName, envHome);

    /* Open the log we just copied. */
    EnvironmentConfig envConfig = TestUtils.initEnvConfig();
    envConfig.setAllowCreate(false);
    envConfig.setReadOnly(true);
    env = new Environment(envHome, envConfig);

    /*
     * Verify the UP of the bad log.  Prior to adding the code in
     * FileSummaryLN.postFetchInit that discards version 1 offsets, this
     * assertion failed.
     */
    UtilizationProfile up =
        DbInternal.envGetEnvironmentImpl(env).getUtilizationProfile();
    assertTrue(up.verifyFileSummaryDatabase());

    env.close();
    env = null;
}
 
开发者ID:nologic,项目名称:nabs,代码行数:32,代码来源:RMWLockingTest.java

示例6: putPerformanceTest

import com.sleepycat.je.Environment; //导入方法依赖的package包/类
public void putPerformanceTest() {
  final int numEntries = 5000;
  final int minEntrySize = 50;
  final int maxEntrySize = 1000;
  final Random random = new Random();
  
  File dbDir = createDbDir("putPerformanceTest");
  Environment dbEnvironment = BerkeleyDBViewComputationCacheSource.constructDatabaseEnvironment(dbDir, false);
  
  BerkeleyDBBinaryDataStore dataStore = new BerkeleyDBBinaryDataStore(dbEnvironment, "putPerformanceTest");
  dataStore.start();
  
  OperationTimer timer = new OperationTimer(s_logger, "Writing {} entries", numEntries);
  
  int randRange = maxEntrySize - minEntrySize;
  for (int i = 0; i < numEntries; i++) {
    int nBytes = minEntrySize + random.nextInt(randRange);
    byte[] bytes = new byte[nBytes];
    random.nextBytes(bytes);
    dataStore.put(i, bytes);
  }
  
  long numMillis = timer.finished();

  double msPerPut = ((double) numMillis) / ((double) numEntries);
  double putsPerSecond = 1000.0 / msPerPut;
  
  s_logger.info("for {} entries, {} ms/put, {} puts/sec", new Object[] {numEntries, msPerPut, putsPerSecond});
  
  dataStore.delete();
  dataStore.stop();
  dbEnvironment.close();
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:34,代码来源:BerkeleyDBValueSpecificationIdentifierBinaryDataStoreTest.java

示例7: reloadPreservesMaxValue

import com.sleepycat.je.Environment; //导入方法依赖的package包/类
@Test
public void reloadPreservesMaxValue() throws IOException {
  File dbDir = createDbDir("reloadPreservesMaxValue");
  Environment dbEnvironment = createDbEnvironment(dbDir);
  FudgeContext fudgeContext = OpenGammaFudgeContext.getInstance();

  BerkeleyDBIdentifierMap idSource = new BerkeleyDBIdentifierMap(dbEnvironment, fudgeContext);
  idSource.start();
  String valueName = "value-5";
  ValueSpecification valueSpec = getValueSpec(valueName);
  long initialIdentifier = idSource.getIdentifier(valueSpec);

  // Cycle everything to simulate a clean shutdown and restart.
  idSource.stop();
  dbEnvironment.close();
  dbEnvironment = createDbEnvironment(dbDir);
  idSource = new BerkeleyDBIdentifierMap(dbEnvironment, fudgeContext);
  idSource.start();

  // Check we get the same thing back.
  valueName = "value-5";
  valueSpec = getValueSpec(valueName);
  long identifier = idSource.getIdentifier(valueSpec);
  assertEquals(initialIdentifier, identifier);

  // Check that the next one is the previous max + 1
  valueName = "value-99999";
  valueSpec = getValueSpec(valueName);
  identifier = idSource.getIdentifier(valueSpec);
  assertEquals(initialIdentifier + 1, identifier);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:32,代码来源:BerkeleyDBValueIdentifierMapTest.java

示例8: UpdataIntegerSetStoreScript

import com.sleepycat.je.Environment; //导入方法依赖的package包/类
public UpdataIntegerSetStoreScript(File datadir) throws DatabaseException {
  environmentConfig = new EnvironmentConfig();
  environmentConfig.setAllowCreate(true);
  environmentConfig.setTransactional(true);
  environmentConfig.setCacheSize(302400000);

  // perform other environment configurations

  environment = new Environment(datadir, environmentConfig);
  List<String> names = environment.getDatabaseNames();
  if (names.contains(datadir.getName())) {
    environment.renameDatabase(null, datadir.getName(), databaseName);
  }
  environment.close();
}
 
开发者ID:BiosemanticsDotOrg,项目名称:GeneDiseasePaper,代码行数:16,代码来源:UpdataIntegerSetStoreScript.java

示例9: testRemoveNonPersistentDbSR15317

import com.sleepycat.je.Environment; //导入方法依赖的package包/类
/**
    * Check that all INs are removed from the INList for a DB that is removed
    * before it is sync'ed (or checkpointed).  Before the bug fix, INs were
    * not removed if the DB root IN was never logged (was still null).  This
    * caused a DatabaseException when evicting, because the evictor expects no
    * INs for deleted DBs on the INList.
    */
   public void testRemoveNonPersistentDbSR15317()
throws Throwable {

Database db = null;
try {
    EnvironmentConfig envConfig = getEnvConfig(true);
           /* Disable compressor for test predictability. */
           envConfig.setConfigParam("je.env.runINCompressor", "false");
    env = new Environment(envHome, envConfig);
    db = createDb(true);
           /* Insert some data to cause eviction later. */
           insert(db, 
                  null,          // txn
                  1,             // start
                  30000,         // end
                  new HashSet(), // expected
                  false);        // useRandom
           db.close();
           env.removeDatabase(null, DBNAME);

           envConfig = env.getConfig();
           /* Switch to a small cache to force eviction. */
           envConfig.setCacheSize(96 * 1024);
           env.setMutableConfig(envConfig);
           for (int i = 0; i < 10; i += 1) {
               env.evictMemory();
           }
       } finally {
           if (env != null) {
               try {
                   env.close();
               } catch (Throwable e) {
                   System.out.println("Ignored: " + e);
               }
               env = null;
           }
       }
   }
 
开发者ID:nologic,项目名称:nabs,代码行数:46,代码来源:DeferredWriteTest.java

示例10: xtestReadOnly

import com.sleepycat.je.Environment; //导入方法依赖的package包/类
public void xtestReadOnly()
    throws Exception {

    /* Make a read-only handle on a read-write environment directory.*/
    Environment env = createEnv(true, envHome);

    try {
        DbBackup backup = new DbBackup(env);
        fail("Should fail because env is read/only.");
    } catch (DatabaseException expected) {
    }

    env.close();

    /*
     * Make a read-only handle on a read-only environment directory. Use a
     * new environment directory because we're going to set it read0nly and
     * there doesn't seem to be a way of undoing that.
     */
    File tempEnvDir = new File(envHome, SAVE1);
    assertTrue(tempEnvDir.mkdirs());
    env = createEnv(false, tempEnvDir);
    growFiles("db1", env, 8);
    env.close();
    //assertTrue(tempEnvDir.setReadOnly());

    env = createEnv(true, tempEnvDir);

    DbBackup backupHelper = new DbBackup(env);
    backupHelper.startBackup();

    FileManager fileManager =
        DbInternal.envGetEnvironmentImpl(env).getFileManager();
    long lastFile = fileManager.getLastFileNum().longValue();
    assertEquals(lastFile, backupHelper.getLastFileInBackupSet());

    backupHelper.endBackup();
    env.close();
    assertTrue(tempEnvDir.delete());
}
 
开发者ID:nologic,项目名称:nabs,代码行数:41,代码来源:DbBackupTest.java

示例11: run

import com.sleepycat.je.Environment; //导入方法依赖的package包/类
public void run(File envHomeDirectory)
    throws DatabaseException, IOException {

    /* Create the environment object. */
    EnvironmentConfig envConfig = new EnvironmentConfig();
    envConfig.setAllowCreate(true);
    Environment env = new Environment(envHomeDirectory, envConfig);

    /* Create the database object. */
    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setAllowCreate(true);
    Database db = env.openDatabase(null, DB_NAME, dbConfig);

    /* Create the sequence oject. */
    SequenceConfig config = new SequenceConfig();
    config.setAllowCreate(true);
    DatabaseEntry key =
        new DatabaseEntry(KEY_NAME.getBytes("UTF-8"));
    Sequence seq = db.openSequence(null, key, config);

    /* Allocate a few sequence numbers. */
    for (int i = 0; i < 10; i++) {
        long seqnum = seq.get(null, 1);
        System.out.println("Got sequence number: " + seqnum);
    }

    /* Close all. */
    seq.close();
    db.close();
    env.close();
}
 
开发者ID:nologic,项目名称:nabs,代码行数:32,代码来源:SequenceExample.java

示例12: testDefaults

import com.sleepycat.je.Environment; //导入方法依赖的package包/类
public void testDefaults()
       throws Exception {

       EnvironmentConfig envConfig = TestUtils.initEnvConfig();
       envConfig.setAllowCreate(true);
       Environment env = new Environment(envHome, envConfig);
       EnvironmentImpl envImpl = DbInternal.envGetEnvironmentImpl(env);
       MemoryBudget testBudget = envImpl.getMemoryBudget();

/*
       System.out.println("max=    " + testBudget.getMaxMemory());
       System.out.println("tree=   " + testBudget.getCacheBudget());
       System.out.println("log=    " + testBudget.getLogBufferBudget());
       System.out.println("thresh= " + testBudget.getEvictorCheckThreshold());
*/

       assertTrue(testBudget.getMaxMemory() > 0);
       assertTrue(testBudget.getCacheBudget() > 0);
       assertTrue(testBudget.getLogBufferBudget() > 0);

       assertTrue(testBudget.getMaxMemory() <=
                  MemoryBudget.getRuntimeMaxMemory());
       assertTrue((testBudget.getLogBufferBudget() +
                   testBudget.getCacheBudget()) <=
                   testBudget.getMaxMemory());

       /*
        * The tree and log buffer budget together is equal to
        * the max memory budget.
        */
       assertEquals((testBudget.getCacheBudget() +
                     testBudget.getLogBufferBudget()),
                     testBudget.getMaxMemory());

       env.close();
   }
 
开发者ID:nologic,项目名称:nabs,代码行数:37,代码来源:MemoryBudgetTest.java

示例13: testOpenableBean

import com.sleepycat.je.Environment; //导入方法依赖的package包/类
/**
 * MBean which can configure and open an environment.
 */
public void testOpenableBean()
    throws Throwable {

    Environment env = null;
    try {
        /* Environment is not open, and we can open. */
        env = openEnv(false);
        env.close();

        DynamicMBean mbean = new JEApplicationMBean(environmentDir);
        validateGetters(mbean, 5);
        validateOperations(mbean, 1, false, null, null); // don't invoke

        /* Open the environment. */
        mbean.invoke(JEApplicationMBean.OP_OPEN, null, null);

        validateGetters(mbean, 7 );
        validateOperations(mbean, 8, true, null, null);

        /*
         * The last call to validateOperations ended up closing the
         * environment.
         */
        validateGetters(mbean, 5);
        validateOperations(mbean, 1, false, null, null);

        /* Should be no open handles. */
        checkForNoOpenHandles(environmentDir);
    } catch (Throwable t) {
        t.printStackTrace();

        if (env != null) {
            env.close();
        }
        throw t;
    }
}
 
开发者ID:nologic,项目名称:nabs,代码行数:41,代码来源:MBeanTest.java

示例14: testDbLookup

import com.sleepycat.je.Environment; //导入方法依赖的package包/类
public void testDbLookup() throws Throwable {
    try {
        EnvironmentConfig envConfig = TestUtils.initEnvConfig();
        envConfig.setTransactional(true);
        envConfig.setConfigParam(EnvironmentParams.NODE_MAX.getName(), "6");
        envConfig.setAllowCreate(true);
        Environment env = new Environment(envHome, envConfig);

        // Make two databases
        DatabaseConfig dbConfig = new DatabaseConfig();
        dbConfig.setTransactional(true);
        dbConfig.setAllowCreate(true);
        Database dbHandleAbcd = env.openDatabase(null, "abcd", dbConfig);
        Database dbHandleXyz = env.openDatabase(null, "xyz", dbConfig);

        // Can we get them back?
        dbConfig.setAllowCreate(false);
        Database newAbcdHandle = env.openDatabase(null, "abcd", dbConfig);
        Database newXyzHandle = env.openDatabase(null, "xyz", dbConfig);

        dbHandleAbcd.close();
        dbHandleXyz.close();
        newAbcdHandle.close();
        newXyzHandle.close();
        env.close();
    } catch (Throwable t) {
        t.printStackTrace();
        throw t;
    }
}
 
开发者ID:nologic,项目名称:nabs,代码行数:31,代码来源:DbTreeTest.java

示例15: main

import com.sleepycat.je.Environment; //导入方法依赖的package包/类
public static void main(String[] args)
    throws Exception {

    if (args.length != 1) {
        throw new Exception("Home directory arg is required.");
    }

    File homeDir = new File(args[0]);
    File logFile = new File(homeDir, TestUtils.LOG_FILE_NAME);

    if (logFile.exists()) {
        throw new Exception("Home directory must be empty of log files.");
    }

    EnvironmentConfig envConfig = TestUtils.initEnvConfig();
    envConfig.setAllowCreate(true);
    envConfig.setTransactional(true);
    /* Make as small a log as possible to save space in CVS. */
    envConfig.setConfigParam
        (EnvironmentParams.JE_LOGGING_LEVEL.getName(),
         Level.OFF.getName());
    envConfig.setConfigParam
        (EnvironmentParams.ENV_RUN_INCOMPRESSOR.getName(), "false");
    envConfig.setConfigParam
        (EnvironmentParams.ENV_RUN_CLEANER.getName(), "false");
    envConfig.setConfigParam
        (EnvironmentParams.ENV_RUN_EVICTOR.getName(), "false");
    envConfig.setConfigParam
        (EnvironmentParams.ENV_RUN_CHECKPOINTER.getName(), "false");

    Environment env = new Environment(homeDir, envConfig);
    env.close();

    if (!logFile.exists()) {
        throw new Exception("Home directory does not contain: " + logFile);
    }

    System.out.println("Sucessfully created: " + logFile);
}
 
开发者ID:nologic,项目名称:nabs,代码行数:40,代码来源:MakeLogHeaderVersionData.java


注:本文中的com.sleepycat.je.Environment.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。