Circuit breaker pattern in Deja vu

This post is part of a series about the framework Deja vu.

The circuit breaker pattern provides a way of ensuring your application will not wait unnecessary on calls to integration points known to be slow or down (a good description can be found here).

Since Deja vu uses the term integration points, it seems obvious to add support for this pattern directly in the framework.

The annotation Impure can actually take an argument, integrationPoint. This argument will tell the framework the name of the circuit breaker to use for this integration point.

Example

An example of an impure method guarded by integration point called ‘cb1’:

A circuit breaker instance manages the state of a circuit breaker and is instantiated with parameters name, timeout milliseconds, and exception threshold. Such an instance must be passed to the framework which will use it on @Impure methods with integration points of this name.

Calling it twice with argument ‘1’ will change the state from ‘Closed’ to ‘Open’. As the state is ‘Open’ all calls to it will result in CircuitOpenException which is thrown without the method being invoked. But if we wait for 600 milliseconds the state will have changed to Half_open. Such a state means the result of the next invocation change the state to either ‘Open’ or ‘Closed’. We run it with input ‘0’ meaning is succeeds so we go to state ‘Closed’.

This post is part of a series about the framework Deja vu. Next: Multi-threading

This Post Has One Comment

Leave a Reply

Close Menu