Пример #1
0
 /**
  * Returns the {@link Set} of {@link EntryType}s for a given {@code group} on a given {@code
  * address}.
  *
  * @param address Address of a server.
  * @param group Group whose {@literal "types"} you want.
  * @return Either of all the types for a given {@code address} and {@code group} or an empty
  *     {@code Set} if there were no matches.
  */
 public Set<EntryType> getTypes(final String address, final String group) {
   Set<EntryType> types = newLinkedHashSet(trie.size());
   for (AddeEntry entry : trie.getPrefixedBy(address + '!' + group + '!').values()) {
     types.add(entry.getEntryType());
   }
   return types;
 }
Пример #2
0
 /**
  * Returns the {@link Set} of {@link AddeEntry} addresses stored in this {@code EntryStore}.
  *
  * @return {@code Set} containing all of the stored addresses. If no addresses are stored, an
  *     empty {@code Set} is returned.
  */
 public Set<String> getAddresses() {
   Set<String> addresses = newLinkedHashSet(trie.size());
   for (AddeEntry entry : trie.values()) {
     addresses.add(entry.getAddress());
   }
   return addresses;
 }
Пример #3
0
 /**
  * Returns the {@link Set} of {@literal "groups"} associated with the given {@code address}.
  *
  * @param address Address of a server.
  * @return Either all of the {@literal "groups"} on {@code address} or an empty {@code Set}.
  */
 public Set<String> getGroups(final String address) {
   notNull(address);
   Set<String> groups = newLinkedHashSet(trie.size());
   for (AddeEntry entry : trie.getPrefixedBy(address + '!').values()) {
     groups.add(entry.getGroup());
   }
   return groups;
 }
Пример #4
0
 /**
  * Adds {@link AddeEntry} objects to a given {@link PatriciaTrie}.
  *
  * @param trie Cannot be {@code null}.
  * @param newEntries Cannot be {@code null}.
  */
 private static void putEntries(
     final PatriciaTrie<String, AddeEntry> trie,
     final Collection<? extends AddeEntry> newEntries) {
   notNull(trie);
   notNull(newEntries);
   for (AddeEntry e : newEntries) {
     trie.put(e.asStringId(), e);
   }
 }
Пример #5
0
 /**
  * Returns a {@link Set} containing <b>ADDRESS/GROUPNAME</b> {@code String}s for each {@link
  * RemoteAddeEntry}.
  *
  * @return The {@literal "entry text"} representations of each {@code RemoteAddeEntry}.
  * @see RemoteAddeEntry#getEntryText()
  */
 public Set<String> getRemoteEntryTexts() {
   Set<String> strs = newLinkedHashSet(trie.size());
   for (AddeEntry entry : trie.values()) {
     if (entry instanceof RemoteAddeEntry) {
       strs.add(entry.getEntryText());
     }
   }
   return strs;
 }
Пример #6
0
 public Set<AddeEntry> getPersistedEntrySet() {
   Set<AddeEntry> entries = newLinkedHashSet(trie.size());
   for (AddeEntry entry : trie.values()) {
     if (!entry.isEntryTemporary()) {
       entries.add(entry);
     }
   }
   return entries;
 }
Пример #7
0
 public List<AddeEntry> getLastAddedByTypes(final EnumSet<EntryType> types) {
   notNull(types);
   List<AddeEntry> entries = arrList(lastAdded.size());
   for (AddeEntry entry : lastAdded) {
     if (types.contains(entry.getEntryType())) {
       entries.add(entry);
     }
   }
   return entries;
 }
Пример #8
0
 /**
  * Searches the newest entries for the entries of the given {@link
  * edu.wisc.ssec.mcidasv.servermanager.AddeEntry.EntryType EntryType}.
  *
  * @param type Look for entries matching this {@code EntryType}. Cannot be {@code null}.
  * @return Either a {@link java.util.List List} of entries or an empty {@code List}.
  * @throws NullPointerException if {@code type} is {@code null}.
  */
 public List<AddeEntry> getLastAddedByType(final EntryType type) {
   notNull(type);
   List<AddeEntry> entries = arrList(lastAdded.size());
   for (AddeEntry entry : lastAdded) {
     if (entry.getEntryType() == type) {
       entries.add(entry);
     }
   }
   return entries;
 }
Пример #9
0
 /**
  * Adds a {@link Set} of {@link AddeEntry}s to {@link #trie}.
  *
  * @param newEntries New entries to add to the server manager. Cannot be {@code null}.
  * @throws NullPointerException if {@code newEntries} is {@code null}.
  */
 public void addEntries(final Collection<? extends AddeEntry> newEntries) {
   notNull(newEntries, "Cannot add a null set");
   for (AddeEntry newEntry : newEntries) {
     trie.put(newEntry.asStringId(), newEntry);
   }
   saveEntries();
   lastAdded.clear();
   lastAdded.addAll(newEntries);
   EventBus.publish(Event.ADDITION);
 }
