/** * get all worksite * * @return */ public WorkSite[] batch() { WorkSite[] sites = null; super.lockMulti(); try { int size = mapSite.size(); if (size > 0) { sites = new WorkSite[size]; mapSite.values().toArray(sites); } } catch (Throwable exp) { Logger.fatal(exp); } finally { super.unlockMulti(); } return sites; }
/* * (non-Javadoc) * @see com.lexst.db.view.View#remove(com.lexst.util.host.SiteHost) */ @Override public int remove(SiteHost host) { int size = mapSet.size(); if (size == 0) return size; int count = 0; ArrayList<ShortRange> a = new ArrayList<ShortRange>(size); for (ShortRange range : mapSet.keySet()) { IdentitySet set = mapSet.get(range); if (set != null) { count += set.remove(host); if (set.isEmpty()) a.add(range); } else { a.add(range); } } for (ShortRange range : a) { mapSet.remove(range); } return count; }
/** 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); } }
/* * (non-Javadoc) * @see com.lexst.db.view.View#remove(com.lexst.util.host.SiteHost, long) */ @Override public int remove(SiteHost host, long chunkId) { int size = mapSet.size(); if (size == 0) return 0; int count = 0; ArrayList<ShortRange> a = new ArrayList<ShortRange>(size); for (ShortRange range : mapSet.keySet()) { IdentitySet set = mapSet.get(range); if (set != null) { boolean success = set.remove(host, chunkId); if (success) count++; if (set.isEmpty()) a.add(range); } else { a.add(range); } } for (ShortRange range : a) { mapSet.remove(range); } return count; }
/* * (non-Javadoc) * @see com.lexst.db.view.View#delete(com.lexst.util.host.SiteHost) */ @Override public List<Long> delete(SiteHost host) { int size = mapSet.size(); if (size == 0) return null; ArrayList<Long> array = new ArrayList<Long>(256); ArrayList<ShortRange> a = new ArrayList<ShortRange>(size); for (ShortRange range : mapSet.keySet()) { IdentitySet set = mapSet.get(range); if (set != null) { set.remove(host, array); if (set.isEmpty()) a.add(range); } else { a.add(range); } } for (ShortRange range : a) { mapSet.remove(range); } return array; }
/* * (non-Javadoc) * @see com.lexst.db.view.View#size() */ @Override public int size() { return mapSet.size(); }