com.indexdata.torus2.rw.impl
Class CachingReaderWriter

java.lang.Object
  extended by com.indexdata.torus2.rw.impl.ProxyReaderWriter
      extended by com.indexdata.torus2.rw.impl.CachingReaderWriter
All Implemented Interfaces:
RealmReaderWriter

public class CachingReaderWriter
extends ProxyReaderWriter

This RW prevents any disk writes or reads that have to do with worlds records and instead caches them purely in memory. The persisted parent list is consulted each time the cache is read, in case world records (full realms) are missing from the cache a request is made to retrieve them.

Author:
jakub

Field Summary
 
Fields inherited from class com.indexdata.torus2.rw.impl.ProxyReaderWriter
rw
 
Constructor Summary
CachingReaderWriter(RealmReaderWriter rw, String host, String proto, boolean honorProto, boolean honorAuth, boolean honorPort)
           
 
Method Summary
 void deleteCachedAsOriginal(String id)
           
 void deleteParentRealm(String prId)
           
 void deleteWorldRecordsByParentId(String prId)
           
 boolean isCachedAsParent()
          In case the realm serves as parent to other realms within the same torus installation, the following function allows for fast propagation of changes to child realms.
 boolean open()
          Attempts to open the realm store pointed to by this instance.
 Record.Layer readWorldRecord(String prefixId)
          Retrieve world (within a set of parents) record by id.
 List<Record.Layer> readWorldRecordsForParent(String prId)
          Retrieve a list of records for a parent specified within this realm,
 Record.Layer updateCachedAsOriginal(Record.Layer original)
           
 ParentRealm writeParentRealm(ParentRealm pr)
           
 List<Record.Layer> writeWorldRecordsForParent(List<Record.Layer> docs, String prId)
          Stores parent records for the given parent, updates each world record with an ID unique to this realm (so world records can be looked up without specifying parent)
 
Methods inherited from class com.indexdata.torus2.rw.impl.ProxyReaderWriter
create, deleteMasterRecord, deleteOverrideRecord, describe, destroy, listRealms, readMasterRecord, readMasterRecords, readOverrideRecord, readOverrideRecords, readParentRealm, readParentRealms, writeMasterRecord, writeMasterRecord, writeOverrideRecord, writeOverrideRecord, writeParentRealm
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachingReaderWriter

public CachingReaderWriter(RealmReaderWriter rw,
                           String host,
                           String proto,
                           boolean honorProto,
                           boolean honorAuth,
                           boolean honorPort)
                    throws InternalIOException
Throws:
InternalIOException
Method Detail

open

public boolean open()
             throws InternalIOException
Description copied from interface: RealmReaderWriter
Attempts to open the realm store pointed to by this instance. Returns true if the realm has been properly opened or false if the realm has already been opened (e.g on consecutive calls)

Specified by:
open in interface RealmReaderWriter
Overrides:
open in class ProxyReaderWriter
Returns:
Throws:
InternalIOException

writeParentRealm

public ParentRealm writeParentRealm(ParentRealm pr)
                             throws InternalIOException
Specified by:
writeParentRealm in interface RealmReaderWriter
Overrides:
writeParentRealm in class ProxyReaderWriter
Throws:
InternalIOException

deleteParentRealm

public void deleteParentRealm(String prId)
                       throws InternalIOException
Specified by:
deleteParentRealm in interface RealmReaderWriter
Overrides:
deleteParentRealm in class ProxyReaderWriter
Throws:
InternalIOException

readWorldRecordsForParent

public List<Record.Layer> readWorldRecordsForParent(String prId)
                                             throws InternalIOException
Description copied from interface: RealmReaderWriter
Retrieve a list of records for a parent specified within this realm,

Specified by:
readWorldRecordsForParent in interface RealmReaderWriter
Overrides:
readWorldRecordsForParent in class ProxyReaderWriter
Returns:
list (possibly empty, e.g when world contains no records) of records
Throws:
InternalIOException - when experiencing problems reading/parsing records

readWorldRecord

public Record.Layer readWorldRecord(String prefixId)
                             throws InternalIOException,
                                    MalformedInputException
Description copied from interface: RealmReaderWriter
Retrieve world (within a set of parents) record by id.

Specified by:
readWorldRecord in interface RealmReaderWriter
Overrides:
readWorldRecord in class ProxyReaderWriter
Returns:
found record
Throws:
InternalIOException - when experiencing problems reading/parsing records
MalformedInputException - when the realmUniqueId is malformed

writeWorldRecordsForParent

public List<Record.Layer> writeWorldRecordsForParent(List<Record.Layer> docs,
                                                     String prId)
                                              throws InternalIOException
Description copied from interface: RealmReaderWriter
Stores parent records for the given parent, updates each world record with an ID unique to this realm (so world records can be looked up without specifying parent)

Specified by:
writeWorldRecordsForParent in interface RealmReaderWriter
Overrides:
writeWorldRecordsForParent in class ProxyReaderWriter
Returns:
Throws:
InternalIOException

deleteWorldRecordsByParentId

public void deleteWorldRecordsByParentId(String prId)
                                  throws InternalIOException
Specified by:
deleteWorldRecordsByParentId in interface RealmReaderWriter
Overrides:
deleteWorldRecordsByParentId in class ProxyReaderWriter
Throws:
InternalIOException

isCachedAsParent

public boolean isCachedAsParent()
                         throws InternalIOException
Description copied from interface: RealmReaderWriter
In case the realm serves as parent to other realms within the same torus installation, the following function allows for fast propagation of changes to child realms.

Specified by:
isCachedAsParent in interface RealmReaderWriter
Overrides:
isCachedAsParent in class ProxyReaderWriter
Throws:
InternalIOException

deleteCachedAsOriginal

public void deleteCachedAsOriginal(String id)
                            throws InternalIOException
Specified by:
deleteCachedAsOriginal in interface RealmReaderWriter
Overrides:
deleteCachedAsOriginal in class ProxyReaderWriter
Throws:
InternalIOException

updateCachedAsOriginal

public Record.Layer updateCachedAsOriginal(Record.Layer original)
                                    throws InternalIOException
Specified by:
updateCachedAsOriginal in interface RealmReaderWriter
Overrides:
updateCachedAsOriginal in class ProxyReaderWriter
Throws:
InternalIOException


Copyright © 2008-2013 Index Data. All Rights Reserved.