lrgs.networkdcp.NetworkDcpStatusList 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!
/**
*
*/
package lrgs.networkdcp;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.TimeZone;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Element;
import ilex.xml.XmlOutputStream;
import ilex.util.Logger;
import lrgs.drgs.DrgsConnectCfg;
import lrgs.statusxml.StatusXmlTags;
import ilex.xml.DomHelper;
/**
* @author mjmaloney
*
*/
public class NetworkDcpStatusList
{
private ArrayList statusList =
new ArrayList();
private SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HHmmss");
public NetworkDcpStatusList()
{
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
}
public ArrayList getStatusList()
{
return statusList;
}
public NetworkDcpStatus getStatus(String host, int port)
{
for(NetworkDcpStatus nds : statusList)
if (host.equalsIgnoreCase(nds.getHost())
&& port == nds.getPort())
return nds;
NetworkDcpStatus nds = new NetworkDcpStatus(host, port);
statusList.add(nds);
//Logger.instance().info("Created new NetworkDcpStatus for host=" + host
//+ ", port=" + port);
return nds;
}
public void remove(String host, int port)
{
for(int i=0; i it = statusList.iterator();
it.hasNext(); )
{
NetworkDcpStatus nds = it.next();
Date d = nds.getLastPollAttempt();
if (nds.getPollingMinutes() > 0
&& d != null
&& System.currentTimeMillis() - d.getTime() > 30*24*3600*1000L)
it.remove();
}
try
{
xos.startElement(StatusXmlTags.networkDcpList);
for(NetworkDcpStatus nds : statusList)
{
xos.startElement(StatusXmlTags.networkDcp,
StatusXmlTags.host, nds.getHost(),
StatusXmlTags.port, ""+nds.getPort());
xos.writeElement(StatusXmlTags.displayName,
nds.getDisplayName());
xos.writeElement(StatusXmlTags.pollingMinutes,
""+nds.getPollingMinutes());
if (nds.getLastPollAttempt() != null)
xos.writeElement(StatusXmlTags.lastPollAttempt,
sdf.format(nds.getLastPollAttempt()));
if (nds.getLastContact() != null)
xos.writeElement(StatusXmlTags.lastContact,
sdf.format(nds.getLastContact()));
xos.writeElement(StatusXmlTags.numGoodPolls,
""+nds.getNumGoodPolls());
xos.writeElement(StatusXmlTags.numFailedPolls,
""+nds.getNumFailedPolls());
xos.writeElement(StatusXmlTags.numMessages,
""+nds.getNumMessages());
xos.endElement(StatusXmlTags.networkDcp);
}
xos.endElement(StatusXmlTags.networkDcpList);
}
catch(IOException iox)
{
Logger.instance().warning("Cannot save NetworkDcpList to XML: "
+ iox);
}
}
public synchronized void initFromXml(Element networkDcpListElem)
{
NodeList networkDcpNodeList = networkDcpListElem.getChildNodes();
if (networkDcpNodeList != null)
for(int i=0; i