diff --git a/htroot/Connections_p.html b/htroot/Connections_p.html
index c02155e4d..6c057642b 100644
--- a/htroot/Connections_p.html
+++ b/htroot/Connections_p.html
@@ -30,7 +30,7 @@
#[dest]# |
#(running)#Waiting for new request nr. # #[reqNr]#::#[command]##(/running)# |
#[used]# |
- [Close] |
+ [Close] |
#{/list}#
diff --git a/htroot/Connections_p.java b/htroot/Connections_p.java
index 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 string
final String virtualHost = sb.getConfig("fileHost","localhost");
+
+ // server sessions
// get the serverCore thread
final 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 not
boolean 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 runtime
final 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 block
e.printStackTrace();
@@ -209,6 +212,7 @@ public final class Connections_p {
prop.putNum("numActiveRunning", numActiveRunning);
prop.putNum("numActivePending", numActivePending);
+
// client sessions
final Set allConnections = HttpConnectionInfo.getAllConnections();
// TODO sorting
diff --git a/source/de/anomic/server/serverCore.java b/source/de/anomic/server/serverCore.java
index 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 server
int commandMaxLength;
private int maxBusySessions;
final ConcurrentHashMap 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 server
maxBusySessions = Math.max(1, Integer.valueOf(switchboard.getConfig("httpdMaxBusySessions","100")).intValue());
busySessions = new ConcurrentHashMap();
+ this.lastAutoTermination = System.currentTimeMillis();
+
// init servercore
init();
}
@@ -485,6 +482,9 @@ public final class serverCore extends serverAbstractBusyThread implements server
this.controlSocket = controlSocket;
this.hashIndex = sessionCounter;
sessionCounter++;
+
+ // close old sessions
+ terminateOldSessions(60000);
if (!this.runningsession) {
// this.setDaemon(true);