Package com.dianping.cat.core.dal

Examples of com.dianping.cat.core.dal.Hostinfo


        if (!insert) {
          m_logger.warn(String.format("Error when insert domain %s info", domain));
        }
      }
      Hostinfo info = m_hostinfoService.findByIp(ip);

      if (info == null) {
        m_hostinfoService.insert(domain, ip);
      } else {
        String oldDomain = info.getDomain();

        if (!domain.equals(oldDomain) && !Constants.CAT.equals(oldDomain)) {
          // only work on online environment
          long current = System.currentTimeMillis();
          Date lastModifiedDate = info.getLastModifiedDate();

          if (lastModifiedDate != null && (current - lastModifiedDate.getTime()) > ONE_HOUR) {
            m_hostinfoService.update(info.getId(), domain, ip);
            m_logger.info(String.format("old domain is %s , change ip %s to %s", oldDomain, ip, domain));
          }
        }
      }
    }
View Full Code Here


  public List<Hostinfo> findAll() throws DalException {
    return new ArrayList<Hostinfo>(m_hostinfos.values());
  }

  public Hostinfo findByIp(String ip) {
    Hostinfo hostinfo = m_hostinfos.get(ip);

    if (hostinfo != null) {
      return hostinfo;
    } else {
      try {
View Full Code Here

    }
  }

  public boolean insert(String domain, String ip) {
    try {
      Hostinfo info = createLocal();

      info.setDomain(domain);
      info.setIp(ip);
      insert(info);
      m_hostinfos.put(ip, info);
      return true;
    } catch (DalException e) {
      Cat.logError(e);
View Full Code Here

  }

  public String queryHostnameByIp(String ip) {
    try {
      if (validateIp(ip)) {
        Hostinfo info = m_hostinfos.get(ip);
        String hostname = null;

        if (info != null) {
          hostname = info.getHostname();

          if (StringUtils.isNotEmpty(hostname)) {
            return hostname;
          }
        }
        info = findByIp(ip);

        if (info != null) {
          m_hostinfos.put(ip, info);
          hostname = info.getHostname();
        }
        return hostname;
      } else {
        return null;
      }
View Full Code Here

      Cat.logError("initialize HostService error", e);
    }
  }

  public boolean update(int id, String domain, String ip) {
    Hostinfo info = createLocal();

    info.setId(id);
    info.setDomain(domain);
    info.setIp(ip);
    info.setLastModifiedDate(new Date());
    updateHostinfo(info);
    m_hostinfos.put(ip, info);
    return true;
  }
View Full Code Here

    private void queryFromDatabase() {
      Set<String> addIps = new HashSet<String>();

      for (String ip : m_unknownIps.keySet()) {
        try {
          Hostinfo hostinfo = findByIp(ip);

          if (hostinfo != null) {
            addIps.add(hostinfo.getIp());
            m_ipDomains.put(hostinfo.getIp(), hostinfo.getDomain());
          }

        } catch (Exception e) {
          // ignore
        }
View Full Code Here

TOP

Related Classes of com.dianping.cat.core.dal.Hostinfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.