Back to JOC 10.1.2 Tutorial Index

Stream Access Objects

It is expected that one common type of object to be cached will be a file or byte array accessed through the Java Stream interface. Whether it is a file or a byte array will depend on the size of the object. To help make managing this type of object easier, the cache provides a StreamAccess object type. With this type of object, the cache will manage the object as either a byte array or a file depending on the size of the object and the memory available. The user will be presented with a Stream object (InputStream for reading, OutputStream for writing) regardless of whether the object is in a file or in memory. This allows the cache user to always access the object in a uniform manner without regard to the object size and resource availability.

To create a stream object createStream is called from the CacheLoader.load() method when the object is loaded into the cache. createStream returns an OutputStream object to be used to load the object into the cache. If the attributes have not already been defined for the object, they should be set with the createStream method. This will ensure the object is managed correctly.

The following is an example of a loader object to load a Stream object into the cache.

import oracle.ias.cache.*;

class YourObjectLoader extends CacheLoader
{

  public Object load(Object handle, Object args)
  {

    OutputStream = out;
    Attributes attr = new Attributes();

    attr.setFlags(Attributes.DISTRIBUTE);

    try
    {

      out = createStream(handle, attr);
      out.write((byte[])getInfoFromSomewhere());

    }
    catch (Exception ex)
    {

      // translate exception to CacheException, and log exception
      throw exception("exception in write", ex);

    }

    return out;

  }

}
The application code would be something like the fragment below. This assumes the "Stock-Market" region has already been defined with a YourObjectLoader loader as the default loader for the region.
import oracle.ias.cache.*;

  try
  {

    InputStream in;
    CacheAccess cacc = CacheAccess.getAccess("Stock-Market");
    in = (InputStream)cacc.get("file object");
    in.read(buf);

    // do something interesting with the data

    cacc.close();

  }
  catch (Exception ex)
  {

    // handle exception

  }
Back to JOC 10.1.2 Tutorial Index
E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy