Author: toad
Date: 2008-03-13 20:40:07 +0000 (Thu, 13 Mar 2008)
New Revision: 18515

Modified:
   trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java
   trunk/freenet/src/freenet/io/comm/IOStatisticCollector.java
   trunk/freenet/src/freenet/io/comm/UdpSocketHandler.java
   trunk/freenet/src/freenet/node/Node.java
   trunk/freenet/src/freenet/node/NodeCrypto.java
   trunk/freenet/src/freenet/node/NodeStats.java
   trunk/plugins/SNMP/SNMP.java
   trunk/plugins/SNMP/snmplib/DataStatisticsInfo.java
   trunk/plugins/SNMP/snmplib/SNMPStarter.java
Log:
Make IOStatisticCollector non-static

Modified: trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java       
2008-03-13 20:39:32 UTC (rev 18514)
+++ trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java       
2008-03-13 20:40:07 UTC (rev 18515)
@@ -782,7 +782,7 @@
        }

        static void drawBandwidth(HTMLNode activityList, Node node, long 
nodeUptimeSeconds, boolean isAdvancedModeEnabled) {
-               long[] total = IOStatisticCollector.getTotalIO();
+               long[] total = node.collector.getTotalIO();
                long total_output_rate = (total[0]) / nodeUptimeSeconds;
                long total_input_rate = (total[1]) / nodeUptimeSeconds;
                long totalPayload = node.getTotalPayloadSent();

Modified: trunk/freenet/src/freenet/io/comm/IOStatisticCollector.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/IOStatisticCollector.java 2008-03-13 
20:39:32 UTC (rev 18514)
+++ trunk/freenet/src/freenet/io/comm/IOStatisticCollector.java 2008-03-13 
20:40:07 UTC (rev 18515)
@@ -15,15 +15,12 @@
        public static final int STATISTICS_DURATION = 
1000*STATISTICS_DURATION_S;
        private long lastrotate;

-       private static IOStatisticCollector _currentSC;
        private static boolean logDEBUG;
        private long totalbytesin;
        private long totalbytesout;
        private final LinkedHashMap targets;

-       private IOStatisticCollector() {
-               // Only I should be able to create myself
-               _currentSC = this;
+       public IOStatisticCollector() {
                targets = new LinkedHashMap();
                // TODO: only for testing!!!!
                // This should only happen once
@@ -32,18 +29,10 @@
                logDEBUG = Logger.shouldLog(Logger.DEBUG, this);
        }

-       private static IOStatisticCollector getSC() {
-               if (_currentSC == null) {
-                       _currentSC = new IOStatisticCollector();
-               }
-               return _currentSC;
-       }
-       
-       public static void addInfo(String key, int inbytes, int outbytes) {
+       public void addInfo(String key, int inbytes, int outbytes) {
                try {
-                       IOStatisticCollector sc = getSC();
-                       synchronized (sc) {
-                               sc._addInfo(key, inbytes, outbytes);
+                       synchronized (this) {
+                               _addInfo(key, inbytes, outbytes);
                        }
                } catch (Throwable t) {
                        t.printStackTrace();
@@ -66,17 +55,15 @@
                }
        }

-       public static void dumpInfo() {
-               IOStatisticCollector sc = getSC();
-               synchronized (sc) {
-                       sc._dumpInfo();
+       public void dumpInfo() {
+               synchronized (this) {
+                       _dumpInfo();
                }
        }

-       public static long[] getTotalIO() {
-               IOStatisticCollector sc = getSC();
-               synchronized (sc) {
-                       return sc._getTotalIO();
+       public long[] getTotalIO() {
+               synchronized (this) {
+                       return _getTotalIO();
                }
        }

@@ -89,10 +76,9 @@
                return ret;
        }

-       public static int[][] getTotalStatistics() {
-               IOStatisticCollector sc = getSC();
-               synchronized (sc) {
-                       return sc._getTotalStatistics();
+       public int[][] getTotalStatistics() {
+               synchronized (this) {
+                       return _getTotalStatistics();
                }
        }


Modified: trunk/freenet/src/freenet/io/comm/UdpSocketHandler.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/UdpSocketHandler.java     2008-03-13 
20:39:32 UTC (rev 18514)
+++ trunk/freenet/src/freenet/io/comm/UdpSocketHandler.java     2008-03-13 
20:40:07 UTC (rev 18515)
@@ -45,9 +45,11 @@
        private final String title;
        private boolean _started;
        private Thread _thread;
+       private final IOStatisticCollector collector;

-       public UdpSocketHandler(int listenPort, InetAddress bindto, Node node, 
long startupTime, String title) throws SocketException {
+       public UdpSocketHandler(int listenPort, InetAddress bindto, Node node, 
long startupTime, String title, IOStatisticCollector collector) throws 
SocketException {
                this.node = node;
+               this.collector = collector;
                this.title = title;
                _bindTo = bindto;
                    // Keep the Updater code in, just commented out, for now
@@ -201,7 +203,7 @@
                try {
                        _sock.receive(packet);
                        // TODO: keep?
-                       IOStatisticCollector.addInfo(packet.getAddress() + ":" 
+ packet.getPort(),
+                       collector.addInfo(packet.getAddress() + ":" + 
packet.getPort(),
                                        packet.getLength(), 0);
                } catch (SocketTimeoutException e1) {
                        return false;
@@ -251,7 +253,7 @@
                try {
                        _sock.send(packet);
                        tracker.sentPacketTo(destination);
-                       IOStatisticCollector.addInfo(address + ":" + port, 0, 
blockToSend.length + UDP_HEADERS_LENGTH); 
+                       collector.addInfo(address + ":" + port, 0, 
blockToSend.length + UDP_HEADERS_LENGTH); 
                        if(logMINOR) Logger.minor(this, "Sent packet length 
"+blockToSend.length+" to "+address+':'+port);
                } catch (IOException e) {
                        if(packet.getAddress() instanceof Inet6Address)

Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java    2008-03-13 20:39:32 UTC (rev 
18514)
+++ trunk/freenet/src/freenet/node/Node.java    2008-03-13 20:40:07 UTC (rev 
18515)
@@ -49,6 +49,7 @@
 import freenet.io.comm.DMT;
 import freenet.io.comm.DisconnectedException;
 import freenet.io.comm.FreenetInetAddress;
+import freenet.io.comm.IOStatisticCollector;
 import freenet.io.comm.Message;
 import freenet.io.comm.MessageCore;
 import freenet.io.comm.MessageFilter;
@@ -406,6 +407,7 @@
        boolean enablePacketCoalescing;
        public static final short DEFAULT_MAX_HTL = (short)10;
        private short maxHTL;
+       public final IOStatisticCollector collector;
        /** Type identifier for fproxy node to node messages, as sent on 
DMT.nodeToNodeMessage's */
        public static final int N2N_MESSAGE_TYPE_FPROXY = 1;
        /** Type identifier for differential node reference messages, as sent 
on DMT.nodeToNodeMessage's */
@@ -598,6 +600,7 @@
                String tmp = "Initializing Node using Freenet Build 
#"+Version.buildNumber()+" r"+Version.cvsRevision+" and freenet-ext Build 
#"+NodeStarter.extBuildNumber+" r"+NodeStarter.extRevisionNumber+" with 
"+System.getProperty("java.vm.vendor")+" JVM version 
"+System.getProperty("java.vm.version")+" running on 
"+System.getProperty("os.arch")+' '+System.getProperty("os.name")+' 
'+System.getProperty("os.version");
                Logger.normal(this, tmp);
                System.out.println(tmp);
+               collector = new IOStatisticCollector();
                this.executor = executor;
                nodeStarter=ns;
                if(logConfigHandler != lc)

Modified: trunk/freenet/src/freenet/node/NodeCrypto.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeCrypto.java      2008-03-13 20:39:32 UTC 
(rev 18514)
+++ trunk/freenet/src/freenet/node/NodeCrypto.java      2008-03-13 20:40:07 UTC 
(rev 18515)
@@ -111,7 +111,7 @@
                        for(int i=0;i<200000;i++) {
                                int portNo = 1024 + random.nextInt(65535-1024);
                                try {
-                                       u = new UdpSocketHandler(portNo, 
bindto.getAddress(), node, startupTime, getTitle(portNo));
+                                       u = new UdpSocketHandler(portNo, 
bindto.getAddress(), node, startupTime, getTitle(portNo), node.collector);
                                        port = u.getPortNumber();
                                        break;
                                } catch (Exception e) {
@@ -125,7 +125,7 @@
                                throw new 
NodeInitException(NodeInitException.EXIT_NO_AVAILABLE_UDP_PORTS, "Could not 
find an available UDP port number for FNP (none specified)");
                } else {
                        try {
-                               u = new UdpSocketHandler(port, 
bindto.getAddress(), node, startupTime, getTitle(port));
+                               u = new UdpSocketHandler(port, 
bindto.getAddress(), node, startupTime, getTitle(port), node.collector);
                        } catch (Exception e) {
                                Logger.error(this, "Caught "+e, e);
                                System.err.println(e);

Modified: trunk/freenet/src/freenet/node/NodeStats.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeStats.java       2008-03-13 20:39:32 UTC 
(rev 18514)
+++ trunk/freenet/src/freenet/node/NodeStats.java       2008-03-13 20:40:07 UTC 
(rev 18515)
@@ -392,7 +392,7 @@

                double bwlimitDelayTime = 
throttledPacketSendAverage.currentValue();

-               long[] total = IOStatisticCollector.getTotalIO();
+               long[] total = node.collector.getTotalIO();
                long totalSent = total[0];
                long totalOverhead = getSentOverhead();
                long uptime = node.getUptime();
@@ -711,7 +711,7 @@
         */
        public void maybeUpdateNodeIOStats(long now) {
                if(now > nextNodeIOStatsUpdateTime) {
-                       long[] io_stats = IOStatisticCollector.getTotalIO();
+                       long[] io_stats = node.collector.getTotalIO();
                        long outdiff;
                        long indiff;
                        synchronized(ioStatSync) {
@@ -842,7 +842,7 @@
                fs.put("numberOfTransferringRequestSenders", 
node.getNumTransferringRequestSenders());
                fs.put("numberOfARKFetchers", node.getNumARKFetchers());

-               long[] total = IOStatisticCollector.getTotalIO();
+               long[] total = node.collector.getTotalIO();
                long total_output_rate = (total[0]) / nodeUptimeSeconds;
                long total_input_rate = (total[1]) / nodeUptimeSeconds;
                long totalPayloadOutput = node.getTotalPayloadSent();

Modified: trunk/plugins/SNMP/SNMP.java
===================================================================
--- trunk/plugins/SNMP/SNMP.java        2008-03-13 20:39:32 UTC (rev 18514)
+++ trunk/plugins/SNMP/SNMP.java        2008-03-13 20:40:07 UTC (rev 18515)
@@ -49,7 +49,7 @@

                        SNMPAgent.setSNMPPort(port);
                        System.out.println("Starting SNMP server on "+bindto+ 
':' +port);
-                       SNMPStarter.initialize();
+                       SNMPStarter.initialize(pr.getNode());
                        Logger.normal(this,"Starting SNMP server on "+bindto+ 
':' +port);
                        while(goon){
                                try {

Modified: trunk/plugins/SNMP/snmplib/DataStatisticsInfo.java
===================================================================
--- trunk/plugins/SNMP/snmplib/DataStatisticsInfo.java  2008-03-13 20:39:32 UTC 
(rev 18514)
+++ trunk/plugins/SNMP/snmplib/DataStatisticsInfo.java  2008-03-13 20:40:07 UTC 
(rev 18515)
@@ -6,12 +6,14 @@
        private String OID;
        int blocks;
        boolean in;
+       private final IOStatisticCollector collector;

-       public DataStatisticsInfo(int blocks, boolean in) {
+       public DataStatisticsInfo(int blocks, boolean in, IOStatisticCollector 
collector) {
                this.OID = "1.1." + blocks + '.' + (in?"1":"0");
                //System.err.println("adding: " + this.OID);
                this.in = in;
                this.blocks = blocks;
+               this.collector = collector;
        }

        public String getSNMPOID() {
@@ -21,12 +23,12 @@

        public Object getSNMPData() {
                if (blocks == 0) {
-                       long io[] = IOStatisticCollector.getTotalIO();
+                       long io[] = collector.getTotalIO();
                        return new SNMPCounter32(io[in?1:0]);
                }
                // else sum all fields up to <blocks>
                int res = 0;
-               int stats[][] = IOStatisticCollector.getTotalStatistics();
+               int stats[][] = collector.getTotalStatistics();
                for (int i = 0 ; i < blocks ; i++)
                        res += stats[i][in?1:0];


Modified: trunk/plugins/SNMP/snmplib/SNMPStarter.java
===================================================================
--- trunk/plugins/SNMP/snmplib/SNMPStarter.java 2008-03-13 20:39:32 UTC (rev 
18514)
+++ trunk/plugins/SNMP/snmplib/SNMPStarter.java 2008-03-13 20:40:07 UTC (rev 
18515)
@@ -13,13 +13,14 @@

        private static boolean has_been_runned = false;

-       public static void initialize() {
+       public static void initialize(Node node) {
                //SNMPAgent.setSNMPPort(port);
                if (has_been_runned) return;
                // 0 is toatl I/O
+               IOStatisticCollector collector = node.collector;
                for (int i = 0 ; i < IOStatisticCollector.STATISTICS_ENTRIES ; 
i++) {
-                       SNMPAgent.getSNMPAgent().addFetcher(new 
DataStatisticsInfo(i, true));
-                       SNMPAgent.getSNMPAgent().addFetcher(new 
DataStatisticsInfo(i, false));
+                       SNMPAgent.getSNMPAgent().addFetcher(new 
DataStatisticsInfo(i, true, collector));
+                       SNMPAgent.getSNMPAgent().addFetcher(new 
DataStatisticsInfo(i, false, collector));
                }
                SNMPAgent.getSNMPAgent().addFetcher(new InfoSystem());



Reply via email to