mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-09 01:47:39 +01:00
parent
d30d87b346
commit
88b30b9287
@ -20,7 +20,6 @@ import com.djrapitops.plan.identification.ServerUUID;
|
|||||||
import com.djrapitops.plan.processing.Processing;
|
import com.djrapitops.plan.processing.Processing;
|
||||||
import com.djrapitops.plan.settings.config.PlanConfig;
|
import com.djrapitops.plan.settings.config.PlanConfig;
|
||||||
import com.djrapitops.plan.settings.config.paths.WebserverSettings;
|
import com.djrapitops.plan.settings.config.paths.WebserverSettings;
|
||||||
import com.djrapitops.plan.utilities.UnitSemaphoreAccessLock;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
@ -29,6 +28,7 @@ import java.util.Optional;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ public class AsyncJSONResolverService {
|
|||||||
private final JSONStorage jsonStorage;
|
private final JSONStorage jsonStorage;
|
||||||
private final Map<String, Future<JSONStorage.StoredJSON>> currentlyProcessing;
|
private final Map<String, Future<JSONStorage.StoredJSON>> currentlyProcessing;
|
||||||
private final Map<String, Long> previousUpdates;
|
private final Map<String, Long> previousUpdates;
|
||||||
private final UnitSemaphoreAccessLock accessLock; // Access lock prevents double processing same resource
|
private final ReentrantLock accessLock; // Access lock prevents double processing same resource
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public AsyncJSONResolverService(
|
public AsyncJSONResolverService(
|
||||||
@ -59,7 +59,7 @@ public class AsyncJSONResolverService {
|
|||||||
|
|
||||||
currentlyProcessing = new ConcurrentHashMap<>();
|
currentlyProcessing = new ConcurrentHashMap<>();
|
||||||
previousUpdates = new ConcurrentHashMap<>();
|
previousUpdates = new ConcurrentHashMap<>();
|
||||||
accessLock = new UnitSemaphoreAccessLock();
|
accessLock = new ReentrantLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> JSONStorage.StoredJSON resolve(
|
public <T> JSONStorage.StoredJSON resolve(
|
||||||
@ -131,7 +131,7 @@ public class AsyncJSONResolverService {
|
|||||||
long updateThreshold = config.get(WebserverSettings.REDUCED_REFRESH_BARRIER);
|
long updateThreshold = config.get(WebserverSettings.REDUCED_REFRESH_BARRIER);
|
||||||
|
|
||||||
Future<JSONStorage.StoredJSON> updatedJSON;
|
Future<JSONStorage.StoredJSON> updatedJSON;
|
||||||
accessLock.enter();
|
accessLock.lock();
|
||||||
try {
|
try {
|
||||||
// Check if the json is already being created
|
// Check if the json is already being created
|
||||||
updatedJSON = currentlyProcessing.get(identifier);
|
updatedJSON = currentlyProcessing.get(identifier);
|
||||||
@ -141,7 +141,7 @@ public class AsyncJSONResolverService {
|
|||||||
currentlyProcessing.put(identifier, updatedJSON);
|
currentlyProcessing.put(identifier, updatedJSON);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
accessLock.exit();
|
accessLock.unlock();
|
||||||
}
|
}
|
||||||
return updatedJSON;
|
return updatedJSON;
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,9 @@ import com.djrapitops.plan.delivery.web.resolver.request.Request;
|
|||||||
import com.djrapitops.plan.delivery.web.resolver.request.WebUser;
|
import com.djrapitops.plan.delivery.web.resolver.request.WebUser;
|
||||||
import com.djrapitops.plan.delivery.webserver.cache.AsyncJSONResolverService;
|
import com.djrapitops.plan.delivery.webserver.cache.AsyncJSONResolverService;
|
||||||
import com.djrapitops.plan.delivery.webserver.cache.DataID;
|
import com.djrapitops.plan.delivery.webserver.cache.DataID;
|
||||||
|
import com.djrapitops.plan.delivery.webserver.cache.JSONStorage;
|
||||||
import com.djrapitops.plan.identification.Identifiers;
|
import com.djrapitops.plan.identification.Identifiers;
|
||||||
|
import com.djrapitops.plan.utilities.java.Maps;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
@ -60,9 +62,19 @@ public class NetworkTabJSONResolver<T> implements Resolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Response getResponse(Request request) {
|
private Response getResponse(Request request) {
|
||||||
|
JSONStorage.StoredJSON json = asyncJSONResolverService.resolve(Identifiers.getTimestamp(request), dataID, jsonCreator);
|
||||||
|
if (json == null) {
|
||||||
|
return Response.builder()
|
||||||
|
.setMimeType(MimeType.JSON)
|
||||||
|
.setJSONContent(Maps.builder(String.class, String.class)
|
||||||
|
.put("error", "Json failed to generate for some reason, see /Plan/logs for errors")
|
||||||
|
.build())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
return Response.builder()
|
return Response.builder()
|
||||||
.setMimeType(MimeType.JSON)
|
.setMimeType(MimeType.JSON)
|
||||||
.setJSONContent(asyncJSONResolverService.resolve(Identifiers.getTimestamp(request), dataID, jsonCreator).json)
|
.setJSONContent(json.json)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user