Class Media
- All Implemented Interfaces:
AutoCloseable,Closeable
It is a basic media, which represents a simple basic building block of the media, which can be extended.
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedMedia(File file, BiConsumer<Media, DataReader> headerStream) Load an existing mediaprotectedMedia(File file, MediaProperties mediaProperties, BiConsumer<Media, DataWriter> headerStream) Create a new media -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the instance of media.voidThis function can be called periodically to close the unused blocks and sequences.static Mediacreate(File file, MediaProperties mediaProperties) Creates a blank mediastatic Mediacreate(File file, MediaProperties mediaProperties, BiConsumer<Media, DataWriter> headerStream) Creates a new media and store with an option to store to headers stream of the media.static <T> Mediacreate(File file, MediaProperties mediaProperties, Function<Media, T> headerFactory) Creates a new media and store a header class to the header of the mediacreateSecondaryBlockAllocator(String allocatorName, long upperBlockNumberLimit) CreatesSecondaryBlockAllocatorbased on the internal root allocator.voiddump()voidfreeBlockContainer(int blockContainerId) Frees a block containerProvides information about block allocation within the mediagetBlockContainer(int blockContainerId) Provides a block container by its idProvides the set of currently openedBlockIndexSequenceProvides the set of currently mapped physical blocksProvides the properties that has been used for the creation of the mediaProvides information about the objects thisMediaholds.Provides the root block allocator.loadSecondaryBlockAllocator(String allocatorName, long startIndex, long upperBlockNumberLimit) LoadsSecondaryBlockAllocatorbased on the internal root allocator.map(long blockIndex) A low-level operation of mapping of the block referenced by its index to the mapped byte buffer.Creates a new Block container, which represents a transactional boundary in ro-store, which must be closed after usage.static MediaOpens the media object from the existing filestatic <T> Mediaopen(File file, Class<T> headerClass, BiConsumer<Media, T> header) Opens a media, reads the header and provides it for further initializationstatic Mediaopen(File file, BiConsumer<Media, DataReader> headerStream) Opens a media, allows to read the header from a binary streamvoidremoveSecondaryBlockAllocator(BlockAllocator blockAllocator) Call to this function will free all the blocks allocated in the secondary allocator.Methods inherited from class org.rostore.v2.media.RootClosableImpl
getStatusMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.rostore.v2.media.Closeable
checkOpened
-
Field Details
-
MAGIC
public static final byte MAGIC- See Also:
-
-
Constructor Details
-
Media
protected Media(File file, MediaProperties mediaProperties, BiConsumer<Media, DataWriter> headerStream) Create a new mediaA is used to extend current media by any functionality that is build on top of it.
The media object is fully constructed when the consumer is executed, so any construction can happen on its basis. The consumer should write the necessary data to the
DataWriterso that the state of the construction can be persisted.- Parameters:
file- a file where the data should be persistedmediaProperties- the properties of the mediaheaderStream- consumer that receives both the created media object and aDataWriterthat can be used to write additional header information, which allows to extend the media header.
-
Media
Load an existing mediaA is used to read the header information that has previously been stored at the creation time to the header of the media in the call to
Media(File, MediaProperties, BiConsumer). This allows to restore the entities created in the media.- Parameters:
file- a file where the data is storedheaderStream- consumer that receives both the created media object and aDataReaderthat can be used to read additional header information, which allows to extend the media basic functionality.
-
-
Method Details
-
getBlockAllocatorListeners
-
getMediaProperties
Provides the properties that has been used for the creation of the media- Returns:
- the media properties
-
getRootBlockAllocator
Provides the root block allocator.- Returns:
- the root block allocator
-
getMemoryConsumption
Provides information about the objects thisMediaholds.- Returns:
- info about the memory consumption
-
getBlockIndexSequences
Provides the set of currently openedBlockIndexSequence- Returns:
- media's currently active block sequences
-
getMappedPhysicalBlocks
Provides the set of currently mapped physical blocks- Returns:
- media's currently active blocks
-
close
public void close()Closes the instance of media.This function will not regard any open
BlockContainer, the caller should finish all the transactions before.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classRootClosableImpl
-
getBlockAllocation
Provides information about block allocation within the mediaAs a source the
RootBlockAllocatoris used.- Returns:
- the block allocation
-
closeExpired
public void closeExpired()This function can be called periodically to close the unused blocks and sequences.This is a proactive operation. The clean-up is also executed on every operation, but to ensure that the clean-up is also executed in the time when media is idling this operation can be used.
-
create
Creates a blank media- Parameters:
file- the file where the media should be persistedmediaProperties- the properties of the media- Returns:
- the constructed media object
-
create
public static <T> Media create(File file, MediaProperties mediaProperties, Function<Media, T> headerFactory) Creates a new media and store a header class to the header of the media- Type Parameters:
T- a type of the header object, must be serializable by theBinaryMapper- Parameters:
file- the file location where the media data should be persistedmediaProperties- the properties of the mediaheaderFactory- creates a header object that will be stored as additional information to the media's header- Returns:
- the created media object
-
create
public static Media create(File file, MediaProperties mediaProperties, BiConsumer<Media, DataWriter> headerStream) Creates a new media and store with an option to store to headers stream of the media.- Parameters:
file- the file where the storage data should be persistedmediaProperties- the properties of the storageheaderStream- a consumer that can write any binary data to the header- Returns:
- the created media
-
open
Opens the media object from the existing file- Parameters:
file- the file where the storage is located- Returns:
- the media object
-
open
Opens a media, reads the header and provides it for further initialization- Type Parameters:
T- the type of the header class- Parameters:
file- the file where the storage data is locatedheaderClass- a class of the custom header, must be serializable byBinaryMapperheader- bi consumer that provides both fully initialized media object and the deserialized header object- Returns:
- the media object
-
open
Opens a media, allows to read the header from a binary stream- Parameters:
file- the file where the storage data is locatedheaderStream- consumer that receives both the fully initialized media object and aDataReaderthat can be used to read additional header information, to initialize further entities- Returns:
- opened media
-
map
A low-level operation of mapping of the block referenced by its index to the mapped byte buffer.This operation should not be used directly by the clients of media, instead
InternalBlockProvidershould be used to get access to the block's data.- Parameters:
blockIndex- the index of the block- Returns:
- the mapped memory block
-
newBlockContainer
Creates a new Block container, which represents a transactional boundary in ro-store, which must be closed after usage.- Returns:
- the block container
-
getBlockContainer
Provides a block container by its idShould not be used directly.
- Parameters:
blockContainerId- the id of the block container- Returns:
- the block container
-
freeBlockContainer
public void freeBlockContainer(int blockContainerId) Frees a block containerShould not be used directly.
- Parameters:
blockContainerId- the id of the block container
-
createSecondaryBlockAllocator
public BlockAllocator createSecondaryBlockAllocator(String allocatorName, long upperBlockNumberLimit) CreatesSecondaryBlockAllocatorbased on the internal root allocator. SeeSecondaryBlockAllocator.create(String, BlockAllocator, long)- Parameters:
allocatorName- the name of the allocatorupperBlockNumberLimit- the maximum number of blocks- Returns:
- the newly created secondary allocator
-
loadSecondaryBlockAllocator
public BlockAllocator loadSecondaryBlockAllocator(String allocatorName, long startIndex, long upperBlockNumberLimit) LoadsSecondaryBlockAllocatorbased on the internal root allocator. SeeSecondaryBlockAllocator.load(String, BlockAllocator, long, long)Media do not hold instances of the secondary allocators, so the client should hold them and prevent several instances of these allocator to be loaded.
- Parameters:
allocatorName- the name of the allocatorstartIndex- the first block of the allocatorupperBlockNumberLimit- the maximum number of blocks- Returns:
- the loaded secondary allocator
-
removeSecondaryBlockAllocator
Call to this function will free all the blocks allocated in the secondary allocator.- Parameters:
blockAllocator- the allocator to clean up
-
dump
public void dump()
-