List:NDB Connectors« Previous MessageNext Message »
From:Monty Taylor Date:December 7 2007 10:03am
Subject:Rev 349: Added Johan's Sample program in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/devel
View as plain text  
At http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/devel

------------------------------------------------------------
revno: 349
revision-id: mtaylor@stripped
parent: mtaylor@stripped
committer: Monty Taylor <mtaylor@stripped>
branch nick: devel
timestamp: Fri 2007-12-07 02:01:58 -0800
message:
  Added Johan's Sample program
modified:
  java/com/mysql/cluster/mgmj/examples/SampleMGMJ.java
samplemgmj.java-20071119093428-2f2zw02dpk5jlq9f-2
=== modified file 'java/com/mysql/cluster/mgmj/examples/SampleMGMJ.java'
--- a/java/com/mysql/cluster/mgmj/examples/SampleMGMJ.java	2007-12-06 08:07:23 +0000
+++ b/java/com/mysql/cluster/mgmj/examples/SampleMGMJ.java	2007-12-07 10:01:58 +0000
@@ -17,44 +17,56 @@
 
 		mgm.setConnectTimeout(4000);
 		mgm.connect(5, 3, true);
-		/*int[] filter = { 15,
NdbMgmEventCategory.NDB_MGM_EVENT_CATEGORY_STATISTIC.swigValue(), 0 };
-		NdbLogEventManager manager = mgm.createNdbLogEventManager(filter); */
+
 
 		NdbFilterList theList = new NdbFilterList();
-		NdbFilterItem theItem = new
NdbFilterItem(15,NdbLogEventCategory.NDB_MGM_EVENT_CATEGORY_STATISTIC);
-		theList.add(theItem);
+		NdbFilterItem theItem1 = new
NdbFilterItem(15,NdbLogEventCategory.NDB_MGM_EVENT_CATEGORY_STATISTIC);
+		NdbFilterItem theItem2 = new
NdbFilterItem(15,NdbLogEventCategory.NDB_MGM_EVENT_CATEGORY_CONNECTION);
+		NdbFilterItem theItem3 = new
NdbFilterItem(15,NdbLogEventCategory.NDB_MGM_EVENT_CATEGORY_NODE_RESTART);
+
+		theList.add(theItem1);
+		theList.add(theItem2);
+		theList.add(theItem3);
+
+
 		NdbLogEventManager manager = mgm.createNdbLogEventManager(theList);
-		TransReportListener theListener = new TransReportListener();
+		TransReportListener theListener1 = new TransReportListener();
+		ConnectedListener theListener2 = new ConnectedListener();
+		DisconnectListener theListener3 = new DisconnectListener();
+		NodeFailReportedListener theListener4 = new NodeFailReportedListener();
+		CommunicationOpenedListener theListener5 = new CommunicationOpenedListener();
+		CommunicationClosedListener theListener6 = new CommunicationClosedListener();
+		StartPhaseListener theListener7 = new StartPhaseListener();
+
 		System.out.println("Registering listener");
-		manager.registerListener(theListener);
+		manager.registerListener(theListener1);
+		manager.registerListener(theListener2);
+		manager.registerListener(theListener3);
+		manager.registerListener(theListener4);
+		manager.registerListener(theListener5);
+		manager.registerListener(theListener6);
+		manager.registerListener(theListener7);
 		System.out.println("Done");
-		
+
+		ClusterState cs = mgm.getStatus();
+		for(int i=0; i< cs.getNoOfNodes(); i++)
+		    {
+			NodeState ns = cs.getNodeState(i);
+			NodeType type= ns.getNodeType();			
+			System.out.println("Type: " + type.toString() + 
+					   " Version " 
+					   + (short)(ns.getVersion()>>16 & 0xFF)
+					   + "." 
+					   + (short)(ns.getVersion()>>8 & 0xFF)
+					   + "." 
+					   + (short)(ns.getVersion()>>0 & 0xFF)
+					   + " connected address " +  ns.getConnectAddress());
+
+		    }
+				
 		while(true) { 	
-			//mgm.dumpState(1, 1000);
+
 			manager.pollEvents(5000); 
-			/*NdbLogEvent event = manager.pollEvents(5000); 
-			if (event != null)  {
-				System.out.println("Got an Event from Node" + event.getSourceNodeId()+" 
"+event.getEventType());
-			if (event.getEventType() == NdbLogEventType.NDB_LE_TransReportCounters) {
-				TransReportCounters theEvent = new TransReportCounters(event);
-				System.out.println("Trans count:"+theEvent.getTransCount());
-				System.out.println("Read count:"+theEvent.getReadCount());
-				System.out.println("Scan count:"+theEvent.getScanCount());
-				System.out.println("Range Scan count:"+theEvent.getRangeScanCount());
-			} else if (event.getEventType() == NdbLogEventType.NDB_LE_MemoryUsage) { 
-				MemoryUsage theEvent = new MemoryUsage(event); 
-				if (theEvent.getPageSizeKb() == 8192) { 
-					System.out.println("Index Memory: "+theEvent.getPagesUsed());
-				} else if (theEvent.getPageSizeKb() == 32768) { 
-					System.out.println("Data Memory: "+theEvent.getPagesUsed());
-				}
-				
-
-			}
-			} else { 
-				//System.out.println("Still null");
-			}
-			*/
 		}
 
 	}
