Package com.mckoi.store
Class ScatteringStoreDataAccessor
- java.lang.Object
-
- com.mckoi.store.ScatteringStoreDataAccessor
-
- All Implemented Interfaces:
StoreDataAccessor
public class ScatteringStoreDataAccessor extends java.lang.Object implements StoreDataAccessor
An implementation of StoreDataAccessor that scatters the addressible data resource across multiple files in the file system. When one store data resource reaches a certain threshold size, the content 'flows' over to the next file.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classScatteringStoreDataAccessor.FileSliceAn object that contains information about a file slice.
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Stringfile_nameThe name of the file in the file system minus the extension.private java.lang.Stringfirst_extThe extension of the first file in the sliced set.private java.lang.ObjectlockA lock when modifying the true_data_size, and slice_list.private longmax_slice_sizeThe maximum size a file slice can grow too before a new slice is created.private booleanopenSet when the store is openned.private java.io.FilepathThe path of this store in the file system.private java.util.ArrayListslice_listThe list of RandomAccessFile objects for each file that represents a slice of the store.private longtrue_file_lengthThe current actual physical size of the store data on disk.
-
Constructor Summary
Constructors Constructor Description ScatteringStoreDataAccessor(java.io.File path, java.lang.String file_name, java.lang.String first_ext, long max_slice_size)Constructs the store data accessor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the underlying data area representation.voidconvertToScatteringStore(java.io.File f)Given a file, this will convert to a scattering file store with files no larger than the maximum slice size.private intcountStoreFiles()Counts the number of files in the file store that represent this store.private StoreDataAccessorcreateSliceDataAccessor(java.io.File file)Creates a StoreDataAccessor object for accessing a given slice.booleandelete()Deletes the data area resource.private longdiscoverSize()Discovers the size of the data resource (doesn't require the file to be open).booleanexists()Returns true if the resource exists.longgetSize()Returns the current size of the underlying data area.voidopen(boolean read_only)Opens the underlying data area representation.voidread(long position, byte[] buf, int off, int len)Reads a block of data from the underlying data area at the given position into the byte array at the given offset.voidsetSize(long length)Sets the size of the underlying data area to the given size.private java.io.FileslicePartFile(int i)Given an index value, this will return a File object for the nth slice in the file system.voidsynch()Synchronizes the data area by forcing any data out of the OS buffers onto the disk.voidwrite(long position, byte[] buf, int off, int len)Writes a block of data to the underlying data area from the byte array at the given offset.
-
-
-
Field Detail
-
path
private final java.io.File path
The path of this store in the file system.
-
file_name
private final java.lang.String file_name
The name of the file in the file system minus the extension.
-
first_ext
private final java.lang.String first_ext
The extension of the first file in the sliced set.
-
max_slice_size
private final long max_slice_size
The maximum size a file slice can grow too before a new slice is created.
-
slice_list
private java.util.ArrayList slice_list
The list of RandomAccessFile objects for each file that represents a slice of the store. (FileSlice objects)
-
true_file_length
private long true_file_length
The current actual physical size of the store data on disk.
-
lock
private final java.lang.Object lock
A lock when modifying the true_data_size, and slice_list.
-
open
private boolean open
Set when the store is openned.
-
-
Method Detail
-
convertToScatteringStore
public void convertToScatteringStore(java.io.File f) throws java.io.IOExceptionGiven a file, this will convert to a scattering file store with files no larger than the maximum slice size.- Throws:
java.io.IOException
-
slicePartFile
private java.io.File slicePartFile(int i)
Given an index value, this will return a File object for the nth slice in the file system. For example, given '4' will return [file name].004, given 1004 will return [file name].1004, etc.
-
countStoreFiles
private int countStoreFiles()
Counts the number of files in the file store that represent this store.
-
createSliceDataAccessor
private StoreDataAccessor createSliceDataAccessor(java.io.File file)
Creates a StoreDataAccessor object for accessing a given slice.
-
discoverSize
private long discoverSize() throws java.io.IOExceptionDiscovers the size of the data resource (doesn't require the file to be open).- Throws:
java.io.IOException
-
open
public void open(boolean read_only) throws java.io.IOExceptionDescription copied from interface:StoreDataAccessorOpens the underlying data area representation. If the resource doesn't exist then it is created and the size is set to 0.- Specified by:
openin interfaceStoreDataAccessor- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOExceptionDescription copied from interface:StoreDataAccessorCloses the underlying data area representation.- Specified by:
closein interfaceStoreDataAccessor- Throws:
java.io.IOException
-
delete
public boolean delete()
Description copied from interface:StoreDataAccessorDeletes the data area resource. Returns true if the delete was successful.- Specified by:
deletein interfaceStoreDataAccessor
-
exists
public boolean exists()
Description copied from interface:StoreDataAccessorReturns true if the resource exists.- Specified by:
existsin interfaceStoreDataAccessor
-
read
public void read(long position, byte[] buf, int off, int len) throws java.io.IOExceptionDescription copied from interface:StoreDataAccessorReads a block of data from the underlying data area at the given position into the byte array at the given offset.- Specified by:
readin interfaceStoreDataAccessor- Throws:
java.io.IOException
-
write
public void write(long position, byte[] buf, int off, int len) throws java.io.IOExceptionDescription copied from interface:StoreDataAccessorWrites a block of data to the underlying data area from the byte array at the given offset.- Specified by:
writein interfaceStoreDataAccessor- Throws:
java.io.IOException
-
setSize
public void setSize(long length) throws java.io.IOExceptionDescription copied from interface:StoreDataAccessorSets the size of the underlying data area to the given size. If the size of the data area is increased, the content between the old size and the new size is implementation defined.- Specified by:
setSizein interfaceStoreDataAccessor- Throws:
java.io.IOException
-
getSize
public long getSize() throws java.io.IOExceptionDescription copied from interface:StoreDataAccessorReturns the current size of the underlying data area.- Specified by:
getSizein interfaceStoreDataAccessor- Throws:
java.io.IOException
-
synch
public void synch() throws java.io.IOExceptionDescription copied from interface:StoreDataAccessorSynchronizes the data area by forcing any data out of the OS buffers onto the disk.- Specified by:
synchin interfaceStoreDataAccessor- Throws:
java.io.IOException
-
-