com.faunos.skwish.sys.mgr
Class FileBackedDeleteSet

java.lang.Object
  extended by com.faunos.skwish.sys.filters.DeleteSet
      extended by com.faunos.skwish.sys.mgr.FileBackedDeleteSet
All Implemented Interfaces:
Closeable

public class FileBackedDeleteSet
extends DeleteSet
implements Closeable

A DeleteSet that is backed by a file. The file format used is super brittle.

File Format

The backing file consists of a list of fixed-width, 8 byte longs representing the list of deleted [entry] IDs. The file's byte size (size / 8 - 2) determines the number deleted IDs. Thus the file size is always a multiple of 8. The list of deleted IDs is not ordered; however, the deleted IDs are unique (i.e., non-repeating).

Layout


      DELETED_ID_LIST := MIN_ID, MAX_ID, <DELETED_ID> n = 0, 1, 2, ..
      MIN_ID := LONG
      MAX_ID := LONG
      DELETED_ID := LONG
      LONG := <BYTE>8
 

Notes:

The implementation does not require that the IDs be unique. (A list containing duplicate entry IDs does not cause loadInstance(FileChannel) to fail.) However, the implementation never produces duplicates, either.

The implementation is not safe for concurrent access. In particular, the backing FileChannel's position is assumed to be owned by the instance.

Author:
Babak Farhang

Field Summary
protected static ChannelUtil<DeleteSetException> helper
           
 
Fields inherited from class com.faunos.skwish.sys.filters.DeleteSet
deletedIds, validator
 
Constructor Summary
protected FileBackedDeleteSet(FileChannel deletedIdsFile, long minId, long maxId)
          Used internally and by subclasses.
 
Method Summary
 void close()
           
 boolean delete(long id)
          Adds the given id to the delete-set.
 void flush()
           
 Set<Long> getRawDeletedIds()
           
 boolean include(DeleteSet other)
          Operation not supported.
 boolean isIncludeSupported()
          Determines whether the instance supports the include method.
static FileBackedDeleteSet loadInstance(FileChannel deletedIdsFile)
          Loads and returns an already existing instance from the given backing file.
static FileBackedDeleteSet writeNewInstance(FileChannel deletedIdsFile, long minId, long maxId)
          Writes a new, empty deleted ID list to the given backing file and returns a new instance of this class.
 
Methods inherited from class com.faunos.skwish.sys.filters.DeleteSet
combine, getCount, getDeletedIds, getMaxId, getMinId, initSet, inRange, isDeleted, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

helper

protected static final ChannelUtil<DeleteSetException> helper
Constructor Detail

FileBackedDeleteSet

protected FileBackedDeleteSet(FileChannel deletedIdsFile,
                              long minId,
                              long maxId)
Used internally and by subclasses.

See Also:
loadInstance(FileChannel), writeNewInstance(FileChannel, long, long)
Method Detail

loadInstance

public static FileBackedDeleteSet loadInstance(FileChannel deletedIdsFile)
                                        throws IOException
Loads and returns an already existing instance from the given backing file. The specified file must be positioned at the start of the list (which need not be zero).

Throws:
IOException

writeNewInstance

public static FileBackedDeleteSet writeNewInstance(FileChannel deletedIdsFile,
                                                   long minId,
                                                   long maxId)
                                            throws IOException
Writes a new, empty deleted ID list to the given backing file and returns a new instance of this class. The file must be positioned at the start of the list (which need not be the same thing as the start of the file). On return, the file size will be truncated in order to reflect an empty deleted ID list.

Throws:
IOException

delete

public boolean delete(long id)
               throws IOException
Description copied from class: DeleteSet
Adds the given id to the delete-set.

Overrides:
delete in class DeleteSet
Parameters:
id - the ID to be deleted, which lie in this delete-set's range
Returns:
true, if the specified id wasn't already deleted; false, o.w.
Throws:
IOException

include

public boolean include(DeleteSet other)
                throws IOException,
                       UnsupportedOperationException
Operation not supported.

Overrides:
include in class DeleteSet
Throws:
UnsupportedOperationException
IOException

isIncludeSupported

public boolean isIncludeSupported()
Description copied from class: DeleteSet
Determines whether the instance supports the include method.

Overrides:
isIncludeSupported in class DeleteSet
Returns:
false

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Throws:
IOException

flush

public void flush()
           throws IOException
Throws:
IOException

getRawDeletedIds

public Set<Long> getRawDeletedIds()


SourceForge.net Logo