Example #1
0
  public void close() throws DatabaseException {

    try {
      if (dbenv != null) dbenv.close();
    } finally {
      dbenv = null;
    }
  }
Example #2
0
  public static void main(String[] args) {

    final Environment env = Environments.newInstance("data");
    try {
      final Store users =
          env.computeInTransaction(
              new TransactionalComputable<Store>() {
                @Override
                public Store compute(@NotNull final Transaction txn) {
                  return env.openStore("Users", WITH_DUPLICATES, txn);
                }
              });
      final Store emails =
          env.computeInTransaction(
              new TransactionalComputable<Store>() {
                @Override
                public Store compute(@NotNull final Transaction txn) {
                  return env.openStore("Emails", WITH_DUPLICATES, txn);
                }
              });

      if (args.length == 0) {
        listAllUsers(env, users);
        return;
      }

      if (args.length == 1 && !isHelpQuery(args[0])) {
        if (args[0].contains("@")) {
          final String email = args[0];
          listUsersBy(env, emails, email);
        } else {
          final String username = args[0];
          listUsersBy(env, users, username);
        }
        return;
      }

      if (args.length == 2) {
        registerNewUser(env, users, emails, args[0], args[1]);
        return;
      }

      System.out.println("Usage:");
      System.out.println("  Users <no params> - list all users;");
      System.out.println(
          "  Users <username | email> - list users with specified username or email;");
      System.out.println("  Users <username> <e-mail> - register new user.");

    } finally {
      env.close();
    }
  }
  @Override
  public void close() throws Exception {
    // it would be nice, if elements in the CoreRegistry implemented (Auto)Closeable

    // The StorageManager creates a thread pool (through TaskMaster)
    // which isn't closed automatically
    StorageManager storageManager = CoreRegistry.get(StorageManager.class);
    if (storageManager != null) {
      storageManager.shutdown();
    }

    CoreRegistry.clear();

    super.close();
  }
  public void tearDown() throws Exception {

    /* Close down environments in case the unit test failed so that
     * the log files can be removed.
     */
    try {
      if (env != null) {
        env.close();
        env = null;
      }
    } catch (Throwable e) {
      System.out.println("tearDown: " + e);
    }

    TestUtils.removeLogFiles("TearDown", envHome, false);
  }
    public void close() {
      if (store != null) {
        try {
          store.close();
          store = null;
        } catch (Exception e) {
          e.printStackTrace();
        }
      }

      if (env != null) {
        try {
          env.close();
          env = null;
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
  /** Test open and close of an environment. */
  public void testCacheStats() throws DatabaseException {

    EnvironmentConfig envConfig = TestUtils.initEnvConfig();
    envConfig.setTransactional(true);
    envConfig.setConfigParam(EnvironmentParams.NODE_MAX.getName(), "6");
    envConfig.setAllowCreate(true);
    env = new Environment(envHome, envConfig);
    EnvironmentStats stat = env.getStats(TestUtils.FAST_STATS);
    env.close();
    env = null;
    assertEquals(0, stat.getNCacheMiss());
    assertEquals(0, stat.getNNotResident());

    // Try to open and close again, now that the environment exists
    envConfig.setAllowCreate(false);
    envConfig.setConfigParam(EnvironmentParams.JE_LOGGING_LEVEL.getName(), "CONFIG");
    env = new Environment(envHome, envConfig);
    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setTransactional(true);
    dbConfig.setAllowCreate(true);
    Database db = env.openDatabase(null, "foo", dbConfig);
    db.put(null, new DatabaseEntry(new byte[0]), new DatabaseEntry(new byte[0]));
    Transaction txn = env.beginTransaction(null, null);
    db.put(txn, new DatabaseEntry(new byte[0]), new DatabaseEntry(new byte[0]));
    stat = env.getStats(TestUtils.FAST_STATS);
    MemoryBudget mb = DbInternal.envGetEnvironmentImpl(env).getMemoryBudget();

    assertEquals(mb.getCacheMemoryUsage(), stat.getCacheTotalBytes());
    assertEquals(mb.getLogBufferBudget(), stat.getBufferBytes());
    assertEquals(mb.getTreeMemoryUsage() + mb.getTreeAdminMemoryUsage(), stat.getDataBytes());
    assertEquals(mb.getLockMemoryUsage(), stat.getLockBytes());
    assertEquals(mb.getAdminMemoryUsage(), stat.getAdminBytes());

    assertTrue(stat.getBufferBytes() > 0);
    assertTrue(stat.getDataBytes() > 0);
    assertTrue(stat.getLockBytes() > 0);
    assertTrue(stat.getAdminBytes() > 0);

    assertEquals(
        stat.getCacheTotalBytes(),
        stat.getBufferBytes() + stat.getDataBytes() + stat.getLockBytes() + stat.getAdminBytes());

    assertEquals(12, stat.getNCacheMiss());
    assertEquals(12, stat.getNNotResident());

    /* Test deprecated getCacheDataBytes method. */
    final EnvironmentStats finalStat = stat;
    final long expectCacheDataBytes = mb.getCacheMemoryUsage() - mb.getLogBufferBudget();
    (new Runnable() {
          @Deprecated
          public void run() {
            assertEquals(expectCacheDataBytes, finalStat.getCacheDataBytes());
          }
        })
        .run();

    txn.abort();
    db.close();
    env.close();
    env = null;
  }
Example #7
0
 private void closeEnvironment() {
   myDbEnvironment.close();
 }