@@ -71,11 +83,107 @@
 	 */
 	@Override
 	public void handleEvent(TransReportCounters event) {
-		System.out.println("Listner Trans count:"+event.getTransCount());
-		System.out.println("Listner Read count:"+event.getReadCount());
-		System.out.println("Listner Scan count:"+event.getScanCount());
-		System.out.println("Listner Range Scan count:"+event.getRangeScanCount());
-	} 
-	
-	
+	    System.out.println("Node " + event.getSourceNodeId() +
+			       ": Listner Trans count:"+ event.getTransCount());
+	    
+	    System.out.println("Node " + event.getSourceNodeId() + 
+			       ": Listner Read count:"+event.getReadCount());
+	    System.out.println("Node " + event.getSourceNodeId() + 
+			       ": Listner Scan count:"+event.getScanCount());
+	    System.out.println("Node " + event.getSourceNodeId() + 
+			       ": Listner Range Scan count:"
+			       +event.getRangeScanCount());
+	} 
+	
+	
+}
+
+
+
+class DisconnectListener extends DisconnectedTypeListener {
+
+
+
+
+	/* (non-Javadoc)
+	 * @see
com.mysql.cluster.mgmj.NdbLogEventCategoryListener#handleEvent(com.mysql.cluster.mgmj.NdbLogEvent)
+	 */
+	@Override
+	public void handleEvent(Disconnected event) {
+		System.out.println("Disconnected node:" + event.getNode());
+	} 
+}
+
+
+
+class ConnectedListener extends ConnectedTypeListener {
+
+	
+	public void handleEvent(Connected event) {
+		System.out.println("Connected node:" + event.getNode());
+	} 
+
+}
+
+
+
+class CommunicationOpenedListener extends CommunicationOpenedTypeListener {
+
+
+
+
+	/* (non-Javadoc)
+	 * @see
com.mysql.cluster.mgmj.NdbLogEventCategoryListener#handleEvent(com.mysql.cluster.mgmj.NdbLogEvent)
+	 */
+	@Override
+	public void handleEvent(CommunicationOpened event) {
+	    System.out.println("Comm opened to node:" + event.getNode() + " reported by " +
event.getSourceNodeId());
+	} 
+}
+
+
+
+class CommunicationClosedListener extends CommunicationClosedTypeListener {
+
+
+
+	/* (non-Javadoc)
+	 * @see
com.mysql.cluster.mgmj.NdbLogEventCategoryListener#handleEvent(com.mysql.cluster.mgmj.NdbLogEvent)
+	 */
+	@Override
+	public void handleEvent(CommunicationClosed event) {
+		System.out.println("Comm closed to node:" + event.getNode());
+	} 
+}
+
+
+class NodeFailReportedListener extends NodeFailReportedTypeListener {
+
+
+
+
+
+	/* (non-Javadoc)
+	 * @see
com.mysql.cluster.mgmj.NdbLogEventCategoryListener#handleEvent(com.mysql.cluster.mgmj.NdbLogEvent)
+	 */
+	@Override
+	public void handleEvent(NodeFailReported event) {
+		System.out.println("Failed node:" + event.getFailedNode());
+	} 
+}
+
+
+
+class StartPhaseListener extends StartPhaseCompletedTypeListener {
+
+
+
+	/* (non-Javadoc)
+	 * @see
com.mysql.cluster.mgmj.NdbLogEventCategoryListener#handleEvent(com.mysql.cluster.mgmj.NdbLogEvent)
+	 */
+	@Override
+	public void handleEvent(StartPhaseCompleted event) {
+		System.out.println("Node " + event.getSourceNodeId() );
+		//				   + ": start phase" + theEvent.getPhase());
+	} 
 }

Thread
Rev 349: Added Johan's Sample program in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/develMonty Taylor7 Dec