@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((movieBasic.getUrl() == null) ? 0 : movieBasic.getUrl().hashCode()); return result; }
@SuppressWarnings("unchecked") @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; UrlHandler other = (UrlHandler) obj; if (movieBasic == null) { if (other.movieBasic != null) return false; } else if (!movieBasic.getUrl().equals(other.movieBasic.getUrl())) return false; return true; }
public void doUrlResultByGetMethod( ExecutorService threadPool, IPDyncDraw ipDynDraw, Map<F, T> urlAndResult, IMovieParse<T> movieParse, Map<F, UrlExecuteStatBean> urlAndExecStats, Integer threadNum, RespUrlType respUrlType) throws Exception { ExecutorCompletionService<UrlHandler> completionService = new ExecutorCompletionService<UrlHandler>(threadPool); int currExecRespUrlSize = 0; if (!urlHandlerColl.isEmpty()) { currExecRespUrlSize = urlHandlerColl.size(); } int respUrlSize = respUrls.size(); List<F> currExecRespUrl = Lists.newArrayList(); for (int i = 0, j = 0; i < (respUrlSize >= threadNum ? (threadNum - currExecRespUrlSize) : respUrlSize); i++) { currExecRespUrl.add(respUrls.remove(j)); } Collection<UrlHandler> tempUrlHandler = this.convertUrlHandler(currExecRespUrl); urlHandlerColl.addAll(tempUrlHandler); for (UrlHandler urlHandler : urlHandlerColl) { this.registerCompletionService(ipDynDraw, httpGet, completionService, urlHandler, movieParse); } int execUrlSize = urlHandlerColl.size(); Set<UrlHandler> passUrl = Sets.newHashSet(); for (int i = 0; i < execUrlSize; i++) { Future<UrlHandler> future = completionService.take(); if (future.isDone()) { UrlHandler urlHandler = future.get(); Exception err = urlHandler.err; F movieBasic = urlHandler.movieBasic; T target = urlHandler.target; MovieCode statCode = urlHandler.statCode; switch (statCode) { case SUCC: // 成功 urlAndResult.put(movieBasic, target); break; case PARSE_ERR: // 解析失败 case SERVICE_ERR: // 服务器错误 String errMsg = err.getMessage(); UrlExecuteStatBean urlExecuteStat = new UrlExecuteStatBean(); urlExecuteStat.setDbId(movieBasic.getId()); urlExecuteStat.setFialMsg(errMsg); urlExecuteStat.setLastExecTm(new Date()); urlExecuteStat.setUrl(MovieDoMain.MOIVE_MAIN_URL + movieBasic.getUrl()); urlExecuteStat.setUrlType(respUrlType.toString()); urlExecuteStat.setFialErrCode(statCode.toString()); urlAndExecStats.put(movieBasic, urlExecuteStat); break; } if (statCode != MovieCode.EXEC_ERR) { passUrl.add(urlHandler); } } } int passUrlSize = passUrl.size(); // 移除成功的url urlHandlerColl.removeAll(passUrl); logger.info( "第 " + atomicInt.incrementAndGet() + " 次,执行完毕,共执行链接 --> " + execUrlSize + " 条,成功 --> " + passUrlSize); }
@Override public String toString() { return "UrlHandler [url=" + movieBasic.getUrl() + ", executeNum=" + executeNum + "]"; }