From 922db8cfe69a6aa59999a89bab233be2b40396ee Mon Sep 17 00:00:00 2001 From: cmarschner Date: Tue, 22 Oct 2002 15:22:59 +0000 Subject: [PATCH] added host semaphores git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150847 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/de/lanlab/larm/net/HostInfo.java | 59 ++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/sandbox/contributions/webcrawler-LARM/src/de/lanlab/larm/net/HostInfo.java b/sandbox/contributions/webcrawler-LARM/src/de/lanlab/larm/net/HostInfo.java index 66ee8800f78..b6265cd8aa1 100644 --- a/sandbox/contributions/webcrawler-LARM/src/de/lanlab/larm/net/HostInfo.java +++ b/sandbox/contributions/webcrawler-LARM/src/de/lanlab/larm/net/HostInfo.java @@ -79,7 +79,62 @@ public class HostInfo private int id; - private int healthyCount = 5; + int healthyCount = 8; + + int locks = 2; // max. concurrent requests + int lockObtained = 0; // for debugging + + Object lockMonitor = new Object(); + public Object getLockMonitor() + { + return lockMonitor; + } + public void releaseLock() + { + synchronized(lockMonitor) + { + if(lockObtained>=0) + { + locks++; + lockObtained--; +// try +// { +// throw new Exception(); +// +// } +// catch(Exception e) +// { +// System.out.println("HostInfo: release called at: " + e.getStackTrace()[1]); +// } +// System.out.println("HostInfo " + hostName + ": releaseing Lock. now " + lockObtained + " locks obtained, " + locks + " available"); + } +// else +// { +// System.out.println("HostInfo: lock released although no lock acquired!?"); +// } + } + } + // must be synchronized + public void obtainLock() + { + locks--; + lockObtained++; +// try +// { +// throw new Exception(); +// +// } +// catch(Exception e) +// { +// System.out.println("obtain called at: " + e.getStackTrace()[1]); +// } +// System.out.println("HostInfo " + hostName + ": obtaining Lock. now " + lockObtained + " locks obtained, " + locks + " available"); + } + // must be synchronized + public boolean isBusy() + { + return locks<=0; + } // five strikes, and you're out private boolean isReachable = true; @@ -194,6 +249,7 @@ public class HostInfo public void badRequest() { healthyCount--; + System.out.println("HostInfo: " + this.hostName + ": badRequest. " + healthyCount + " left"); } @@ -205,6 +261,7 @@ public class HostInfo public void setReachable(boolean reachable) { isReachable = reachable; + System.out.println("HostInfo: " + this.hostName + ": setting to " + (reachable ? "reachable" : "unreachable")); }