Adam Bien's Weblog

Configurable CircuitBreaker For Java EE

breakr is a simplistic interceptor (6KB) which ignores all calls to the decorated component when a configurable threshold is reached.

The decision when to open or close the circuit and the information about the state of the breakr is maintained in the class com.airhacks.breakr.Circuit.

To introduce custom behavior, just inherit from the Circuit and introduce your own business logic:


@ApplicationScoped
@Specializes
public class CustomCircuit extends Circuit {

    private AtomicBoolean open = new AtomicBoolean(false);

    @Override
    public boolean isOpen(long maxFailures) {
        return open.get();
    }

    public long getFailureCount() {
        return failureCounter.get();
    }

    /**
     * controls the closing and opening of the circuit
     */
    public void setOpen(boolean open) {
        this.open.set(open);
    }
}


For more details checkout github.com/AdamBien/breakr.

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.


NEW workshop: HTML 5 and JavaScript Essentials, Three days in April 2017: from Java EE 7 Architectures over Microservices to Performance, Troubleshooting and Monitoring
On demand workshops: Java EE 7: Bootstrap, Effective, Testing and Microservices available for streaming.

Newsletter: airhacks.news

A book about rethinking Java EE Patterns

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
realworldpatterns.com
Online Workshops
...the last 150 posts
...the last 10 comments
License