X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=datarouter-node%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Fnode%2FDeliveryTask.java;h=7e10d5a0ce64ec3f1c3ec43cb4749438eae2a0a2;hb=a9002c0a305c1af016272deb9fc2e2ffd1160d55;hp=76bf04e2ac97e2bdf57d33c92892ff00f107fc12;hpb=8cbe8a88bc6dfe8673a33a017fe6a5a3e7ce86c3;p=dmaap%2Fdatarouter.git diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DeliveryTask.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DeliveryTask.java index 76bf04e2..7e10d5a0 100644 --- a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DeliveryTask.java +++ b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DeliveryTask.java @@ -38,7 +38,7 @@ import org.apache.log4j.Logger; * the file and its delivery data as well as to attempt delivery. */ public class DeliveryTask implements Runnable, Comparable { - private static Logger logger = Logger.getLogger("org.onap.dmaap.datarouter.node.DeliveryTask"); + private static Logger loggerDeliveryTask = Logger.getLogger("org.onap.dmaap.datarouter.node.DeliveryTask"); private DeliveryTaskHelper dth; private String pubid; private DestInfo di; @@ -56,36 +56,6 @@ public class DeliveryTask implements Runnable, Comparable { private int attempts; private String[][] hdrs; - /** - * Is the object a DeliveryTask with the same publication ID? - */ - public boolean equals(Object o) { - if (!(o instanceof DeliveryTask)) { - return (false); - } - return (pubid.equals(((DeliveryTask) o).pubid)); - } - - /** - * Compare the publication IDs. - */ - public int compareTo(DeliveryTask o) { - return (pubid.compareTo(o.pubid)); - } - - /** - * Get the hash code of the publication ID. - */ - public int hashCode() { - return (pubid.hashCode()); - } - - /** - * Return the publication ID. - */ - public String toString() { - return (pubid); - } /** * Create a delivery task for a given delivery queue and pub ID @@ -109,8 +79,8 @@ public class DeliveryTask implements Runnable, Comparable { boolean monly = di.isMetaDataOnly(); date = Long.parseLong(pubid.substring(0, pubid.indexOf('.'))); Vector hdrv = new Vector(); - try { - BufferedReader br = new BufferedReader(new FileReader(metafile)); + + try (BufferedReader br = new BufferedReader(new FileReader(metafile))) { String s = br.readLine(); int i = s.indexOf('\t'); method = s.substring(0, i); @@ -134,13 +104,42 @@ public class DeliveryTask implements Runnable, Comparable { } hdrv.add(new String[]{h, v}); } - br.close(); } catch (Exception e) { + loggerDeliveryTask.error("Exception "+e.getStackTrace(),e); } hdrs = hdrv.toArray(new String[hdrv.size()][]); url = dth.getDestURL(fileid); } + /** + * Is the object a DeliveryTask with the same publication ID? + */ + public boolean equals(Object o) { + if (!(o instanceof DeliveryTask)) { + return (false); + } + return (pubid.equals(((DeliveryTask) o).pubid)); + } + + /** + * Compare the publication IDs. + */ + public int compareTo(DeliveryTask o) { + return (pubid.compareTo(o.pubid)); + } + /** + * Get the hash code of the publication ID. + */ + public int hashCode() { + return (pubid.hashCode()); + } + + /** + * Return the publication ID. + */ + public String toString() { + return (pubid); + } /** * Get the publish ID */ @@ -186,12 +185,12 @@ public class DeliveryTask implements Runnable, Comparable { } catch (ProtocolException pe) { dth.reportDeliveryExtra(this, -1L); // Rcvd error instead of 100-continue + loggerDeliveryTask.error("Exception "+pe.getStackTrace(),pe); } if (os != null) { long sofar = 0; - try { + try (InputStream is = new FileInputStream(datafile)) { byte[] buf = new byte[1024 * 1024]; - InputStream is = new FileInputStream(datafile); while (sofar < length) { int i = buf.length; if (sofar + i > length) { @@ -204,7 +203,6 @@ public class DeliveryTask implements Runnable, Comparable { sofar += i; os.write(buf, 0, i); } - is.close(); os.close(); } catch (IOException ioe) { dth.reportDeliveryExtra(this, sofar); @@ -243,6 +241,7 @@ public class DeliveryTask implements Runnable, Comparable { } dth.reportStatus(this, rc, xpubid, rmsg); } catch (Exception e) { + loggerDeliveryTask.error("Exception "+e.getStackTrace(),e); dth.reportException(this, e); } }