[mapdb] Make serialization asynchronous (#14900)
* [mapdb] Make serialization asynchronous --------- Signed-off-by: Jan N. Klug <github@klug.nrw>
This commit is contained in:
@@ -73,7 +73,9 @@ public class MapDbPersistenceService implements QueryablePersistenceService {
|
||||
|
||||
private final ExecutorService threadPool = ThreadPoolManager.getPool(getClass().getSimpleName());
|
||||
|
||||
/** holds the local instance of the MapDB database */
|
||||
/**
|
||||
* holds the local instance of the MapDB database
|
||||
*/
|
||||
|
||||
private @NonNullByDefault({}) DB db;
|
||||
private @NonNullByDefault({}) Map<String, String> map;
|
||||
@@ -182,12 +184,12 @@ public class MapDbPersistenceService implements QueryablePersistenceService {
|
||||
mItem.setName(localAlias);
|
||||
mItem.setState(state);
|
||||
mItem.setTimestamp(new Date());
|
||||
String json = serialize(mItem);
|
||||
map.put(localAlias, json);
|
||||
commit();
|
||||
if (logger.isDebugEnabled()) {
|
||||
threadPool.submit(() -> {
|
||||
String json = serialize(mItem);
|
||||
map.put(localAlias, json);
|
||||
db.commit();
|
||||
logger.debug("Stored '{}' with state '{}' as '{}' in MapDB database", localAlias, state, json);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -217,10 +219,6 @@ public class MapDbPersistenceService implements QueryablePersistenceService {
|
||||
return Optional.of(item);
|
||||
}
|
||||
|
||||
private void commit() {
|
||||
threadPool.submit(() -> db.commit());
|
||||
}
|
||||
|
||||
private static <T> Stream<T> streamOptional(Optional<T> opt) {
|
||||
return opt.isPresent() ? Stream.of(opt.get()) : Stream.empty();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user