/** * refresh work site * * @param host * @return */ public short refresh(SiteHost host) { short code = Response.SERVER_ERROR; this.lockSingle(); try { WorkSite site = mapSite.get(host); if (site != null) { mapTime.put(host, System.currentTimeMillis()); code = Response.ISEE; } else { code = Response.NOTLOGIN; } } catch (Throwable exp) { Logger.error(exp); } finally { this.unlockSingle(); } Logger.debug("WorkPool.refresh, site %s refresh status %d", host, code); return code; }
/** check timeout site */ private void check() { int size = mapTime.size(); if (size == 0) return; ArrayList<SiteHost> dels = new ArrayList<SiteHost>(size); ArrayList<SiteHost> notifys = new ArrayList<SiteHost>(size); super.lockSingle(); try { long nowTime = System.currentTimeMillis(); for (SiteHost host : mapTime.keySet()) { Long value = mapTime.get(host); if (value == null) { dels.add(host); continue; } long time = value.longValue(); if (nowTime - time >= deleteTime) { dels.add(host); } else if (nowTime - time >= refreshTimeout) { notifys.add(host); } } } catch (Throwable exp) { exp.printStackTrace(); } finally { super.unlockSingle(); } // remove timeout site for (SiteHost host : dels) { Logger.error("WorkPool.check, delete timeout site:%s", host); remove(host); } // notify site SiteHost listen = Launcher.getInstance().getLocalHost(); for (SiteHost host : notifys) { Logger.warning("WorkPool.check, notify timeout site:%s", host); this.sendTimeout(host, listen, 2); } }
private boolean add(Site object, boolean notify) { if (object == null || !object.isWork()) { return false; } WorkSite site = (WorkSite) object; SiteHost host = site.getHost(); Logger.info("WorkPool.add, work site %s", host); boolean success = false; this.lockSingle(); try { if (mapSite.containsKey(host)) { return false; } // save site mapSite.put(host, site); mapTime.put(host, System.currentTimeMillis()); for (Naming naming : site.list()) { SiteSet set = mapNaming.get(naming); if (set == null) { set = new SiteSet(); mapNaming.put(naming, set); } set.add(host); } success = true; if (notify) { CallPool.getInstance().refreshWorkSite(); } } catch (Throwable exp) { Logger.error(exp); } finally { this.unlockSingle(); } return success; }