mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-14 04:16:53 +00:00
feat[orm]: lpmap增加clear方法
This commit is contained in:
1 parent
8a6c7bbbc1
commit
1d89a78488
7 files changed
+48
No files matched your search
@@ -73,6 +73,17 @@ public class ConcurrentFileChannelHeapMap<V extends IPacket> implements LpMap<V>
|
||||
return concurrentHeapMap.getIncrementIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
fileChannelLock.lock();
|
||||
try {
|
||||
fileChannelMap.clear();
|
||||
concurrentHeapMap.clear();
|
||||
} finally {
|
||||
fileChannelLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private void load() {
|
||||
var maxIndex = fileChannelMap.getMaxIndex();
|
||||
if (maxIndex <= 0) {
|
||||
|
||||
@@ -69,6 +69,12 @@ public class ConcurrentHeapMap<V extends IPacket> implements LpMap<V> {
|
||||
return maxIndexAtomic.incrementAndGet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
map.clear();
|
||||
maxIndexAtomic.set(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(BiConsumer<Long, V> biConsumer) {
|
||||
map.forEach(biConsumer);
|
||||
|
||||
@@ -60,6 +60,12 @@ public class FileChannelHeapMap<V extends IPacket> implements LpMap<V> {
|
||||
return heapMap.getIncrementIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
fileChannelMap.clear();
|
||||
heapMap.clear();
|
||||
}
|
||||
|
||||
private void load() {
|
||||
var maxIndex = fileChannelMap.getMaxIndex();
|
||||
if (maxIndex <= 0) {
|
||||
|
||||
@@ -156,6 +156,17 @@ public class FileChannelMap<V extends IPacket> implements LpMap<V>, Closeable {
|
||||
return maxIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
try {
|
||||
setMaxIndex(0);
|
||||
dbFileRandomAccess.setLength(0);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void setKeyValue(long key, V value) {
|
||||
try {
|
||||
clearByteBuf();
|
||||
|
||||
@@ -82,6 +82,12 @@ public class FileHeapMap<V extends IPacket> implements LpMap<V> {
|
||||
return heapMap.getIncrementIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
heapMap.clear();
|
||||
save();
|
||||
}
|
||||
|
||||
private void load() {
|
||||
FileInputStream fileInputStream = null;
|
||||
FileChannel fileChannel = null;
|
||||
|
||||
@@ -70,6 +70,12 @@ public class HeapMap<V extends IPacket> implements LpMap<V> {
|
||||
return maxIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
maxIndex = 0;
|
||||
map.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(BiConsumer<Long, V> biConsumer) {
|
||||
map.forEach(biConsumer);
|
||||
|
||||
@@ -42,6 +42,8 @@ public interface LpMap<V extends IPacket> {
|
||||
|
||||
long getIncrementIndex();
|
||||
|
||||
void clear();
|
||||
|
||||
default void checkKey(long key) {
|
||||
if (key <= 0) {
|
||||
throw new RunException("key[{}]不能为负数或0", key);
|
||||
|
||||
Reference in new issue
Block a user