mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-11-05 10:20:23 +01:00
Moved interfaces to inside the using class.
This commit is contained in:
parent
e9b9c68d07
commit
a62e15fccd
@ -1,6 +1,5 @@
|
||||
package com.djrapitops.plan.system.cache;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.connection.WebException;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBException;
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.system.PlanSystem;
|
||||
@ -61,11 +60,7 @@ public class SessionCache {
|
||||
new Processor<PlanSystem>(system) {
|
||||
@Override
|
||||
public void process() {
|
||||
try {
|
||||
system.getInfoSystem().generateAndCachePlayerPage(uuid);
|
||||
} catch (WebException e) {
|
||||
WebExceptionLogger.log(this.getClass(), e);
|
||||
}
|
||||
WebExceptionLogger.logIfOccurs(this.getClass(), () -> system.getInfoSystem().generateAndCachePlayerPage(uuid));
|
||||
}
|
||||
}.queue();
|
||||
}
|
||||
@ -82,11 +77,8 @@ public class SessionCache {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
} finally {
|
||||
activeSessions.remove(uuid);
|
||||
try {
|
||||
system.getInfoSystem().generateAndCachePlayerPage(uuid);
|
||||
} catch (WebException e) {
|
||||
WebExceptionLogger.log(this.getClass(), e);
|
||||
}
|
||||
|
||||
WebExceptionLogger.logIfOccurs(this.getClass(), () -> system.getInfoSystem().generateAndCachePlayerPage(uuid));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,14 +14,14 @@ import com.djrapitops.plugin.api.utility.log.Log;
|
||||
*/
|
||||
public class WebExceptionLogger {
|
||||
|
||||
public static void log(Class c, ExceptionLoggingAction action) {
|
||||
public static void logIfOccurs(Class c, ExceptionLoggingAction action) {
|
||||
try {
|
||||
action.performAction();
|
||||
} catch (ConnectionFailException | UnsupportedTransferDatabaseException | UnauthorizedServerException
|
||||
| NotFoundException | NoServersException e) {
|
||||
Log.warn(e.getMessage());
|
||||
} catch (WebException e) {
|
||||
Log.toLog(WebExceptionLogger.class, e);
|
||||
Log.toLog(c, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,15 +0,0 @@
|
||||
package com.djrapitops.plan.system.webserver.response.cache;
|
||||
|
||||
import com.djrapitops.plan.system.webserver.response.Response;
|
||||
|
||||
/**
|
||||
* This interface is used for providing the method to load the page.
|
||||
*
|
||||
* @author Fuzzlemann
|
||||
* @since 3.6.0
|
||||
*/
|
||||
public interface PageLoader {
|
||||
|
||||
Response createResponse();
|
||||
|
||||
}
|
@ -29,18 +29,18 @@ public class ResponseCache {
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the page from the page cache.
|
||||
* Loads the response from the response cache.
|
||||
* <p>
|
||||
* If the {@link Response} isn't cached, {@link PageLoader#createResponse()} in the {@code loader}
|
||||
* If the {@link Response} isn't cached, {@link ResponseLoader#createResponse()} in the {@code loader}
|
||||
* is called to create the Response.
|
||||
* <p>
|
||||
* If the Response is created, it's automatically cached.
|
||||
*
|
||||
* @param identifier The identifier of the page
|
||||
* @param loader The {@link PageLoader} (How should it load the page if it's not cached)
|
||||
* @return The Response that was cached or created by the {@link PageLoader loader}
|
||||
* @param loader The {@link ResponseLoader} (How should it load the page if it's not cached)
|
||||
* @return The Response that was cached or created by the {@link ResponseLoader loader}
|
||||
*/
|
||||
public static Response loadResponse(String identifier, PageLoader loader) {
|
||||
public static Response loadResponse(String identifier, ResponseLoader loader) {
|
||||
Response response = loadResponse(identifier);
|
||||
|
||||
if (response != null) {
|
||||
@ -72,7 +72,7 @@ public class ResponseCache {
|
||||
* @param identifier The identifier of the page
|
||||
* @return Copied Response of loadResponse, so that cache contents are not changed.
|
||||
*/
|
||||
public static Response copyResponse(String identifier, PageLoader loader) {
|
||||
public static Response copyResponse(String identifier, ResponseLoader loader) {
|
||||
Response response = loadResponse(identifier, loader);
|
||||
if (response instanceof InspectPageResponse) {
|
||||
return InspectPageResponse.copyOf((InspectPageResponse) response);
|
||||
@ -86,9 +86,9 @@ public class ResponseCache {
|
||||
* If the cache already inherits that {@code identifier}, it's renewed.
|
||||
*
|
||||
* @param identifier The identifier of the page
|
||||
* @param loader The {@link PageLoader} (How it should load the page)
|
||||
* @param loader The {@link ResponseLoader} (How it should load the page)
|
||||
*/
|
||||
public static void cacheResponse(String identifier, PageLoader loader) {
|
||||
public static void cacheResponse(String identifier, ResponseLoader loader) {
|
||||
Response response = loader.createResponse();
|
||||
cache.put(identifier, response);
|
||||
}
|
||||
@ -122,4 +122,16 @@ public class ResponseCache {
|
||||
public static void clearCache() {
|
||||
cache.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* This interface is used for providing the method to load the page.
|
||||
*
|
||||
* @author Fuzzlemann
|
||||
* @since 4.2.0
|
||||
*/
|
||||
public interface ResponseLoader {
|
||||
|
||||
Response createResponse();
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user