Пример #10
0
 /**
  * Searches the set of servers in an attempt to locate the accounting information for the matching
  * server. <b>Note</b> that because the data structure is a {@link Set}, there <i>cannot</i> be
  * duplicate entries, so there is no need to worry about our criteria finding multiple matches.
  *
  * <p>Also note that none of the given parameters accept {@code null} values.
  *
  * @param address Address of the server.
  * @param group Dataset.
  * @param type Group type.
  * @return Either the {@link AddeAccount} for the given criteria, or {@link
  *     AddeEntry#DEFAULT_ACCOUNT} if there was no match.
  * @see RemoteAddeEntry#equals(Object)
  */
 public AddeAccount getAccountingFor(final String address, final String group, EntryType type) {
   Collection<AddeEntry> entries =
       trie.getPrefixedBy(address + '!' + group + '!' + type.name()).values();
   for (AddeEntry entry : entries) {
     if (!isInvalidEntry(entry)) {
       return entry.getAccount();
     }
   }
   return AddeEntry.DEFAULT_ACCOUNT;
 }
Пример #11
0
 /**
  * Returns the {@link Set} of {@link AddeEntry#getGroup()}s that match the given {@code address}
  * and {@code type}.
  *
  * @param address ADDE server address whose groups are needed. Cannot be {@code null}.
  * @param type Only include groups that match {@link EntryType}. Cannot be {@code null}.
  * @return Either a set containing the desired groups, or an empty set if there were no matches.
  */
 public Set<String> getGroupsFor(final String address, EntryType type) {
   notNull(address);
   notNull(type);
   Set<String> groups = newLinkedHashSet(trie.size());
   for (AddeEntry entry : trie.getPrefixedBy(address + '!').values()) {
     if (entry.getAddress().equals(address) && entry.getEntryType() == type) {
       groups.add(entry.getGroup());
     }
   }
   return groups;
 }
Пример #12
0
  // TODO(jon): better name
  public Map<EntryType, Set<AddeEntry>> getVerifiedEntriesByTypes() {
    Map<EntryType, Set<AddeEntry>> entryMap = newLinkedHashMap(EntryType.values().length);
    int size = trie.size();
    for (EntryType type : EntryType.values()) {
      entryMap.put(type, new LinkedHashSet<AddeEntry>(size));
    }

    for (AddeEntry entry : trie.values()) {
      Set<AddeEntry> entrySet = entryMap.get(entry.getEntryType());
      entrySet.add(entry);
    }
    return entryMap;
  }
Пример #13
0
 /**
  * Searches {@code entries} for {@link AddeEntry} objects with two characteristics:
  *
  * <ul>
  *   <li>the object source is {@link EntrySource#SYSTEM}
  *   <li>the object is <b>not</b> in {@code systemEntries}
  * </ul>
  *
  * <p>The intent behind this method is to safely remove {@literal "system"} entries that have been
  * stored to a user's preferences. {@code entries} can be generated from anywhere you like, but
  * {@code systemEntries} should almost always be created from {@literal "addeservers.xml"}.
  *
  * @param entries Cannot be {@code null}.
  * @param systemEntries Cannot be {@code null}.
  * @return {@code Set} of entries that are not system resources that have been removed, or an
  *     empty {@code Set}.
  */
 private static Set<AddeEntry> removeDeletedSystemEntries(
     final Collection<? extends AddeEntry> entries,
     final Collection<? extends AddeEntry> systemEntries) {
   Set<AddeEntry> pruned = newLinkedHashSet(entries.size());
   for (AddeEntry entry : entries) {
     if (entry.getEntrySource() != EntrySource.SYSTEM) {
       pruned.add(entry);
     } else if (systemEntries.contains(entry)) {
       pruned.add(entry);
     } else {
       continue;
     }
   }
   return pruned;
 }
Пример #14
0
  /**
   * Returns the {@link Set} of {@link AddeEntry}s that are known to work (for a given {@link
   * EntryType} of entries).
   *
   * @param type The {@code EntryType} you are interested in.
   * @return A {@code Set} of matching {@code RemoteAddeEntry}s. If there were no matches, an empty
   *     {@code Set} is returned.
   */
  public Set<AddeEntry> getVerifiedEntries(final EntryType type) {
    notNull(type);
    Set<AddeEntry> verified = newLinkedHashSet(trie.size());
    for (AddeEntry entry : trie.values()) {
      if (entry.getEntryType() != type) {
        continue;
      }

      if (entry instanceof LocalAddeEntry) {
        verified.add(entry);
      } else if (entry.getEntryValidity() == EntryValidity.VERIFIED) {
        verified.add(entry);
      }
    }
    return verified;
  }
Пример #15
0
  public Set<AddeServer.Group> getIdvStyleRemoteGroups(final String server, final EntryType type) {
    Set<AddeServer.Group> idvGroups = newLinkedHashSet(trie.size());
    String typeStr = type.name();
    for (AddeEntry matched : trie.getPrefixedBy(server).values()) {
      if (matched == RemoteAddeEntry.INVALID_ENTRY) {
        continue;
      }

      if ((matched.getEntryStatus() == EntryStatus.ENABLED)
          && (matched.getEntryValidity() == EntryValidity.VERIFIED)
          && (matched.getEntryType() == type)) {
        String group = matched.getGroup();
        idvGroups.add(new AddeServer.Group(typeStr, group, group));
      }
    }
    return idvGroups;
  }
Пример #16
0
  /**
   * Replaces the {@link AddeEntry}s within {@code trie} with the contents of {@code newEntries}.
   *
   * @param oldEntries Entries to be replaced. Cannot be {@code null}.
   * @param newEntries Entries to use as replacements. Cannot be {@code null}.
   * @throws NullPointerException if either of {@code oldEntries} or {@code newEntries} is {@code
   *     null}.
   */
  public void replaceEntries(
      final Collection<? extends AddeEntry> oldEntries,
      final Collection<? extends AddeEntry> newEntries) {
    notNull(oldEntries, "Cannot replace a null set");
    notNull(newEntries, "Cannot add a null set");

    for (AddeEntry oldEntry : oldEntries) {
      trie.remove(oldEntry.asStringId());
    }
    for (AddeEntry newEntry : newEntries) {
      trie.put(newEntry.asStringId(), newEntry);
    }
    lastAdded.clear();
    lastAdded.addAll(newEntries); // should probably be more thorough
    saveEntries();
    EventBus.publish(Event.REPLACEMENT);
  }
Пример #17
0
 /**
  * Adds a single {@link AddeEntry} to {@link #trie}.
  *
  * @param entry Entry to add. Cannot be {@code null}.
  * @throws NullPointerException if {@code entry} is {@code null}.
  */
 public void addEntry(final AddeEntry entry) {
   notNull(entry, "Cannot add a null entry");
   trie.put(entry.asStringId(), entry);
   saveEntries();
   lastAdded.clear();
   lastAdded.add(entry);
   EventBus.publish(Event.ADDITION);
 }
Пример #18
0
 /**
  * Removes a single {@link AddeEntry} from the set of available entries.
  *
  * @param entry Entry to remove. Cannot be {@code null}.
  * @return {@code true} if something was removed, {@code false} otherwise.
  */
 public boolean removeEntry(final AddeEntry entry) {
   notNull(entry);
   boolean val = trie.remove(entry.asStringId()) != null;
   logger.trace("attempted remove={} status={}", entry, val);
   Event evt = val ? Event.REMOVAL : Event.FAILURE;
   saveEntries();
   EventBus.publish(evt);
   return val;
 }
Пример #19
0
  public boolean removeEntries(final Collection<? extends AddeEntry> removedEntries) {
    notNull(removedEntries);

    boolean val = true;
    boolean tmpVal = true;
    for (AddeEntry entry : removedEntries) {
      if (entry.getEntrySource() != EntrySource.SYSTEM) {
        tmpVal = trie.remove(entry.asStringId()) != null;
        logger.trace("attempted bulk remove={} status={}", entry, tmpVal);
        if (!tmpVal) {
          val = tmpVal;
        }
      }
    }
    Event evt = (val) ? Event.REMOVAL : Event.FAILURE;
    saveEntries();
    EventBus.publish(evt);
    return val;
  }
Пример #20
0
 /**
  * Determine the validity of a given {@link edu.wisc.ssec.mcidasv.servermanager.AddeEntry
  * AddeEntry}.
  *
  * @param entry Entry to check. Cannot be {@code null}.
  * @return {@code true} if {@code entry} is invalid or {@code false} otherwise.
  * @throws AssertionError if {@code entry} is somehow neither a {@code RemoteAddeEntry} or {@code
  *     LocalAddeEntry}.
  * @see edu.wisc.ssec.mcidasv.servermanager.LocalAddeEntry#INVALID_ENTRY
  * @see edu.wisc.ssec.mcidasv.servermanager.RemoteAddeEntry#INVALID_ENTRY
  */
 public static boolean isInvalidEntry(final AddeEntry entry) {
   notNull(entry);
   boolean retVal = true;
   if (entry instanceof RemoteAddeEntry) {
     retVal = RemoteAddeEntry.INVALID_ENTRY.equals(entry);
   } else if (entry instanceof LocalAddeEntry) {
     retVal = LocalAddeEntry.INVALID_ENTRY.equals(entry);
   } else {
     throw new AssertionError("Unknown AddeEntry type: " + entry.getClass().getName());
   }
   return retVal;
 }