delombok.io.github.qsy7.examples.proxy.ByteBuddyProxyExampleCommandLineHandler Maven / Gradle / Ivy
The newest version!
// Generated by delombok at Sat Jan 13 17:02:35 EST 2024
package io.github.qsy7.examples.proxy;
import io.github.qsy7.inject.cli.service.CommandLineHandler;
import jakarta.inject.Inject;
import net.bytebuddy.ByteBuddy;
import net.bytebuddy.agent.ByteBuddyAgent;
import net.bytebuddy.dynamic.loading.ClassReloadingStrategy;
import net.bytebuddy.implementation.MethodDelegation;
import net.bytebuddy.matcher.ElementMatchers;
public class ByteBuddyProxyExampleCommandLineHandler implements CommandLineHandler {
// @Inject
// public ByteBuddyProxyExampleCommandLineHandler(
// @Property(CommandLineHandlerShutdownTimeout.class) int shutdownTimeoutInSeconds) {
// super(shutdownTimeoutInSeconds);
// }
@Override
public void run(String... arguments) {
setupByteBuddy();
testInvocation();
}
protected void setupByteBuddy() {
ByteBuddyAgent.install();
final ByteBuddy byteBuddy = new ByteBuddy();
// AgentBuilder.RedefinitionListenable.Default.di
byteBuddy.redefine(ByteBuddyFoo.class).method(ElementMatchers.named("anotherMethod").or(ElementMatchers.named("toString"))).intercept(MethodDelegation.to(MethodInterceptor.class)).make().load(ByteBuddyFoo.class.getClassLoader(), ClassReloadingStrategy.fromInstalledAgent());
}
protected void testInvocation() {
ByteBuddyFoo f = new ByteBuddyFoo();
// invoke another method multiple times just to illustrate we're intercepting it
f.anotherMethod("message goes here");
f.anotherMethod("message goes here");
f.anotherMethod("message goes here");
}
@Inject
@java.lang.SuppressWarnings("all")
public ByteBuddyProxyExampleCommandLineHandler() {
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy