Getting started - Pscheidl/FortEE GitHub Wiki

FortEE makes sure no unexpected exceptions or errors get past methods guarded by FortEE interceptors.

To start using FortEE, two steps are required.

  1. Add FortEE dependency to your project
  2. Use FortEE annotations

Adding FortEE dependency

FortEE is released and published into Maven central repository.

Maven

<dependency>
    <groupId>com.github.pscheidl</groupId>
    <artifactId>fortee</artifactId>
    <version>1.1.0</version>
</dependency>

Gradle

compile 'com.github.pscheidl:fortee:1.1.0'

Using FortEE annotations

Failsafe

Basic fault tolerance mechanism leveraging java.util.Optional<T>. The underlying method either did return a value or did not.

  • Methods annotated with @Failsafe must return Optional. This is checked at startup-time. If this condition is not met, exception is thrown during startup phase with details about which methods failed the test.
  • Beans annotated with @Failsafe must enforce this Optional return type on all declared methods.
@Named
public class ServiceImplementation implements SomeService {

// Will return Optional.empty()
@Failsafe
public Optional<String> maybeFail(){
  throw new RuntimeException("Failed on purpose");
}

}

On-fail event observation

@Named
public class ExecutionErrorObserver {

public void observe(@Observes ExecutionErrorEvent executionError){
  // Do whatever is needed e.g. log the Throwable cause
}

}

Semisafe - allowed exceptions & errors

The @Semisafe annotation allows listing Throwables allowed to be thrown.

  • Methods annotated with @Semisafe({}) must return Optional. This is checked at startup-time. If this condition is not met, exception is thrown during startup phase with details about which methods failed the test.
  • Methods annotated with @Semisafe must enforce this Optional return type on all declared methods.
@Named
public class ServiceImplementation implements SomeService {

// Will end with RuntimeException
@Semisafe({RuntimeException.class})
public Optional<String> maybeFail(){
  throw new RuntimeException("Failed on purpose");
}

}
@Named
public class ServiceImplementation implements SomeService {

// Will return Optional.empty()
@Semisafe({RuntimeException.class})
public Optional<String> maybeFail(){
  throw new AnyUnlistedException("This exception will be converted");
}

}
⚠️ **GitHub.com Fallback** ⚠️