use of org.apache.drill.common.concurrent.AutoCloseableLock in project drill by apache.
the class CustomHandlerRegistry method registerCustomHandler.
public <REQUEST, RESPONSE> void registerCustomHandler(int messageTypeId, CustomMessageHandler<REQUEST, RESPONSE> handler, Controller.CustomSerDe<REQUEST> requestSerde, Controller.CustomSerDe<RESPONSE> responseSerde) {
Preconditions.checkNotNull(handler);
Preconditions.checkNotNull(requestSerde);
Preconditions.checkNotNull(responseSerde);
try (AutoCloseableLock lock = write.open()) {
ParsingHandler<?, ?> parsingHandler = handlers.get(messageTypeId);
if (parsingHandler != null) {
throw new IllegalStateException(String.format("Only one handler can be registered for a given custom message type. You tried to register a handler for " + "the %d message type but one had already been registered.", messageTypeId));
}
parsingHandler = new ParsingHandler<REQUEST, RESPONSE>(handler, requestSerde, responseSerde);
handlers.put(messageTypeId, parsingHandler);
}
}
use of org.apache.drill.common.concurrent.AutoCloseableLock in project drill by apache.
the class LocalPersistentStore method contains.
@Override
public boolean contains(String key, DataChangeVersion dataChangeVersion) {
try (AutoCloseableLock lock = readLock.open()) {
try {
Path path = makePath(key);
boolean exists = fs.exists(path);
if (exists && dataChangeVersion != null) {
dataChangeVersion.setVersion(version);
}
return exists;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
use of org.apache.drill.common.concurrent.AutoCloseableLock in project drill by apache.
the class LocalPersistentStore method getRange.
@Override
public Iterator<Map.Entry<String, V>> getRange(int skip, int take) {
try (AutoCloseableLock lock = readLock.open()) {
try {
List<FileStatus> f = fs.list(false, basePath);
if (f == null || f.isEmpty()) {
return Collections.emptyIterator();
}
List<String> files = Lists.newArrayList();
for (FileStatus stat : f) {
String s = stat.getPath().getName();
if (s.endsWith(DRILL_SYS_FILE_SUFFIX)) {
files.add(s.substring(0, s.length() - DRILL_SYS_FILE_SUFFIX.length()));
}
}
Collections.sort(files);
return Iterables.transform(Iterables.limit(Iterables.skip(files, skip), take), new Function<String, Entry<String, V>>() {
@Nullable
@Override
public Entry<String, V> apply(String key) {
return new ImmutableEntry<>(key, get(key));
}
}).iterator();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
use of org.apache.drill.common.concurrent.AutoCloseableLock in project drill by apache.
the class InMemoryStore method delete.
@Override
public void delete(final String key) {
try (AutoCloseableLock lock = writeLock.open()) {
store.remove(key);
version++;
}
}
use of org.apache.drill.common.concurrent.AutoCloseableLock in project drill by apache.
the class InMemoryStore method put.
@Override
public void put(final String key, final V value, final DataChangeVersion dataChangeVersion) {
try (AutoCloseableLock lock = writeLock.open()) {
if (dataChangeVersion != null && dataChangeVersion.getVersion() != version) {
throw new VersionMismatchException("Version mismatch detected", dataChangeVersion.getVersion());
}
store.put(key, value);
if (currentSize.incrementAndGet() > capacity) {
//Pop Out Oldest
store.pollLastEntry();
currentSize.decrementAndGet();
}
version++;
}
}
Aggregations