EIDSProductReceiver.java

  1. /*
  2.  * EIDSProductReceiver
  3.  */
  4. package gov.usgs.earthquake.eids;

  5. import gov.usgs.earthquake.distribution.EIDSNotificationReceiver;
  6. import gov.usgs.earthquake.distribution.Notification;
  7. import gov.usgs.earthquake.distribution.ProductSender;
  8. import gov.usgs.earthquake.eidsutil.EIDSMessageEvent;
  9. import gov.usgs.earthquake.product.Product;
  10. import gov.usgs.earthquake.product.io.ObjectProductSource;
  11. import gov.usgs.util.Config;

  12. /**
  13.  * Wrap EIDSProductBuilder in NotificationReceiver interface.
  14.  */
  15. public class EIDSProductReceiver extends EIDSNotificationReceiver {

  16.     /** The EIDS builder. */
  17.     private EIDSProductBuilder builder;

  18.     /**
  19.      * Construct a new EIDSProductReceiver.
  20.      *
  21.      * Uses the Configurable interface, see EIDSNotificationReceiver.
  22.      */
  23.     public EIDSProductReceiver() {
  24.         builder = new EIDSProductBuilder();

  25.         // add a product sender that sends to this receiver
  26.         builder.addProductSender(new ProductSender() {

  27.             @Override
  28.             public void configure(Config arg0) throws Exception {
  29.             }

  30.             @Override
  31.             public void shutdown() throws Exception {
  32.             }

  33.             @Override
  34.             public void startup() throws Exception {
  35.             }

  36.             @Override
  37.             public void sendProduct(Product product) throws Exception {
  38.                 // forward built products to receiver
  39.                 Notification notification = storeProductSource(new ObjectProductSource(
  40.                         product));
  41.                 receiveNotification(notification);
  42.             }

  43.             @Override
  44.             public String getName() {
  45.                 return null;
  46.             }

  47.             @Override
  48.             public void setName(String arg0) {
  49.             }
  50.         });
  51.     }

  52.     /**
  53.      * Receive messages from the EIDSNotificationReceiver EIDS Client.s
  54.      *
  55.      * Forwards messages to builder, which sends built products to
  56.      * receiveNotification method.
  57.      */
  58.     public void onEIDSMessage(EIDSMessageEvent event) {
  59.         // forward eids messages to builder
  60.         builder.onEIDSMessage(event);
  61.     }

  62.     @Override
  63.     public void configure(final Config config) throws Exception {
  64.         super.configure(config);

  65.         // load builder configuration properties too
  66.         builder.configure(config);
  67.     }
  68. }