All Downloads are FREE. Search and download functionalities are using the official Maven repository.

xapi.util.impl.RemovesMultiHandlers Maven / Gradle / Ivy

Go to download

Everything needed to run a comprehensive dev environment. Just type X_ and pick a service from autocomplete; new dev modules will be added as they are built. The only dev service not included in the uber jar is xapi-dev-maven, as it includes all runtime dependencies of maven, adding ~4 seconds to build time, and 6 megabytes to the final output jar size (without xapi-dev-maven, it's ~1MB).

The newest version!
package xapi.util.impl;

import xapi.collect.api.Fifo;
import xapi.collect.impl.SimpleFifo;
import xapi.util.api.RemovalHandler;

/**
 * Handy wrapper class for bundling multiple RemovesHandlers into a single callback.
 *
 * Most often used to combie multiple RemovalHandler objects into a single returned object.
 *
 * @author James X. Nelson ([email protected], @james)
 *
 */
public class RemovesMultiHandlers implements RemovalHandler{

  private final Fifo handles;
  public RemovesMultiHandlers() {
    // we by default use the simple, concurrent fifo, to avoid dependency
    // on the injection library too early in our module structure
    handles = new SimpleFifo();
  }

  @Override
  public void remove() {
    while(!handles.isEmpty()){
      RemovalHandler handle = handles.take();
      handle.remove();
    }
  }
  /**
   * Push a handler onto our callback stack
   *
   * @param handle - Handler to be called on remove
   * @return - this, for chaining
   */
  public RemovesMultiHandlers addHandler(RemovalHandler handle){
    handles.give(handle);
    return this;
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy