当前位置: 首页>>代码示例>>Java>>正文


Java Buffer类代码示例

本文整理汇总了Java中org.apache.commons.collections15.Buffer的典型用法代码示例。如果您正苦于以下问题:Java Buffer类的具体用法?Java Buffer怎么用?Java Buffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Buffer类属于org.apache.commons.collections15包,在下文中一共展示了Buffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: requeueReservation

import org.apache.commons.collections15.Buffer; //导入依赖的package包/类
/**
 * 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
 */
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));
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:27,代码来源:SEATSClient.java

示例2: testBlockedGetWithAdd

import org.apache.commons.collections15.Buffer; //导入依赖的package包/类
/**
 * Tests {@link BlockingBuffer#get()} in combination with {@link BlockingBuffer#add()} using multiple read threads.
 * <p/>
 * Two read threads should block on an empty buffer until one object
 * is added then both threads should complete.
 */
public void testBlockedGetWithAdd() {

    Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer());
    Object obj = new Object();
    
    // run methods will get and compare -- must wait for add
    Thread thread1 = new ReadThread(blockingBuffer, obj);
    Thread thread2 = new ReadThread(blockingBuffer, obj);
    thread1.start();
    thread2.start();
    
    // give hungry read threads ample time to hang
    delay();
       
    // notifyAll should allow both read threads to complete
    blockingBuffer.add(obj);
    
    // allow notified threads to complete 
    delay();
    
    // There should not be any threads waiting.
    if (thread1.isAlive() || thread2.isAlive())
        fail("Live thread(s) when both should be dead.");
}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:31,代码来源:TestBlockingBuffer.java

示例3: testBlockedGetWithAddAll

import org.apache.commons.collections15.Buffer; //导入依赖的package包/类
/**
 * Tests {@link BlockingBuffer#get()} in combination with {@link BlockingBuffer#addAll()} using multiple read threads.
 * <p/>
 * Two read threads should block on an empty buffer until a
 * singleton is added then both threads should complete.
 */
public void testBlockedGetWithAddAll() {

    Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer());
    Object obj = new Object();
    
    // run methods will get and compare -- must wait for addAll
    Thread thread1 = new ReadThread(blockingBuffer, obj);
    Thread thread2 = new ReadThread(blockingBuffer, obj);
    thread1.start();
    thread2.start();
    
    // give hungry read threads ample time to hang
    delay();
       
    // notifyAll should allow both read threads to complete
    blockingBuffer.addAll(Collections.singleton(obj));
           
    // allow notified threads to complete 
    delay();
    
    // There should not be any threads waiting.
    if (thread1.isAlive() || thread2.isAlive())
        fail("Live thread(s) when both should be dead.");
}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:31,代码来源:TestBlockingBuffer.java

示例4: testInterruptedGet

import org.apache.commons.collections15.Buffer; //导入依赖的package包/类
/**
 * Tests interrupted {@link BlockingBuffer#get()}.
 */
public void testInterruptedGet() {

    Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer());
    Object obj = new Object();
    
    // spawn a read thread to wait on the empty buffer
    ArrayList exceptionList = new ArrayList();
    Thread thread = new ReadThread(blockingBuffer, obj, exceptionList);
    thread.start();
    
    // Interrupting the thread should cause it to throw BufferUnderflowException
    thread.interrupt();
    
    // Chill, so thread can throw and add message to exceptionList
    delay();

    assertTrue("Thread interrupt should have led to underflow", exceptionList.contains("BufferUnderFlow"));

    if (thread.isAlive()) {
        fail("Read thread has hung.");
    }

}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:27,代码来源:TestBlockingBuffer.java

示例5: testInterruptedRemove

import org.apache.commons.collections15.Buffer; //导入依赖的package包/类
/**
 * Tests interrupted remove.
 */
public void testInterruptedRemove() {

    Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer());
    Object obj = new Object();
    
    // spawn a read thread to wait on the empty buffer
    ArrayList exceptionList = new ArrayList();
    Thread thread = new ReadThread(blockingBuffer, obj, exceptionList, "remove");
    thread.start();
    
    // Interrupting the thread should cause it to throw BufferUnderflowException
    thread.interrupt();
    
    // Chill, so thread can throw and add message to exceptionList
    delay();

    assertTrue("Thread interrupt should have led to underflow", exceptionList.contains("BufferUnderFlow"));

    if (thread.isAlive()) {
        fail("Read thread has hung.");
    }

}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:27,代码来源:TestBlockingBuffer.java

