ContentOutputThread.java

  1. package gov.usgs.earthquake.product.io;

  2. import java.util.logging.Level;
  3. import java.util.logging.Logger;

  4. import gov.usgs.earthquake.product.Content;
  5. import gov.usgs.earthquake.product.ProductId;

  6. /**
  7.  * Deliver content in a separate thread.
  8.  */
  9. public class ContentOutputThread extends Thread {

  10.     private static final Logger LOGGER = Logger
  11.             .getLogger(ContentOutputThread.class.getName());

  12.     private final ProductHandler handler;
  13.     private final ProductId id;
  14.     private final String path;
  15.     private final Content content;

  16.     /**
  17.      * Constructor
  18.      * @param handler A product handler
  19.      * @param id A product ID
  20.      * @param path String path
  21.      * @param content Content
  22.      */
  23.     public ContentOutputThread(final ProductHandler handler,
  24.             final ProductId id, final String path, final Content content) {
  25.         this.handler = handler;
  26.         this.id = id;
  27.         this.path = path;
  28.         this.content = content;
  29.     }

  30.     @Override
  31.     public void run() {
  32.         try {
  33.             handler.onContent(id, path, content);
  34.         } catch (Exception e) {
  35.             LOGGER.log(Level.WARNING, "Exception delivering content '" + path
  36.                     + "'", e);
  37.         } finally {
  38.             content.close();
  39.         }
  40.     }

  41. }