Author: jflesch
Date: 2007-03-13 10:04:53 +0000 (Tue, 13 Mar 2007)
New Revision: 12108

Added:
   trunk/apps/Thaw/src/thaw/fcp/FCPGetNode.java
   trunk/apps/Thaw/src/thaw/plugins/PeerMonitor.java
Log:
I forgot two files ...

Added: trunk/apps/Thaw/src/thaw/fcp/FCPGetNode.java
===================================================================
--- trunk/apps/Thaw/src/thaw/fcp/FCPGetNode.java                                
(rev 0)
+++ trunk/apps/Thaw/src/thaw/fcp/FCPGetNode.java        2007-03-13 10:04:53 UTC 
(rev 12108)
@@ -0,0 +1,128 @@
+package thaw.fcp;
+
+import java.util.Observable;
+import java.util.Observer;
+
+import java.util.Hashtable;
+
+
+public class FCPGetNode extends Observable implements FCPQuery, Observer {
+       public final static String[] refElements = {
+               "identity",
+               "location",
+               "testnet",
+               "myName",
+               "lastGoodVersion",
+               "sig",
+               "version",
+               "dsaPubKey.y",
+               "physical.udp",
+               "oldark.pubURI",
+               "oldark.number",
+               "dsaGroup.g",
+               "dsaGroup.q",
+               "dsaGroup.p",
+               "ark.pubURI",
+               "ark.number"
+       };
+
+       private String ref;
+
+       public final static String maxMemElement = "volatile.maximumJavaMemory";
+       private long maxMem  = 134217728;
+
+       public final static String usedMemElement = "volatile.usedJavaMemory";
+       private long usedMem = 0;
+
+       public final static String netSizeSessionElement = 
"volatile.networkSizeEstimateSession";
+       private int netSizeSession = 0;
+
+
+       private boolean withPrivate;
+       private boolean withVolatile;
+
+       private Hashtable allParameters;
+
+
+       public FCPGetNode(boolean withPrivate, boolean withVolatile) {
+               this.withPrivate = withPrivate;
+               this.withVolatile = withVolatile;
+       }
+
+       public boolean start(FCPQueueManager queueManager) {
+               assert (queueManager != null);
+
+               FCPMessage msg = new FCPMessage();
+
+               msg.setMessageName("GetNode");
+               msg.setValue("WithPrivate", Boolean.toString(withPrivate));
+               msg.setValue("WithVolatile", Boolean.toString(withVolatile));
+
+               queueManager.getQueryManager().addObserver(this);
+
+               return queueManager.getQueryManager().writeMessage(msg);
+       }
+
+       public boolean stop(FCPQueueManager queueManager) {
+               queueManager.getQueryManager().deleteObserver(this);
+               return true;
+       }
+
+       public int getQueryType() {
+               return 0;
+       }
+
+
+
+
+       public void update(Observable o, Object param) {
+
+               if (o instanceof FCPQueryManager) {
+                       final FCPMessage msg = (FCPMessage)param;
+
+                       if (msg.getMessageName() == null
+                           || !msg.getMessageName().equals("NodeData"))
+                               return;
+
+                       ref = "";
+
+                       for (int i = 0 ; i < refElements.length ; i++) {
+                               ref += refElements[i] + "=" +
+                                       (msg.getValue(refElements[i]) != null ? 
msg.getValue(refElements[i]) : "???")
+                                       + "\n";
+                       }
+
+                       ref += "End\n";
+
+                       if (withVolatile) {
+                               if (msg.getValue(maxMemElement) != null)
+                                       maxMem = 
Long.parseLong(msg.getValue(maxMemElement));
+
+                               if (msg.getValue(usedMemElement) != null)
+                                       usedMem = 
Long.parseLong(msg.getValue(usedMemElement));
+                       }
+
+                       allParameters = msg.getValues();
+
+                       setChanged();
+                       notifyObservers(this);
+               }
+       }
+
+
+       public String getRef() {
+               return ref;
+       }
+
+       public long getMaxJavaMemory() {
+               return maxMem;
+       }
+
+       public long getUsedJavaMemory() {
+               return usedMem;
+       }
+
+       public Hashtable getAllParameters() {
+               return allParameters;
+       }
+}

