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

org.cometd.javascript.Latch Maven / Gradle / Ivy

package org.cometd.javascript;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import org.mozilla.javascript.ScriptableObject;

/**
 * @version $Revision: 1036 $ $Date: 2010-03-22 18:17:18 +0100 (Mon, 22 Mar 2010) $
 */
public class Latch extends ScriptableObject
{
    private volatile CountDownLatch latch;

    public String getClassName()
    {
        return "Latch";
    }

    public void jsConstructor(int count)
    {
        reset(count);
    }

    public void reset(int count)
    {
        latch = new CountDownLatch(count);
    }

    public boolean await(long timeout) throws InterruptedException
    {
        return latch.await(timeout, TimeUnit.MILLISECONDS);
    }

    public void jsFunction_countDown()
    {
        latch.countDown();
    }

    public long jsGet_count()
    {
        return latch.getCount();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy