Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
automated interruption of dead incoming connections, if they are there for more than one minute
orbiter1ba43019202f
diff --git a/htroot/Connections_p.html b/htroot/Connections_p.htmlindex c02155e4d..6c057642b 100644--- a/htroot/Connections_p.html+++ b/htroot/Connections_p.html@@ -30,7 +30,7 @@<td>#[dest]#</td><td>#(running)#Waiting for new request nr. # #[reqNr]#::#[command]##(/running)#</td><td>#[used]#</td>- <td><a href="Connections_p.html?closeSession=#[sessionID]#">[Close]</a></td>+ <td><a href="Connections_p.html?closeServerSession=#[serverSessionID]#">[Close]</a></td></tr>#{/list}#</table>diff --git a/htroot/Connections_p.java b/htroot/Connections_p.javaindex d31cb329c..e8a883f6c 100644--- a/htroot/Connections_p.java+++ b/htroot/Connections_p.java@@ -59,13 +59,15 @@ public final class Connections_p {// get the virtualHost stringfinal String virtualHost = sb.getConfig("fileHost","localhost");++ // server sessions// get the serverCore threadfinal serverThread httpd = sb.getThread("10_httpd");/* waiting for all threads to finish */int threadCount = serverCore.sessionThreadGroup.activeCount();final Thread[] threadList = new Thread[((serverCore) httpd).getJobCount()];- threadCount = serverCore.sessionThreadGroup.enumerate(threadList);+ threadCount = serverCore.sessionThreadGroup.enumerate(threadList);// determines if name lookup should be done or notboolean doNameLookup = false;@@ -73,8 +75,8 @@ public final class Connections_p {if (post.containsKey("nameLookup") && post.get("nameLookup","true").equals("true")) {doNameLookup = true;}- if (post.containsKey("closeSession")) {- final String sessionName = post.get("closeSession",null);+ if (post.containsKey("closeServerSession")) {+ final String sessionName = post.get("closeServerSession",null);if (sessionName != null) {for ( int currentThreadIdx = 0; currentThreadIdx < threadCount; currentThreadIdx++ ) {final Thread currentThread = threadList[currentThreadIdx];@@ -103,6 +105,7 @@ public final class Connections_p {if (currentThread.isAlive()) {try { currentThread.join(500); } catch (final InterruptedException ex) {}}+ break;}}}@@ -117,7 +120,7 @@ public final class Connections_p {final Thread currentThread = threadList[currentThreadIdx];if ((currentThread != null) && (currentThread instanceof serverCore.Session) && (currentThread.isAlive())) {// getting the session object- final Session currentSession = ((Session)currentThread);+ final Session currentSession = ((Session) currentThread);// getting the session runtimefinal long sessionTime = currentSession.getTime();@@ -174,7 +177,7 @@ 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"));+ prop.put("list_" + idx + "_serverSessionID",URLEncoder.encode(currentSession.getName(),"UTF8"));} catch (final UnsupportedEncodingException e) {// TODO Auto-generated catch blocke.printStackTrace();@@ -209,6 +212,7 @@ public final class Connections_p {prop.putNum("numActiveRunning", numActiveRunning);prop.putNum("numActivePending", numActivePending);+// client sessionsfinal Set<HttpConnectionInfo> allConnections = HttpConnectionInfo.getAllConnections();// TODO sortingdiff --git a/source/de/anomic/server/serverCore.java b/source/de/anomic/server/serverCore.javaindex cc82662fc..e44213a01 100644--- a/source/de/anomic/server/serverCore.java+++ b/source/de/anomic/server/serverCore.java@@ -135,46 +135,41 @@ public final class serverCore extends serverAbstractBusyThread implements serverint commandMaxLength;private int maxBusySessions;final ConcurrentHashMap<Session, Object> busySessions;+ private long lastAutoTermination;- /*- private static ServerSocketFactory getServerSocketFactory(boolean dflt, File keyfile, String passphrase) {- // see doc's at- // http://java.sun.com/developer/technicalArticles/Security/secureinternet/- if (dflt) {- return ServerSocketFactory.getDefault();- } else {- SSLServerSocketFactory ssf = null;- try {- // set up key manager to do server authentication- SSLContext ctx;- KeyManagerFactory kmf;- KeyStore ks;- char[] pp = passphrase.toCharArray();-- // open keystore- ks = KeyStore.getInstance("JKS");- ks.load(new FileInputStream(keyfile), pp);-- // get a KeyManager Factory- String algorithm = KeyManagerFactory.getDefaultAlgorithm(); // should be "SunX509"- kmf = KeyManagerFactory.getInstance(algorithm);- kmf.init(ks, pp);+ public final void terminateOldSessions(long minage) {+ if (System.currentTimeMillis() - lastAutoTermination < 30000) return;+ this.lastAutoTermination = System.currentTimeMillis();++ int threadCount = serverCore.sessionThreadGroup.activeCount();+ final Thread[] threadList = new Thread[this.getJobCount()];+ threadCount = serverCore.sessionThreadGroup.enumerate(threadList);+ for ( int currentThreadIdx = 0; currentThreadIdx < threadCount; currentThreadIdx++ ) {+ final Thread currentThread = threadList[currentThreadIdx];+ if (+ (currentThread != null) &&+ (currentThread instanceof Session) &&+ (currentThread.isAlive()) &&+ (((Session) currentThread).getTime() > minage)+ ) {+ log.logInfo("check for " + currentThread.getName() + ": " + ((Session) currentThread).getTime() + " ms alive, stopping thread");+ // trying to stop session+ ((Session)currentThread).setStopped(true);+ try { Thread.sleep(100); } catch (final InterruptedException ex) {}- // create a ssl context with the keyManager Factory- //ctx = SSLContext.getInstance("TLS");- ctx = SSLContext.getInstance("SSLv3");+ // trying to interrupt session+ if (currentThread.isAlive()) {+ currentThread.interrupt();+ try { Thread.sleep(10); } catch (final InterruptedException ex) {}+ }- ctx.init(kmf.getKeyManagers(), null, null);-- ssf = ctx.getServerSocketFactory();- return ssf;- } catch (Exception e) {- e.printStackTrace();- return null;- }- }+ // trying to close socket+ if (currentThread.isAlive()) {+ ((Session)currentThread).close();+ }+ }+ }}- */public static String clientAddress(final Socket s) {final InetAddress uAddr = s.getInetAddress();@@ -213,6 +208,8 @@ public final class serverCore extends serverAbstractBusyThread implements servermaxBusySessions = Math.max(1, Integer.valueOf(switchboard.getConfig("httpdMaxBusySessions","100")).intValue());busySessions = new ConcurrentHashMap<Session, Object>();+ this.lastAutoTermination = System.currentTimeMillis();+// init servercoreinit();}@@ -485,6 +482,9 @@ public final class serverCore extends serverAbstractBusyThread implements serverthis.controlSocket = controlSocket;this.hashIndex = sessionCounter;sessionCounter++;++ // close old sessions+ terminateOldSessions(60000);if (!this.runningsession) {// this.setDaemon(true);