Added: trunk/apps/Thaw/src/thaw/plugins/PeerMonitor.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/PeerMonitor.java                           
(rev 0)
+++ trunk/apps/Thaw/src/thaw/plugins/PeerMonitor.java   2007-03-13 10:04:53 UTC 
(rev 12108)
@@ -0,0 +1,128 @@
+package thaw.plugins;
+
+import java.util.Observable;
+import java.util.Observer;
+import java.util.Vector;
+import java.util.HashMap;
+
+import thaw.core.I18n;
+import thaw.core.Core;
+
+import thaw.plugins.peerMonitor.*;
+import thaw.fcp.*;
+
+
+public class PeerMonitor implements thaw.core.Plugin
+{
+       public final static int DEFAULT_REFRESH_RATE = 10; /* in sec */
+
+       private PeerMonitorPanel peerPanel;
+       private Core core;
+
+       private boolean running = false;
+
+       private boolean isRefSet = false;
+
+       public PeerMonitor() {
+
+       }
+
+
+       protected class DisplayRefresher implements Observer, Runnable{
+               private FCPGetNode getNode = null;
+               private FCPListPeers listPeers = null;
+
+               public DisplayRefresher() {
+
+               }
+
+               public void run() {
+                       while(running) {
+                               if (getNode == null) {
+                                       getNode = new FCPGetNode(false /* 
private */, true /* volatile */);
+                                       getNode.addObserver(this);
+                               }
+
+                               getNode.start(core.getQueueManager());
+
+                               if (listPeers == null) {
+                                       listPeers = new FCPListPeers(false /* 
metadata */, true /* volatile */);
+                                       listPeers.addObserver(this);
+                               }
+
+                               listPeers.start(core.getQueueManager());
+
+                               try {
+                                       Thread.sleep(DEFAULT_REFRESH_RATE * 
1000);
+                               } catch(InterruptedException e) {
+                                       /* \_o< \_o< \_o< */
+                               }
+
+                               if (!running)
+                                       return;
+                       }
+               }
+
+               public void update(Observable o, Object param) {
+                       if (!running)
+                               return;
+
+                       if (o instanceof FCPGetNode) {
+
+                               FCPGetNode gN = (FCPGetNode)o;
+
+                               peerPanel.setMemBar(gN.getUsedJavaMemory(), 
gN.getMaxJavaMemory());
+                               peerPanel.setNodeInfos(gN.getAllParameters());
+
+                               if (!isRefSet) {
+                                       peerPanel.setRef(gN.getRef());
+                                       isRefSet = true;
+                               }
+                       }
+
+                       if (o instanceof FCPListPeers) {
+
+                               FCPListPeers lP = (FCPListPeers)o;
+
+                               peerPanel.setPeerList(lP.getPeers());
+                       }
+               }
+       }
+
+
+       public boolean run(Core core) {
+               this.core = core;
+
+               peerPanel = new PeerMonitorPanel(core.getConfig());
+
+               
core.getMainWindow().addTab(I18n.getMessage("thaw.plugin.peerMonitor.peerMonitor"),
+                                           thaw.gui.IconBox.minPeerMonitor,
+                                           peerPanel.getPanel());
+
+               running = true;
+               isRefSet = false;
+               Thread th = new Thread(new DisplayRefresher());
+               th.start();
+
+               return true;
+       }
+
+
+       public boolean stop() {
+               core.getMainWindow().removeTab(peerPanel.getPanel());
+               running = false;
+               return false;
+       }
+
+
+
+
+       public String getNameForUser() {
+               return I18n.getMessage("thaw.plugin.peerMonitor.peerMonitor");
+       }
+
+       public javax.swing.ImageIcon getIcon() {
+               return thaw.gui.IconBox.peerMonitor;
+       }
+
+}


Reply via email to