Ejemplo n.º 1
0
 /* (non-Javadoc)
  * @see com.lexst.thread.VirtualThread#process()
  */
 @Override
 public void process() {
   Logger.info("WorkPool.process, into...");
   while (!isInterrupted()) {
     this.check();
     this.delay(1000);
   }
   Logger.info("WorkPool.process, exit");
 }
Ejemplo n.º 2
0
  /**
   * @param host
   * @param notify
   * @return
   */
  private boolean remove(SiteHost host, boolean notify) {
    Logger.info("WorkPool.remove, work site %s", host);

    boolean success = false;
    this.lockSingle();
    try {
      mapTime.remove(host);
      WorkSite site = mapSite.remove(host);
      if (site != null) {
        for (Naming naming : site.list()) {
          SiteSet set = mapNaming.get(naming);
          if (set != null) {
            set.remove(host);
          }
          if (set == null || set.isEmpty()) {
            mapNaming.remove(naming);
          }
        }
        success = true;

        if (notify) {
          CallPool.getInstance().refreshWorkSite();
        }
      }
    } catch (Throwable exp) {
      Logger.error(exp);
    } finally {
      this.unlockSingle();
    }
    return success;
  }
Ejemplo n.º 3
0
 /**
  * update work site
  *
  * @param site
  * @return
  */
 public boolean update(Site site) {
   if (site == null || !site.isWork()) {
     return false;
   }
   SiteHost host = site.getHost();
   Logger.info("WorkPool.update, work site %s", host);
   remove(host, false);
   return add(site, true);
 }
Ejemplo n.º 4
0
  /**
   * find work site by naming
   *
   * @param naming
   * @return
   */
  public SiteHost[] find(String naming) {
    Naming s = new Naming(naming);

    Logger.info("WorkPool.find, find work site by '%s'", s);

    ArrayList<SiteHost> a = new ArrayList<SiteHost>();
    this.lockSingle();
    try {
      SiteSet set = mapNaming.get(s);
      if (set != null) {
        a.addAll(set.list());
      }
    } catch (Throwable exp) {
      Logger.error(exp);
    } finally {
      this.unlockSingle();
    }

    if (a.isEmpty()) return null;
    SiteHost[] hosts = new SiteHost[a.size()];
    return a.toArray(hosts);
  }
Ejemplo n.º 5
0
  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;
  }