com.datasift.dropwizard.hbase.util.PermitReleasingCallback Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dropwizard-extra-hbase Show documentation
Show all versions of dropwizard-extra-hbase Show documentation
Dropwizard integration for working with HBase in Scala.
package com.datasift.dropwizard.hbase.util;
import com.stumbleupon.async.Callback;
import java.util.concurrent.Semaphore;
/**
* A {@link Callback} that releases a permit on a given {@link Semaphore}.
*/
public class PermitReleasingCallback implements Callback {
/**
* The {@link Semaphore} to release the permit to.
*/
private final Semaphore semaphore;
/**
* Creates a new {@link Callback} that releases a permit on the given semaphore on completion.
*
* @param semaphore the {@link Semaphore} to release the permit to on completion.
*/
public PermitReleasingCallback(final Semaphore semaphore) {
this.semaphore = semaphore;
}
/**
* Releases a permit to the registered {@link Semaphore} and proxies any argument through
* verbatim.
*
* @param arg the argument (if any) to pass-through.
*
* @return the argument (if any), returned verbatim.
*
* @throws Exception if an error occurs releasing the permit to the {@link Semaphore}.
*/
public T call(final T arg) throws Exception {
semaphore.release();
return arg;
}
}