From fa6d17a1b80334a5542997990803602b1ced0fe0 Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Thu, 15 Oct 2009 22:42:22 +0000
Subject: [PATCH]     * ProfileOrganizerRenderer:       - Move to routerconsole
       - Write directly to Writer for speed

---
 .../i2p/router/web}/ProfileOrganizerRenderer.java |  5 ++++-
 .../src/net/i2p/router/web/ProfilesHelper.java    | 15 +++++++--------
 apps/routerconsole/jsp/configpeer.jsp             |  1 +
 apps/routerconsole/jsp/profiles.jsp               |  1 +
 .../net/i2p/router/peermanager/PeerManager.java   |  4 ----
 .../router/peermanager/PeerManagerFacadeImpl.java |  2 +-
 .../i2p/router/peermanager/ProfileOrganizer.java  |  7 +------
 7 files changed, 15 insertions(+), 20 deletions(-)
 rename {router/java/src/net/i2p/router/peermanager => apps/routerconsole/java/src/net/i2p/router/web}/ProfileOrganizerRenderer.java (98%)

diff --git a/router/java/src/net/i2p/router/peermanager/ProfileOrganizerRenderer.java b/apps/routerconsole/java/src/net/i2p/router/web/ProfileOrganizerRenderer.java
similarity index 98%
rename from router/java/src/net/i2p/router/peermanager/ProfileOrganizerRenderer.java
rename to apps/routerconsole/java/src/net/i2p/router/web/ProfileOrganizerRenderer.java
index e75db83b4b..f0f44c4c19 100644
--- a/router/java/src/net/i2p/router/peermanager/ProfileOrganizerRenderer.java
+++ b/apps/routerconsole/java/src/net/i2p/router/web/ProfileOrganizerRenderer.java
@@ -1,4 +1,4 @@
-package net.i2p.router.peermanager;
+package net.i2p.router.web;
 
 import java.io.IOException;
 import java.io.Writer;
@@ -12,6 +12,9 @@ import net.i2p.data.DataHelper;
 import net.i2p.data.Hash;
 import net.i2p.data.RouterInfo;
 import net.i2p.router.RouterContext;
+import net.i2p.router.peermanager.DBHistory;
+import net.i2p.router.peermanager.PeerProfile;
+import net.i2p.router.peermanager.ProfileOrganizer;
 import net.i2p.stat.Rate;
 import net.i2p.stat.RateStat;
 
diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ProfilesHelper.java b/apps/routerconsole/java/src/net/i2p/router/web/ProfilesHelper.java
index ce2242aa71..3b02f6b30a 100644
--- a/apps/routerconsole/java/src/net/i2p/router/web/ProfilesHelper.java
+++ b/apps/routerconsole/java/src/net/i2p/router/web/ProfilesHelper.java
@@ -1,30 +1,29 @@
 package net.i2p.router.web;
 
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.io.OutputStreamWriter;
 
 
 public class ProfilesHelper extends HelperBase {
     public ProfilesHelper() {}
     
+    /** @return empty string, writes directly to _out */
     public String getProfileSummary() {
-        ByteArrayOutputStream baos = new ByteArrayOutputStream(16*1024);
         try {
-            _context.profileOrganizer().renderStatusHTML(new OutputStreamWriter(baos));
+            ProfileOrganizerRenderer rend = new ProfileOrganizerRenderer(_context.profileOrganizer(), _context);
+            rend.renderStatusHTML(_out);
         } catch (IOException ioe) {
             ioe.printStackTrace();
         }
-        return new String(baos.toByteArray());
+        return "";
     }
     
+    /** @return empty string, writes directly to _out */
     public String getShitlistSummary() {
-        ByteArrayOutputStream baos = new ByteArrayOutputStream(4*1024);
         try {
-            _context.shitlist().renderStatusHTML(new OutputStreamWriter(baos));
+            _context.shitlist().renderStatusHTML(_out);
         } catch (IOException ioe) {
             ioe.printStackTrace();
         }
-        return new String(baos.toByteArray());
+        return "";
     }
 }
