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

com.datasift.dropwizard.hbase.util.PermitReleasingCallback Maven / Gradle / Ivy

There is a newer version: 0.7.1-1
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy