com.dronjax.java.objectshutdownproxy.ObjectShutdownProxyComponent Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of object-shutdown-proxy Show documentation
Show all versions of object-shutdown-proxy Show documentation
Create proxy for your java object to synchronously wait for all methods to finish calling.
The newest version!
package com.dronjax.java.objectshutdownproxy;
import java.lang.reflect.Proxy;
public final class ObjectShutdownProxyComponent {
private final T service;
private final ObjectShutdownInvocationHandler invocationHandler;
private ObjectShutdownProxyComponent(
final T service,
final Class clazzContract,
final boolean ignoreAnnotation
) {
this.invocationHandler = new ObjectShutdownInvocationHandler<>(
service,
clazzContract,
ignoreAnnotation
);
this.service = createProxy(
service,
clazzContract
);
}
public static ObjectShutdownProxyComponent coverAllPublicClassMethod(
final T service,
final Class clazzContract
) {
return new ObjectShutdownProxyComponent<>(
service,
clazzContract,
true
);
}
public static ObjectShutdownProxyComponent coverAnnotatedClassOrMethod(
final T service,
final Class clazzContract
) {
return new ObjectShutdownProxyComponent<>(
service,
clazzContract,
false
);
}
public T getProxiedService() {
return service;
}
public ShutdownHandler getShutdownHandler() {
return invocationHandler;
}
@SuppressWarnings("unchecked")
private T createProxy(
final T service,
final Class clazzContract
) {
return (T) Proxy.newProxyInstance(
service.getClass().getClassLoader(),
new Class[]{clazzContract},
invocationHandler
);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy