Better method disabling for DataExtension API

This commit is contained in:
Risto Lahtela 2020-05-23 12:13:11 +03:00
parent e725cc2086
commit 15e7d38043
4 changed files with 11 additions and 3 deletions

View File

@ -1,6 +1,7 @@
dependencies {
compile "com.djrapitops:AbstractPluginFramework-api:$abstractPluginFrameworkVersion"
compile project(":api")
compileOnly project(":extensions")
compile project(path: ":extensions", configuration: 'shadow')
compile "org.apache.httpcomponents:httpclient:$httpClientVersion"
compile "org.apache.commons:commons-text:$commonsTextVersion"

View File

@ -29,9 +29,9 @@ public class DataExtensionMethodCallException extends IllegalStateException {
private final String pluginName;
// Non serializable field due to Method not being serializable.
private final transient MethodWrapper method;
private final transient MethodWrapper<?> method;
public DataExtensionMethodCallException(Throwable cause, String pluginName, MethodWrapper method) {
public DataExtensionMethodCallException(Throwable cause, String pluginName, MethodWrapper<?> method) {
super(cause);
this.pluginName = pluginName;
this.method = method;
@ -41,7 +41,7 @@ public class DataExtensionMethodCallException extends IllegalStateException {
return pluginName;
}
public Optional<MethodWrapper> getMethod() {
public Optional<MethodWrapper<?>> getMethod() {
// method is transient and might be lost if flushed to disk.
return Optional.ofNullable(method);
}

View File

@ -34,6 +34,7 @@ public class MethodWrapper<T> {
private final Method method;
private final Class<T> returnType;
private final MethodType methodType;
private boolean disabled = false;
public MethodWrapper(Method method, Class<T> returnType) {
this.method = method;
@ -42,6 +43,7 @@ public class MethodWrapper<T> {
}
public T callMethod(DataExtension extension, Parameters with) {
if (disabled) return null;
try {
return returnType.cast(with.usingOn(extension, method));
} catch (InvocationTargetException notReadyToBeCalled) {
@ -67,6 +69,10 @@ public class MethodWrapper<T> {
return returnType;
}
public void disable() {
this.disabled = true;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;

View File

@ -105,6 +105,7 @@ public class ProviderValueGatherer {
}
public void disableMethodFromUse(MethodWrapper<?> method) {
method.disable();
dataProviders.removeProviderWithMethod(method);
}