Grab a RAC environment and configure a service, ons and so on…
Create a java Project with your preferred tool and add the simplefan.jar library you can find in the jdbc distributions and create a java class like this:
package es.jmu.oracle.altamira.gk; import java.util.Properties; import oracle.simplefan.FanEventListener; import oracle.simplefan.FanManager; import oracle.simplefan.FanSubscription; import oracle.simplefan.LoadAdvisoryEvent; import oracle.simplefan.NodeDownEvent; import oracle.simplefan.ServiceDownEvent; public class FanListener { public FanListener() { super(); } static int DUERMETE_MI_NINO = 1000; public static void main(String[] args) { //FanListener fanSample = new FanListener(); /* * TEST DATA */ String onsNodes = "192.168.56.110:6200,192.168.56.210:6200"; String service = "tfanservice"; Properties props = new Properties(); props.setProperty("onsNodes", onsNodes); FanManager.getInstance().configure(props); props = new Properties(); props.setProperty("serviceName", service); FanSubscription fsub = FanManager.getInstance().subscribe(props); System.out.println("Listening to FAN events coming from " + onsNodes + " for service " + service); fsub.addListener(new FanEventListener() { /* * Fired when service goes down */ public void handleEvent(ServiceDownEvent arg0) { System.out.println("Service Down!"); System.out.println("============="); System.out.println("Database : " + arg0.getDatabaseUniqueName()); System.out.println("Kind : " + arg0.getKind()); System.out.println("Service Name : " + arg0.getServiceName()); System.out.println("Reason : " + arg0.getReason()); System.out.println("ServiceMemberEvent: " + arg0.getServiceMemberEvent()); System.out.println("Observed at : " + arg0.getTimestamp().getTime() + "\n\n"); } /* * Fired when a node goes down */ public void handleEvent(NodeDownEvent arg0) { System.out.println("Node Down"); System.out.println("========="); System.out.println("Incarnation: " + arg0.getIncarnation() + "\n\n"); } /* * Fired when */ public void handleEvent(LoadAdvisoryEvent arg0) { System.out.println("Load Advisory event"); System.out.println("==================="); System.out.println("Database : " + arg0.getDatabaseUniqueName()); System.out.println("Instance : " + arg0.getInstanceName()); System.out.println("Service Name : " + arg0.getServiceName()); System.out.println("Service Quality : " + arg0.getServiceQuality()); System.out.println("Percent : " + arg0.getPercent()); System.out.println("Observed at : " + arg0.getTimestamp().getTime() + "\n\n"); } } ); while(true){ try{Thread.sleep(DUERMETE_MI_NINO);}catch(Exception e){;} } } }
Run the java class and be a bad boy with the RAC env (start/stop services|instances, generate load…) and see what happens…
Enjoy 😉
Hi Javier,
unfortunately, the links to the simplefan.jar and Java Class don’t work anymore… Please, could you provide the right ones?
Thanks & keep up the good work!
LikeLike
hi,
simplefan.jar is now shipped on every jdbc distribution, for example following is for 21C https://www.oracle.com/database/technologies/appdev/jdbc-ucp-21-1-c-downloads.html but you can find (or google) for other versions. Regarding the java class, I’m putting it in the post “as is”, hope it helps
LikeLike