<dependency>
<groupId>com.github.iroh</groupId>
<artifactId>iroh</artifactId>
<version>1.0.0</version>
</dependency>
groovy
implementation 'com.github.iroh:iroh:1.0.0'
import com.github.iroh.aspect.Aspect;
import com.github.iroh.interceptor.MethodInterceptor;
import com.github.iroh.location.Location;
import com.github.iroh.location.LocationContext;
public class LoggingAspect implements Aspect {
@Override
public void before(LocationContext locationContext) {
Location location = locationContext.getLocation();
System.out.println("Before executing method: " + location.getMethod());
}
@Override
public void afterReturning(LocationContext locationContext, Object returnValue) {
Location location = locationContext.getLocation();
System.out.println("After executing method: " + location.getMethod());
}
@Override
public void afterThrowing(LocationContext locationContext, Throwable throwable) {
Location location = locationContext.getLocation();
System.out.println("Exception occurred in method: " + location.getMethod());
throwable.printStackTrace();
}
@Override
public void addInterceptors(MethodInterceptor methodInterceptor) {
methodInterceptor.addPattern("*"); // Intercepts all methods
}
}
public class MyLibrary {
public void doSomething() {
System.out.println("Doing something...");
}
public void doSomethingWithOptions(boolean enabled) {
if (enabled) {
System.out.println("Doing something with options enabled...");
} else {
System.out.println("Doing something with options disabled...");
}
}
}
import com.github.iroh.Iroh;
import com.github.iroh.Iroh.Builder;
public class Main {
public static void main(String[] args) {
Builder builder = Iroh.builder(); // Create an instance of Iroh.Builder
builder.add(new LoggingAspect()); // Add LoggingAspect to it
Iroh iroh = builder.build(); // Build the Iroh instance
iroh.start(); // Start Iroh
MyLibrary myLibrary = new MyLibrary();
myLibrary.doSomething();
myLibrary.doSomethingWithOptions(true);
iroh.stop(); // Stop Iroh
}
}