示例6: testCircularFifoBufferCircular

import org.apache.commons.collections15.Buffer; //导入依赖的package包/类
/**
 * Tests that the removal operation actually removes the first element.
 */
public void testCircularFifoBufferCircular() {
    List list = new ArrayList();
    list.add("A");
    list.add("B");
    list.add("C");
    Buffer buf = new CircularFifoBuffer(list);

    assertEquals(true, buf.contains("A"));
    assertEquals(true, buf.contains("B"));
    assertEquals(true, buf.contains("C"));

    buf.add("D");

    assertEquals(false, buf.contains("A"));
    assertEquals(true, buf.contains("B"));
    assertEquals(true, buf.contains("C"));
    assertEquals(true, buf.contains("D"));

    assertEquals("B", buf.get());
    assertEquals("B", buf.remove());
    assertEquals("C", buf.remove());
    assertEquals("D", buf.remove());
}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:27,代码来源:TestCircularFifoBuffer.java

示例7: clearCache

import org.apache.commons.collections15.Buffer; //导入依赖的package包/类
protected final void clearCache() {
    for (BitSet seats : CACHE_BOOKED_SEATS.values()) {
        seats.clear();
    } // FOR
    for (Buffer<Reservation> queue : CACHE_RESERVATIONS.values()) {
        queue.clear();
    } // FOR
    for (Set<Long> f_ids : CACHE_CUSTOMER_BOOKED_FLIGHTS.values()) {
        synchronized (f_ids) {
            f_ids.clear();
        } // SYNCH
    } // FOR
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:14,代码来源:SEATSClient.java

示例8: testTransformedBuffer

import org.apache.commons.collections15.Buffer; //导入依赖的package包/类
public void testTransformedBuffer() {
    Buffer buffer = TransformedBuffer.decorate(new ArrayStack(), TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER);
    assertEquals(0, buffer.size());
    Object[] els = new Object[]{"1", "3", "5", "7", "2", "4", "6"};
    for (int i = 0; i < els.length; i++) {
        buffer.add(els[i]);
        assertEquals(i + 1, buffer.size());
        assertEquals(true, buffer.contains(new Integer((String) els[i])));
        assertEquals(false, buffer.contains(els[i]));
    }

    assertEquals(false, buffer.remove(els[0]));
    assertEquals(true, buffer.remove(new Integer((String) els[0])));

}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:16,代码来源:TestTransformedBuffer.java

示例9: testGetWithAdd

import org.apache.commons.collections15.Buffer; //导入依赖的package包/类
/**
 * Tests {@link BlockingBuffer#get()} in combination with {@link BlockingBuffer#add()}.
 */
public void testGetWithAdd() {

    Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer());
    Object obj = new Object();

    new DelayedAdd(blockingBuffer, obj).start();

    // verify does not throw BufferUnderflowException; should block until other thread has added to the buffer .
    assertSame(obj, blockingBuffer.get());
}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:14,代码来源:TestBlockingBuffer.java

示例10: testGetWithAddAll

import org.apache.commons.collections15.Buffer; //导入依赖的package包/类
/**
 * Tests {@link BlockingBuffer#get()} in combination with {@link BlockingBuffer#addAll()}.
 */
public void testGetWithAddAll() {

    Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer());
    Object obj = new Object();

    new DelayedAddAll(blockingBuffer, obj).start();

    // verify does not throw BufferUnderflowException; should block until other thread has added to the buffer .
    assertSame(obj, blockingBuffer.get());
}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:14,代码来源:TestBlockingBuffer.java

示例11: testRemoveWithAdd

import org.apache.commons.collections15.Buffer; //导入依赖的package包/类
/**
 * Tests {@link BlockingBuffer#remove()} in combination with {@link BlockingBuffer#add()}.
 */
public void testRemoveWithAdd() {

    Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer());
    Object obj = new Object();

    new DelayedAdd(blockingBuffer, obj).start();

    // verify does not throw BufferUnderflowException; should block until other thread has added to the buffer .
    assertSame(obj, blockingBuffer.remove());
}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:14,代码来源:TestBlockingBuffer.java

示例12: testRemoveWithAddAll

import org.apache.commons.collections15.Buffer; //导入依赖的package包/类
/**
 * Tests {@link BlockingBuffer#remove()} in combination with {@link BlockingBuffer#addAll()}.
 */
