Omaha #3361 reduce number of extraneous localization requests at GFE

startup

Change-Id: Ib33eadd0ef11ad0ef778538061c53ee88e4228ed

Former-commit-id: efa10ca2702ecee4535711be06373e5d079ac117
This commit is contained in:
Nate Jensen 2014-07-08 17:27:20 -05:00
parent 6a197f845d
commit 5547ea1c7d
7 changed files with 79 additions and 557 deletions

View file

@ -1,25 +0,0 @@
package com.raytheon.viz.gfe.actions.parametervalues;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.commands.IParameterValues;
import com.raytheon.viz.gfe.procedures.ProcedureCatalog;
public class ProcedureValues implements IParameterValues {
@SuppressWarnings("rawtypes")
@Override
public Map getParameterValues() {
Map<String, String> values = new HashMap<String, String>();
ProcedureCatalog catalog = new ProcedureCatalog();
for (String name : catalog.getNames()) {
values.put(name, name);
}
return values;
}
}

View file

@ -24,20 +24,22 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import jep.JepException;
import com.raytheon.uf.common.dataplugin.gfe.python.GfePyIncludeUtil;
import com.raytheon.uf.common.localization.LocalizationFile;
import com.raytheon.uf.common.localization.PathManagerFactory;
import com.raytheon.uf.common.python.PyUtil;
import com.raytheon.uf.common.python.PythonScript;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.viz.gfe.core.script.AbstractScriptCatalog;
import com.raytheon.uf.common.util.FileUtil;
/**
* TODO Add Description
* Catalog of gfe config files
*
* <pre>
*
@ -45,6 +47,7 @@ import com.raytheon.viz.gfe.core.script.AbstractScriptCatalog;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 21, 2010 randerso Initial creation
* Jul 08, 2014 3361 njensen Consolidated code
*
* </pre>
*
@ -52,11 +55,12 @@ import com.raytheon.viz.gfe.core.script.AbstractScriptCatalog;
* @version 1.0
*/
public class ConfigCatalog extends AbstractScriptCatalog {
public class ConfigCatalog {
private static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(ConfigCatalog.class);
private static final String[] EXTENSIONS = new String[] { ".py" };
private static final String EXTENSION = ".py";
protected List<String> preEvals;
@ -68,41 +72,6 @@ public class ConfigCatalog extends AbstractScriptCatalog {
}
/*
* (non-Javadoc)
*
* @see com.raytheon.viz.gfe.core.script.AbstractScriptCatalog#
* getScriptTypePathPrefix()
*/
@Override
public String getScriptTypePathPrefix() {
return GfePyIncludeUtil.CONFIG;
}
/*
* (non-Javadoc)
*
* @see com.raytheon.viz.gfe.core.script.AbstractScriptCatalog#getExtensions
* ()
*/
@Override
public String[] getExtensions() {
return EXTENSIONS;
}
/*
* (non-Javadoc)
*
* @see com.raytheon.viz.gfe.core.script.AbstractScriptCatalog#getNames()
*/
@Override
public Collection<String> getNames() {
Collection<String> result = new HashSet<String>();
LocalizationFile[] procFiles = getFiles();
result = scriptNames(procFiles);
return result;
}
/**
* Return true if HideConfigFile is set to true when the script is loaded.
*
@ -145,4 +114,67 @@ public class ConfigCatalog extends AbstractScriptCatalog {
}
return rtnVal;
}
/**
* Get all the localization files for this catalog.
*
* @return the localization files for the procedures.
*/
public LocalizationFile[] getFiles() {
LocalizationFile[] procFiles = PathManagerFactory.getPathManager()
.listStaticFiles(GfePyIncludeUtil.CONFIG,
new String[] { EXTENSION },
false, true);
return procFiles;
}
/**
* Get the simple names of the procedures.
*
* @return the simple names of the procedures.
*/
public Collection<String> getNames() {
Collection<String> result = new HashSet<String>();
LocalizationFile[] procFiles = getFiles();
result = scriptNames(procFiles);
return result;
}
/**
* @param scriptName
* The simple name of a procedure, i.e., "Align_Grids".
* @return The localization file for the script
*/
public LocalizationFile getFile(String scriptName) {
String fname = GfePyIncludeUtil.CONFIG + File.separator + scriptName
+ EXTENSION;
LocalizationFile file = PathManagerFactory.getPathManager()
.getStaticLocalizationFile(fname);
return file;
}
/**
* Get the script names from an array of LocalizationFiles, with any leading
* directories and trailing ".py"s removed.
*
* @param scriptFiles
* the array of LocalizationFiles.
* @return a Collection of simple script names with no duplicates.
*/
protected Collection<String> scriptNames(LocalizationFile[] scriptFiles) {
Set<String> procs = new HashSet<String>();
String fname = null;
String[] fsplit = null;
String script = null;
if (scriptFiles != null) {
for (LocalizationFile file : scriptFiles) {
fname = file.getName();
fsplit = fname.split(FileUtil.fileSeparatorRegex);
script = fsplit[fsplit.length - 1].replaceAll("\\.py$", "");
procs.add(script);
}
}
return procs;
}
}

View file

@ -40,6 +40,7 @@ import com.raytheon.viz.gfe.core.DataManager;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Dec 20, 2011 dgilling Initial creation
* Jul 08, 2014 3361 njensen Only build include path once
*
* </pre>
*
@ -49,6 +50,8 @@ import com.raytheon.viz.gfe.core.DataManager;
public class VCModuleControllerFactory {
private static String includePath;
/**
* A private constructor so that Java does not attempt to create one for us.
* As this class should not be instantiated, do not attempt to ever call
@ -69,10 +72,14 @@ public class VCModuleControllerFactory {
public static VCModuleController buildInstance(DataManager dataMgr)
throws JepException {
String includePath = PyUtil.buildJepIncludePath(
synchronized (VCModuleController.class) {
if (includePath == null) {
includePath = PyUtil.buildJepIncludePath(
GfePyIncludeUtil.getVCModUtilsIncludePath(),
GfePyIncludeUtil.getVCModulesIncludePath(),
GfePyIncludeUtil.getCommonPythonIncludePath());
}
}
return new VCModuleController(getScriptPath(), includePath,
VCModuleControllerFactory.class.getClassLoader(), dataMgr);

View file

@ -1,180 +0,0 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
/**
*
*/
package com.raytheon.viz.gfe.core.script;
import java.io.File;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import com.raytheon.uf.common.localization.ILocalizationFileObserver;
import com.raytheon.uf.common.localization.IPathManager;
import com.raytheon.uf.common.localization.LocalizationContext;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
import com.raytheon.uf.common.localization.LocalizationFile;
import com.raytheon.uf.common.localization.PathManagerFactory;
import com.raytheon.uf.common.util.FileUtil;
/**
* @author wldougher
*
*/
public abstract class AbstractScriptCatalog {
protected IPathManager pathManager;
protected LocalizationFile baseDir;
protected LocalizationFile procDir;
protected LocalizationFile siteDir;
/**
*
*/
public AbstractScriptCatalog() {
IPathManager defaultPathManager = PathManagerFactory.getPathManager();
setPathManager(defaultPathManager);
}
/**
* Set the path manager used by this catalog. This is a public method to
* facilitate unit testing. The userCtx and procDir fields, which depend
* entirely on static constants and the path manager, are set, too.
*
* @param pathManager
*/
protected void setPathManager(IPathManager pathManager) {
if (pathManager == null) {
throw new NullPointerException("Attempt to set a null path manager");
}
this.pathManager = pathManager;
LocalizationContext userCtx = pathManager.getContext(
LocalizationType.CAVE_STATIC, LocalizationLevel.USER);
LocalizationContext siteCtx = pathManager.getContext(
LocalizationType.CAVE_STATIC, LocalizationLevel.SITE);
LocalizationContext baseCtx = pathManager.getContext(
LocalizationType.CAVE_STATIC, LocalizationLevel.BASE);
String pathPrefix = getScriptTypePathPrefix();
procDir = pathManager.getLocalizationFile(userCtx, pathPrefix);
siteDir = pathManager.getLocalizationFile(siteCtx, pathPrefix);
baseDir = pathManager.getLocalizationFile(baseCtx, pathPrefix);
}
/**
* Get all the localization files representing Python procedures.
*
* @return the localization files for the procedures.
*/
public LocalizationFile[] getFiles() {
LocalizationFile[] procFiles = pathManager.listStaticFiles(
getScriptTypePathPrefix(), getExtensions(), false, true);
return procFiles;
}
/**
* Get the simple names of the procedures.
*
* @return the simple names of the procedures.
*/
public Collection<String> getNames() {
Collection<String> result = new HashSet<String>();
LocalizationFile[] procFiles = getFiles();
result = scriptNames(procFiles);
return result;
}
/**
* @param scriptName
* The simple name of a procedure, i.e., "Align_Grids".
* @return The localization file for the script
*/
public LocalizationFile getFile(String scriptName) {
String fname = getScriptTypePathPrefix() + File.separator + scriptName
+ getExtensions()[0];
LocalizationFile file = pathManager.getStaticLocalizationFile(fname);
return file;
}
/**
* Add an observer that will be notified when the directory of the procedure
* catalog changes. This is just a wrapper around the appropriate method of
* procDir. Users are responsible for removing any listeners they create.
*
* @param observer
* the observer to add
*/
public void addObserver(ILocalizationFileObserver observer) {
procDir.addFileUpdatedObserver(observer);
siteDir.addFileUpdatedObserver(observer);
baseDir.addFileUpdatedObserver(observer);
}
/**
* Remove the specified observer.
*
* @param observer
* The observer to remove.
*/
public void removeObserver(ILocalizationFileObserver observer) {
procDir.removeFileUpdatedObserver(observer);
siteDir.removeFileUpdatedObserver(observer);
baseDir.removeFileUpdatedObserver(observer);
}
/**
* Get the script names from an array of LocalizationFiles, with any leading
* directories and trailing ".py"s removed.
*
* @param scriptFiles
* the array of LocalizationFiles.
* @return a Collection of simple script names with no duplicates.
*/
protected Collection<String> scriptNames(LocalizationFile[] scriptFiles) {
Set<String> procs = new HashSet<String>();
String fname = null;
String[] fsplit = null;
String script = null;
if (scriptFiles != null) {
for (LocalizationFile file : scriptFiles) {
fname = file.getName();
fsplit = fname.split(FileUtil.fileSeparatorRegex);
script = fsplit[fsplit.length - 1].replaceAll("\\.py$", "");
procs.add(script);
}
}
return procs;
}
/**
* @return
*/
public abstract String getScriptTypePathPrefix();
/**
* @return
*/
public abstract String[] getExtensions();
}

View file

@ -1,53 +0,0 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
/**
*
*/
package com.raytheon.viz.gfe.procedures;
import com.raytheon.uf.common.dataplugin.gfe.python.GfePyIncludeUtil;
import com.raytheon.viz.gfe.core.script.AbstractScriptCatalog;
/**
* @author wldougher
*
*/
public class ProcedureCatalog extends AbstractScriptCatalog {
private static final String[] EXTENSIONS = new String[] { ".py" };
/*
* (non-Javadoc)
*
* @seecom.raytheon.viz.gfe.core.script.AbstractScriptCatalog#
* getScriptTypePathPrefix()
*/
@Override
public String getScriptTypePathPrefix() {
return GfePyIncludeUtil.PROCEDURES;
}
/**
* @return
*/
public String[] getExtensions() {
return EXTENSIONS;
}
}

View file

@ -1,203 +0,0 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
/**
*
*/
package com.raytheon.viz.gfe.textproduct;
import java.io.File;
import java.util.Arrays;
import com.raytheon.uf.common.dataplugin.gfe.python.GfePyIncludeUtil;
import com.raytheon.uf.common.localization.ILocalizationFileObserver;
import com.raytheon.uf.common.localization.IPathManager;
import com.raytheon.uf.common.localization.LocalizationContext;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
import com.raytheon.uf.common.localization.LocalizationFile;
import com.raytheon.viz.gfe.core.script.AbstractScriptCatalog;
/**
* @author wldougher
*
*/
public class TextProductCatalog extends AbstractScriptCatalog {
private static final String[] EXTENSIONS = { ".py" };
private LocalizationFile siteConfDir;
private LocalizationFile siteModDir;
private LocalizationFile userDir;
/**
* @see com.raytheon.viz.gfe.core.script.AbstractScriptCatalog#getExtensions()
*/
@Override
public String[] getExtensions() {
return EXTENSIONS;
}
/**
* @see com.raytheon.viz.gfe.core.script.AbstractScriptCatalog#getScriptTypePathPrefix()
*/
@Override
public String getScriptTypePathPrefix() {
return GfePyIncludeUtil.TEXT_PRODUCTS;
}
/*
* (non-Javadoc)
*
* @see com.raytheon.viz.gfe.core.script.AbstractScriptCatalog#getFiles()
*/
@Override
public LocalizationFile[] getFiles() {
LocalizationFile[] modProducts = pathManager.listStaticFiles(
getScriptTypePathPrefix() + File.separator + "modified",
getExtensions(), false, true);
LocalizationFile[] confProducts = pathManager.listStaticFiles(
getScriptTypePathPrefix() + File.separator + "configured",
getExtensions(), false, true);
LocalizationFile[] userProducts = pathManager.listFiles(pathManager
.getContext(LocalizationType.CAVE_STATIC,
LocalizationLevel.USER), getScriptTypePathPrefix(),
getExtensions(), false, true);
// combine arrays, setting the modified products first in order
return concatArrays(userProducts, modProducts, confProducts);
}
private LocalizationFile[] concatArrays(LocalizationFile[] first,
LocalizationFile[]... rest) {
int totalLength = first.length;
for (LocalizationFile[] array : rest) {
totalLength += array.length;
}
LocalizationFile[] result = Arrays.copyOf(first, totalLength);
int offset = first.length;
for (LocalizationFile[] array : rest) {
System.arraycopy(array, 0, result, offset, array.length);
offset += array.length;
}
return result;
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.viz.gfe.core.script.AbstractScriptCatalog#addObserver(com
* .raytheon.uf.common.localization.ILocalizationFileObserver)
*/
@Override
public void addObserver(ILocalizationFileObserver observer) {
userDir.addFileUpdatedObserver(observer);
siteConfDir.addFileUpdatedObserver(observer);
siteModDir.addFileUpdatedObserver(observer);
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.viz.gfe.core.script.AbstractScriptCatalog#getFile(java.lang
* .String)
*/
@Override
public LocalizationFile getFile(String scriptName) {
String path;
LocalizationFile result;
path = getScriptTypePathPrefix() + File.separator + scriptName;
result = pathManager.getLocalizationFile(pathManager.getContext(
LocalizationType.CAVE_STATIC, LocalizationLevel.USER), path);
if (result != null && !result.exists()) {
result = null;
}
if (result == null) {
path = GfePyIncludeUtil.TEXT_PRODUCTS + File.separator + scriptName;
result = pathManager
.getLocalizationFile(pathManager.getContext(
LocalizationType.CAVE_STATIC,
LocalizationLevel.SITE), path);
}
if (result != null && !result.exists()) {
result = null;
}
if (result == null) {
path = GfePyIncludeUtil.TEXT_PRODUCTS + File.separator + scriptName;
result = pathManager.getLocalizationFile(
pathManager.getContext(LocalizationType.CAVE_STATIC,
LocalizationLevel.CONFIGURED), path);
}
if (result != null && !result.exists()) {
result = null;
}
return result;
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.viz.gfe.core.script.AbstractScriptCatalog#removeObserver
* (com.raytheon.uf.common.localization.ILocalizationFileObserver)
*/
@Override
public void removeObserver(ILocalizationFileObserver observer) {
userDir.removeFileUpdatedObserver(observer);
siteConfDir.removeFileUpdatedObserver(observer);
siteModDir.removeFileUpdatedObserver(observer);
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.viz.gfe.core.script.AbstractScriptCatalog#setPathManager
* (com.raytheon.uf.common.localization.IPathManager)
*/
@Override
protected void setPathManager(IPathManager pathManager) {
if (pathManager == null) {
throw new NullPointerException("Attempt to set a null path manager");
}
this.pathManager = pathManager;
LocalizationContext userCtx = pathManager.getContext(
LocalizationType.CAVE_STATIC, LocalizationLevel.USER);
LocalizationContext siteCtx = pathManager.getContext(
LocalizationType.CAVE_STATIC, LocalizationLevel.SITE);
String pathPrefix = getScriptTypePathPrefix();
userDir = pathManager.getLocalizationFile(userCtx, pathPrefix);
siteConfDir = pathManager.getLocalizationFile(siteCtx, pathPrefix
+ File.separator + "configured");
siteModDir = pathManager.getLocalizationFile(siteCtx, pathPrefix
+ File.separator + "modified");
}
}

View file

@ -1,56 +0,0 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
/**
*
*/
package com.raytheon.viz.gfe.textproduct;
import java.io.File;
import com.raytheon.uf.common.dataplugin.gfe.python.GfePyIncludeUtil;
import com.raytheon.viz.gfe.core.script.AbstractScriptCatalog;
/**
* @author wldougher
*
*/
public class TextUtilityCatalog extends AbstractScriptCatalog {
private static final String[] EXTENSIONS = { ".py" };
private static final String PATH_PREFIX = GfePyIncludeUtil.TEXT_UTILITIES
+ File.separator + "regular";
/**
* @see com.raytheon.viz.gfe.core.script.AbstractScriptCatalog#getExtensions()
*/
@Override
public String[] getExtensions() {
return EXTENSIONS;
}
/**
* @see com.raytheon.viz.gfe.core.script.AbstractScriptCatalog#getScriptTypePathPrefix()
*/
@Override
public String getScriptTypePathPrefix() {
return PATH_PREFIX;
}
}