public synchronized void logUnavailableHost(URL url) { if (this.offlineMode) return; if (url == null) { String message = Logging.getMessage("nullValue.URLIsNull"); Logging.error(message); throw new IllegalArgumentException(message); } String hostName = url.getHost(); HostInfo hi = this.hostMap.get(hostName); if (hi != null) { if (!hi.isUnavailable()) { hi.logCount.incrementAndGet(); if (hi.isUnavailable()) // host just became unavailable this.firePropertyChange(NetworkStatus.HOST_UNAVAILABLE, null, url); } hi.lastLogTime.set(System.currentTimeMillis()); } else { hi = new HostInfo(this.attemptLimit.get(), this.tryAgainInterval.get()); hi.logCount.set(1); if (hi.isUnavailable()) // the attempt limit may be as low as 1, so handle that case here this.firePropertyChange(NetworkStatus.HOST_UNAVAILABLE, null, url); this.hostMap.put(hostName, hi); } this.lastUnavailableLogTime.set(System.currentTimeMillis()); }
public void setTryAgainInterval(long interval) { if (interval < 0) { String message = Logging.getMessage("NetworkStatus.InvalidTryAgainInterval"); Logging.error(message); throw new IllegalArgumentException(message); } this.tryAgainInterval.set(interval); }
public void setAttemptLimit(int limit) { if (limit < 1) { String message = Logging.getMessage("NetworkStatus.InvalidAttemptLimit"); Logging.error(message); throw new IllegalArgumentException(message); } this.attemptLimit.set(limit); }
public synchronized void logAvailableHost(URL url) { if (this.offlineMode) return; if (url == null) { String message = Logging.getMessage("nullValue.URLIsNull"); Logging.error(message); throw new IllegalArgumentException(message); } String hostName = url.getHost(); HostInfo hi = this.hostMap.get(hostName); if (hi != null) { this.hostMap.remove(hostName); // host is available again firePropertyChange(NetworkStatus.HOST_AVAILABLE, null, url); } this.lastAvailableLogTime.set(System.currentTimeMillis()); }
public boolean isHostUnavailable(URL url) { if (this.offlineMode) return true; if (url == null) { String message = Logging.getMessage("nullValue.URLIsNull"); Logging.error(message); throw new IllegalArgumentException(message); } String hostName = url.getHost(); HostInfo hi = this.hostMap.get(hostName); if (hi == null) return false; if (hi.isTimeToTryAgain()) { hi.logCount.set(0); // info removed from table in logAvailableHost return false; } return hi.isUnavailable(); }