org.apache.commons.lang3.concurrent.TimedSemaphore Java Examples

The following examples show how to use org.apache.commons.lang3.concurrent.TimedSemaphore. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SqlManager.java    From ReplicaDB with Apache License 2.0 6 votes vote down vote up
/**
 * Create a bandwith cap, estimating the size of the first row returned by the resultset
 * and using it as permits in the rate limit.
 *
 * @param resultSet the resultset cursor moved to the first row (resultSet.next())
 * @param rsmd      the result set metadata object
 * @throws SQLException
 */
protected void bandwidthThrottlingCreate(ResultSet resultSet, ResultSetMetaData rsmd) throws SQLException {
    int kilobytesPerSecond = options.getBandwidthThrottling();

    if (kilobytesPerSecond > 0) {
        // Stimate the Row Size
        for (int i = 1; i <= rsmd.getColumnCount(); i++) {

            if (rsmd.getColumnType(i) != Types.BLOB) {
                String columnValue = resultSet.getString(i);
                if (columnValue != null && !resultSet.getString(i).isEmpty())
                    rowSize = rowSize + resultSet.getString(i).length();
            }
        }

        double limit = ((1.0 * kilobytesPerSecond) / rowSize) / (options.getFetchSize() * 1.0 / 1000);
        if (limit == 0) limit = 1;
        this.bandwidthRateLimiter = new TimedSemaphore(1, TimeUnit.SECONDS, (int) Math.round(limit));

        LOG.info("Estimated Row Size: {} KB. Estimated limit of fetchs per second: {} ", rowSize, limit);


    }
}
 
Example #2
Source File: LimitedRendezvousListener.java    From cyberduck with GNU General Public License v3.0 4 votes vote down vote up
public LimitedRendezvousListener(final Set<RendezvousListener> listeners) {
    this(new TimedSemaphore(
            1L, TimeUnit.MINUTES, PreferencesFactory.get().getInteger("rendezvous.notification.limit")), listeners);
}
 
Example #3
Source File: LimitedRendezvousListener.java    From cyberduck with GNU General Public License v3.0 4 votes vote down vote up
public LimitedRendezvousListener(final TimedSemaphore limit, final Set<RendezvousListener> listeners) {
    this.limit = limit;
    this.listeners = listeners;
}
 
Example #4
Source File: DelayQueueUsingTimedSemaphore.java    From tutorials with MIT License 4 votes vote down vote up
DelayQueueUsingTimedSemaphore(long period, int slotLimit) {
    semaphore = new TimedSemaphore(period, TimeUnit.SECONDS, slotLimit);
}