-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement DBLevelAsyncIndexManagerDecorator
- Loading branch information
Showing
6 changed files
with
90 additions
and
25 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/main/java/com/github/sepgh/internal/index/DBLevelAsyncIndexManagerDecorator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.github.sepgh.internal.index; | ||
|
||
import com.github.sepgh.internal.index.tree.node.BaseTreeNode; | ||
|
||
import java.io.IOException; | ||
import java.util.Optional; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.locks.ReentrantReadWriteLock; | ||
|
||
public class DBLevelAsyncIndexManagerDecorator extends IndexManagerDecorator { | ||
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); | ||
private final ReentrantReadWriteLock.ReadLock readLock = lock.readLock(); | ||
private final ReentrantReadWriteLock.WriteLock writeLock = lock.writeLock(); | ||
public DBLevelAsyncIndexManagerDecorator(IndexManager indexManager) { | ||
super(indexManager); | ||
} | ||
|
||
@Override | ||
public BaseTreeNode addIndex(int table, long identifier, Pointer pointer) throws ExecutionException, InterruptedException, IOException { | ||
writeLock.lock(); | ||
try { | ||
return super.addIndex(table, identifier, pointer); | ||
} finally { | ||
writeLock.unlock(); | ||
} | ||
} | ||
|
||
@Override | ||
public Optional<Pointer> getIndex(int table, long identifier) throws ExecutionException, InterruptedException, IOException { | ||
readLock.lock(); | ||
try { | ||
return super.getIndex(table, identifier); | ||
} finally { | ||
readLock.unlock(); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean removeIndex(int table, long identifier) throws ExecutionException, InterruptedException, IOException { | ||
writeLock.lock(); | ||
try { | ||
return super.removeIndex(table, identifier); | ||
} finally { | ||
writeLock.unlock(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters