Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
*) Adding possibility to close open connections via Connections_p.html
thelida81d7db174a
diff --git a/htroot/Connections_p.html b/htroot/Connections_p.htmlindex c7507cff7..c591d45c8 100644--- a/htroot/Connections_p.html+++ b/htroot/Connections_p.html@@ -20,6 +20,7 @@ Showing #[numActiveRunning]# active, #[numActivePending]# pending connections fr<td class="small">Dest. IP[:Port]</td><td class="small">Command</td><td class="small">Used</td>+ <td class="small">Close</td></tr>#{list}#<tr class="TableCell#(dark)#Light::Dark::Summary#(/dark)#" title="#[sessionName]#">@@ -29,6 +30,7 @@ Showing #[numActiveRunning]# active, #[numActivePending]# pending connections fr<td class="small">#[dest]#</td><td class="small">#(running)#Waiting for new request nr. # #[reqNr]#::#[command]##(/running)#</td><td class="small">#[used]#</td>+ <td class="small"><a href="Connections_p.html?closeSession=#[sessionID]#"><font class="small">[Close]</font></a></td></tr>#{/list}#</table>diff --git a/htroot/Connections_p.java b/htroot/Connections_p.javaindex 850f800d1..7f521a87e 100644--- a/htroot/Connections_p.java+++ b/htroot/Connections_p.java@@ -46,7 +46,9 @@//javac -classpath .:../classes Network.java//if the shell's current path is HTROOT+import java.io.UnsupportedEncodingException;import java.net.InetAddress;+import java.net.URLEncoder;import java.util.Properties;import org.apache.commons.pool.impl.GenericObjectPool;@@ -65,18 +67,13 @@ import de.anomic.urlRedirector.urlRedirectord;import de.anomic.yacy.yacyCore;import de.anomic.yacy.yacySeed;-public final class Connections_p {+public final class Connections_p {public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch sb) {// return variable that accumulates replacementsplasmaSwitchboard switchboard = (plasmaSwitchboard) sb;serverObjects prop = new serverObjects();-- // determines if name lookup should be done or not- boolean doNameLookup = false;- if ((post != null) && post.containsKey("nameLookup") && post.get("nameLookup","true").equals("true")) {- doNameLookup = true;- }+// getting the virtualHost stringString virtualHost = switchboard.getConfig("fileHost","localhost");@@ -93,7 +90,55 @@ public final class Connections_p {/* waiting for all threads to finish */int threadCount = httpSessions.activeCount();Thread[] threadList = new Thread[httpdPoolConfig.maxActive];- threadCount = httpSessions.enumerate(threadList);+ threadCount = httpSessions.enumerate(threadList);++ // determines if name lookup should be done or not+ boolean doNameLookup = false;+ if (post != null) {+ if (post.containsKey("nameLookup") && post.get("nameLookup","true").equals("true")) {+ doNameLookup = true;+ }+ if (post.containsKey("closeSession")) {+ String sessionName = post.get("closeSession",null);+ if (sessionName != null) {+ for ( int currentThreadIdx = 0; currentThreadIdx < threadCount; currentThreadIdx++ ) {+ Thread currentThread = threadList[currentThreadIdx];+ if (+ (currentThread != null) &&+ (currentThread instanceof serverCore.Session) &&+ (currentThread.isAlive()) &&+ (currentThread.getName().equals(sessionName))+ ){+ // trying to gracefull stop session+ ((Session)currentThread).setStopped(true);+ try { Thread.sleep(100); } catch (InterruptedException ex) {}++ // trying to interrupt session+ if (currentThread.isAlive()) {+ currentThread.interrupt();+ try { Thread.sleep(100); } catch (InterruptedException ex) {}+ }++ // trying to close socket+ if (currentThread.isAlive()) {+ ((Session)currentThread).close();+ }++ // waiting for session to finish+ if (currentThread.isAlive()) {+ try { currentThread.join(500); } catch (InterruptedException ex) {}+ }+++ }+ }++ }++ prop.put("LOCATION","");+ return prop;+ }+ }int idx = 0, numActiveRunning = 0, numActivePending = 0, numMax = ((serverCore)httpd).getMaxSessionCount();boolean dark = true;@@ -155,6 +200,12 @@ public final class Connections_p {}prop.put("list_" + idx + "_dark", ((dark) ? 1 : 0) ); dark=!dark;+ try {+ prop.put("list_" + idx + "_sessionID",URLEncoder.encode(currentSession.getName(),"UTF8"));+ } catch (UnsupportedEncodingException e) {+ // TODO Auto-generated catch block+ e.printStackTrace();+ }prop.put("list_" + idx + "_sessionName",currentSession.getName());prop.put("list_" + idx + "_proto",prot);if (sessionTime > 1000*60) {diff --git a/source/de/anomic/server/serverCore.java b/source/de/anomic/server/serverCore.javaindex 4914ad2fc..bc210ed3b 100644--- a/source/de/anomic/server/serverCore.java+++ b/source/de/anomic/server/serverCore.java@@ -949,6 +949,13 @@ public final class serverCore extends serverAbstractThread implements serverThre// e1.printStackTrace();this.stopped = true;}+ } else if (!serverCore.this.theSessionPool.isClosed) {+ try {+ serverCore.this.theSessionPool.invalidateObject(this);+ } catch (Exception e) {+ // TODO Auto-generated catch block+ e.printStackTrace();+ }}}}