Library Version 12.1.6.2

Administrative Functions
Prev | Chapter 3. Berkeley DB Client Driver APIs | Next

## Administrative Functions

Several functions are added to the client driver APIs to control the server, to clean up open handles and to delete unused environments. These functions do not rely on open handles and are put together into the `BdbServerAdmin` class.

### Shutdown the Server

You can shutdown the server using the `shutdownServer` method:

    BdbServerConnection conn =
         BdbServerConnection.connect("localhost", 8080);

    // Get an instance of the BdbServerAdmin class
    BdbServerAdmin adminService = conn.adminService();

    // Shutdown the server. After this method, close the connection.
    adminService.shutdownServer();

    // Close the connection.
    conn.close();

### Using ping

You can test the server's reachability using the `ping` method:

    BdbServerConnection conn =
         BdbServerConnection.connect("localhost", 8080);

    // Get an instance of the BdbServerAdmin class
    BdbServerAdmin adminService = conn.adminService();

    // Test if the server is reachable. If the server is not
    // reachable, an SDatabaseException is thrown.
    adminService.ping();

    ...

### Getting the server version

You can get the version of Berkeley DB library used by the server using the `getServerBdbVersion` method:

    BdbServerConnection conn =
         BdbServerConnection.connect("localhost", 8080);

    // Get an instance of the BdbServerAdmin class
    BdbServerAdmin adminService = conn.adminService();

    // Get the version of the Berkeley DB library used by the server.
    String serverBdbVersion = adminService.getServerBdbVersion();

    ...

### Cleaning up Inactive Handles

Sometimes a handle may be left open for a long time on the server. This can be caused by a client application error, crash or hang. If this handle holds critical resources (e.g locks), it may slow down or even block other client applications.

The Berkeley DB server can be configured to close these inactive handles periodically with the `cleanup.interval` and `handle.timeout` properties. For more information, see Server Configuration Options

In addition, the driver APIs also provide functions to clean up inactive environment and database handles. For example:

### Note

When an environment or database handle is closed, all handles that depend on it are also closed. For example, when an environment handle is closed, all transaction handles opened under the environment handles are also closed.

    BdbServerConnection conn =
         BdbServerConnection.connect("localhost", 8080);

    // Get an instance of the BdbServerAdmin class
    BdbServerAdmin adminService = conn.adminService();

    // Close handles opened on the environment whose home directory
    // is "env", if they have not been accessed in the last 10 seconds.
    adminService.closeEnvironmentHandles("env", 10 * 1000L);

    // Close handles opened on the database specified with the given
    // environment home directory, database file name and sub-database
    // name, if they have not been accessed in the last 10 seconds.
    adminService.closeDatabaseHandles("home", "dbFile", "subDb", 10 * 1000L);

    // Shutdown the server. After this method, close the connection.
    adminService.shutdownServer();

    // Close the connection.
    conn.close();

### Deleting an Environment and Its Databases

With the embedded Berkeley DB, you can remove an environment and all its databases by removing the environment home directory and any additional data, log and blob directories. The driver APIs also provide a way to do this:

    BdbServerConnection conn =
         BdbServerConnection.connect("localhost", 8080);

    // Get an instance of the BdbServerAdmin class
    BdbServerAdmin adminService = conn.adminService();

    // Delete the environment whose home directory is "env" and all the
    // databases opened in it. Close all open handles on the environment
    // and databases.
    adminService.deleteEnvironmentAndDatabases("env", true);

    // Shutdown the server. After this method, close the connection.
    adminService.shutdownServer();

    // Close the connection.
    conn.close();

Prev | Up | Next
Connecting to a Server with SSL | Home | Removing and Renaming Objects