diff --git a/apps/routerconsole/jsp/configpeer.jsp b/apps/routerconsole/jsp/configpeer.jsp
index 007452229d..b58d86fe18 100644
--- a/apps/routerconsole/jsp/configpeer.jsp
+++ b/apps/routerconsole/jsp/configpeer.jsp
@@ -71,6 +71,7 @@
  <a name="shitlist"> </a>
  <jsp:useBean class="net.i2p.router.web.ProfilesHelper" id="profilesHelper" scope="request" />
  <jsp:setProperty name="profilesHelper" property="contextId" value="<%=(String)session.getAttribute("i2p.contextId")%>" />
+ <jsp:setProperty name="profilesHelper" property="writer" value="<%=out%>" />
  <jsp:getProperty name="profilesHelper" property="shitlistSummary" />
  <hr>
  <div class="wideload">
diff --git a/apps/routerconsole/jsp/profiles.jsp b/apps/routerconsole/jsp/profiles.jsp
index 2ae4ff6b26..6eae2642fd 100644
--- a/apps/routerconsole/jsp/profiles.jsp
+++ b/apps/routerconsole/jsp/profiles.jsp
@@ -9,6 +9,7 @@
 <div class="main" id="main"><div class="wideload">
  <jsp:useBean class="net.i2p.router.web.ProfilesHelper" id="profilesHelper" scope="request" />
  <jsp:setProperty name="profilesHelper" property="contextId" value="<%=(String)session.getAttribute("i2p.contextId")%>" />
+ <jsp:setProperty name="profilesHelper" property="writer" value="<%=out%>" />
  <jsp:getProperty name="profilesHelper" property="profileSummary" />
  <br>
  <a name="shitlist"> </a>
diff --git a/router/java/src/net/i2p/router/peermanager/PeerManager.java b/router/java/src/net/i2p/router/peermanager/PeerManager.java
index 41110c3069..009a6ed506 100644
--- a/router/java/src/net/i2p/router/peermanager/PeerManager.java
+++ b/router/java/src/net/i2p/router/peermanager/PeerManager.java
@@ -250,8 +250,4 @@ class PeerManager {
             return rv;
         }
     }
-
-    public void renderStatusHTML(Writer out) throws IOException { 
-        _organizer.renderStatusHTML(out); 
-    }
 }
diff --git a/router/java/src/net/i2p/router/peermanager/PeerManagerFacadeImpl.java b/router/java/src/net/i2p/router/peermanager/PeerManagerFacadeImpl.java
index 3483873a5a..14ee5317e2 100644
--- a/router/java/src/net/i2p/router/peermanager/PeerManagerFacadeImpl.java
+++ b/router/java/src/net/i2p/router/peermanager/PeerManagerFacadeImpl.java
@@ -78,8 +78,8 @@ public class PeerManagerFacadeImpl implements PeerManagerFacade {
         return _manager.getPeersByCapability(capability); 
     }
 
+    /** @deprecated, moved to routerconsole */
     public void renderStatusHTML(Writer out) throws IOException { 
-        _manager.renderStatusHTML(out); 
     }
     
 }
diff --git a/router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java b/router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java
index 07d25fce85..4fd812efa9 100644
--- a/router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java
+++ b/router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java
@@ -139,7 +139,7 @@ public class ProfileOrganizer {
     }
 
     public void setUs(Hash us) { _us = us; }
-    Hash getUs() { return _us; }
+    public Hash getUs() { return _us; }
     
     public double getSpeedThreshold() { return _thresholdSpeedValue; }
     public double getCapacityThreshold() { return _thresholdCapacityValue; }
@@ -258,11 +258,6 @@ public class ProfileOrganizer {
             _persistenceHelper.writeProfile(prof, out);
     }
     
-    public void renderStatusHTML(Writer out) throws IOException {
-        ProfileOrganizerRenderer rend = new ProfileOrganizerRenderer(this, _context);
-        rend.renderStatusHTML(out);
-    }
-    
     /**
      * Return a set of Hashes for peers that are both fast and reliable.  If an insufficient
      * number of peers are both fast and reliable, fall back onto high capacity peers, and if that
-- 
GitLab