automated interruption of dead incoming connections, if they are there for more than one minute

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5622 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 16 years ago
parent c12bb8a6d0
commit 1ba4301920

@ -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>

@ -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<HttpConnectionInfo> allConnections = HttpConnectionInfo.getAllConnections();
// TODO sorting

@ -135,46 +135,41 @@ public final class serverCore extends serverAbstractBusyThread implements server
int 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 server
maxBusySessions = Math.max(1, Integer.valueOf(switchboard.getConfig("httpdMaxBusySessions","100")).intValue());
busySessions = new ConcurrentHashMap<Session, Object>();
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);

Loading…
Cancel
Save