Beispiel #1
0
 /**
  * Returns ordered intent key from network and two hosts.
  *
  * @param network network name
  * @param one host one
  * @param two host two
  * @return canonical intent string key
  */
 protected Key generateKey(String network, HostId one, HostId two) {
   String hosts =
       one.toString().compareTo(two.toString()) < 0
           ? format(HOST_FORMAT, one, two)
           : format(HOST_FORMAT, two, one);
   return Key.of(format(KEY_FORMAT, network, hosts), appId);
 }
Beispiel #2
0
  /**
   * Matches an intent to a network and optional host.
   *
   * @param network network name
   * @param id optional host id, wildcard if missing
   * @param intent intent to match
   * @return true if intent matches, false otherwise
   */
  protected boolean matches(String network, Optional<HostId> id, Intent intent) {
    if (!Objects.equals(appId, intent.appId())) {
      // different app ids
      return false;
    }

    String key = intent.key().toString();
    if (!key.startsWith(network)) {
      // different network
      return false;
    }

    if (!id.isPresent()) {
      // no host id specified; wildcard match
      return true;
    }

    HostId hostId = id.get();
    String[] fields = key.split(",");
    // return result of id match in host portion of key
    return fields.length > 1 && fields[1].contains(hostId.toString());
  }