Storing data from an IBM Director Server extension

There are many different ways for your code to store data under IBM Director

The persistent store

This is a collection of three files that contains everything that extends TWGPersistentObject including:

  1. Managed objects
  2. Tasks
  3. SQL queries
  4. Groups (TWGFilters)
  5. IBM Director users

Every time the IBM Director Server starts, the objects in the persistent store are read and instantiated in the JVM. your TWGManagedObjects, tasks will automatically be saved in the persistent store. For additional application-specific data, it is often best to use a different storage mechanism. Several are listed below.

The SQL database

The database is intended to hold only inventory data. Only data from your inventory collectors should be stored here.

Datastores

A dataStore is an IBM Director class that uses an indexed file for storing byte arrays. The index is always an integer; this works very well if the data is related to specific managed objects (you can use the MOID as an index.) Datastores also work best when everything stored in a specific dataStore is of the same type.

To use a datastore, you would first declare it like this:

DataStore file = null;

Then you would open/create it like this:

static final int SAMPLE_FILE_SIGNATURE       = 0x378A5A2B;
file = new DataStore(filename, SAMPLE_FILE_SIGNATURE, true, false);

You can test to see if the file was created new:

file.isNew()

You can write an item like this:

long key = file.add(data, data.length);

The key that is returned can be used to look up the data later.

Alternatively, you can write data with a specific key (for example, a MOID) like this

file.add(key, data, data.length);

You can read (enumerate) all the entries in the file with code like this:

   EnumerateDataStore enumerator = new EnumerateDataStore();
   file.enumerate(enumerator);
.
.
.            
   private static class EnumerateDataStore implements DataStoreEnumeration
   {
      public void element(long key, byte[] data, int length)
      {
         // Add your code to process the data here
      }
   }

You can remove data from the dataStore like this:

remove( key );

Note: For most of the APIs in dataStore, you will have to add a try-catch to catch DataStoreException.

Note: Ensure that you place your files in IBM Director's data directory.


Properties files

Properties are a part of Java. Properties files save name-value pairs. They work well if you need to allow IBM Director administrators to customize your extension without a GUI. For example, an administrator can edit a properties file to override default timeouts and your code could read the file when the IBM Director Server starts.

It is also possible for your program to write the properties to a file and then read them back later.

 Use the standard Java APIs to read, manipulate, and write Properties.
Note: Ensure that you place your files in IBM Director's data directory.