<commit_before>package com.codingchili.core.Storage;

import io.vertx.core.*;
import io.vertx.core.json.JsonObject;

import java.util.Optional;

import com.codingchili.core.Context.StorageContext;
import com.codingchili.core.Files.JsonFileStore;

/**
 * @author <NAME>
 *         <p>
 *         Map backed by a json-file.
 */
public class AsyncJsonMap<Key, Value> implements AsyncStorage<Key, Value> {
    private static final String ASYNCJSONMAP_WORKERS = "asyncjsonmap.workers";
    private final WorkerExecutor fileWriter;
    private JsonObject db = new JsonObject();
    private StorageContext<Value> context;

    public AsyncJsonMap(Future<AsyncStorage<Key, Value>> future, StorageContext<Value> context) {
        this.context = context;
        this.fileWriter = context.vertx().createSharedWorkerExecutor(ASYNCJSONMAP_WORKERS);
        future.complete(this);
    }

    @Override
    public void get(Key key, Handler<AsyncResult<Value>> handler) {
        Optional<Value> value = get(key);

        if (value.isPresent()) {
            handler.handle(Future.succeededFuture(value.get()));
        } else {
            handler.handle(Future.succeededFuture());
        }
    }

    @Override
    public void put(Key key, Value value, Handler<AsyncResult<Void>> handler) {
        put(key, value);
        handler.handle(Future.succeededFuture());
    }

    @Override
    public void put(Key key, Value value, long ttl, Handler<AsyncResult<Void>> handler) {
        put(key, value, handler);

        context.timer(ttl, event -> remove(key));
    }
<commit_msg>json-file storage plugin loads DB from disk on startup.<commit_after>package com.codingchili.core.Storage;

import io.vertx.core.*;
import io.vertx.core.json.JsonObject;

import java.io.IOException;
import java.util.Optional;

import com.codingchili.core.Configuration.Strings;
import com.codingchili.core.Context.StorageContext;
import com.codingchili.core.Files.JsonFileStore;

/**
 * @author <NAME>
 *         <p>
 *         Map backed by a json-file.
 */
public class AsyncJsonMap<Key, Value> implements AsyncStorage<Key, Value> {
    private static final String ASYNCJSONMAP_WORKERS = "asyncjsonmap.workers";
    private final WorkerExecutor fileWriter;
    private JsonObject db;
    private StorageContext<Value> context;

    public AsyncJsonMap(Future<AsyncStorage<Key, Value>> future, StorageContext<Value> context) {
        this.context = context;
        this.fileWriter = context.vertx().createSharedWorkerExecutor(ASYNCJSONMAP_WORKERS);

        try {
            db = JsonFileStore.readObject(context.DB());
        } catch (IOException e) {
            db = new JsonObject();
            context.console().log(Strings.getFileReadError(context.DB()));
        }

        future.complete(this);
    }

    @Override
    public void get(Key key, Handler<AsyncResult<Value>> handler) {
        Optional<Value> value = get(key);

        if (value.isPresent()) {
            handler.handle(Future.succeededFuture(value.get()));
        } else {
            handler.handle(Future.succeededFuture());
        }
    }

    @Override
    public void put(Key key, Value value, Handler<AsyncResult<Void>> handler) {
        put(key, value);
        handler.handle(Future.succeededFuture());
    }

    @Override
    public void put(Key key, Value value, long ttl, Handler<AsyncResult<Void>> handler) {
        put(key, value, handler);

        context.timer(ttl, event -> remove(key));
    }

{'fraction_non_alphanumeric': 0.11646007494955318, 'fraction_numerical': 0.0, 'mean_word_length': 3.160671462829736, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2651148', 'n_tokens_mistral': 1022, 'n_tokens_neox': 988, 'n_words': 220}