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

com.amazonaws.services.kinesis.leases.impl.GenericLeaseSelector Maven / Gradle / Ivy

Go to download

The Amazon Kinesis Client Library for Java enables Java developers to easily consume and process data from Amazon Kinesis.

There is a newer version: 1.15.2
Show newest version
package com.amazonaws.services.kinesis.leases.impl;

import com.amazonaws.services.kinesis.leases.interfaces.LeaseSelector;

import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * GenericLeaseSelector abstracts away the lease selection logic from the application code that's using leasing.
 * It owns filtering of the leases to be taken.
 */
public class GenericLeaseSelector implements LeaseSelector {

    /**
     * Provides the list of leases to be taken.
     * @param expiredLeases list of leases that are currently expired
     * @param numLeasesToReachTarget the number of leases to be taken
     * @return
     */
    @Override
    public Set getLeasesToTakeFromExpiredLeases(List expiredLeases, int numLeasesToReachTarget) {
        Set leasesToTake = new HashSet();

        // If we have expired leases, get up to  leases from expiredLeases
        for (; numLeasesToReachTarget > 0 && expiredLeases.size() > 0; numLeasesToReachTarget--) {
            leasesToTake.add(expiredLeases.remove(0));
        }

        return leasesToTake;
    }

    /**
     * Provides the number of leases that should be taken by the worker.
     * @param allLeases list of all existing leases
     * @return
     */
    @Override
    public int getLeaseCountThatCanBeTaken(Collection allLeases) {
        return allLeases.size();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy