Sarge not working with pre-instantiated objects
I'm not sure if this is a bug, not supported, or I am simply misunderstanding how Sarge works. If I have Sarge instantiate the supervised object and return it everything works as expected. However if I instantiate the object myself and pass into a Sarge instance then Sarge does nothing when an exception occurs.
This works:
Sarge sarge = new Sarge();
Plan plan = Plans.retryOn(IllegalStateException.class, 5, Duration.seconds(10)).make();
Foo foo = sarge.supervised(Foo.class, plan);
This does not:
Sarge sarge = new Sarge();
Plan plan = Plans.retryOn(IllegalStateException.class, 5, Duration.seconds(10)).make();
Foo foo = new Foo();
sarge.supervise(foo, plan);
@dfdemar The short of this is that Sarge needs to be involved in the instantiation of an object, typically by calling Sarge.supervised. The reason is that Sarge uses method interceptors to handle invocation failures according to your plan, and those interceptors can only be installed at object creation time (more or less).
For objects that can't be simply constructed, such as with a default constructor, Sarge supports integration with 3rd party DI libraries like Guice and Spring via its SupervisedInterceptor. This allows you to construct objects via those libraries while still hooking Sarge into the objects so it can supervise them for failures.
So in the second code block, foo needs to be a supervisable object created via Sarge.supervisable, or created via some 3rd party with Sarge's SupervisedInterceptor installed. See the example integrations for more on this.