public void testRemoveWithAddAll() {

    Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer());
    Object obj = new Object();

    new DelayedAddAll(blockingBuffer, obj).start();

    // verify does not throw BufferUnderflowException; should block until other thread has added to the buffer .
    assertSame(obj, blockingBuffer.remove());
}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:14,代码来源:TestBlockingBuffer.java

示例13: testBlockedRemoveWithAdd

import org.apache.commons.collections15.Buffer; //导入依赖的package包/类
/**
 * Tests {@link BlockingBuffer#remove()} in combination with {@link BlockingBuffer#add()} using multiple read threads.
 * <p/>
 * Two read threads should block on an empty buffer until one
 * object is added then one thread should complete. The remaining
 * thread should complete after the addition of a second object.
 */
public void testBlockedRemoveWithAdd() {

    Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer());
    Object obj = new Object();
    
    // run methods will remove and compare -- must wait for add
    Thread thread1 = new ReadThread(blockingBuffer, obj, null, "remove");
    Thread thread2 = new ReadThread(blockingBuffer, obj, null, "remove");
    thread1.start();
    thread2.start();
    
    // give hungry read threads ample time to hang
    delay();

    blockingBuffer.add(obj);
    
    // allow notified threads to complete 
    delay();
    
    // There should be one thread waiting.
    assertTrue("There is one thread waiting", thread1.isAlive() ^ thread2.isAlive());

    blockingBuffer.add(obj);
    
    // allow notified thread to complete 
    delay();

    // There should not be any threads waiting.
    if (thread1.isAlive() || thread2.isAlive())
        fail("Live thread(s) when both should be dead.");
}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:39,代码来源:TestBlockingBuffer.java

示例14: testBlockedRemoveWithAddAll1

import org.apache.commons.collections15.Buffer; //导入依赖的package包/类
/**
 * Tests {@link BlockingBuffer#remove()} in combination with {@link BlockingBuffer#addAll()} using multiple read threads.
 * <p/>
 * Two read threads should block on an empty buffer until a
 * singleton collection is added then one thread should
 * complete. The remaining thread should complete after the
 * addition of a second singleton.
 */
public void testBlockedRemoveWithAddAll1() {

    Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer());
    Object obj = new Object();
    
    // run methods will remove and compare -- must wait for addAll
    Thread thread1 = new ReadThread(blockingBuffer, obj, null, "remove");
    Thread thread2 = new ReadThread(blockingBuffer, obj, null, "remove");
    thread1.start();
    thread2.start();
    
    // give hungry read threads ample time to hang
    delay();

    blockingBuffer.addAll(Collections.singleton(obj));
    
    // allow notified threads to complete 
    delay();
    
    // There should be one thread waiting.
    assertTrue("There is one thread waiting", thread1.isAlive() ^ thread2.isAlive());

    blockingBuffer.addAll(Collections.singleton(obj));
    
    // allow notified thread to complete 
    delay();

    // There should not be any threads waiting.
    if (thread1.isAlive() || thread2.isAlive())
        fail("Live thread(s) when both should be dead.");
}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:40,代码来源:TestBlockingBuffer.java

示例15: testBlockedRemoveWithAddAll2

import org.apache.commons.collections15.Buffer; //导入依赖的package包/类
/**
 * Tests {@link BlockingBuffer#remove()} in combination with {@link BlockingBuffer#addAll()} using multiple read threads.
 * <p/>
 * Two read threads should block on an empty buffer until a
 * collection with two distinct objects is added then both
 * threads should complete. Each thread should have read a
 * different object.
 */
public void testBlockedRemoveWithAddAll2() {

    Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer());
    Object obj1 = new Object();
    Object obj2 = new Object();

    Set objs = Collections.synchronizedSet(new HashSet());
    objs.add(obj1);
    objs.add(obj2);

    // run methods will remove and compare -- must wait for addAll
    Thread thread1 = new ReadThread(blockingBuffer, objs, "remove");
    Thread thread2 = new ReadThread(blockingBuffer, objs, "remove");
    thread1.start();
    thread2.start();
    
    // give hungry read threads ample time to hang
    delay();

    blockingBuffer.addAll(objs);
    
    // allow notified threads to complete 
    delay();

    assertEquals("Both objects were removed", 0, objs.size());

    // There should not be any threads waiting.
    if (thread1.isAlive() || thread2.isAlive())
        fail("Live thread(s) when both should be dead.");
}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:39,代码来源:TestBlockingBuffer.java


注:本文中的org.apache.commons.collections15.Buffer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。