Esempio n. 1
0
  public String getForeignSource(InetAddress address) {
    getReadLock().lock();
    try {
      LOG.debug(
          "Looking for matching foreign source specific IP or IP range with address: {}...",
          address);

      List<Specific> specificCollection = getConfiguration().getSpecificCollection();
      for (Specific specific : specificCollection) {
        String ipAddr = specific.getContent();

        if (ipAddr.equals(InetAddressUtils.str(address))) {

          String foreignSource = specific.getForeignSource();
          LOG.debug(
              "Matched foreign source {} matching address: {} against specific {}.",
              foreignSource,
              address,
              ipAddr);
          return foreignSource;
        }
      }

      final byte[] laddr = address.getAddress();

      List<IncludeRange> includeRangeCollection = getConfiguration().getIncludeRangeCollection();
      for (IncludeRange range : includeRangeCollection) {

        if (InetAddressUtils.isInetAddressInRange(laddr, range.getBegin(), range.getEnd())) {

          String foreignSource = range.getForeignSource();
          LOG.debug(
              "Found foreign source {} with address {} in the range begin: {} and end: {}.",
              foreignSource,
              address,
              range.getBegin(),
              range.getEnd());
          return foreignSource;
        }
      }

      List<IncludeUrl> includeUrlCollection = getConfiguration().getIncludeUrlCollection();
      for (IncludeUrl includeUrl : includeUrlCollection) {
        String ipAddr = includeUrl.getContent();
        if (ipAddr.equals(InetAddressUtils.str(address))) {

          String foreignSource = includeUrl.getForeignSource();
          LOG.debug(
              "Matched foreign source {} matching address: {} in specified URL.",
              foreignSource,
              address);
          return foreignSource;
        }
      }

      return getConfiguration().getForeignSource();
    } finally {
      getReadLock().unlock();
    }
  }
  /**
   * getSpecifics
   *
   * @return a {@link java.util.List} object.
   */
  public List<IPPollAddress> getSpecifics() {
    final List<IPPollAddress> specifics = new LinkedList<IPPollAddress>();

    getReadLock().lock();

    try {
      Long defaultTimeout = null;
      Integer defaultRetries = null;
      if (getConfiguration().hasTimeout()) defaultTimeout = getConfiguration().getTimeout();
      if (getConfiguration().hasRetries()) defaultRetries = getConfiguration().getRetries();

      for (final Specific s : getConfiguration().getSpecificCollection()) {

        long timeout = 800L;
        if (s.hasTimeout()) {
          timeout = s.getTimeout();
        } else if (defaultTimeout != null) {
          timeout = defaultTimeout;
        }

        int retries = 3;
        if (s.hasRetries()) {
          retries = s.getRetries();
        } else if (defaultRetries != null) {
          retries = defaultRetries;
        }

        try {
          specifics.add(new IPPollAddress(s.getContent(), timeout, retries));
        } catch (final UnknownHostException uhE) {
          LogUtils.warnf(this, uhE, "Failed to convert address %s", s.getContent());
        }
      }
      return specifics;
    } finally {
      getReadLock().unlock();
    }
  }
Esempio n. 3
0
  /**
   * getSpecifics
   *
   * @return a {@link java.util.List} object.
   */
  public List<IPPollAddress> getSpecifics() {
    final List<IPPollAddress> specifics = new LinkedList<IPPollAddress>();

    getReadLock().lock();
    try {
      Long defaultTimeout = null;
      Integer defaultRetries = null;
      if (getConfiguration().hasTimeout()) defaultTimeout = getConfiguration().getTimeout();
      if (getConfiguration().hasRetries()) defaultRetries = getConfiguration().getRetries();

      for (final Specific s : getConfiguration().getSpecificCollection()) {

        long timeout = 800L;
        if (s.hasTimeout()) {
          timeout = s.getTimeout();
        } else if (defaultTimeout != null) {
          timeout = defaultTimeout;
        }

        int retries = 3;
        if (s.hasRetries()) {
          retries = s.getRetries();
        } else if (defaultRetries != null) {
          retries = defaultRetries;
        }

        final String address = s.getContent();

        try {
          specifics.add(new IPPollAddress(InetAddressUtils.addr(address), timeout, retries));
        } catch (final IllegalArgumentException e) {
          LOG.warn("Failed to convert address {}", address, e);
        }
      }
      return specifics;
    } finally {
      getReadLock().unlock();
    }
  }