1 24 package org.archive.crawler.datamodel; 25 26 import java.io.Serializable ; 27 import java.net.InetAddress ; 28 import java.util.logging.Level ; 29 import java.util.logging.Logger ; 30 31 import org.archive.util.InetAddressUtil; 32 33 41 public class CrawlHost implements Serializable , CrawlSubstats.HasCrawlSubstats { 42 43 private static final long serialVersionUID = -5494573967890942895L; 44 45 private static final Logger logger = Logger.getLogger(CrawlHost.class.getName()); 46 47 public static final long IP_NEVER_EXPIRES = -1; 48 49 public static final long IP_NEVER_LOOKED_UP = -2; 50 private String hostname; 51 private String countryCode; 52 private InetAddress ip; 53 private long ipFetched = IP_NEVER_LOOKED_UP; 54 protected CrawlSubstats substats = new CrawlSubstats(); 55 67 private long ipTTL = IP_NEVER_LOOKED_UP; 68 69 private long earliestNextURIEmitTime = 0; 71 72 77 public CrawlHost(String hostname) { 78 this(hostname, null); 79 } 80 81 87 public CrawlHost(String hostname, String countryCode) { 88 this.hostname = hostname; 89 this.countryCode = countryCode; 90 InetAddress tmp = InetAddressUtil.getIPHostAddress(hostname); 91 if (tmp != null) { 92 setIP(tmp, IP_NEVER_EXPIRES); 93 } 94 } 95 96 102 public boolean hasBeenLookedUp() { 103 return ipFetched != IP_NEVER_LOOKED_UP; 104 } 105 106 113 public void setIP(InetAddress address, long ttl) { 114 this.ip = address; 115 this.ipFetched = System.currentTimeMillis(); 118 this.ipTTL = ttl; 119 if (logger.isLoggable(Level.FINE)) { 120 logger.fine(hostname + ": " + 121 ((address != null)? address.toString(): "null")); 122 } 123 } 124 125 129 public InetAddress getIP() { 130 return ip; 131 } 132 133 137 public long getIpFetched() { 138 return ipFetched; 139 } 140 141 147 public long getIpTTL() { 148 return this.ipTTL; 149 } 150 151 public String toString() { 152 return "CrawlHost<" + hostname + "(ip:" + ip + ")>"; 153 } 154 155 159 public String getHostName() { 160 return hostname; 161 } 162 163 169 public long getEarliestNextURIEmitTime() { 170 return earliestNextURIEmitTime; 171 } 172 173 179 public void setEarliestNextURIEmitTime(long earliestNextURIEmitTime) { 180 this.earliestNextURIEmitTime = earliestNextURIEmitTime; 181 } 182 183 188 public String getCountryCode() { 189 return countryCode; 190 } 191 192 197 public void setCountryCode(String countryCode) { 198 this.countryCode = countryCode; 199 } 200 201 204 public CrawlSubstats getSubstats() { 205 return substats; 206 } 207 } 208 | Popular Tags |