diff --git a/htroot/Connections_p.html b/htroot/Connections_p.html index c7507cff7..c591d45c8 100644 --- a/htroot/Connections_p.html +++ b/htroot/Connections_p.html @@ -20,6 +20,7 @@ Showing #[numActiveRunning]# active, #[numActivePending]# pending connections fr Dest. IP[:Port] Command Used + Close #{list}# @@ -29,6 +30,7 @@ Showing #[numActiveRunning]# active, #[numActivePending]# pending connections fr #[dest]# #(running)#Waiting for new request nr. # #[reqNr]#::#[command]##(/running)# #[used]# + [Close] #{/list}# diff --git a/htroot/Connections_p.java b/htroot/Connections_p.java index 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 replacements plasmaSwitchboard 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 string String 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.java index 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(); + } } } }