mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-21 05:50:18 +08:00
Better method disabling for DataExtension API
This commit is contained in:
parent
e725cc2086
commit
15e7d38043
@ -1,6 +1,7 @@
|
|||||||
dependencies {
|
dependencies {
|
||||||
compile "com.djrapitops:AbstractPluginFramework-api:$abstractPluginFrameworkVersion"
|
compile "com.djrapitops:AbstractPluginFramework-api:$abstractPluginFrameworkVersion"
|
||||||
compile project(":api")
|
compile project(":api")
|
||||||
|
compileOnly project(":extensions")
|
||||||
compile project(path: ":extensions", configuration: 'shadow')
|
compile project(path: ":extensions", configuration: 'shadow')
|
||||||
compile "org.apache.httpcomponents:httpclient:$httpClientVersion"
|
compile "org.apache.httpcomponents:httpclient:$httpClientVersion"
|
||||||
compile "org.apache.commons:commons-text:$commonsTextVersion"
|
compile "org.apache.commons:commons-text:$commonsTextVersion"
|
||||||
|
@ -29,9 +29,9 @@ public class DataExtensionMethodCallException extends IllegalStateException {
|
|||||||
|
|
||||||
private final String pluginName;
|
private final String pluginName;
|
||||||
// Non serializable field due to Method not being serializable.
|
// 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);
|
super(cause);
|
||||||
this.pluginName = pluginName;
|
this.pluginName = pluginName;
|
||||||
this.method = method;
|
this.method = method;
|
||||||
@ -41,7 +41,7 @@ public class DataExtensionMethodCallException extends IllegalStateException {
|
|||||||
return pluginName;
|
return pluginName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<MethodWrapper> getMethod() {
|
public Optional<MethodWrapper<?>> getMethod() {
|
||||||
// method is transient and might be lost if flushed to disk.
|
// method is transient and might be lost if flushed to disk.
|
||||||
return Optional.ofNullable(method);
|
return Optional.ofNullable(method);
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ public class MethodWrapper<T> {
|
|||||||
private final Method method;
|
private final Method method;
|
||||||
private final Class<T> returnType;
|
private final Class<T> returnType;
|
||||||
private final MethodType methodType;
|
private final MethodType methodType;
|
||||||
|
private boolean disabled = false;
|
||||||
|
|
||||||
public MethodWrapper(Method method, Class<T> returnType) {
|
public MethodWrapper(Method method, Class<T> returnType) {
|
||||||
this.method = method;
|
this.method = method;
|
||||||
@ -42,6 +43,7 @@ public class MethodWrapper<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public T callMethod(DataExtension extension, Parameters with) {
|
public T callMethod(DataExtension extension, Parameters with) {
|
||||||
|
if (disabled) return null;
|
||||||
try {
|
try {
|
||||||
return returnType.cast(with.usingOn(extension, method));
|
return returnType.cast(with.usingOn(extension, method));
|
||||||
} catch (InvocationTargetException notReadyToBeCalled) {
|
} catch (InvocationTargetException notReadyToBeCalled) {
|
||||||
@ -67,6 +69,10 @@ public class MethodWrapper<T> {
|
|||||||
return returnType;
|
return returnType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void disable() {
|
||||||
|
this.disabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
|
@ -105,6 +105,7 @@ public class ProviderValueGatherer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void disableMethodFromUse(MethodWrapper<?> method) {
|
public void disableMethodFromUse(MethodWrapper<?> method) {
|
||||||
|
method.disable();
|
||||||
dataProviders.removeProviderWithMethod(method);
|
dataProviders.removeProviderWithMethod(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user