Fabric3 makes implementing highly-available clustered singletons trivial by using the @Scope("DOMAIN") annotation:
@Scope("DOMAIN") public class TheComponent ... { public void onEvent(Event event) { //... } }
As explained in Java Components, a clustered singleton instance is created on the zone leader. If the leader fails or otherwise becomes inactive, a new instance is created on the newly elected leader.
There are a number of common use cases for clustered singletons:
- Timers that can only have a single emitter but must be highly-available (see Timer Components)
- Consumers that listen on a remote channel bound to a transport such as JMS which can only have one instance active at a time
Add Comment