Package com.graphhopper.storage
Class MMapDataAccess
java.lang.Object
com.graphhopper.storage.AbstractDataAccess
com.graphhopper.storage.MMapDataAccess
- All Implemented Interfaces:
DataAccess,Closeable,AutoCloseable
A DataAccess implementation using a memory-mapped file, i.e. a facility of the
operating system to access a file like an area of RAM.
Java presents the mapped memory as a ByteBuffer, and ByteBuffer is not thread-safe, which means that access to a ByteBuffer must be externally synchronized.
This class itself is intended to be as thread-safe as other DataAccess implementations are.
The exact behavior of memory-mapping is reported to be wildly platform-dependent.
- Author:
- Peter Karich, Michael Zilske
-
Field Summary
Fields inherited from class com.graphhopper.storage.AbstractDataAccess
bitUtil, byteOrder, closed, EMPTY, header, HEADER_OFFSET, indexDivisor, name, SEGMENT_SIZE_MIN, segmentSizeInBytes, segmentSizePower -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcleanMappedByteBuffer(ByteBuffer buffer) voidclose()This method makes sure that the underlying used resources are released.create(long bytes) The first time you use a DataAccess object after configuring it you need to call this method.booleanensureCapacity(long bytes) Ensures that the capacity of this object is at least the specified bytes.voidflush()This method makes sure that the underlying data is written to the storage.bytegetByte(long bytePos) voidgetBytes(long bytePos, byte[] values, int length) Get bytes from position 'index'longintgetInt(long bytePos) Get 4 bytes from position 'bytePos'intshortgetShort(long bytePos) Get 2 bytes from position 'index'getType()voidload(int percentage) Load memory mapped files into physical memory.booleanvoidsetByte(long bytePos, byte value) voidsetBytes(long bytePos, byte[] values, int length) Set bytes from position 'index' to the specified valuesvoidsetInt(long bytePos, int value) Set 4 bytes at position 'bytePos' to the specified valuevoidsetShort(long bytePos, short value) Set 2 bytes at position 'index' to the specified valueMethods inherited from class com.graphhopper.storage.AbstractDataAccess
copyHeader, getFullName, getHeader, getName, getSegmentSize, isClosed, isIntBased, isStoring, readHeader, setHeader, toString, writeHeader
-
Method Details
-
cleanMappedByteBuffer
-
create
Description copied from interface:DataAccessThe first time you use a DataAccess object after configuring it you need to call this method. After that first call you have to use ensureCapacity to ensure that enough space is reserved. -
ensureCapacity
public boolean ensureCapacity(long bytes) Description copied from interface:DataAccessEnsures that the capacity of this object is at least the specified bytes. The first time you have to call 'create' instead.- Returns:
- true if size was increased
- See Also:
-
loadExisting
public boolean loadExisting()- Returns:
- true if successfully loaded from persistent storage.
-
flush
public void flush()Description copied from interface:DataAccessThis method makes sure that the underlying data is written to the storage. Keep in mind that a disc normally has an IO cache so that flush() is (less) probably not save against power loses. -
load
public void load(int percentage) Load memory mapped files into physical memory. -
close
public void close()Description copied from interface:DataAccessThis method makes sure that the underlying used resources are released. WARNING: it does NOT flush on close!- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceDataAccess- Overrides:
closein classAbstractDataAccess
-
setInt
public void setInt(long bytePos, int value) Description copied from interface:DataAccessSet 4 bytes at position 'bytePos' to the specified value -
getInt
public int getInt(long bytePos) Description copied from interface:DataAccessGet 4 bytes from position 'bytePos' -
setShort
public void setShort(long bytePos, short value) Description copied from interface:DataAccessSet 2 bytes at position 'index' to the specified value -
getShort
public short getShort(long bytePos) Description copied from interface:DataAccessGet 2 bytes from position 'index' -
setBytes
public void setBytes(long bytePos, byte[] values, int length) Description copied from interface:DataAccessSet bytes from position 'index' to the specified values -
getBytes
public void getBytes(long bytePos, byte[] values, int length) Description copied from interface:DataAccessGet bytes from position 'index'values- acts as output
-
setByte
public void setByte(long bytePos, byte value) -
getByte
public byte getByte(long bytePos) -
getCapacity
public long getCapacity()- Returns:
- the allocated storage size in bytes
-
getSegments
public int getSegments()- Returns:
- the number of segments.
-
getType
- Returns:
- the data access type of this object.
-