DefaultStorageListener.java

  1. package gov.usgs.earthquake.distribution;

  2. import gov.usgs.util.Config;
  3. import gov.usgs.util.DefaultConfigurable;

  4. import java.util.logging.Level;
  5. import java.util.logging.Logger;

  6. public class DefaultStorageListener extends DefaultConfigurable implements
  7.         StorageListener {

  8.     private static final Logger LOGGER = Logger
  9.             .getLogger(DefaultStorageListener.class.getName());

  10.     @Override
  11.     public void configure(Config arg0) throws Exception {
  12.         // Nothing to do for default configure
  13.     }

  14.     @Override
  15.     public void shutdown() throws Exception {
  16.         // Nothing to do for default shutdown
  17.     }

  18.     @Override
  19.     public void startup() throws Exception {
  20.         // Nothing to do for default startup
  21.     }

  22.     /**
  23.      * Simple dispatch method for listeners who are only interested in certain
  24.      * types of <code>StorageEvent</code>s.
  25.      *
  26.      * @param event
  27.      *            The event that triggered the call
  28.      */
  29.     @Override
  30.     public void onStorageEvent(StorageEvent event) {
  31.         StorageEvent.StorageEventType type = event.getType();
  32.         try {
  33.             if (type == StorageEvent.PRODUCT_STORED) {
  34.                 onProductStored(event);
  35.             } else if (type == StorageEvent.PRODUCT_REMOVED) {
  36.                 onProductRemoved(event);
  37.             }
  38.         } catch (Exception e) {
  39.             LOGGER.log(Level.WARNING, "[" + getName() + "] exception processing storage event", e);
  40.         }
  41.     }

  42.     /**
  43.      * Dispatched method called when the type of event is
  44.      * <code>StorageEvent.StorageEventType.PRODUCT_STORED</code>.
  45.      *
  46.      * @param event The event that triggered the call
  47.      * @throws Exception if error occurs
  48.      */
  49.     public void onProductStored(StorageEvent event) throws Exception {
  50.         LOGGER.info("onProductStored::" + event.getProductId().toString());
  51.     }

  52.     /**
  53.      * Dispatched method called when the type of event is
  54.      * <code>StorageEvent.StorageEventType.PRODUCT_REMOVED</code>.
  55.      *
  56.      * @param event The event that triggered the call
  57.      * @throws Exception if error occurs
  58.      */
  59.     public void onProductRemoved(StorageEvent event) throws Exception {
  60.         LOGGER.info("onProductRemoved::" + event.getProductId().toString());
  61.     }

  62. }