![JAR search and dependency download from the Maven repository](/logo.png)
com.kolibrifx.plovercrest.server.internal.protocol.ReadContinuationCache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of plovercrest-server Show documentation
Show all versions of plovercrest-server Show documentation
Plovercrest server library.
The newest version!
/*
* Copyright (c) 2010-2017, KolibriFX AS. Licensed under the Apache License, version 2.0.
*/
package com.kolibrifx.plovercrest.server.internal.protocol;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;
import com.kolibrifx.plovercrest.server.internal.streams.RuntimeReadContinuation;
import com.kolibrifx.plovercrest.server.streams.ReaderPosition;
public class ReadContinuationCache {
private static final Logger log = Logger.getLogger(ReadContinuationCache.class);
private final Map> map = new HashMap<>();
public void register(final String tableName, final RuntimeReadContinuation continuation) {
if (log.isDebugEnabled() && map.containsKey(tableName)) {
log.debug("Overwriting continuation for table: " + tableName);
}
map.put(tableName, continuation);
}
public RuntimeReadContinuation tryGetAndRemove(final String tableName, final ReaderPosition position) {
final RuntimeReadContinuation continuation = map.get(tableName);
if (continuation == null) {
return null;
}
final ReaderPosition readerPosition = continuation.getReader().getReaderPosition();
if (!readerPosition.equals(position)) {
if (log.isDebugEnabled()) {
log.debug("Performance note: found continuation for " + tableName + ", but its position ("
+ readerPosition + ") does not match the request: " + position);
}
return null;
}
// Remove the continuation: it will normally be registered again when the read request (chunk) is finished.
map.remove(tableName);
return continuation;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy