Class EntryStore

java.lang.Object
edu.wisc.ssec.mcidasv.servermanager.EntryStore

public class EntryStore extends Object
McIDAS-V ADDE server manager. This class is essentially the "gatekeeper" for anything having to do with the application's collection of ADDE servers. This class is also responsible for controlling the thread used to manage the external mcservl binary.
See Also:
  • Field Details

  • Constructor Details

    • EntryStore

      public EntryStore(ucar.unidata.idv.IdvObjectStore store, ucar.unidata.idv.IdvResourceManager rscManager)
      Constructs a server manager.
      Parameters:
      store - McIDAS-V's preferences store. Cannot be null.
      rscManager - McIDAS-V's resource manager. Cannot be null.
      Throws:
      NullPointerException - if either of store or rscManager is null.
  • Method Details

    • removeDeletedSystemEntries

      private static Set<AddeEntry> removeDeletedSystemEntries(Collection<? extends AddeEntry> entries, Collection<? extends AddeEntry> systemEntries)
      Searches entries for AddeEntry objects with two characteristics:

      The intent behind this method is to safely remove "system" entries that have been stored to a user's preferences. entries can be generated from anywhere you like, but systemEntries should almost always be created from "addeservers.xml".

      Parameters:
      entries - Cannot be null.
      systemEntries - Cannot be null.
      Returns:
      Set of entries that are not system resources that have been removed, or an empty Set.
    • putEntries

      private static void putEntries(org.apache.commons.collections4.trie.PatriciaTrie<AddeEntry> trie, Collection<? extends AddeEntry> newEntries)
      Adds AddeEntry objects to a given PatriciaTrie.
      Parameters:
      trie - Cannot be null.
      newEntries - Cannot be null.
    • getIdvStore

      public ucar.unidata.idv.IdvObjectStore getIdvStore()
      Returns the IdvObjectStore used to save user preferences.
      Returns:
      IdvObjectStore used by the rest of McIDAS-V.
    • getWindowsAddeEnv

      protected String[] getWindowsAddeEnv()
      Returns environment variables that allow mcservl to run on Windows.
      Returns:
      String array containing mcservl's environment variables.
    • getUnixAddeEnv

      protected String[] getUnixAddeEnv()
      Returns environment variables that allow mcservl to run on "unix-like" systems.
      Returns:
      String array containing mcservl's environment variables.
    • getAddeCommands

      protected String[] getAddeCommands()
      Returns command line used to launch mcservl.
      Returns:
      String array that represents an invocation of mcservl.
    • isInvalidEntry

      public static boolean isInvalidEntry(AddeEntry entry)
      Determine the validity of a given AddeEntry.
      Parameters:
      entry - Entry to check. Cannot be null.
      Returns:
      true if entry is invalid or false otherwise.
      Throws:
      NullPointerException - if entry is null.
      AssertionError - if entry is somehow neither a RemoteAddeEntry or LocalAddeEntry.
      See Also:
    • extractPreferencesEntries

      private Set<AddeEntry> extractPreferencesEntries(ucar.unidata.idv.IdvObjectStore store)
      Returns the AddeEntries stored in the user's preferences.
      Parameters:
      store - Object store that represents the user's preferences. Cannot be null.
      Returns:
      Either the AddeEntrys stored in the prefs or an empty Set.
    • onEvent

      public void onEvent(EntryStore.Event evt)
      Responds to server manager events being passed with the event bus.
      Parameters:
      evt - Event to which this method is responding. Cannot be null.
      Throws:
      NullPointerException - if evt is null.
    • saveEntries

      public void saveEntries()
      Saves the current set of ADDE servers to the user's preferences and ADDE_RESOLV.
    • saveForShutdown

      public void saveForShutdown()
      Saves the list of ADDE entries to both the user's preferences and ADDE_RESOLV.
    • getLastAddedByType

      Searches the newest entries for the entries of the given AddeEntry.EntryType.
      Parameters:
      type - Look for entries matching this EntryType. Cannot be null.
      Returns:
      Either a List of entries or an empty List.
      Throws:
      NullPointerException - if type is null.
    • getLastAddedByTypes

      Returns the AddeEntries that were added last, filtered by the given EntryTypes.
      Parameters:
      types - Filter the last added entries by these entry type. Cannot be null.
      Returns:
      List of the last added entries, filtered by types.
      Throws:
      NullPointerException - if types is null.
    • getLastAdded

      Returns the AddeEntries that were added last. Note that this value is not preserved between sessions.
      Returns:
      List of the last ADDE entries that were added. May be empty.
    • getVerifiedEntries

      Returns the Set of AddeEntries that are known to work (for a given AddeEntry.EntryType of entries).
      Parameters:
      type - The EntryType you are interested in. Cannot be null.
      Returns:
      A Set of matching remote ADDE entries. If there were no matches, an empty Set is returned.
      Throws:
      NullPointerException - if type is null.
    • getVerifiedEntriesByTypes

      Returns the available AddeEntries, grouped by AddeEntry.EntryType.
      Returns:
      Map of EntryType to a Set containing all of the entries that match that EntryType.
    • getGroupsFor

      public Set<String> getGroupsFor(String address, AddeEntry.EntryType type)
      Returns the Set of groups that match the given address and type.
      Parameters:
      address - ADDE server address whose groups are needed. Cannot be null.
      type - Only include groups that match AddeEntry.EntryType. Cannot be null.
      Returns:
      Either a set containing the desired groups, or an empty set if there were no matches.
      Throws:
      NullPointerException - if either address or type is null.
    • searchWithPrefix

      Search the server manager for entries that match prefix.
      Parameters:
      prefix - String to match. Cannot be null.
      Returns:
      List containing matching entries. If there were no matches the List will be empty.
      Throws:
      NullPointerException - if prefix is null.
      See Also:
    • getAddresses

      public Set<String> getAddresses()
      Returns the Set of AddeEntry addresses stored in this EntryStore.
      Returns:
      Set containing all of the stored addresses. If no addresses are stored, an empty Set is returned.
    • getRemoteEntryTexts

      Returns a Set containing ADDRESS/GROUPNAME Strings for each RemoteAddeEntry.
      Returns:
      The "entry text" representations of each RemoteAddeEntry.
      See Also:
    • getGroups

      public Set<String> getGroups(String address)
      Returns the Set of "groups" associated with the given address.
      Parameters:
      address - Address of a server.
      Returns:
      Either all of the "groups" on address or an empty Set.
    • getTypes

      public Set<AddeEntry.EntryType> getTypes(String address, String group)
      Returns the Set of EntryTypes for a given group on a given address.
      Parameters:
      address - Address of a server.
      group - Group whose "types" you want.
      Returns:
      Either of all the types for a given address and group or an empty Set if there were no matches.
    • getAccountingFor

      Searches the set of servers in an attempt to locate the accounting information for the matching server. Note that because the data structure is a Set, there cannot be duplicate entries, so there is no need to worry about our criteria finding multiple matches.

      Also note that none of the given parameters accept null values.

      Parameters:
      address - Address of the server.
      group - Dataset.
      type - Group type.
      Returns:
      Either the AddeAccount for the given criteria, or AddeEntry.DEFAULT_ACCOUNT if there was no match.
      See Also:
    • getAccountingFor

      public AddeAccount getAccountingFor(ucar.unidata.idv.chooser.adde.AddeServer idvServer, String typeAsStr)
      Returns the accounting for the given idvServer and typeAsStr.
      Parameters:
      idvServer - Server to search for.
      typeAsStr - One of "IMAGE", "POINT", "GRID", "TEXT", "NAV", "RADAR", "UNKNOWN", or "INVALID".
      Returns:
      AddeAccount associated with idvServer and typeAsStr.
    • getEntrySet

      Returns the complete Set of AddeEntries.
      Returns:
      All of the managed ADDE entries.
    • getPersistedEntrySet

      Returns all non-temporary AddeEntries.
      Returns:
      Set of ADDE entries that stick around between McIDAS-V sessions.
    • getRemoteEntries

      Returns the complete Set of RemoteAddeEntries.
      Returns:
      Set of remote ADDE entries stored within the available entries.
    • getLocalEntries

      Returns the complete Set of LocalAddeEntries.
      Returns:
      Set of local ADDE entries stored within the available entries.
    • getPersistedLocalEntries

      Returns the Set of LocalAddeEntries that will be saved between McIDAS-V sessions.

      Note: all this does is check LocalAddeEntry.isEntryTemporary().

      Returns:
      Local ADDE entries that will be saved for the next session.
    • getTemporaryLocalEntries

      Returns any LocalAddeEntries that will be removed at the end of the current McIDAS-V session.
      Returns:
      Set of all the temporary local ADDE entries.
    • filterLocalEntriesByTemporaryStatus

      private Set<LocalAddeEntry> filterLocalEntriesByTemporaryStatus(boolean getTemporaryEntries)
      Filters the local entries by whether or not they are set as "temporary".
      Parameters:
      getTemporaryEntries - true returns temporary local entries; false returns local entries that are permanent.
      Returns:
      Set of filtered local ADDE entries.
    • removeEntries

      public boolean removeEntries(Collection<? extends AddeEntry> removedEntries)
      Removes the given AddeEntries.
      Parameters:
      removedEntries - AddeEntry objects to remove. Cannot be null.
      Returns:
      Whether or not removeEntries were removed.
      Throws:
      NullPointerException - if removedEntries is null.
    • removeEntry

      public boolean removeEntry(AddeEntry entry)
      Removes a single AddeEntry from the set of available entries.
      Parameters:
      entry - Entry to remove. Cannot be null.
      Returns:
      true if something was removed, false otherwise.
      Throws:
      NullPointerException - if entry is null.
    • addEntry

      public void addEntry(AddeEntry entry)
      Adds a single AddeEntry to trie.
      Parameters:
      entry - Entry to add. Cannot be null.
      Throws:
      NullPointerException - if entry is null.
    • addEntries

      public void addEntries(Collection<? extends AddeEntry> newEntries)
      Adds a Set of AddeEntries to trie.
      Parameters:
      newEntries - New entries to add to the server manager. Cannot be null.
      Throws:
      NullPointerException - if newEntries is null.
    • replaceEntries

      public void replaceEntries(Collection<? extends AddeEntry> oldEntries, Collection<? extends AddeEntry> newEntries)
      Replaces the AddeEntries within trie with the contents of newEntries.
      Parameters:
      oldEntries - Entries to be replaced. Cannot be null.
      newEntries - Entries to use as replacements. Cannot be null.
      Throws:
      NullPointerException - if either of oldEntries or newEntries is null.
    • getIdvStyleLocalGroups

      public Set<ucar.unidata.idv.chooser.adde.AddeServer.Group> getIdvStyleLocalGroups()
      Returns all enabled, valid LocalAddeEntries as a collection of "IDV style" AddeServer.Group objects.
      Returns:
      Set of AddeServer.Group objects that corresponds with the enabled, valid local ADDE entries.
    • getIdvStyleRemoteGroups

      public Set<ucar.unidata.idv.chooser.adde.AddeServer.Group> getIdvStyleRemoteGroups(String server, String typeAsStr)
      Returns the entries matching the given server and typeAsStr parameters as a collection of AddeServer.Group objects.
      Parameters:
      server - Remote ADDE server. Should not be null.
      typeAsStr - Entry type. One of "IMAGE", "POINT", "GRID", "TEXT", "NAV", "RADAR", "UNKNOWN", or "INVALID". Should not be null.
      Returns:
      Set of AddeServer.Group objects that corresponds to the entries associated with server and typeAsStr.
    • getIdvStyleRemoteGroups

      public Set<ucar.unidata.idv.chooser.adde.AddeServer.Group> getIdvStyleRemoteGroups(String server, AddeEntry.EntryType type)
      Returns the entries matching the given server and type parameters as a collection of AddeServer.Group objects.
      Parameters:
      server - Remote ADDE server. Should not be null.
      type - Entry type. Should not be null.
      Returns:
      Set of AddeServer.Group objects that corresponds to the entries associated with server and type.
    • getIdvStyleEntries

      public List<ucar.unidata.idv.chooser.adde.AddeServer> getIdvStyleEntries()
      Returns a list of all available ADDE datasets, converted to IDV AddeServer objects.
      Returns:
      List of AddeServer objects for each ADDE entry.
    • getIdvStyleEntries

      public Set<ucar.unidata.idv.chooser.adde.AddeServer> getIdvStyleEntries(AddeEntry.EntryType type)
      Returns a list that consists of the available ADDE datasets for a given AddeEntry.EntryType, converted to IDV AddeServer objects.
      Parameters:
      type - Only add entries with this type to the returned list. Cannot be null.
      Returns:
      AddeServer objects for each ADDE entry of the given type.
    • getIdvStyleEntries

      public Set<ucar.unidata.idv.chooser.adde.AddeServer> getIdvStyleEntries(String typeAsStr)
      Returns a list that consists of the available ADDE datasets for a given AddeEntry.EntryType, converted to IDV AddeServer objects.
      Parameters:
      typeAsStr - Only add entries with this type to the returned list. Cannot be null and must be a value that works with EntryTransforms.strToEntryType(String).
      Returns:
      AddeServer objects for each ADDE entry of the given type.
      See Also:
    • extractResourceEntries

      private Set<AddeEntry> extractResourceEntries(AddeEntry.EntrySource source, ucar.unidata.xml.XmlResourceCollection xmlResources)
      Process all of the "IDV-style" XML resources for a given "source".
      Parameters:
      source - Origin of the XML resources.
      xmlResources - Actual XML resources.
      Returns:
      Set of the AddeEntrys extracted from xmlResources.
    • extractUserEntries

      private Set<AddeEntry> extractUserEntries(ucar.unidata.xml.XmlResourceCollection xmlResources)
      Process all of the "user" XML resources.
      Parameters:
      xmlResources - Resource collection. Cannot be null.
      Returns:
      Set of RemoteAddeEntries contained within resource.
    • getAddeRootDirectory

      public static String getAddeRootDirectory()
      Returns the path to where the root directory of the user's McIDAS-X binaries should be. The path may be invalid.

      The default path is determined like so:

       System.getProperty("user.dir") + File.separatorChar + "adde"
       

      Users can provide an arbitrary path at runtime by setting the debug.localadde.rootdir system property.

      Returns:
      String containing the path to the McIDAS-X root directory.
      See Also:
    • isAddeDebugEnabled

      public static boolean isAddeDebugEnabled(boolean defValue)
      Checks the value of the debug.adde.reqs system property to determine whether or not the user has requested ADDE URL debugging output. Output is sent to System.out.

      Please keep in mind that the debug.adde.reqs can not force debugging for all ADDE requests. To do so will require updates to the VisAD ADDE library.

      Parameters:
      defValue - Value to return if debug.adde.reqs has not been set.
      Returns:
      If it exists, the value of debug.adde.reqs. Otherwise debug.adde.reqs.
      See Also:
    • setAddeDebugEnabled

      public static boolean setAddeDebugEnabled(boolean value)
      Sets the value of the debug.adde.reqs system property so that debugging output can be controlled without restarting McIDAS-V.

      Please keep in mind that the debug.adde.reqs can not force debugging for all ADDE requests. To do so will require updates to the VisAD ADDE library.

      Parameters:
      value - New value of debug.adde.reqs.
      Returns:
      Previous value of debug.adde.reqs.
      See Also:
    • setLocalPort

      public static void setLocalPort(String port)
      Change the port we are listening on.
      Parameters:
      port - New port number.
    • getLocalPort

      public static String getLocalPort()
      Ask for the port we are listening on.
      Returns:
      String representation of the listening port.
    • nextLocalPort

      protected static String nextLocalPort()
      Get the next port by incrementing current port.
      Returns:
      The next port that will be tried.
    • startLocalServer

      public void startLocalServer()
      Starts the local server thread (if it isn't already running).
    • stopLocalServer

      public void stopLocalServer()
      Stops the local server thread if it is running.
    • testLocalServer

      public boolean testLocalServer()
      Test to see if the thread can access userpath
      Returns:
      true if the local server can access userpath, false otherwise.
    • checkLocalServer

      public boolean checkLocalServer()
      Check to see if the thread is running.
      Returns:
      true if the local server thread is running; false otherwise.