Omaha #5244 Replace deprecated LocalizationFile methods.
Change-Id: Iea447bd018d203cf9c6a59fc9ed66e00e2b265a7 Former-commit-id: 580b44fedef93778e24af685d0e7d7e03810b6fa
This commit is contained in:
parent
09697836d9
commit
87ac557aa0
17 changed files with 652 additions and 723 deletions
|
@ -2,7 +2,7 @@ Manifest-Version: 1.0
|
|||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: FFMP common Plug-in
|
||||
Bundle-SymbolicName: com.raytheon.uf.common.dataplugin.ffmp
|
||||
Bundle-Version: 1.14.0.qualifier
|
||||
Bundle-Version: 1.16.0.qualifier
|
||||
Bundle-Vendor: RAYTHEON
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
|
||||
Export-Package: com.raytheon.uf.common.dataplugin.ffmp,
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.awt.Rectangle;
|
|||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
@ -35,17 +36,20 @@ import java.util.Map.Entry;
|
|||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import com.raytheon.uf.common.datastorage.StorageException;
|
||||
import com.raytheon.uf.common.gridcoverage.GridCoverage;
|
||||
import com.raytheon.uf.common.hydro.spatial.HRAPCoordinates;
|
||||
import com.raytheon.uf.common.hydro.spatial.HRAPSubGrid;
|
||||
import com.raytheon.uf.common.localization.ILocalizationFile;
|
||||
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.localization.SaveableOutputStream;
|
||||
import com.raytheon.uf.common.localization.exception.LocalizationException;
|
||||
import com.raytheon.uf.common.monitor.config.FFMPRunConfigurationManager;
|
||||
import com.raytheon.uf.common.monitor.config.FFMPSourceConfigurationManager;
|
||||
|
@ -60,7 +64,6 @@ import com.raytheon.uf.common.serialization.SerializationUtil;
|
|||
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.uf.common.util.FileUtil;
|
||||
import com.vividsolutions.jts.geom.Coordinate;
|
||||
import com.vividsolutions.jts.geom.Envelope;
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
|
@ -94,6 +97,7 @@ import com.vividsolutions.jts.io.WKBReader;
|
|||
* Nov 18, 2014 3831 dhladky StatusHandler logging. Proper list sizing. Geometry chunk sizing.
|
||||
* Aug 08, 2015 4722 dhladky Improved Grid support.
|
||||
* Nov 12, 2015 4834 njensen Changed LocalizationOpFailedException to LocalizationException
|
||||
* Feb 15, 2016 5244 nabowle Replace deprecated LocalizationFile methods.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -398,21 +402,28 @@ public class FFMPTemplates {
|
|||
}
|
||||
|
||||
try {
|
||||
|
||||
LocalizationContext lc = pathManager.getContext(
|
||||
LocalizationType.COMMON_STATIC, LocalizationLevel.SITE);
|
||||
LocalizationFile lfmap = pathManager.getLocalizationFile(lc,
|
||||
ILocalizationFile lfmap = pathManager.getLocalizationFile(lc,
|
||||
getAbsoluteFileName(dataKey, "VIRTUAL", cwa, "map"));
|
||||
LocalizationFile lflist = pathManager.getLocalizationFile(lc,
|
||||
ILocalizationFile lflist = pathManager.getLocalizationFile(lc,
|
||||
getAbsoluteFileName(dataKey, "VIRTUAL", cwa, "list"));
|
||||
|
||||
FileUtil.bytes2File(SerializationUtil.transformToThrift(list),
|
||||
lflist.getFile(), true);
|
||||
lflist.save();
|
||||
try (SaveableOutputStream listSos = lflist.openOutputStream();
|
||||
GZIPOutputStream listGos = new GZIPOutputStream(listSos);
|
||||
SaveableOutputStream mapSos = lfmap.openOutputStream();
|
||||
GZIPOutputStream mapGos = new GZIPOutputStream(mapSos)) {
|
||||
|
||||
FileUtil.bytes2File(SerializationUtil.transformToThrift(map),
|
||||
lfmap.getFile(), true);
|
||||
lfmap.save();
|
||||
listGos.write(SerializationUtil.transformToThrift(list));
|
||||
listGos.finish();
|
||||
listGos.flush();
|
||||
listSos.save();
|
||||
|
||||
mapGos.write(SerializationUtil.transformToThrift(map));
|
||||
mapGos.finish();
|
||||
mapGos.flush();
|
||||
mapSos.save();
|
||||
}
|
||||
|
||||
list = null;
|
||||
|
||||
|
@ -451,44 +462,34 @@ public class FFMPTemplates {
|
|||
}
|
||||
|
||||
try {
|
||||
if (huc.equals(FFMPRecord.ALL)) {
|
||||
LocalizationContext lc = pathManager.getContext(
|
||||
LocalizationType.COMMON_STATIC, LocalizationLevel.SITE);
|
||||
|
||||
LocalizationContext lc = pathManager.getContext(
|
||||
LocalizationType.COMMON_STATIC, LocalizationLevel.SITE);
|
||||
ILocalizationFile lflist = pathManager.getLocalizationFile(lc,
|
||||
getAbsoluteFileName(dataKey, huc, cwa, "list"));
|
||||
ILocalizationFile lfmap = pathManager.getLocalizationFile(lc,
|
||||
getAbsoluteFileName(dataKey, huc, cwa, "map"));
|
||||
|
||||
LocalizationFile lflist = pathManager.getLocalizationFile(lc,
|
||||
getAbsoluteFileName(dataKey, huc, cwa, "list"));
|
||||
LocalizationFile lfmap = pathManager.getLocalizationFile(lc,
|
||||
getAbsoluteFileName(dataKey, huc, cwa, "map"));
|
||||
try (SaveableOutputStream listSos = lflist.openOutputStream();
|
||||
GZIPOutputStream listGos = new GZIPOutputStream(listSos);
|
||||
SaveableOutputStream mapSos = lfmap.openOutputStream();
|
||||
GZIPOutputStream mapGos = new GZIPOutputStream(mapSos)) {
|
||||
|
||||
FileUtil.bytes2File(SerializationUtil.transformToThrift(list),
|
||||
lflist.getFile(), true);
|
||||
FileUtil.bytes2File(SerializationUtil.transformToThrift(map),
|
||||
lfmap.getFile(), true);
|
||||
listGos.write(SerializationUtil.transformToThrift(list));
|
||||
listGos.finish();
|
||||
listGos.flush();
|
||||
|
||||
lflist.save();
|
||||
lfmap.save();
|
||||
|
||||
} else {
|
||||
|
||||
LocalizationContext lc = pathManager.getContext(
|
||||
LocalizationType.COMMON_STATIC, LocalizationLevel.SITE);
|
||||
|
||||
LocalizationFile lfmap = pathManager.getLocalizationFile(lc,
|
||||
getAbsoluteFileName(dataKey, huc, cwa, "map"));
|
||||
LocalizationFile lflist = pathManager.getLocalizationFile(lc,
|
||||
getAbsoluteFileName(dataKey, huc, cwa, "list"));
|
||||
|
||||
FileUtil.bytes2File(
|
||||
SerializationUtil
|
||||
.transformToThrift(toPrimitive((LinkedHashMap<Long, ArrayList<Long>>) map)),
|
||||
lfmap.getFile(), true);
|
||||
FileUtil.bytes2File(SerializationUtil.transformToThrift(list),
|
||||
lflist.getFile(), true);
|
||||
|
||||
lfmap.save();
|
||||
lflist.save();
|
||||
if (huc.equals(FFMPRecord.ALL)) {
|
||||
mapGos.write(SerializationUtil.transformToThrift(map));
|
||||
} else {
|
||||
mapGos.write(SerializationUtil
|
||||
.transformToThrift(toPrimitive((LinkedHashMap<Long, ArrayList<Long>>) map)));
|
||||
}
|
||||
mapGos.finish();
|
||||
mapGos.flush();
|
||||
|
||||
listSos.save();
|
||||
mapSos.save();
|
||||
}
|
||||
|
||||
list = null;
|
||||
|
@ -949,9 +950,9 @@ public class FFMPTemplates {
|
|||
|
||||
LocalizationContext lc = pathManager.getContext(
|
||||
LocalizationType.COMMON_STATIC, LocalizationLevel.SITE);
|
||||
LocalizationFile listf = pathManager.getLocalizationFile(lc,
|
||||
ILocalizationFile listf = pathManager.getLocalizationFile(lc,
|
||||
getAbsoluteFileName(dataKey, huc, cwa, "list"));
|
||||
LocalizationFile mapf = pathManager.getLocalizationFile(lc,
|
||||
ILocalizationFile mapf = pathManager.getLocalizationFile(lc,
|
||||
getAbsoluteFileName(dataKey, huc, cwa, "map"));
|
||||
|
||||
if (listf.exists()) {
|
||||
|
@ -2019,18 +2020,16 @@ public class FFMPTemplates {
|
|||
|
||||
LocalizationContext lc = pathManager.getContext(
|
||||
LocalizationType.COMMON_STATIC, LocalizationLevel.SITE);
|
||||
LocalizationFile f = pathManager.getLocalizationFile(lc,
|
||||
ILocalizationFile f = pathManager.getLocalizationFile(lc,
|
||||
getAbsoluteFileName(dataKey, huc, cwa, "list"));
|
||||
|
||||
try {
|
||||
list = SerializationUtil.transformFromThrift(long[].class,
|
||||
FileUtil.file2bytes(f.getFile(), true));
|
||||
} catch (SerializationException se) {
|
||||
statusHandler.error("Serialization Exception: Read Domain: cwa: "
|
||||
+ cwa + " dataKey: " + dataKey + " huc: " + huc, se);
|
||||
} catch (IOException e) {
|
||||
statusHandler.error("IO Exception: Read Domain: cwa: " + cwa
|
||||
+ " dataKey: " + dataKey + " huc: " + huc, e);
|
||||
try (InputStream is = f.openInputStream();
|
||||
GZIPInputStream gis = new GZIPInputStream(is)) {
|
||||
list = SerializationUtil.transformFromThrift(long[].class, gis);
|
||||
} catch (SerializationException | IOException | LocalizationException e) {
|
||||
statusHandler.error(
|
||||
"Exception reading domain list: Read Domain. cwa: " + cwa
|
||||
+ " dataKey: " + dataKey + " huc: " + huc, e);
|
||||
}
|
||||
|
||||
return list;
|
||||
|
@ -2050,24 +2049,15 @@ public class FFMPTemplates {
|
|||
|
||||
LocalizationContext lc = pathManager.getContext(
|
||||
LocalizationType.COMMON_STATIC, LocalizationLevel.SITE);
|
||||
LocalizationFile f = pathManager.getLocalizationFile(lc,
|
||||
ILocalizationFile f = pathManager.getLocalizationFile(lc,
|
||||
getAbsoluteFileName(dataKey, huc, cwa, "map"));
|
||||
|
||||
try {
|
||||
if (huc.equals(FFMPRecord.ALL)) {
|
||||
|
||||
map = SerializationUtil.transformFromThrift(HashMap.class,
|
||||
FileUtil.file2bytes(f.getFile(), true));
|
||||
} else {
|
||||
map = SerializationUtil.transformFromThrift(HashMap.class,
|
||||
FileUtil.file2bytes(f.getFile(), true));
|
||||
}
|
||||
} catch (SerializationException se) {
|
||||
statusHandler.error("Serialization Exception: Domain Map: "
|
||||
+ dataKey + " cwa:" + cwa + " huc: " + huc, se);
|
||||
} catch (IOException e) {
|
||||
statusHandler.error("IO Exception: Domain Map: " + dataKey
|
||||
+ " cwa:" + cwa + " huc: " + huc, e);
|
||||
try (InputStream is = f.openInputStream();
|
||||
GZIPInputStream gis = new GZIPInputStream(is)) {
|
||||
map = SerializationUtil.transformFromThrift(HashMap.class, gis);
|
||||
} catch (SerializationException | IOException | LocalizationException e) {
|
||||
statusHandler.error("Exception reading domain map. Domain Map: "
|
||||
+ dataKey + " cwa:" + cwa + " huc: " + huc, e);
|
||||
}
|
||||
|
||||
return map;
|
||||
|
@ -2088,25 +2078,23 @@ public class FFMPTemplates {
|
|||
|
||||
LocalizationContext lc = pathManager.getContext(
|
||||
LocalizationType.COMMON_STATIC, LocalizationLevel.SITE);
|
||||
LocalizationFile f = pathManager.getLocalizationFile(lc,
|
||||
ILocalizationFile f = pathManager.getLocalizationFile(lc,
|
||||
getAbsoluteFileName(dataKey, FFMPRecord.VIRTUAL, cwa, "map"));
|
||||
|
||||
try {
|
||||
map = SerializationUtil.transformFromThrift(HashMap.class,
|
||||
FileUtil.file2bytes(f.getFile(), true));
|
||||
} catch (SerializationException se) {
|
||||
statusHandler.error("Serialization Exception: Virtual Basins: "
|
||||
+ dataKey + " cwa: " + cwa, se);
|
||||
} catch (IOException e) {
|
||||
statusHandler.error("IO Exception: Virtual Basins: " + dataKey
|
||||
+ " cwa: " + cwa, e);
|
||||
try (InputStream is = f.openInputStream();
|
||||
GZIPInputStream gis = new GZIPInputStream(is)) {
|
||||
map = SerializationUtil.transformFromThrift(HashMap.class, gis);
|
||||
} catch (SerializationException | IOException | LocalizationException e) {
|
||||
statusHandler.error(
|
||||
"Exception reading VHB Domain map. Virtual Basins: "
|
||||
+ dataKey + " cwa: " + cwa, e);
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the actual VGB domain map
|
||||
* Reads the actual VGB domain list
|
||||
*
|
||||
* @param huc
|
||||
* @param cwa
|
||||
|
@ -2118,19 +2106,16 @@ public class FFMPTemplates {
|
|||
|
||||
LocalizationContext lc = pathManager.getContext(
|
||||
LocalizationType.COMMON_STATIC, LocalizationLevel.SITE);
|
||||
LocalizationFile f = pathManager.getLocalizationFile(lc,
|
||||
ILocalizationFile f = pathManager.getLocalizationFile(lc,
|
||||
getAbsoluteFileName(dataKey, FFMPRecord.VIRTUAL, cwa, "list"));
|
||||
|
||||
try {
|
||||
list = SerializationUtil.transformFromThrift(String[].class,
|
||||
FileUtil.file2bytes(f.getFile(), true));
|
||||
} catch (SerializationException se) {
|
||||
try (InputStream is = f.openInputStream();
|
||||
GZIPInputStream gis = new GZIPInputStream(is)) {
|
||||
list = SerializationUtil.transformFromThrift(String[].class, gis);
|
||||
} catch (SerializationException | IOException | LocalizationException e) {
|
||||
statusHandler.error(
|
||||
"Serialization Exception: : Read Virtual Domain: cwa: "
|
||||
+ cwa + " dataKey: " + dataKey, se);
|
||||
} catch (IOException e) {
|
||||
statusHandler.error("IO Exception: : Read Virtual Domain: cwa: "
|
||||
+ cwa + " dataKey: " + dataKey, e);
|
||||
"Exception reading VGB Domain List. Read Virtual Domain: cwa: "
|
||||
+ cwa + " dataKey: " + dataKey, e);
|
||||
}
|
||||
|
||||
return list;
|
||||
|
@ -2457,37 +2442,36 @@ public class FFMPTemplates {
|
|||
|
||||
LocalizationContext lc = pathManager.getContext(
|
||||
LocalizationType.COMMON_STATIC, LocalizationLevel.SITE);
|
||||
LocalizationFile lfTemplateDir = pathManager.getLocalizationFile(lc,
|
||||
"ffmp/");
|
||||
ILocalizationFile[] lfs = pathManager.listFiles(lc, "ffmp/", null,
|
||||
false, false);
|
||||
|
||||
if (lfTemplateDir != null) {
|
||||
File templateDirFile = lfTemplateDir.getFile();
|
||||
if (templateDirFile != null) {
|
||||
File[] files = templateDirFile.listFiles();
|
||||
if (files.length > 0) {
|
||||
synchronized (files) {
|
||||
for (File file : files) {
|
||||
if (file.isDirectory()
|
||||
&& file.listFiles().length > 0) {
|
||||
for (File iFile : file.listFiles()) {
|
||||
iFile.delete();
|
||||
}
|
||||
statusHandler.handle(
|
||||
Priority.INFO,
|
||||
"Deleted Template directory..."
|
||||
+ file.getName());
|
||||
}
|
||||
if (lfs != null) {
|
||||
for (ILocalizationFile lf : lfs) {
|
||||
if (lf.isDirectory()) {
|
||||
ILocalizationFile[] files = pathManager.listFiles(lc,
|
||||
lf.getPath(), null, false, true);
|
||||
for (ILocalizationFile file : files) {
|
||||
try {
|
||||
file.delete();
|
||||
} catch (LocalizationException e) {
|
||||
statusHandler
|
||||
.handle(Priority.PROBLEM,
|
||||
"Error deleting " + file.getPath(), e);
|
||||
}
|
||||
|
||||
// write out the config XML so templates
|
||||
// don't keep regening
|
||||
ftcm.setRegenerate(false);
|
||||
ftcm.saveConfigXml();
|
||||
template = null;
|
||||
}
|
||||
statusHandler.handle(
|
||||
Priority.INFO,
|
||||
"Deleted Template directory..."
|
||||
+ lf.getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// write out the config XML so templates
|
||||
// don't keep regening
|
||||
ftcm.setRegenerate(false);
|
||||
ftcm.saveConfigXml();
|
||||
template = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,8 +20,6 @@
|
|||
package com.raytheon.uf.common.dataplugin.ffmp;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.util.ArrayList;
|
||||
|
@ -33,6 +31,7 @@ import java.util.Set;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import com.raytheon.uf.common.localization.IPathManager;
|
||||
import com.raytheon.uf.common.localization.LocalizationContext;
|
||||
|
@ -40,12 +39,12 @@ 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.localization.SaveableOutputStream;
|
||||
import com.raytheon.uf.common.localization.exception.LocalizationException;
|
||||
import com.raytheon.uf.common.serialization.SerializationUtil;
|
||||
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.uf.common.util.FileUtil;
|
||||
import com.vividsolutions.jts.geom.Envelope;
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
import com.vividsolutions.jts.geom.GeometryFactory;
|
||||
|
@ -71,6 +70,7 @@ import com.vividsolutions.jts.simplify.TopologyPreservingSimplifier;
|
|||
* Apr 25, 2013 1954 bsteffen Undo last commit to avoid invalid geoms.
|
||||
* Jul 03, 2013 2152 rjpeter Use streams for serialization
|
||||
* Nov 12, 2015 4834 njensen Changed LocalizationOpFailedException to LocalizationException
|
||||
* Feb 15, 2016 5244 nabowle Replace deprecated LocalizationFile methods.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -133,23 +133,19 @@ public class HucLevelGeometriesFactory {
|
|||
getGeomPath(dataKey, cwa, huc));
|
||||
|
||||
if (f.exists()) {
|
||||
InputStream is = null;
|
||||
boolean deleteFile = false;
|
||||
long length = f.getFile().length();
|
||||
|
||||
try {
|
||||
File file = f.getFile();
|
||||
long length = file.length();
|
||||
// read from disk in 8k chunks
|
||||
int bufferSize = 8 * 1024;
|
||||
if (bufferSize > length) {
|
||||
bufferSize = (int) length;
|
||||
}
|
||||
|
||||
// read from disk in 8k chunks
|
||||
int bufferSize = 8 * 1024;
|
||||
if (bufferSize > length) {
|
||||
bufferSize = (int) length;
|
||||
}
|
||||
try (InputStream is = f.openInputStream();
|
||||
GZIPInputStream gis = new GZIPInputStream(is, bufferSize)) {
|
||||
|
||||
is = new GZIPInputStream(new FileInputStream(file),
|
||||
bufferSize);
|
||||
|
||||
map = SerializationUtil.transformFromThrift(Map.class, is);
|
||||
map = SerializationUtil.transformFromThrift(Map.class, gis);
|
||||
int sizeGuess = Math.max(
|
||||
Math.abs(pfafs.size() - map.size()), 10);
|
||||
pfafsToGenerate = new ArrayList<Long>(sizeGuess);
|
||||
|
@ -166,14 +162,6 @@ public class HucLevelGeometriesFactory {
|
|||
deleteFile = true;
|
||||
pfafsToGenerate = pfafs;
|
||||
} finally {
|
||||
if (is != null) {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e1) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
if (deleteFile) {
|
||||
try {
|
||||
f.delete();
|
||||
|
@ -387,9 +375,14 @@ public class HucLevelGeometriesFactory {
|
|||
LocalizationType.COMMON_STATIC, LocalizationLevel.SITE);
|
||||
LocalizationFile lf = pathManager.getLocalizationFile(lc,
|
||||
getGeomPath(dataKey, cwa, huc));
|
||||
FileUtil.bytes2File(SerializationUtil.transformToThrift(map),
|
||||
lf.getFile(), true);
|
||||
lf.save();
|
||||
|
||||
try (SaveableOutputStream mapSos = lf.openOutputStream();
|
||||
GZIPOutputStream mapGos = new GZIPOutputStream(mapSos)) {
|
||||
mapGos.write(SerializationUtil.transformToThrift(map));
|
||||
mapGos.finish();
|
||||
mapGos.flush();
|
||||
mapSos.save();
|
||||
}
|
||||
}
|
||||
|
||||
protected synchronized String getGeomPath(String dataKey, String cwa,
|
||||
|
@ -448,23 +441,18 @@ public class HucLevelGeometriesFactory {
|
|||
getEnvelopePath(dataKey, cwa, huc));
|
||||
|
||||
if (f.exists()) {
|
||||
InputStream is = null;
|
||||
boolean deleteFile = false;
|
||||
long length = f.getFile().length();
|
||||
|
||||
try {
|
||||
File file = f.getFile();
|
||||
long length = file.length();
|
||||
// read from disk in 8k chunks
|
||||
int bufferSize = 8 * 1024;
|
||||
if (bufferSize > length) {
|
||||
bufferSize = (int) length;
|
||||
}
|
||||
try (InputStream is = f.openInputStream();
|
||||
GZIPInputStream gis = new GZIPInputStream(is, bufferSize)) {
|
||||
|
||||
// read from disk in 8k chunks
|
||||
int bufferSize = 8 * 1024;
|
||||
if (bufferSize > length) {
|
||||
bufferSize = (int) length;
|
||||
}
|
||||
|
||||
is = new GZIPInputStream(new FileInputStream(file),
|
||||
bufferSize);
|
||||
|
||||
map = SerializationUtil.transformFromThrift(Map.class, is);
|
||||
map = SerializationUtil.transformFromThrift(Map.class, gis);
|
||||
int sizeGuess = Math.max(
|
||||
Math.abs(pfafs.size() - map.size()), 10);
|
||||
pfafsToGenerate = new ArrayList<Long>(sizeGuess);
|
||||
|
@ -481,14 +469,6 @@ public class HucLevelGeometriesFactory {
|
|||
deleteFile = true;
|
||||
pfafsToGenerate = pfafs;
|
||||
} finally {
|
||||
if (is != null) {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e1) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
if (deleteFile) {
|
||||
try {
|
||||
f.delete();
|
||||
|
@ -534,8 +514,14 @@ public class HucLevelGeometriesFactory {
|
|||
LocalizationType.COMMON_STATIC, LocalizationLevel.SITE);
|
||||
LocalizationFile lf = pathManager.getLocalizationFile(lc,
|
||||
getEnvelopePath(dataKey, cwa, huc));
|
||||
FileUtil.bytes2File(SerializationUtil.transformToThrift(map),
|
||||
lf.getFile(), true);
|
||||
|
||||
try (SaveableOutputStream sos = lf.openOutputStream();
|
||||
GZIPOutputStream gos = new GZIPOutputStream(sos)) {
|
||||
SerializationUtil.transformToThriftUsingStream(map, gos);
|
||||
gos.finish();
|
||||
gos.flush();
|
||||
sos.save();
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void clear() {
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
**/
|
||||
package com.raytheon.uf.common.dataplugin.grid.dataset;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -28,6 +30,7 @@ import com.raytheon.uf.common.localization.IPathManager;
|
|||
import com.raytheon.uf.common.localization.LocalizationContext;
|
||||
import com.raytheon.uf.common.localization.LocalizationFile;
|
||||
import com.raytheon.uf.common.localization.PathManagerFactory;
|
||||
import com.raytheon.uf.common.localization.exception.LocalizationException;
|
||||
import com.raytheon.uf.common.serialization.SerializationException;
|
||||
import com.raytheon.uf.common.serialization.SingleTypeJAXBManager;
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
|
@ -47,6 +50,7 @@ import com.raytheon.uf.common.status.UFStatus;
|
|||
* Feb 27, 2012 bsteffen Initial creation
|
||||
* Dec 16, 2013 2574 bsteffen Update deprecated method call.
|
||||
* Jul 21, 2014 3373 bclement changed to use single type JAXB manager
|
||||
* Feb 15, 2016 5244 nabowle Replace deprecated LocalizationFile methods.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -99,15 +103,15 @@ public class DatasetInfoLookup {
|
|||
if (file == null || !file.exists()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
DatasetInfoSet set = manager.unmarshalFromXmlFile(file
|
||||
.getFile());
|
||||
try (InputStream is = file.openInputStream()) {
|
||||
DatasetInfoSet set = manager.unmarshalFromInputStream(is);
|
||||
for (DatasetInfo info : set.getInfos()) {
|
||||
infoMap.put(info.getDatasetId(), info);
|
||||
}
|
||||
} catch (SerializationException e) {
|
||||
} catch (SerializationException | IOException
|
||||
| LocalizationException e) {
|
||||
statusHandler.error(
|
||||
"Error reading dataset info: " + file.getName()
|
||||
"Error reading dataset info: " + file.getPath()
|
||||
+ " has been ignored.", e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ Manifest-Version: 1.0
|
|||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: Radar
|
||||
Bundle-SymbolicName: com.raytheon.uf.common.dataplugin.radar
|
||||
Bundle-Version: 1.14.1.qualifier
|
||||
Bundle-Version: 1.16.0.qualifier
|
||||
Eclipse-RegisterBuddy: org.geotools
|
||||
Bundle-Vendor: RAYTHEON
|
||||
Require-Bundle: com.raytheon.uf.common.dataplugin;bundle-version="1.12.1174",
|
||||
|
|
|
@ -21,8 +21,8 @@ package com.raytheon.uf.common.dataplugin.radar.util;
|
|||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
@ -36,6 +36,7 @@ import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
|
|||
import com.raytheon.uf.common.localization.LocalizationFile;
|
||||
import com.raytheon.uf.common.localization.PathManager;
|
||||
import com.raytheon.uf.common.localization.PathManagerFactory;
|
||||
import com.raytheon.uf.common.localization.exception.LocalizationException;
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||
|
@ -49,7 +50,9 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
|
|||
* SOFTWARE HISTORY
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Jul 14, 2010 mnash Initial creation
|
||||
* Jul 14, 2010 mnash Initial creation
|
||||
* Feb 15, 2016 5244 nabowle Replace deprecated LocalizationFile methods.
|
||||
*
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -118,25 +121,27 @@ public class RadarsInUseUtil {
|
|||
+ radarSite + ". Using the base file.");
|
||||
}
|
||||
if (file != null) {
|
||||
BufferedReader buf = new BufferedReader(new FileReader(
|
||||
file.getFile()));
|
||||
String temp = buf.readLine();
|
||||
temp = buf.readLine();
|
||||
String radarType = "";
|
||||
List<String> sites = new ArrayList<String>();
|
||||
while (temp != null) {
|
||||
temp = temp.trim();
|
||||
if (temp.startsWith("#")) {
|
||||
sites = new ArrayList<String>();
|
||||
radarType = temp.substring(1, temp.indexOf(" ", 2));
|
||||
siteMap.put(radarType.trim(), sites);
|
||||
} else if (!temp.trim().isEmpty()) {
|
||||
sites.add(temp);
|
||||
}
|
||||
try (BufferedReader buf = new BufferedReader(new InputStreamReader(
|
||||
file.openInputStream()))) {
|
||||
String temp = buf.readLine();
|
||||
temp = buf.readLine();
|
||||
String radarType = "";
|
||||
List<String> sites = new ArrayList<String>();
|
||||
while (temp != null) {
|
||||
temp = temp.trim();
|
||||
if (temp.startsWith("#")) {
|
||||
sites = new ArrayList<String>();
|
||||
radarType = temp.substring(1, temp.indexOf(" ", 2));
|
||||
siteMap.put(radarType.trim(), sites);
|
||||
} else if (!temp.trim().isEmpty()) {
|
||||
sites.add(temp);
|
||||
}
|
||||
temp = buf.readLine();
|
||||
}
|
||||
} catch (LocalizationException e) {
|
||||
throw new IOException("Error while reading " + file.getPath(),
|
||||
e);
|
||||
}
|
||||
buf.close();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,17 +21,18 @@ package com.raytheon.uf.common.dataplugin.radar.util;
|
|||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.raytheon.uf.common.localization.LocalizationContext;
|
||||
import com.raytheon.uf.common.localization.LocalizationFile;
|
||||
import com.raytheon.uf.common.localization.PathManager;
|
||||
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.PathManager;
|
||||
import com.raytheon.uf.common.localization.PathManagerFactory;
|
||||
import com.raytheon.uf.common.localization.exception.LocalizationException;
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||
|
@ -44,6 +45,7 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* 03/07/13 DR15495 zwang Handle SSSS radars
|
||||
* Feb 15, 2016 5244 nabowle Replace deprecated LocalizationFile methods.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -53,15 +55,15 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
|
|||
|
||||
public class SsssRadarUtil {
|
||||
|
||||
private static final transient IUFStatusHandler statusHandler = UFStatus
|
||||
private static final transient IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(RadarsInUseUtil.class);
|
||||
|
||||
private static final IUFStatusHandler handler = UFStatus
|
||||
private static final IUFStatusHandler handler = UFStatus
|
||||
.getHandler(RadarsInUseUtil.class);
|
||||
|
||||
private static List<String> ssssRadars;
|
||||
private static List<String> ssssRadars;
|
||||
|
||||
private static boolean parsed = false;
|
||||
private static boolean parsed = false;
|
||||
|
||||
private static synchronized void parseFile() throws IOException{
|
||||
PathManager pm = (PathManager) PathManagerFactory.getPathManager();
|
||||
|
@ -81,48 +83,50 @@ public class SsssRadarUtil {
|
|||
statusHandler.info("File ssssRadars.txt not found ");
|
||||
}
|
||||
else{
|
||||
BufferedReader buf = new BufferedReader(new FileReader(
|
||||
file.getFile()));
|
||||
String temp = buf.readLine();
|
||||
while (temp != null) {
|
||||
temp = temp.trim();
|
||||
if (temp.startsWith("#")) {
|
||||
// Skip comment lines if any
|
||||
break;
|
||||
} else if (!temp.trim().isEmpty()) {
|
||||
ssssRadars.add(temp);
|
||||
try (BufferedReader buf = new BufferedReader(new InputStreamReader(
|
||||
file.openInputStream()))) {
|
||||
String temp = buf.readLine();
|
||||
while (temp != null) {
|
||||
temp = temp.trim();
|
||||
if (temp.startsWith("#")) {
|
||||
// Skip comment lines if any
|
||||
break;
|
||||
} else if (!temp.trim().isEmpty()) {
|
||||
ssssRadars.add(temp);
|
||||
}
|
||||
temp = buf.readLine();
|
||||
}
|
||||
temp = buf.readLine();
|
||||
} catch (LocalizationException e) {
|
||||
throw new IOException("Error reading " + file.getPath(), e);
|
||||
}
|
||||
buf.close();
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> getSsssRadars() {
|
||||
if (parsed)
|
||||
return ssssRadars;
|
||||
return ssssRadars;
|
||||
else {
|
||||
try {
|
||||
parseFile();
|
||||
} catch (IOException e) {
|
||||
handler.handle(Priority.ERROR, "Error occurred looking up radars",
|
||||
e);
|
||||
}
|
||||
try {
|
||||
parseFile();
|
||||
} catch (IOException e) {
|
||||
handler.handle(Priority.ERROR,
|
||||
"Error occurred looking up radars", e);
|
||||
}
|
||||
}
|
||||
return ssssRadars;
|
||||
}
|
||||
|
||||
public static boolean isSsssRadar(String radar) {
|
||||
if (!parsed) {
|
||||
try {
|
||||
parseFile();
|
||||
} catch (IOException e) {
|
||||
handler.handle(Priority.ERROR, "Error occurred looking up radars",
|
||||
e);
|
||||
}
|
||||
}
|
||||
if (!parsed) {
|
||||
try {
|
||||
parseFile();
|
||||
} catch (IOException e) {
|
||||
handler.handle(Priority.ERROR,
|
||||
"Error occurred looking up radars", e);
|
||||
}
|
||||
}
|
||||
|
||||
return ssssRadars.contains(radar);
|
||||
return ssssRadars.contains(radar);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
package com.raytheon.uf.common.dataplugin.warning.util;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import com.raytheon.uf.common.dataplugin.warning.WarningConstants;
|
||||
import com.raytheon.uf.common.localization.IPathManager;
|
||||
|
@ -13,6 +12,7 @@ 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.localization.exception.LocalizationException;
|
||||
|
||||
/**
|
||||
* Utility class to retrieve the appropriate file in localization and in backup
|
||||
|
@ -26,6 +26,7 @@ import com.raytheon.uf.common.localization.PathManagerFactory;
|
|||
* ------------ ---------- ----------- --------------------------
|
||||
* Apr 28, 2014 3033 jsanchez Searches the backup site directory before the localized site directory.
|
||||
* Jul 02, 2014 DR 17450 D. Friedman Support using list of templates from backup site.
|
||||
* Feb 15, 2016 5244 nabowle Replace deprecated LocalizationFile methods.
|
||||
* </pre>
|
||||
*
|
||||
* @author jsanchez
|
||||
|
@ -126,38 +127,29 @@ public class WarnFileUtil {
|
|||
public static String convertFileContentsToString(String filename,
|
||||
String localizedSite, String backupSite)
|
||||
throws FileNotFoundException, IOException {
|
||||
File file = findFileInLocalizationIncludingBackupSite(filename, localizedSite, backupSite)
|
||||
.getFile();
|
||||
LocalizationFile file = findFileInLocalizationIncludingBackupSite(
|
||||
filename, localizedSite, backupSite);
|
||||
return convertFileContentsToString(file);
|
||||
}
|
||||
|
||||
public static String convertFileContentsToStringNoUser(String filename,
|
||||
String site) throws FileNotFoundException {
|
||||
File file = findFileInLocalizationIncludingBackupSite(filename, site, null, false).getFile();
|
||||
LocalizationFile file = findFileInLocalizationIncludingBackupSite(
|
||||
filename, site, null, false);
|
||||
return convertFileContentsToString(file);
|
||||
}
|
||||
|
||||
private static String convertFileContentsToString(File file) {
|
||||
private static String convertFileContentsToString(LocalizationFile file) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
BufferedReader input = null;
|
||||
try {
|
||||
input = new BufferedReader(new FileReader(file));
|
||||
try (BufferedReader input = new BufferedReader(new InputStreamReader(
|
||||
file.openInputStream()))) {
|
||||
|
||||
String line = null;
|
||||
while ((line = input.readLine()) != null) {
|
||||
sb.append(line + "\n");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
} catch (IOException | LocalizationException e) {
|
||||
|
||||
} finally {
|
||||
if (input != null) {
|
||||
try {
|
||||
input.close();
|
||||
input = null;
|
||||
} catch (Exception e) {
|
||||
input = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
|
|
@ -2,11 +2,12 @@ Manifest-Version: 1.0
|
|||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: Cpg Plug-in
|
||||
Bundle-SymbolicName: com.raytheon.uf.common.monitor.cpg
|
||||
Bundle-Version: 1.14.0.qualifier
|
||||
Bundle-Version: 1.16.0.qualifier
|
||||
Bundle-Vendor: RAYTHEON
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Export-Package: com.raytheon.uf.common.monitor.cpg
|
||||
Require-Bundle: com.raytheon.uf.common.localization;bundle-version="1.11.17",
|
||||
com.raytheon.uf.common.serialization;bundle-version="1.11.26",
|
||||
com.raytheon.uf.common.serialization.comm;bundle-version="1.11.26"
|
||||
com.raytheon.uf.common.serialization.comm;bundle-version="1.11.26",
|
||||
com.raytheon.uf.common.status;bundle-version="1.15.0"
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package com.raytheon.uf.common.monitor.cpg;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
|
||||
import com.raytheon.uf.common.localization.IPathManager;
|
||||
import com.raytheon.uf.common.localization.LocalizationContext;
|
||||
|
@ -28,6 +29,9 @@ 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.serialization.SingleTypeJAXBManager;
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||
|
||||
/**
|
||||
* Monitor State Configuration XML File Manager.
|
||||
|
@ -39,6 +43,9 @@ import com.raytheon.uf.common.serialization.SingleTypeJAXBManager;
|
|||
* ------------ ---------- ----------- --------------------------
|
||||
* Jan 05, 2009 dhladky Initial creation
|
||||
* Oct 01, 2013 2361 njensen Use JAXBManager for XML
|
||||
* Feb 15, 2016 5244 nabowle Replace deprecated LocalizationFile methods.
|
||||
* Replace system.out with UFStatus.
|
||||
*
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -48,6 +55,9 @@ import com.raytheon.uf.common.serialization.SingleTypeJAXBManager;
|
|||
|
||||
public class MonitorStateConfigurationManager {
|
||||
|
||||
private static final IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(MonitorStateConfigurationManager.class);
|
||||
|
||||
/** Path to Monitoring Area Configuration XML. */
|
||||
private static final String CONFIG_FILE_NAME = "monitoring"
|
||||
+ File.separatorChar + "MonitorPluginState.xml";
|
||||
|
@ -82,38 +92,6 @@ public class MonitorStateConfigurationManager {
|
|||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the XML configuration data to the current XML file name.
|
||||
*/
|
||||
public void saveConfigXml() {
|
||||
// Save the xml object to disk
|
||||
IPathManager pm = PathManagerFactory.getPathManager();
|
||||
LocalizationContext lc = pm.getContext(LocalizationType.COMMON_STATIC,
|
||||
LocalizationLevel.BASE);
|
||||
LocalizationFile newXmlFile = pm.getLocalizationFile(lc,
|
||||
CONFIG_FILE_NAME);
|
||||
|
||||
if (newXmlFile.getFile().getParentFile().exists() == false) {
|
||||
System.out.println("Creating new directory");
|
||||
|
||||
if (newXmlFile.getFile().getParentFile().mkdirs() == false) {
|
||||
System.out.println("Could not create new directory...");
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
System.out.println("Saving -- "
|
||||
+ newXmlFile.getFile().getAbsolutePath());
|
||||
jaxb.marshalToXmlFile(configXml, newXmlFile.getFile()
|
||||
.getAbsolutePath());
|
||||
newXmlFile.save();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
readConfigXml();
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the XML configuration data for the current XML file name.
|
||||
*/
|
||||
|
@ -122,15 +100,18 @@ public class MonitorStateConfigurationManager {
|
|||
IPathManager pm = PathManagerFactory.getPathManager();
|
||||
LocalizationContext lc = pm.getContext(
|
||||
LocalizationType.COMMON_STATIC, LocalizationLevel.BASE);
|
||||
File file = pm.getFile(lc, CONFIG_FILE_NAME);
|
||||
System.out.println("Reading -- " + file.getAbsolutePath());
|
||||
MonitorStateXML configXmltmp = jaxb.unmarshalFromXmlFile(file
|
||||
.getAbsolutePath());
|
||||
configXml = configXmltmp;
|
||||
LocalizationFile lf = pm.getLocalizationFile(lc, CONFIG_FILE_NAME);
|
||||
|
||||
statusHandler.handle(Priority.INFO, "Reading -- " + lf.getPath());
|
||||
try (InputStream is = lf.openInputStream()) {
|
||||
MonitorStateXML configXmltmp = jaxb
|
||||
.unmarshalFromInputStream(is);
|
||||
configXml = configXmltmp;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.err.println("No configuration file found");
|
||||
statusHandler.handle(Priority.INFO, "No configuration file found",
|
||||
e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ Manifest-Version: 1.0
|
|||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: Monitor Plug-in
|
||||
Bundle-SymbolicName: com.raytheon.uf.common.monitor
|
||||
Bundle-Version: 1.14.0.qualifier
|
||||
Bundle-Version: 1.16.0.qualifier
|
||||
Bundle-Vendor: RAYTHEON
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
|
||||
Bundle-ActivationPolicy: lazy
|
||||
|
|
|
@ -21,16 +21,20 @@ package com.raytheon.uf.common.monitor.config;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.raytheon.uf.common.localization.ILocalizationFile;
|
||||
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.localization.SaveableOutputStream;
|
||||
import com.raytheon.uf.common.monitor.xml.FFFGDataXML;
|
||||
import com.raytheon.uf.common.monitor.xml.FFFGSourceItemXML;
|
||||
import com.raytheon.uf.common.monitor.xml.FFFGSourceXML;
|
||||
import com.raytheon.uf.common.serialization.SingleTypeJAXBManager;
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -44,6 +48,8 @@ import com.raytheon.uf.common.serialization.SingleTypeJAXBManager;
|
|||
* ------------ ---------- ----------- --------------------------
|
||||
* Mar 10, 2010 #4517 lvenable Initial creation
|
||||
* Oct 02, 2013 2361 njensen Use JAXBManager for XML
|
||||
* Feb 15, 2016 5244 nabowle Replace deprecated LocalizationFile methods.
|
||||
* Replace System.out calls.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -52,6 +58,9 @@ import com.raytheon.uf.common.serialization.SingleTypeJAXBManager;
|
|||
*/
|
||||
public class FFFGXmlMgr {
|
||||
|
||||
private static final IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(FFFGXmlMgr.class);
|
||||
|
||||
private static final SingleTypeJAXBManager<FFFGDataXML> jaxb = SingleTypeJAXBManager
|
||||
.createWithoutException(FFFGDataXML.class);
|
||||
|
||||
|
@ -154,13 +163,12 @@ public class FFFGXmlMgr {
|
|||
IPathManager pm = PathManagerFactory.getPathManager();
|
||||
String path = pm.getStaticFile(fullPathAndFileName)
|
||||
.getAbsolutePath();
|
||||
// System.out.println("*** reading XML path = " + path);
|
||||
|
||||
dataXML = jaxb.unmarshalFromXmlFile(path);
|
||||
setForcingConfigured();
|
||||
} catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
System.out.println("*** FFFGMasterData.xml not available.");
|
||||
statusHandler.handle(Priority.WARN,
|
||||
"*** FFFGMasterData.xml not available.", e);
|
||||
dataXML = null;
|
||||
}
|
||||
}
|
||||
|
@ -186,22 +194,15 @@ public class FFFGXmlMgr {
|
|||
IPathManager pm = PathManagerFactory.getPathManager();
|
||||
LocalizationContext context = pm.getContext(
|
||||
LocalizationType.COMMON_STATIC, LocalizationLevel.SITE);
|
||||
LocalizationFile locFile = pm.getLocalizationFile(context,
|
||||
ILocalizationFile locFile = pm.getLocalizationFile(context,
|
||||
fullPathAndFileName);
|
||||
|
||||
if (locFile.getFile().getParentFile().exists() == false) {
|
||||
System.out.println("Creating new directory");
|
||||
statusHandler.handle(Priority.INFO,
|
||||
"--- Saving XML path = " + locFile.getPath());
|
||||
|
||||
if (locFile.getFile().getParentFile().mkdirs() == false) {
|
||||
System.out.println("Could not create new directory...");
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
System.out.println("--- Saving XML path = "
|
||||
+ locFile.getFile().getAbsolutePath());
|
||||
jaxb.marshalToXmlFile(dataXML, locFile.getFile().getAbsolutePath());
|
||||
locFile.save();
|
||||
try (SaveableOutputStream sos = locFile.openOutputStream()) {
|
||||
jaxb.marshalToStream(dataXML, sos);
|
||||
sos.save();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -214,41 +215,47 @@ public class FFFGXmlMgr {
|
|||
*/
|
||||
public void printData() {
|
||||
if (xmlType == FFFGXmlType.MASTER) {
|
||||
System.out.println("******* Master XML Data *********");
|
||||
statusHandler.handle(Priority.INFO,
|
||||
"******* Master XML Data *********");
|
||||
} else {
|
||||
System.out.println("******* User XML Data *********");
|
||||
statusHandler.handle(Priority.INFO,
|
||||
"******* User XML Data *********");
|
||||
}
|
||||
|
||||
System.out.println("Experation Time = " + dataXML.getExpTimeInMillis());
|
||||
statusHandler.handle(Priority.INFO,
|
||||
"Expiration Time = " + dataXML.getExpTimeInMillis());
|
||||
|
||||
ArrayList<FFFGSourceXML> sources = dataXML.getSources();
|
||||
|
||||
for (FFFGSourceXML src : sources) {
|
||||
if (src.getSourceName() == null) {
|
||||
System.out.println("+++ Source Name is null ");
|
||||
statusHandler.handle(Priority.INFO, "+++ Source Name is null ");
|
||||
} else {
|
||||
System.out.println("+++ Source Name = " + src.getSourceName());
|
||||
statusHandler.handle(Priority.INFO,
|
||||
"+++ Source Name = " + src.getSourceName());
|
||||
}
|
||||
|
||||
if (src.getAreaFFGValue() == null) {
|
||||
System.out.println("+++ Area FFG is null");
|
||||
statusHandler.handle(Priority.INFO, "+++ Area FFG is null");
|
||||
} else {
|
||||
System.out
|
||||
.println("+++ Area FFG = " + src.getAreaFFGValue());
|
||||
statusHandler.handle(Priority.INFO,
|
||||
"+++ Area FFG = " + src.getAreaFFGValue());
|
||||
}
|
||||
|
||||
ArrayList<FFFGSourceItemXML> srcItems = src.getSourceItems();
|
||||
|
||||
if (srcItems == null) {
|
||||
System.out.println("Source Items are null");
|
||||
statusHandler.handle(Priority.INFO, "Source Items are null");
|
||||
return;
|
||||
}
|
||||
|
||||
for (FFFGSourceItemXML si : srcItems) {
|
||||
System.out.println("------ type = " + si.getType());
|
||||
System.out.println("------ name = " + si.getName());
|
||||
System.out.println("------ id = " + si.getId());
|
||||
System.out.println("------ val = " + si.getValue());
|
||||
statusHandler.handle(
|
||||
Priority.INFO,
|
||||
"------ type = " + si.getType() + "\n------ name = "
|
||||
+ si.getName() + "\n------ id = "
|
||||
+ si.getId() + "\n------ val = "
|
||||
+ si.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,19 +19,21 @@
|
|||
**/
|
||||
package com.raytheon.uf.common.monitor.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import com.raytheon.uf.common.localization.FileUpdatedMessage;
|
||||
import com.raytheon.uf.common.localization.ILocalizationFileObserver;
|
||||
import com.raytheon.uf.common.localization.ILocalizationFile;
|
||||
import com.raytheon.uf.common.localization.ILocalizationPathObserver;
|
||||
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.localization.SaveableOutputStream;
|
||||
import com.raytheon.uf.common.localization.exception.LocalizationException;
|
||||
import com.raytheon.uf.common.monitor.events.MonitorConfigEvent;
|
||||
import com.raytheon.uf.common.monitor.events.MonitorConfigListener;
|
||||
import com.raytheon.uf.common.monitor.xml.DomainXML;
|
||||
|
@ -58,12 +60,13 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
|
|||
* Apr 26, 2013 1954 bsteffen Minor code cleanup throughout FFMP.
|
||||
* Aug 13, 2013 1742 dhladky Concurrent mod exception on update fixed
|
||||
* Oct 02, 2013 2361 njensen Use JAXBManager for XML
|
||||
* Feb 15, 2016 5244 nabowle Replace deprecated LocalizationFile methods.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
*/
|
||||
|
||||
public class FFMPRunConfigurationManager implements ILocalizationFileObserver {
|
||||
public class FFMPRunConfigurationManager implements ILocalizationPathObserver {
|
||||
|
||||
/** Path to FFMP Source config. */
|
||||
private static final String CONFIG_FILE_NAME = "ffmp"
|
||||
|
@ -82,14 +85,12 @@ public class FFMPRunConfigurationManager implements ILocalizationFileObserver {
|
|||
|
||||
protected boolean isPopulated;
|
||||
|
||||
private LocalizationFile lf = null;
|
||||
|
||||
private CopyOnWriteArrayList<MonitorConfigListener> listeners = new CopyOnWriteArrayList<MonitorConfigListener>();
|
||||
|
||||
/** Singleton instance of this class */
|
||||
private static FFMPRunConfigurationManager instance = new FFMPRunConfigurationManager();
|
||||
|
||||
/* Private Constructor */
|
||||
/** Private Constructor */
|
||||
private FFMPRunConfigurationManager() {
|
||||
isPopulated = false;
|
||||
|
||||
|
@ -136,19 +137,23 @@ public class FFMPRunConfigurationManager implements ILocalizationFileObserver {
|
|||
LocalizationContext lc = pm.getContext(LocalizationType.COMMON_STATIC,
|
||||
LocalizationLevel.SITE);
|
||||
|
||||
lf = pm.getLocalizationFile(lc, CONFIG_FILE_NAME);
|
||||
lf.addFileUpdatedObserver(this);
|
||||
File file = lf.getFile();
|
||||
ILocalizationFile lf = pm.getLocalizationFile(lc, CONFIG_FILE_NAME);
|
||||
pm.addLocalizationPathObserver(CONFIG_FILE_NAME, this);
|
||||
// System.out.println("Reading -- " + file.getAbsolutePath());
|
||||
if (!file.exists()) {
|
||||
System.out.println("WARNING [FFMP] FFMPRunConfigurationManager: "
|
||||
+ file.getAbsolutePath() + " does not exist.");
|
||||
if (!lf.exists()) {
|
||||
statusHandler.handle(Priority.WARN, lf.getPath()
|
||||
+ " does not exist.");
|
||||
return;
|
||||
}
|
||||
|
||||
FFMPRunConfigXML configXmltmp = null;
|
||||
|
||||
configXmltmp = jaxb.unmarshalFromXmlFile(file.getAbsolutePath());
|
||||
try (InputStream is = lf.openInputStream()) {
|
||||
configXmltmp = jaxb.unmarshalFromInputStream(is);
|
||||
} catch (IOException | LocalizationException e) {
|
||||
throw new SerializationException("Error unmarshalling "
|
||||
+ lf.getPath(), e);
|
||||
}
|
||||
|
||||
configXml = configXmltmp;
|
||||
isPopulated = true;
|
||||
|
@ -164,25 +169,12 @@ public class FFMPRunConfigurationManager implements ILocalizationFileObserver {
|
|||
LocalizationContext lc = pm.getContext(LocalizationType.COMMON_STATIC,
|
||||
LocalizationLevel.SITE);
|
||||
|
||||
LocalizationFile newXmlFile = pm.getLocalizationFile(lc,
|
||||
ILocalizationFile newXmlFile = pm.getLocalizationFile(lc,
|
||||
CONFIG_FILE_NAME);
|
||||
|
||||
if (newXmlFile.getFile().getParentFile().exists() == false) {
|
||||
// System.out.println("Creating new directory");
|
||||
|
||||
if (newXmlFile.getFile().getParentFile().mkdirs() == false) {
|
||||
// System.out.println("Could not create new directory...");
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// System.out.println("Saving -- "
|
||||
// + newXmlFile.getFile().getAbsolutePath());
|
||||
jaxb.marshalToXmlFile(configXml, newXmlFile.getFile()
|
||||
.getAbsolutePath());
|
||||
newXmlFile.save();
|
||||
|
||||
lf = newXmlFile;
|
||||
try (SaveableOutputStream sos = newXmlFile.openOutputStream()) {
|
||||
jaxb.marshalToStream(configXml, sos);
|
||||
sos.save();
|
||||
} catch (Exception e) {
|
||||
statusHandler.handle(Priority.ERROR, "Couldn't save config file.",
|
||||
e);
|
||||
|
@ -272,9 +264,8 @@ public class FFMPRunConfigurationManager implements ILocalizationFileObserver {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void fileUpdated(FileUpdatedMessage message) {
|
||||
|
||||
if (message.getFileName().equals(CONFIG_FILE_NAME)) {
|
||||
public void fileChanged(ILocalizationFile file) {
|
||||
if (file.getPath().equals(CONFIG_FILE_NAME)) {
|
||||
try {
|
||||
readConfigXml();
|
||||
|
||||
|
@ -285,7 +276,7 @@ public class FFMPRunConfigurationManager implements ILocalizationFileObserver {
|
|||
|
||||
} catch (SerializationException e) {
|
||||
statusHandler.handle(Priority.WARN,
|
||||
"FFMPRunConfigurationManager: " + message.getFileName()
|
||||
"FFMPRunConfigurationManager: " + file.getPath()
|
||||
+ " couldn't be updated.", e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,19 +19,21 @@
|
|||
**/
|
||||
package com.raytheon.uf.common.monitor.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import com.raytheon.uf.common.localization.FileUpdatedMessage;
|
||||
import com.raytheon.uf.common.localization.ILocalizationFileObserver;
|
||||
import com.raytheon.uf.common.localization.ILocalizationFile;
|
||||
import com.raytheon.uf.common.localization.ILocalizationPathObserver;
|
||||
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.localization.SaveableOutputStream;
|
||||
import com.raytheon.uf.common.localization.exception.LocalizationException;
|
||||
import com.raytheon.uf.common.monitor.events.MonitorConfigEvent;
|
||||
import com.raytheon.uf.common.monitor.events.MonitorConfigListener;
|
||||
import com.raytheon.uf.common.monitor.xml.FFMPSourceConfigXML;
|
||||
|
@ -57,13 +59,14 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
|
|||
* Oct 02, 2013 2361 njensen Use JAXBManager for XML
|
||||
* Aug 15, 2015 4722 dhladky Added new types to be used for new Guidance sources, etc
|
||||
* Sep 17, 2015 4756 dhladky Fixed bugs for multiple guidance sources.
|
||||
* Feb 15, 2016 5244 nabowle Replace deprecated LocalizationFile methods.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
*/
|
||||
|
||||
public class FFMPSourceConfigurationManager implements
|
||||
ILocalizationFileObserver {
|
||||
ILocalizationPathObserver {
|
||||
|
||||
/** Path to FFMP Source config. */
|
||||
private static final String CONFIG_FILE_NAME = "ffmp"
|
||||
|
@ -72,10 +75,11 @@ public class FFMPSourceConfigurationManager implements
|
|||
private static final IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(FFMPSourceConfigurationManager.class);
|
||||
|
||||
// This needs to initialize before the instance since the constructor will
|
||||
// makes use of JAXB. JVM spec 12.4.2 step 9 indicates this will
|
||||
// initialize ahead of the instance since it is earlier in
|
||||
// in the text source.
|
||||
/*
|
||||
* This needs to initialize before the instance since the constructor will
|
||||
* makes use of JAXB. JVM spec 12.4.2 step 9 indicates this will initialize
|
||||
* ahead of the instance since it is earlier in in the text source.
|
||||
*/
|
||||
private static final SingleTypeJAXBManager<FFMPSourceConfigXML> jaxb = SingleTypeJAXBManager
|
||||
.createWithoutException(FFMPSourceConfigXML.class);
|
||||
|
||||
|
@ -97,13 +101,13 @@ public class FFMPSourceConfigurationManager implements
|
|||
|
||||
private List<String> accumulators = null;
|
||||
|
||||
private LocalizationFile lf = null;
|
||||
|
||||
private List<MonitorConfigListener> listeners = new CopyOnWriteArrayList<MonitorConfigListener>();
|
||||
|
||||
/* Private Constructor */
|
||||
private FFMPSourceConfigurationManager() {
|
||||
configXml = new FFMPSourceConfigXML();
|
||||
IPathManager pm = PathManagerFactory.getPathManager();
|
||||
pm.addLocalizationPathObserver(CONFIG_FILE_NAME, this);
|
||||
readConfigXml();
|
||||
}
|
||||
|
||||
|
@ -129,32 +133,32 @@ public class FFMPSourceConfigurationManager implements
|
|||
*/
|
||||
public synchronized void readConfigXml() {
|
||||
IPathManager pm = PathManagerFactory.getPathManager();
|
||||
|
||||
try {
|
||||
LocalizationContext lc = pm.getContext(
|
||||
LocalizationType.COMMON_STATIC, LocalizationLevel.SITE);
|
||||
lf = pm.getLocalizationFile(lc, CONFIG_FILE_NAME);
|
||||
lf.addFileUpdatedObserver(this);
|
||||
File file = lf.getFile();
|
||||
ILocalizationFile lf = pm.getLocalizationFile(lc, CONFIG_FILE_NAME);
|
||||
|
||||
FFMPSourceConfigXML configXmltmp = jaxb.unmarshalFromXmlFile(file);
|
||||
|
||||
configXml = configXmltmp;
|
||||
try (InputStream is = lf.openInputStream()) {
|
||||
FFMPSourceConfigXML configXmltmp = jaxb
|
||||
.unmarshalFromInputStream(is);
|
||||
|
||||
configXml = configXmltmp;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
statusHandler.error("No SITE FFMP Source configuration file found");
|
||||
|
||||
// fall back to BASE
|
||||
LocalizationContext lc = pm.getContext(
|
||||
LocalizationType.COMMON_STATIC, LocalizationLevel.BASE);
|
||||
lf = pm.getLocalizationFile(lc, CONFIG_FILE_NAME);
|
||||
lf.addFileUpdatedObserver(this);
|
||||
File file = lf.getFile();
|
||||
ILocalizationFile lf = pm.getLocalizationFile(lc, CONFIG_FILE_NAME);
|
||||
|
||||
FFMPSourceConfigXML configXmltmp = null;
|
||||
try {
|
||||
configXmltmp = jaxb.unmarshalFromXmlFile(file);
|
||||
} catch (SerializationException e1) {
|
||||
try (InputStream is = lf.openInputStream()) {
|
||||
configXmltmp = jaxb.unmarshalFromInputStream(is);
|
||||
|
||||
configXml = configXmltmp;
|
||||
} catch (SerializationException | LocalizationException
|
||||
| IOException e1) {
|
||||
statusHandler.handle(Priority.ERROR,
|
||||
"Couldn't deserialize file.", e1);
|
||||
}
|
||||
|
@ -173,19 +177,12 @@ public class FFMPSourceConfigurationManager implements
|
|||
IPathManager pm = PathManagerFactory.getPathManager();
|
||||
LocalizationContext lc = pm.getContext(LocalizationType.COMMON_STATIC,
|
||||
LocalizationLevel.SITE);
|
||||
LocalizationFile newXmlFile = pm.getLocalizationFile(lc,
|
||||
ILocalizationFile newXmlFile = pm.getLocalizationFile(lc,
|
||||
CONFIG_FILE_NAME);
|
||||
File file = newXmlFile.getFile();
|
||||
|
||||
if (file.getParentFile().exists() == false) {
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
|
||||
try {
|
||||
jaxb.marshalToXmlFile(configXml, file.getAbsolutePath());
|
||||
newXmlFile.save();
|
||||
lf = newXmlFile;
|
||||
lf.addFileUpdatedObserver(this);
|
||||
try (SaveableOutputStream sos = newXmlFile.openOutputStream()) {
|
||||
jaxb.marshalToStream(configXml, sos);
|
||||
sos.save();
|
||||
} catch (Exception e) {
|
||||
statusHandler.handle(Priority.ERROR, "Couldn't save config file.",
|
||||
e);
|
||||
|
@ -514,8 +511,8 @@ public class FFMPSourceConfigurationManager implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public void fileUpdated(FileUpdatedMessage message) {
|
||||
if (message.getFileName().equals(CONFIG_FILE_NAME)) {
|
||||
public void fileChanged(ILocalizationFile file) {
|
||||
if (file.getPath().equals(CONFIG_FILE_NAME)) {
|
||||
try {
|
||||
readConfigXml();
|
||||
// inform listeners
|
||||
|
@ -526,11 +523,10 @@ public class FFMPSourceConfigurationManager implements
|
|||
statusHandler.handle(
|
||||
Priority.WARN,
|
||||
"FFMPSourceConfigurationManager: "
|
||||
+ message.getFileName()
|
||||
+ file.getPath()
|
||||
+ " couldn't be updated.", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,17 +20,18 @@
|
|||
package com.raytheon.uf.common.monitor.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import com.raytheon.uf.common.localization.FileUpdatedMessage;
|
||||
import com.raytheon.uf.common.localization.ILocalizationFileObserver;
|
||||
import com.raytheon.uf.common.localization.ILocalizationFile;
|
||||
import com.raytheon.uf.common.localization.ILocalizationPathObserver;
|
||||
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.localization.SaveableOutputStream;
|
||||
import com.raytheon.uf.common.monitor.events.MonitorConfigEvent;
|
||||
import com.raytheon.uf.common.monitor.events.MonitorConfigListener;
|
||||
import com.raytheon.uf.common.monitor.xml.FFMPTemplateXML;
|
||||
|
@ -52,6 +53,7 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
|
|||
* Oct 25, 2012 DR 15514 gzhang Adding getHucLevelsInArray()
|
||||
* Aug 18, 2013 1742 dhladky Concurrent mod exception on update fixed
|
||||
* Oct 02, 2013 2361 njensen Use JAXBManager for XML
|
||||
* Feb 15, 2016 5244 nabowle Replace deprecated LocalizationFile methods.
|
||||
* </pre>
|
||||
*
|
||||
* @author dhladky
|
||||
|
@ -59,7 +61,7 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
|
|||
*/
|
||||
|
||||
public class FFMPTemplateConfigurationManager implements
|
||||
ILocalizationFileObserver {
|
||||
ILocalizationPathObserver {
|
||||
|
||||
/** Path to FFMP Template config. */
|
||||
private static final String CONFIG_FILE_NAME = "ffmp" + File.separatorChar
|
||||
|
@ -78,8 +80,6 @@ public class FFMPTemplateConfigurationManager implements
|
|||
|
||||
private ArrayList<String> hucLevels = null;
|
||||
|
||||
private LocalizationFile lf = null;
|
||||
|
||||
private CopyOnWriteArrayList<MonitorConfigListener> listeners = new CopyOnWriteArrayList<MonitorConfigListener>();
|
||||
|
||||
private static final IUFStatusHandler statusHandler = UFStatus
|
||||
|
@ -91,8 +91,7 @@ public class FFMPTemplateConfigurationManager implements
|
|||
IPathManager pm = PathManagerFactory.getPathManager();
|
||||
LocalizationContext lc = pm.getContext(LocalizationType.COMMON_STATIC,
|
||||
LocalizationLevel.SITE);
|
||||
lf = pm.getLocalizationFile(lc, CONFIG_FILE_NAME);
|
||||
lf.addFileUpdatedObserver(this);
|
||||
pm.addLocalizationPathObserver(CONFIG_FILE_NAME, this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -121,18 +120,15 @@ public class FFMPTemplateConfigurationManager implements
|
|||
*/
|
||||
public void readConfigXml() throws Exception {
|
||||
|
||||
if (lf == null) {
|
||||
IPathManager pm = PathManagerFactory.getPathManager();
|
||||
LocalizationContext lc = pm.getContext(
|
||||
LocalizationType.COMMON_STATIC, LocalizationLevel.SITE);
|
||||
lf = pm.getLocalizationFile(lc, CONFIG_FILE_NAME);
|
||||
lf.addFileUpdatedObserver(this);
|
||||
}
|
||||
IPathManager pm = PathManagerFactory.getPathManager();
|
||||
LocalizationContext lc = pm.getContext(LocalizationType.COMMON_STATIC,
|
||||
LocalizationLevel.SITE);
|
||||
ILocalizationFile lf = pm.getLocalizationFile(lc, CONFIG_FILE_NAME);
|
||||
|
||||
File file = lf.getFile();
|
||||
FFMPTemplateXML configXmltmp = jaxb.unmarshalFromXmlFile(file
|
||||
.getAbsolutePath());
|
||||
configXml = configXmltmp;
|
||||
try (InputStream is = lf.openInputStream()) {
|
||||
FFMPTemplateXML configXmltmp = jaxb.unmarshalFromInputStream(is);
|
||||
configXml = configXmltmp;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -143,25 +139,12 @@ public class FFMPTemplateConfigurationManager implements
|
|||
IPathManager pm = PathManagerFactory.getPathManager();
|
||||
LocalizationContext lc = pm.getContext(LocalizationType.COMMON_STATIC,
|
||||
LocalizationLevel.SITE);
|
||||
LocalizationFile newXmlFile = pm.getLocalizationFile(lc,
|
||||
ILocalizationFile newXmlFile = pm.getLocalizationFile(lc,
|
||||
CONFIG_FILE_NAME);
|
||||
|
||||
if (newXmlFile.getFile().getParentFile().exists() == false) {
|
||||
// System.out.println("Creating new directory");
|
||||
|
||||
if (newXmlFile.getFile().getParentFile().mkdirs() == false) {
|
||||
// System.out.println("Could not create new directory...");
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// System.out.println("Saving -- "
|
||||
// + newXmlFile.getFile().getAbsolutePath());
|
||||
jaxb.marshalToXmlFile(configXml, newXmlFile.getFile()
|
||||
.getAbsolutePath());
|
||||
newXmlFile.save();
|
||||
|
||||
lf = newXmlFile;
|
||||
try (SaveableOutputStream sos = newXmlFile.openOutputStream()) {
|
||||
jaxb.marshalToStream(configXml, sos);
|
||||
sos.save();
|
||||
} catch (Exception e) {
|
||||
statusHandler.handle(Priority.ERROR, "Couldn't save config file.",
|
||||
e);
|
||||
|
@ -256,9 +239,9 @@ public class FFMPTemplateConfigurationManager implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public void fileUpdated(FileUpdatedMessage message) {
|
||||
public void fileChanged(ILocalizationFile localizationFile) {
|
||||
|
||||
if (message.getFileName().equals(CONFIG_FILE_NAME)) {
|
||||
if (localizationFile.getPath().equals(CONFIG_FILE_NAME)) {
|
||||
try {
|
||||
readConfigXml();
|
||||
// inform listeners
|
||||
|
@ -271,7 +254,7 @@ public class FFMPTemplateConfigurationManager implements
|
|||
statusHandler.handle(
|
||||
Priority.WARN,
|
||||
"FFMPTemplateConfigurationManager: "
|
||||
+ message.getFileName()
|
||||
+ localizationFile.getPath()
|
||||
+ " couldn't be updated.", e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,19 +21,23 @@
|
|||
package com.raytheon.uf.common.monitor.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.raytheon.uf.common.localization.FileUpdatedMessage;
|
||||
import com.raytheon.uf.common.localization.ILocalizationFileObserver;
|
||||
import com.raytheon.uf.common.localization.ILocalizationFile;
|
||||
import com.raytheon.uf.common.localization.ILocalizationPathObserver;
|
||||
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.localization.SaveableOutputStream;
|
||||
import com.raytheon.uf.common.monitor.xml.FFTIDataXML;
|
||||
import com.raytheon.uf.common.monitor.xml.FFTISettingXML;
|
||||
import com.raytheon.uf.common.serialization.SingleTypeJAXBManager;
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||
|
||||
/**
|
||||
* Singleton data manager for FFTI.
|
||||
|
@ -46,13 +50,18 @@ import com.raytheon.uf.common.serialization.SingleTypeJAXBManager;
|
|||
* ------------ ---------- ----------- --------------------------
|
||||
* --/--/---- Initial creation
|
||||
* Oct 02, 2013 2361 njensen Use JAXBManager for XML
|
||||
* Feb 15, 2016 5244 nabowle Replace deprecated LocalizationFile methods.
|
||||
* Replace system.out with UFStatus.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author lvenable
|
||||
* @version 1.0
|
||||
*/
|
||||
public class FFTIDataManager implements ILocalizationFileObserver {
|
||||
public class FFTIDataManager implements ILocalizationPathObserver {
|
||||
|
||||
private static final IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(FFTIDataManager.class);
|
||||
|
||||
/** Path to FFTI config. */
|
||||
private static final String CONFIG_FILE_NAME = "ffmp" + File.separatorChar
|
||||
|
@ -73,11 +82,11 @@ public class FFTIDataManager implements ILocalizationFileObserver {
|
|||
*/
|
||||
protected FFTIDataXML configXml;
|
||||
|
||||
private LocalizationFile lf = null;
|
||||
|
||||
/* Private Constructor */
|
||||
private FFTIDataManager() {
|
||||
configXml = new FFTIDataXML();
|
||||
IPathManager pm = PathManagerFactory.getPathManager();
|
||||
pm.addLocalizationPathObserver(CONFIG_FILE_NAME, this);
|
||||
readConfigXml();
|
||||
}
|
||||
|
||||
|
@ -98,18 +107,16 @@ public class FFTIDataManager implements ILocalizationFileObserver {
|
|||
IPathManager pm = PathManagerFactory.getPathManager();
|
||||
LocalizationContext lc = pm.getContext(
|
||||
LocalizationType.COMMON_STATIC, LocalizationLevel.SITE);
|
||||
lf = pm.getLocalizationFile(lc, CONFIG_FILE_NAME);
|
||||
lf.addFileUpdatedObserver(this);
|
||||
ILocalizationFile lf = pm.getLocalizationFile(lc, CONFIG_FILE_NAME);
|
||||
|
||||
File file = lf.getFile();
|
||||
|
||||
FFTIDataXML configXmltmp = jaxb.unmarshalFromXmlFile(file
|
||||
.getAbsolutePath());
|
||||
|
||||
configXml = configXmltmp;
|
||||
try (InputStream is = lf.openInputStream()) {
|
||||
FFTIDataXML configXmltmp = jaxb.unmarshalFromInputStream(is);
|
||||
configXml = configXmltmp;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("No SITE FFTI Source configuration file found.");
|
||||
statusHandler.handle(Priority.WARN,
|
||||
"No SITE FFTI Source configuration file found.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,28 +128,15 @@ public class FFTIDataManager implements ILocalizationFileObserver {
|
|||
IPathManager pm = PathManagerFactory.getPathManager();
|
||||
LocalizationContext lc = pm.getContext(LocalizationType.COMMON_STATIC,
|
||||
LocalizationLevel.SITE);
|
||||
LocalizationFile newXmlFile = pm.getLocalizationFile(lc,
|
||||
ILocalizationFile newXmlFile = pm.getLocalizationFile(lc,
|
||||
CONFIG_FILE_NAME);
|
||||
|
||||
if (newXmlFile.getFile().getParentFile().exists() == false) {
|
||||
// System.out.println("Creating new directory");
|
||||
|
||||
if (newXmlFile.getFile().getParentFile().mkdirs() == false) {
|
||||
// System.out.println("Could not create new directory...");
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// System.out.println("Saving -- "
|
||||
// + newXmlFile.getFile().getAbsolutePath());
|
||||
jaxb.marshalToXmlFile(configXml, newXmlFile.getFile()
|
||||
.getAbsolutePath());
|
||||
newXmlFile.save();
|
||||
|
||||
lf = newXmlFile;
|
||||
try (SaveableOutputStream sos = newXmlFile.openOutputStream()) {
|
||||
jaxb.marshalToStream(configXml, sos);
|
||||
sos.save();
|
||||
} catch (Exception e) {
|
||||
System.err
|
||||
.println("Failed to save SITE FFTI Source configuration file.");
|
||||
statusHandler.handle(Priority.WARN,
|
||||
"Failed to save SITE FFTI Source configuration file.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -171,14 +165,15 @@ public class FFTIDataManager implements ILocalizationFileObserver {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void fileUpdated(FileUpdatedMessage message) {
|
||||
public void fileChanged(ILocalizationFile file) {
|
||||
|
||||
try {
|
||||
if (message.getFileName().equals(CONFIG_FILE_NAME)) {
|
||||
if (file.getPath().equals(CONFIG_FILE_NAME)) {
|
||||
readConfigXml();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
statusHandler.handle(Priority.WARN, "Error handling file changed.",
|
||||
e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,19 +20,24 @@
|
|||
package com.raytheon.uf.common.monitor.scan.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Set;
|
||||
|
||||
import com.raytheon.uf.common.localization.ILocalizationFile;
|
||||
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.localization.SaveableOutputStream;
|
||||
import com.raytheon.uf.common.monitor.scan.xml.SCANTrendSetXML;
|
||||
import com.raytheon.uf.common.monitor.scan.xml.SCANTrendSetsXML;
|
||||
import com.raytheon.uf.common.serialization.SingleTypeJAXBManager;
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -47,6 +52,8 @@ import com.raytheon.uf.common.serialization.SingleTypeJAXBManager;
|
|||
* ------------ ---------- ----------- --------------------------
|
||||
* Dec 3, 2009 #3039 lvenable Initial creation
|
||||
* Oct 2, 2013 2361 njensen Use JAXBManager for XML
|
||||
* Feb 15, 2016 5244 nabowle Replace deprecated LocalizationFile methods.
|
||||
* Add statusHandler.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -55,6 +62,9 @@ import com.raytheon.uf.common.serialization.SingleTypeJAXBManager;
|
|||
*/
|
||||
public class TrendSetConfigMgr {
|
||||
|
||||
private static final IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(TrendSetConfigMgr.class);
|
||||
|
||||
private static final SingleTypeJAXBManager<SCANTrendSetsXML> jaxb = SingleTypeJAXBManager
|
||||
.createWithoutException(SCANTrendSetsXML.class);
|
||||
|
||||
|
@ -63,10 +73,6 @@ public class TrendSetConfigMgr {
|
|||
*/
|
||||
private String configXml = null;
|
||||
|
||||
/**
|
||||
* Full XML file path.
|
||||
*/
|
||||
private String fullXMLFilePath = null;
|
||||
|
||||
/**
|
||||
* Trend sets XML.
|
||||
|
@ -106,11 +112,14 @@ public class TrendSetConfigMgr {
|
|||
private void readDefaultConfig() {
|
||||
try {
|
||||
IPathManager pm = PathManagerFactory.getPathManager();
|
||||
fullXMLFilePath = pm.getStaticFile(getFullConfigFileNameStr())
|
||||
.getAbsolutePath();
|
||||
trendSets = jaxb.unmarshalFromXmlFile(fullXMLFilePath);
|
||||
ILocalizationFile file = pm
|
||||
.getStaticLocalizationFile(getFullConfigFileNameStr());
|
||||
try (InputStream is = file.openInputStream()) {
|
||||
trendSets = jaxb.unmarshalFromInputStream(is);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
statusHandler.handle(Priority.WARN,
|
||||
"Error reading default config.", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -186,23 +195,14 @@ public class TrendSetConfigMgr {
|
|||
IPathManager pm = PathManagerFactory.getPathManager();
|
||||
LocalizationContext context = pm.getContext(
|
||||
LocalizationType.CAVE_STATIC, LocalizationLevel.SITE);
|
||||
LocalizationFile locFile = pm.getLocalizationFile(context,
|
||||
ILocalizationFile locFile = pm.getLocalizationFile(context,
|
||||
getFullConfigFileNameStr());
|
||||
|
||||
if (locFile.getFile().exists() == false) {
|
||||
if (locFile.getFile().getParentFile().mkdirs() == false) {
|
||||
System.out.println("Did not not create directory(ies): "
|
||||
+ locFile.getFile().getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
jaxb.marshalToXmlFile(trendSets, locFile.getFile()
|
||||
.getAbsolutePath());
|
||||
|
||||
locFile.save();
|
||||
try (SaveableOutputStream sos = locFile.openOutputStream()) {
|
||||
jaxb.marshalToStream(trendSets, sos);
|
||||
sos.save();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
statusHandler.handle(Priority.WARN, "Error saving trend sets.", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue