Package org.kairosdb.bigqueue.page
Class MappedPageFactoryImpl
- java.lang.Object
-
- org.kairosdb.bigqueue.page.MappedPageFactoryImpl
-
- All Implemented Interfaces:
IMappedPageFactory
public class MappedPageFactoryImpl extends Object implements IMappedPageFactory
Mapped mapped page resource manager, responsible for the creation, cache, recycle of the mapped pages. automatic paging and swapping algorithm is leveraged to ensure fast page fetch while keep memory usage efficient at the same time.- Author:
- bulldog
-
-
Field Summary
Fields Modifier and Type Field Description static StringPAGE_FILE_NAMEstatic StringPAGE_FILE_SUFFIX
-
Constructor Summary
Constructors Constructor Description MappedPageFactoryImpl(int pageSize, String pageDir, long cacheTTL)MappedPageFactoryImpl(int pageSize, String pageDir, long cacheTTL, Clock clock, FileFactory fileFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description IMappedPageacquirePage(long index)Acquire a mapped page with specific index from the factoryvoiddeleteAllPages()thread unsafe, caller need synchronizationvoiddeletePage(long index)thread unsafe, caller need synchronizationvoiddeletePages(Set<Long> indexes)thread unsafe, caller need synchronizationvoiddeletePagesBefore(long timestamp)thread unsafe, caller need synchronizationvoiddeletePagesBeforePageIndex(long pageIndex)Delete all pages before the specific indexvoidflush()thread unsafe, caller need synchronizationSet<String>getBackPageFileSet()A set of back page file nameslonggetBackPageFileSize()Total size of all page filesintgetCacheSize()For test, get current cache sizeSet<Long>getExistingBackFileIndexSet()For test, get a list of indexes of current existing back files.longgetFirstPageIndexBefore(long timestamp)Get index of a page file with last modified timestamp closest to specific timestamp.StringgetPageDir()Current set page directory.longgetPageFileLastModifiedTime(long index)Get last modified timestamp of page file indexSet<Long>getPageIndexSetBefore(long timestamp)Get all indexes of pages with last modified timestamp before the specific timestamp.intgetPageSize()Current set page size, when creating pages, the factory will only create pages with this size.voidreleaseCachedPages()thread unsafe, caller need synchronizationvoidreleasePage(long index)Return the mapped page to the factory, calling thread release the page to inform the factory that it has finished with the page, so the factory get a chance to recycle the page to save memory.
-
-
-
Field Detail
-
PAGE_FILE_NAME
public static final String PAGE_FILE_NAME
- See Also:
- Constant Field Values
-
PAGE_FILE_SUFFIX
public static final String PAGE_FILE_SUFFIX
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MappedPageFactoryImpl
public MappedPageFactoryImpl(int pageSize, String pageDir, long cacheTTL, Clock clock, FileFactory fileFactory)
-
MappedPageFactoryImpl
public MappedPageFactoryImpl(int pageSize, String pageDir, long cacheTTL)
-
-
Method Detail
-
acquirePage
public IMappedPage acquirePage(long index) throws IOException
Description copied from interface:IMappedPageFactoryAcquire a mapped page with specific index from the factory- Specified by:
acquirePagein interfaceIMappedPageFactory- Parameters:
index- the index of the page- Returns:
- a mapped page
- Throws:
IOException- exception thrown if there was any IO error during the acquire operation
-
getPageSize
public int getPageSize()
Description copied from interface:IMappedPageFactoryCurrent set page size, when creating pages, the factory will only create pages with this size.- Specified by:
getPageSizein interfaceIMappedPageFactory- Returns:
- an integer number
-
getPageDir
public String getPageDir()
Description copied from interface:IMappedPageFactoryCurrent set page directory.- Specified by:
getPageDirin interfaceIMappedPageFactory- Returns:
- directory name
-
releasePage
public void releasePage(long index)
Description copied from interface:IMappedPageFactoryReturn the mapped page to the factory, calling thread release the page to inform the factory that it has finished with the page, so the factory get a chance to recycle the page to save memory.- Specified by:
releasePagein interfaceIMappedPageFactory- Parameters:
index- the index of the page
-
releaseCachedPages
public void releaseCachedPages() throws IOExceptionthread unsafe, caller need synchronization- Specified by:
releaseCachedPagesin interfaceIMappedPageFactory- Throws:
IOException- exception thrown if there was any IO error during the release operation.
-
deleteAllPages
public void deleteAllPages() throws IOExceptionthread unsafe, caller need synchronization- Specified by:
deleteAllPagesin interfaceIMappedPageFactory- Throws:
IOException- exception thrown if there was any IO error during the delete operation.
-
deletePages
public void deletePages(Set<Long> indexes) throws IOException
thread unsafe, caller need synchronization- Specified by:
deletePagesin interfaceIMappedPageFactory- Parameters:
indexes- the indexes of the pages- Throws:
IOException- exception thrown if IO error occurs
-
deletePage
public void deletePage(long index) throws IOExceptionthread unsafe, caller need synchronization- Specified by:
deletePagein interfaceIMappedPageFactory- Parameters:
index- the index of the page- Throws:
IOException- exception thrown if there was any IO error during the delete operation.
-
getPageIndexSetBefore
public Set<Long> getPageIndexSetBefore(long timestamp)
Description copied from interface:IMappedPageFactoryGet all indexes of pages with last modified timestamp before the specific timestamp.- Specified by:
getPageIndexSetBeforein interfaceIMappedPageFactory- Parameters:
timestamp- the timestamp to check- Returns:
- a set of indexes
-
deletePagesBefore
public void deletePagesBefore(long timestamp) throws IOExceptionthread unsafe, caller need synchronization- Specified by:
deletePagesBeforein interfaceIMappedPageFactory- Parameters:
timestamp- the timestamp to check- Throws:
IOException- exception thrown if IO error occurs
-
deletePagesBeforePageIndex
public void deletePagesBeforePageIndex(long pageIndex) throws IOExceptionDescription copied from interface:IMappedPageFactoryDelete all pages before the specific index- Specified by:
deletePagesBeforePageIndexin interfaceIMappedPageFactory- Parameters:
pageIndex- page file index to check- Throws:
IOException- exception thrown if there was any IO error during the delete operation.
-
getExistingBackFileIndexSet
public Set<Long> getExistingBackFileIndexSet()
Description copied from interface:IMappedPageFactoryFor test, get a list of indexes of current existing back files.- Specified by:
getExistingBackFileIndexSetin interfaceIMappedPageFactory- Returns:
- a set of indexes
-
getCacheSize
public int getCacheSize()
Description copied from interface:IMappedPageFactoryFor test, get current cache size- Specified by:
getCacheSizein interfaceIMappedPageFactory- Returns:
- an integer number
-
getPageFileLastModifiedTime
public long getPageFileLastModifiedTime(long index)
Description copied from interface:IMappedPageFactoryGet last modified timestamp of page file index- Specified by:
getPageFileLastModifiedTimein interfaceIMappedPageFactory- Parameters:
index- page index- Returns:
- last modified time
-
getFirstPageIndexBefore
public long getFirstPageIndexBefore(long timestamp)
Description copied from interface:IMappedPageFactoryGet index of a page file with last modified timestamp closest to specific timestamp.- Specified by:
getFirstPageIndexBeforein interfaceIMappedPageFactory- Parameters:
timestamp- the timestamp to check- Returns:
- a page index
-
flush
public void flush()
thread unsafe, caller need synchronization- Specified by:
flushin interfaceIMappedPageFactory
-
getBackPageFileSet
public Set<String> getBackPageFileSet()
Description copied from interface:IMappedPageFactoryA set of back page file names- Specified by:
getBackPageFileSetin interfaceIMappedPageFactory- Returns:
- file name set
-
getBackPageFileSize
public long getBackPageFileSize()
Description copied from interface:IMappedPageFactoryTotal size of all page files- Specified by:
getBackPageFileSizein interfaceIMappedPageFactory- Returns:
- total size
-
-