Example usage for org.apache.commons.collections15 Buffer size

List of usage examples for org.apache.commons.collections15 Buffer size

Introduction

In this page you can find the example usage for org.apache.commons.collections15 Buffer size.

Prototype

int size();

Source Link

Document

Returns the number of elements in this collection.

Usage

From source file:edu.brown.benchmark.seats.SEATSClient.java

/**
 * Take an existing Reservation that we know is legit and randomly decide to 
 * either queue it for a later update or delete transaction 
 * @param r//from   w w  w  . j  a  v a2  s . c om
 */
protected void requeueReservation(Reservation r) {
    int idx = rng.nextInt(100);
    if (idx > 20)
        return;

    // Queue this motha trucka up for a deletin' or an updatin'
    CacheType ctype = null;
    if (rng.nextBoolean()) {
        ctype = CacheType.PENDING_DELETES;
    } else {
        ctype = CacheType.PENDING_UPDATES;
    }
    assert (ctype != null);

    Buffer<Reservation> cache = CACHE_RESERVATIONS.get(ctype);
    assert (cache != null);
    cache.add(r);
    if (debug.val)
        LOG.debug(String.format("Queued %s for %s [cacheSize=%d]\nFlightId: %d\nCustomerId: %d", r, ctype,
                cache.size(), r.flight_id, r.customer_id));
}

From source file:edu.brown.benchmark.seats.SEATSClient.java

protected Pair<Object[], ProcedureCallback> getNewReservationParams() {
    Reservation reservation = null;/*from   www.  j av a2 s.  c  o m*/
    BitSet seats = null;
    Buffer<Reservation> cache = CACHE_RESERVATIONS.get(CacheType.PENDING_INSERTS);
    assert (cache != null) : "Unexpected " + CacheType.PENDING_INSERTS;

    if (debug.val)
        LOG.debug(String.format("Attempting to get a new pending insert Reservation [totalPendingInserts=%d]",
                cache.size()));
    while (reservation == null) {
        Reservation r = null;
        synchronized (cache) {
            if (cache.isEmpty() == false)
                r = cache.remove();
        } // SYNCH
        if (r == null) {
            if (debug.val)
                LOG.warn("Unable to execute " + Transaction.DELETE_RESERVATION
                        + " - No available reservations to insert");
            break;
        }

        seats = this.getSeatsBitSet(r.flight_id);

        if (this.isFlightFull(seats)) {
            if (debug.val)
                LOG.debug(String.format("%s is full", r.flight_id));
            continue;
        }
        // PAVLO: Not sure why this is always coming back as reserved? 
        //            else if (seats.get(r.seatnum)) {
        //                if (debug.val)
        //                    LOG.debug(String.format("Seat #%d on %s is already booked", r.seatnum, r.flight_id));
        //                continue;
        //            }
        else if (this.isCustomerBookedOnFlight(r.customer_id, r.flight_id)) {
            if (debug.val)
                LOG.debug(String.format("%s is already booked on %s", r.customer_id, r.flight_id));
            continue;
        }
        reservation = r;
    } // WHILE
    if (reservation == null) {
        if (debug.val)
            LOG.debug("Failed to find a valid pending insert Reservation\n" + this.toString());
        return (null);
    }

    // Generate a random price for now
    double price = 2.0 * rng.number(SEATSConstants.RESERVATION_PRICE_MIN, SEATSConstants.RESERVATION_PRICE_MAX);

    // Generate random attributes
    long attributes[] = new long[SEATSConstants.NEW_RESERVATION_ATTRS_SIZE];
    for (int i = 0; i < attributes.length; i++) {
        attributes[i] = rng.nextLong();
    } // FOR

    // boolean updateCustomer = (rng.nextInt(100) < SEATSConstants.PROB_UPDATE_CUSTOMER_NEW_RESERVATION);

    Object params[] = new Object[] { reservation.id, reservation.customer_id, reservation.flight_id,
            reservation.seatnum, price, attributes, new TimestampType() };
    if (trace.val)
        LOG.trace("Calling " + Transaction.NEW_RESERVATION.getExecName());
    return new Pair<Object[], ProcedureCallback>(params, new NewReservationCallback(reservation));
}