Package com.leansoft.bigqueue

Examples of com.leansoft.bigqueue.IBigQueue


public class BigQueueTutorial {

  @Test
  public void demo() throws IOException {
   
    IBigQueue bigQueue = null;
   
    try {
      // create a new big queue
      bigQueue = new BigQueueImpl("d:/bigqueue/tutorial", "demo");
       
      // ensure the new big queue is empty
      assertNotNull(bigQueue);
      assertTrue(bigQueue.size() == 0);
      assertTrue(bigQueue.isEmpty());
      assertNull(bigQueue.dequeue());
      assertNull(bigQueue.peek());
     
      // enqueue some items
      for(int i = 0; i < 10; i++) {
        String item = String.valueOf(i);
        bigQueue.enqueue(item.getBytes());
      }
      // now the big queue is not empty
      assertTrue(!bigQueue.isEmpty());
      assertTrue(bigQueue.size() == 10);
     
      // peek the front of the queue
      assertEquals(String.valueOf(0), new String(bigQueue.peek()));
     
      // dequeue some items
      for(int i = 0; i < 5; i++) {
        String item = new String(bigQueue.dequeue());
        assertEquals(String.valueOf(i), item);
      }
      // the big queue is not empty yet
      assertTrue(!bigQueue.isEmpty());
      assertTrue(bigQueue.size() == 5);
     
      // dequeue all remaining items
      while(true) {
        byte[] data = bigQueue.dequeue();
        if (data == null) break;
      }
      // now the big is empty since all items have been dequeued
      assertTrue(bigQueue.isEmpty());
     
    } finally {
      // release resources
      bigQueue.close();
    }
  }
View Full Code Here

TOP

Related Classes of com.leansoft.bigqueue.IBigQueue

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.