Hi,
Recently I have created a Circuit Breaker implementation in Streamflow,
which we use to guard against faulty external systems (e.g. mail servers
being down, web services being down). I have now committed this code to
Qi4j as qi4j-lib-circuitbreaker. Do an update of Qi4j Libraries to check
it out.
There's a couple of differences between this implementation and others
I've seen on the net, but I've also heavily borrowed from others. The
first difference is that I've not focused on performance at all. For
some reason other implementations make a point about doing "atomic
changes" with various tricks, to ensure good performance. Since this is
used to guard access to external systems, where latencies range in
milliseconds and up, that seems completely useless, so I've just put
"synchronized" on all methods, which should be safe. "It works" is
better than "it's fast" for these types of things.
Second, other implementations have had really crude logic for what types
of exceptions cause the circuit to break. The most crude is "all", more
advanced ones allow exceptions that be excepted to be registered, but in
real cases this is not enough. Case in point is JDBC exceptions where
you want to fail on "connect exception" but not necessarily "invalid SQL
syntax". So instead I've leveraged the Specification API in Qi4j where
you get to provide your own specification that can use any logic to
determine whether a particular exception is ok or not.
Third, there's a big focus on manageability through JMX. A
circuitbreaker can be easily exposed in JMX as an MBean, where you can
track service levels and see exception messages, and trip/enable circuit
breakers.
Fourth, if an external system is unavailable due to a circuitbreaker
tripping it should be possible to expose this to other Qi4j services.
There is a standard implementation of the Availability interface that
delegates to a circuit breaker and the Enabled configuration flag, which
is what I'd suspect will be used in most cases where external systems
are invoked.
That's about it! Take a look at the code and the tests for usage
instructions.
/Rickard
_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev