edu.wisc.ssec.mcidasv.servermanager
Class EntryStore

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

public class EntryStore
extends Object


Nested Class Summary
static class EntryStore.Event
          Enumeration of the various server manager events.
 
Field Summary
private  String ADDE_BIN
          Path to local server binaries.
private  String ADDE_DATA
          Path to local server data.
private  String ADDE_DIRECTORY
          "Root" local server directory.
private  String ADDE_MCSERVL
          Path to mcservl.
private  String ADDE_RESOLV
          Path to the user's "RESOLV.SRV".
private  IdvObjectStore idvStore
           
private  List<AddeEntry> lastAdded
          The last AddeEntrys added to the manager.
private static String localPort
          Which port is this particular manager operating on
private static org.slf4j.Logger logger
          Logging object.
private  String MCTRACE
           
private static String PREF_ADDE_ENTRIES
           
private static String PROP_DEBUG_ADDEURL
          Property that allows users to control debug output from ADDE requests.
private static String PROP_DEBUG_LOCALROOT
          Property that allows users to supply arbitrary paths to McIDAS-X binaries used by mcservl.
private  boolean restartingMcserv
           
private static AddeThread thread
          Thread that monitors the mcservl process.
private  PatriciaTrie<String,AddeEntry> trie
          The ADDE servers known to McIDAS-V.
private  String USER_DIRECTORY
          Path to the user's "userpath" directory.
 
Constructor Summary
EntryStore(IdvObjectStore store, IdvResourceManager rscManager)
          Constructs a server manager.
 
Method Summary
 void addEntries(Collection<? extends AddeEntry> newEntries)
          Adds a Set of AddeEntrys to trie.
 void addEntry(AddeEntry entry)
          Adds a single AddeEntry to trie.
 boolean checkLocalServer()
          Check to see if the thread is running.
private  Set<AddeEntry> extractPreferencesEntries(IdvObjectStore store)
          Returns the AddeEntrys stored in the user's preferences.
private  Set<AddeEntry> extractResourceEntries(AddeEntry.EntrySource source, XmlResourceCollection xmlResources)
          Process all of the "IDV-style" XML resources for a given "source".
private  Set<AddeEntry> extractUserEntries(XmlResourceCollection xmlResources)
          Process all of the "user" XML resources.
private  Set<LocalAddeEntry> filterLocalEntriesByTemporaryStatus(boolean getTemporaryEntries)
           
 AddeAccount getAccountingFor(AddeServer idvServer, String typeAsStr)
           
 AddeAccount getAccountingFor(String address, String group, AddeEntry.EntryType type)
          Searches the set of servers in an attempt to locate the accounting information for the matching server.
protected  String[] getAddeCommands()
           
static String getAddeRootDirectory()
          Returns the path to where the root directory of the user's McIDAS-X binaries should be.
 Set<String> getAddresses()
          Returns the Set of AddeEntry addresses stored in this EntryStore.
 Set<AddeEntry> getEntrySet()
          Returns the complete Set of AddeEntrys.
 Set<String> getGroups(String address)
          Returns the Set of "groups" associated with the given address.
 Set<String> getGroupsFor(String address, AddeEntry.EntryType type)
          Returns the Set of AddeEntry.getGroup()s that match the given address and type.
 IdvObjectStore getIdvStore()
           
 List<AddeServer> getIdvStyleEntries()
          Returns a list of all available ADDE datasets, converted to IDV AddeServer objects.
 Set<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.
 Set<AddeServer> getIdvStyleEntries(String typeAsStr)
          Returns a list that consists of the available ADDE datasets for a given AddeEntry.EntryType, converted to IDV AddeServer objects.
 Set<AddeServer.Group> getIdvStyleLocalGroups()
           
 Set<AddeServer.Group> getIdvStyleRemoteGroups(String server, AddeEntry.EntryType type)
           
 Set<AddeServer.Group> getIdvStyleRemoteGroups(String server, String typeAsStr)
           
 List<AddeEntry> getLastAdded()
           
 List<AddeEntry> getLastAddedByType(AddeEntry.EntryType type)
          Searches the newest entries for the entries of the given EntryType.
 List<AddeEntry> getLastAddedByTypes(EnumSet<AddeEntry.EntryType> types)
           
 Set<LocalAddeEntry> getLocalEntries()
          Returns the complete Set of LocalAddeEntrys.
static String getLocalPort()
          Ask for the port we are listening on.
 Set<AddeEntry> getPersistedEntrySet()
           
 Set<LocalAddeEntry> getPersistedLocalEntries()
          Returns the Set of LocalAddeEntries that will be saved between McIDAS-V sessions.
 Set<RemoteAddeEntry> getRemoteEntries()
          Returns the complete Set of RemoteAddeEntrys.
 Set<String> getRemoteEntryTexts()
          Returns a Set containing ADDRESS/GROUPNAME Strings for each RemoteAddeEntry.
 Set<LocalAddeEntry> getTemporaryLocalEntries()
           
 Set<AddeEntry.EntryType> getTypes(String address, String group)
          Returns the Set of AddeEntry.EntryTypes for a given group on a given address.
protected  String[] getUnixAddeEnv()
           
 Set<AddeEntry> getVerifiedEntries(AddeEntry.EntryType type)
          Returns the Set of AddeEntrys that are known to work (for a given AddeEntry.EntryType of entries).
 Map<AddeEntry.EntryType,Set<AddeEntry>> getVerifiedEntriesByTypes()
           
protected  String[] getWindowsAddeEnv()
           
static boolean isAddeDebugEnabled(boolean defaultValue)
          Checks the value of the debug.adde.reqs system property to determine whether or not the user has requested ADDE URL debugging output.
static boolean isInvalidEntry(AddeEntry entry)
          Determine the validity of a given AddeEntry.
protected static String nextLocalPort()
          Get the next port by incrementing current port.
 void onEvent(EntryStore.Event evt)
          Responds to server manager events being passed with the event bus.
private static void putEntries(PatriciaTrie<String,AddeEntry> trie, Collection<? extends AddeEntry> newEntries)
          Adds AddeEntry objects to a given PatriciaTrie.
private static Set<AddeEntry> removeDeletedSystemEntries(Collection<? extends AddeEntry> entries, Collection<? extends AddeEntry> systemEntries)
          Searches entries for AddeEntry objects with two characteristics: the object source is EntrySource#System the object is not in systemEntries The intent behind this method is to safely remove "system" entries that have been stored to a user's preferences.
 boolean removeEntries(Collection<? extends AddeEntry> removedEntries)
           
 boolean removeEntry(AddeEntry entry)
          Removes a single AddeEntry from the set of available entries.
 void replaceEntries(Collection<? extends AddeEntry> oldEntries, Collection<? extends AddeEntry> newEntries)
          Replaces the AddeEntrys within trie with the contents of newEntries.
 void saveEntries()
          Saves the current set of ADDE servers to the user's preferences.
 void saveForShutdown()
           
 List<AddeEntry> searchWithPrefix(String prefix)
          Search the server manager for entries that match prefix.
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.
static void setLocalPort(String port)
          Change the port we are listening on.
 void startLocalServer()
          Starts the local server thread (if it isn't already running).
 void stopLocalServer()
          Stops the local server thread if it is running.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_DEBUG_LOCALROOT

private static final String PROP_DEBUG_LOCALROOT
Property that allows users to supply arbitrary paths to McIDAS-X binaries used by mcservl.

See Also:
getAddeRootDirectory(), Constant Field Values

PROP_DEBUG_ADDEURL

private static final String PROP_DEBUG_ADDEURL
Property that allows users to control debug output from ADDE requests.

See Also:
isAddeDebugEnabled(boolean), setAddeDebugEnabled(boolean), Constant Field Values

logger

private static final org.slf4j.Logger logger
Logging object.


PREF_ADDE_ENTRIES

private static final String PREF_ADDE_ENTRIES
See Also:
Constant Field Values

trie

private final PatriciaTrie<String,AddeEntry> trie
The ADDE servers known to McIDAS-V.


ADDE_DIRECTORY

private final String ADDE_DIRECTORY
"Root" local server directory.


ADDE_BIN

private final String ADDE_BIN
Path to local server binaries.


ADDE_DATA

private final String ADDE_DATA
Path to local server data.


ADDE_MCSERVL

private final String ADDE_MCSERVL
Path to mcservl.


USER_DIRECTORY

private final String USER_DIRECTORY
Path to the user's "userpath" directory.


ADDE_RESOLV

private final String ADDE_RESOLV
Path to the user's "RESOLV.SRV".


MCTRACE

private final String MCTRACE

localPort

private static String localPort
Which port is this particular manager operating on


thread

private static AddeThread thread
Thread that monitors the mcservl process.


lastAdded

private final List<AddeEntry> lastAdded
The last AddeEntrys added to the manager.


idvStore

private final IdvObjectStore idvStore

restartingMcserv

private boolean restartingMcserv
Constructor Detail

EntryStore

public EntryStore(IdvObjectStore store,
                  IdvResourceManager rscManager)
Constructs a server manager.

Parameters:
store -
rscManager -
Method Detail

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(PatriciaTrie<String,AddeEntry> trie,
                               Collection<? extends AddeEntry> newEntries)
Adds AddeEntry objects to a given PatriciaTrie.

Parameters:
trie - Cannot be null.
newEntries - Cannot be null.

getIdvStore

public IdvObjectStore getIdvStore()

getWindowsAddeEnv

protected String[] getWindowsAddeEnv()

getUnixAddeEnv

protected String[] getUnixAddeEnv()

getAddeCommands

protected String[] getAddeCommands()

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:
AssertionError - if entry is somehow neither a RemoteAddeEntry or LocalAddeEntry.
See Also:
LocalAddeEntry.INVALID_ENTRY, RemoteAddeEntry.INVALID_ENTRY

extractPreferencesEntries

private Set<AddeEntry> extractPreferencesEntries(IdvObjectStore store)
Returns the AddeEntrys 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.

saveEntries

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


saveForShutdown

public void saveForShutdown()

getLastAddedByType

public List<AddeEntry> getLastAddedByType(AddeEntry.EntryType type)
Searches the newest entries for the entries of the given 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

public List<AddeEntry> getLastAddedByTypes(EnumSet<AddeEntry.EntryType> types)

getLastAdded

public List<AddeEntry> getLastAdded()

getVerifiedEntries

public Set<AddeEntry> getVerifiedEntries(AddeEntry.EntryType type)
Returns the Set of AddeEntrys that are known to work (for a given AddeEntry.EntryType of entries).

Parameters:
type - The EntryType you are interested in.
Returns:
A Set of matching RemoteAddeEntrys. If there were no matches, an empty Set is returned.

getVerifiedEntriesByTypes

public Map<AddeEntry.EntryType,Set<AddeEntry>> getVerifiedEntriesByTypes()

getGroupsFor

public Set<String> getGroupsFor(String address,
                                AddeEntry.EntryType type)
Returns the Set of AddeEntry.getGroup()s 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.

searchWithPrefix

public List<AddeEntry> searchWithPrefix(String prefix)
Search the server manager for entries that match prefix.

Parameters:
prefix - String to match.
Returns:
List containing matching entries. If there were no matches the List will be empty.
See Also:
AddeEntry.asStringId()

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

public Set<String> getRemoteEntryTexts()
Returns a Set containing ADDRESS/GROUPNAME Strings for each RemoteAddeEntry.

Returns:
The "entry text" representations of each RemoteAddeEntry.
See Also:
RemoteAddeEntry.getEntryText()

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 AddeEntry.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

public AddeAccount getAccountingFor(String address,
                                    String group,
                                    AddeEntry.EntryType type)
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:
RemoteAddeEntry.equals(Object)

getAccountingFor

public AddeAccount getAccountingFor(AddeServer idvServer,
                                    String typeAsStr)

getEntrySet

public Set<AddeEntry> getEntrySet()
Returns the complete Set of AddeEntrys.


getPersistedEntrySet

public Set<AddeEntry> getPersistedEntrySet()

getRemoteEntries

public Set<RemoteAddeEntry> getRemoteEntries()
Returns the complete Set of RemoteAddeEntrys.

Returns:
The RemoteAddeEntrys stored within the available entries.

getLocalEntries

public Set<LocalAddeEntry> getLocalEntries()
Returns the complete Set of LocalAddeEntrys.

Returns:
The LocalAddeEntrys stored within the available entries.

getPersistedLocalEntries

public Set<LocalAddeEntry> getPersistedLocalEntries()
Returns the Set of LocalAddeEntries that will be saved between McIDAS-V sessions.

Note: all this does is check LocalAddeEntry.isTemporary field.

Returns:
LocalAddeEntrys that will be saved for the next session.

getTemporaryLocalEntries

public Set<LocalAddeEntry> getTemporaryLocalEntries()

filterLocalEntriesByTemporaryStatus

private Set<LocalAddeEntry> filterLocalEntriesByTemporaryStatus(boolean getTemporaryEntries)

removeEntries

public boolean removeEntries(Collection<? extends AddeEntry> removedEntries)

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.

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 AddeEntrys 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 AddeEntrys 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<AddeServer.Group> getIdvStyleLocalGroups()

getIdvStyleRemoteGroups

public Set<AddeServer.Group> getIdvStyleRemoteGroups(String server,
                                                     String typeAsStr)

getIdvStyleRemoteGroups

public Set<AddeServer.Group> getIdvStyleRemoteGroups(String server,
                                                     AddeEntry.EntryType type)

getIdvStyleEntries

public List<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<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<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:
EntryTransforms.strToEntryType(String)

extractResourceEntries

private Set<AddeEntry> extractResourceEntries(AddeEntry.EntrySource source,
                                              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(XmlResourceCollection xmlResources)
Process all of the "user" XML resources.

Parameters:
xmlResources - Resource collection. Cannot be null.
Returns:
Set of RemoteAddeEntrys 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:
PROP_DEBUG_LOCALROOT

isAddeDebugEnabled

public static boolean isAddeDebugEnabled(boolean defaultValue)
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:
defaultValue - 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:
AddeURL, PROP_DEBUG_ADDEURL

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:
AddeURL, PROP_DEBUG_ADDEURL

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.


checkLocalServer

public boolean checkLocalServer()
Check to see if the thread is running.

Returns:
true if the local server thread is running; false otherwise.