private static void closeEnv() {
    System.out.println("Closing env and databases");
    if (myDb != null) {
      try {
        myDb.close();
      } catch (DatabaseException e) {
        System.err.println("closeEnv: myDb: " + e.toString());
        e.printStackTrace();
      }
    }

    if (myClassDb != null) {
      try {
        myClassDb.close();
      } catch (DatabaseException e) {
        System.err.println("closeEnv: myClassDb: " + e.toString());
        e.printStackTrace();
      }
    }

    if (myEnv != null) {
      try {
        myEnv.close();
      } catch (DatabaseException e) {
        System.err.println("closeEnv: " + e.toString());
        e.printStackTrace();
      }
    }
  }
 public static void main(String args[]) {
   ExampleInventoryRead eir = new ExampleInventoryRead();
   try {
     eir.run(args);
   } catch (DatabaseException dbe) {
     System.err.println("ExampleInventoryRead: " + dbe.toString());
     dbe.printStackTrace();
   } finally {
     myDbEnv.close();
   }
   System.out.println("All done.");
 }
Ejemplo n.º 3
0
  // Close the environment
  public boolean close() {
    if (m_env != null) {
      try {
        //            	StatsConfig config = new StatsConfig();
        //            	config.setClear(true);
        //            	System.err.println(m_env.getStats(config));

        // Finally, close the environment.
        m_env.close();
      } catch (DatabaseException dbe) {
        System.err.println("Error closing MyDbEnv: " + dbe.toString());
        return false;
      }
    }
    return true;
  }
Ejemplo n.º 4
0
  public void close() {

    if (myEnv != null) {
      try {
        Iterator<Entry<String, Database>> it = myDbHashHandle.entrySet().iterator();
        while (it.hasNext()) {
          Database thisDb = it.next().getValue();
          if (thisDb != null) {
            thisDb.close();
          }
        }
        myEnv.close();
      } catch (DatabaseException dbe) {
        System.err.println("Error closing Envorionment" + dbe.toString());
      }
    }
  }
  private void doClose(boolean doCheckpoint) throws DatabaseException {

    StringBuffer errors = new StringBuffer();

    try {
      // refined trace Tracer.trace(Level.FINE, this, "Close of
      // environment " + envHome + " started");

      try {
        envState.checkState(DbEnvState.VALID_FOR_CLOSE, DbEnvState.CLOSED);
      } catch (DatabaseException DBE) {
        throw DBE;
      }

      /*
       * Begin shutdown of the deamons before checkpointing. Cleaning
       * during the checkpoint is wasted and slows down the checkpoint.
       */
      requestShutdownDaemons();

      /* Checkpoint to bound recovery time. */
      if (doCheckpoint
          && !isReadOnly
          && (envState != DbEnvState.INVALID)
          && logManager.getLastLsnAtRecovery() != fileManager.getLastUsedLsn()) {

        /*
         * Force a checkpoint. Don't allow deltas (minimize recovery
         * time) because they cause inefficiencies for two reasons: (1)
         * recovering BINDeltas causes extra random I/O in order to
         * reconstitute BINS, which can greatly increase recovery time,
         * and (2) logging deltas during close causes redundant logging
         * by the full checkpoint after recovery.
         */
        CheckpointConfig ckptConfig = new CheckpointConfig();
        ckptConfig.setForce(true);
        ckptConfig.setMinimizeRecoveryTime(true);
        try {
          invokeCheckpoint(
              ckptConfig,
              false, // flushAll
              "close");
        } catch (DatabaseException IE) {
          errors.append("\nException performing checkpoint: ");
          errors.append(IE.toString()).append("\n");
        }
      }

      try {
        shutdownDaemons();
      } catch (InterruptedException IE) {
        errors.append("\nException shutting down daemon threads: ");
        errors.append(IE.toString()).append("\n");
      }

      /* Flush log. */
      // refined trace Tracer.trace(Level.FINE, this, "Env " + envHome + "
      // daemons shutdown");
      try {
        logManager.flush();
      } catch (DatabaseException DBE) {
        errors.append("\nException flushing log manager: ");
        errors.append(DBE.toString()).append("\n");
      }

      try {
        fileManager.clear();
      } catch (IOException IOE) {
        errors.append("\nException clearing file manager: ");
        errors.append(IOE.toString()).append("\n");
      } catch (DatabaseException DBE) {
        errors.append("\nException clearing file manager: ");
        errors.append(DBE.toString()).append("\n");
      }

      try {
        fileManager.close();
      } catch (IOException IOE) {
        errors.append("\nException clearing file manager: ");
        errors.append(IOE.toString()).append("\n");
      } catch (DatabaseException DBE) {
        errors.append("\nException clearing file manager: ");
        errors.append(DBE.toString()).append("\n");
      }

      try {
        inMemoryINs.clear();
      } catch (DatabaseException DBE) {
        errors.append("\nException closing file manager: ");
        errors.append(DBE.toString()).append("\n");
      }

      hook_afterDoClose(errors);
    } finally {
      envState = DbEnvState.CLOSED;
    }

    if (errors.length() > 0 && savedInvalidatingException == null) {

      /* Don't whine again if we've already whined. */
      throw new RunRecoveryException(this, errors.toString());
    }
  }