lrgs.edl.EdlMonitorThread Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of opendcs Show documentation
Show all versions of opendcs Show documentation
A collection of software for aggregatting and processing environmental data such as from NOAA GOES satellites.
The newest version!
/*
* $Id$
*
* This software was written by Cove Software, LLC ("COVE") under contract
* to Alberta Environment and Sustainable Resource Development (Alberta ESRD).
* No warranty is provided or implied other than specific contractual terms
* between COVE and Alberta ESRD.
*
* Copyright 2014 Alberta Environment and Sustainable Resource Development.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package lrgs.edl;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.Date;
import decodes.datasource.EdlPMParser;
import decodes.datasource.GoesPMParser;
import decodes.datasource.HeaderParseException;
import decodes.datasource.RawMessage;
import lrgs.common.DcpAddress;
import lrgs.common.DcpMsg;
import lrgs.common.DcpMsgFlag;
import lrgs.lrgsmain.LrgsConfig;
import ilex.util.DirectoryMonitorThread;
import ilex.util.EnvExpander;
import ilex.util.FileUtil;
import ilex.util.Logger;
import ilex.var.Variable;
public class EdlMonitorThread
extends DirectoryMonitorThread
{
private File doneDir = null;
private EdlInputInterface parent = null;
private EdlPMParser pmParser = new EdlPMParser();
private static String module = "EdlMonitor";
private long startTime;
public EdlMonitorThread(EdlInputInterface parent)
{
this.parent = parent;
configure();
startTime = System.currentTimeMillis();
}
/**
* Configure the monitor once upon starting up.
*/
private void configure()
{
this.setSleepEveryCycle(true);
this.setSleepInterval(1000L);
this.myDirs.clear();
File topdir = new File(EnvExpander.expand(LrgsConfig.instance().edlIngestDirectory));
if (!topdir.isDirectory())
topdir.mkdirs();
this.addDirectory(topdir);
if (LrgsConfig.instance().edlIngestRecursive)
expand(myDirs.get(0));
doneDir = null;
if (LrgsConfig.instance().edlDoneDirectory != null
&& LrgsConfig.instance().edlDoneDirectory.trim().length() > 0)
{
String exp = EnvExpander.expand(LrgsConfig.instance().edlDoneDirectory.trim());
Logger.instance().info(module + " configuring with edlDoneDirecgtory='" +
LrgsConfig.instance().edlDoneDirectory + "' expanded='" + exp + "'");
doneDir = new File(exp);
if (!doneDir.isDirectory())
doneDir.mkdirs();
}
this.setFilenameFilter(null);
if (LrgsConfig.instance().edlFilenameSuffix != null
&& LrgsConfig.instance().edlFilenameSuffix.trim().length() > 0)
{
this.setFilenameFilter(
new FilenameFilter()
{
@Override
public boolean accept(File dir, String name)
{
return name.endsWith(LrgsConfig.instance().edlFilenameSuffix);
}
});
}
Logger.instance().debug1(module + " After configuration, there are " + myDirs.size()
+ " directories in the list.");
}
/**
* Recursively expand the top dir.
* @param dir
*/
private void expand(File dir)
{
File[] files = dir.listFiles();
for(int i=0; i