@Test public void testPush() throws Exception { final int queueSize = 300; String id = "testPush"; FbQueue<String> queue = makeQueue(id, queueSize); for(int i = 0; i < queueSize * 3; ++i) { queue.push("<" + i + ">"); } Assert.assertEquals(queueSize, queue.size()); for(int i = queueSize * 2; i < queueSize * 3; ++i) { String poll = queue.poll(); Assert.assertEquals("<" + i + ">", poll); } String poll = queue.poll(); Assert.assertNull(poll); Assert.assertEquals(0, queue.size()); }
public void push(E e) { Assert.notNull(e, "element is null"); synchronized (lock) { int size = 0; QFileHandle<E> last = null; for(QFileHandle<E> fh: files) { size += fh.count(); last = fh; } while(size >= maxSize) { poll(); size--; } while(true) { if(last != null && last.offer(e)) { return; } last = allocate(last); } } }
FbQueue extends AbstractQueue<E> implements FileBased { public void push(E e) { Assert.notNull(e, "element is null"); synchronized (lock) { int size = 0; QFileHandle<E> last = null; for(QFileHandle<E> fh: files) { size += fh.count(); last = fh; } while(size >= maxSize) { poll(); size--; } while(true) { if(last != null && last.offer(e)) { return; } last = allocate(last); } } } }
FbQueue extends AbstractQueue<E> implements FileBased { public void push(E e) { Assert.notNull(e, "element is null"); synchronized (lock) { int size = 0; QFileHandle<E> last = null; for(QFileHandle<E> fh: files) { size += fh.count(); last = fh; } while(size >= maxSize) { poll(); size--; } while(true) { if(last != null && last.offer(e)) { return; } last = allocate(last); } } } private  FbQueue(Builder<E> b); }
FbQueue extends AbstractQueue<E> implements FileBased { public void push(E e) { Assert.notNull(e, "element is null"); synchronized (lock) { int size = 0; QFileHandle<E> last = null; for(QFileHandle<E> fh: files) { size += fh.count(); last = fh; } while(size >= maxSize) { poll(); size--; } while(true) { if(last != null && last.offer(e)) { return; } last = allocate(last); } } } private  FbQueue(Builder<E> b); String getId(); int getMaxSize(); int getMaxItemsInFile(); static Builder<E> builder(FbAdapter<E> adapter); @Override Iterator<E> iterator(); Iterator<E> iterator(int last); @Override int size(); @Override boolean offer(E e); void push(E e); @Override E poll(); @Override E peek(); @Override void close(); }
FbQueue extends AbstractQueue<E> implements FileBased { public void push(E e) { Assert.notNull(e, "element is null"); synchronized (lock) { int size = 0; QFileHandle<E> last = null; for(QFileHandle<E> fh: files) { size += fh.count(); last = fh; } while(size >= maxSize) { poll(); size--; } while(true) { if(last != null && last.offer(e)) { return; } last = allocate(last); } } } private  FbQueue(Builder<E> b); String getId(); int getMaxSize(); int getMaxItemsInFile(); static Builder<E> builder(FbAdapter<E> adapter); @Override Iterator<E> iterator(); Iterator<E> iterator(int last); @Override int size(); @Override boolean offer(E e); void push(E e); @Override E poll(); @Override E peek(); @Override void close();  }