@Test public void testResize() throws Exception { final TransferQueue queue = new TransferQueue(1); final DownloadTransfer d1 = new DownloadTransfer(new Host(new TestProtocol()), new Path("/t1", EnumSet.of(Path.Type.directory)), null); final DownloadTransfer d2 = new DownloadTransfer(new Host(new TestProtocol()), new Path("/t2", EnumSet.of(Path.Type.directory)), null); queue.add(d1, new DisabledProgressListener()); final CountDownLatch c = new CountDownLatch(1); final AtomicBoolean set = new AtomicBoolean(); new Thread(new Runnable() { @Override public void run() { queue.add(d2, new DisabledProgressListener() { @Override public void message(final String message) { assertEquals("Maximum allowed connections exceeded. Waiting", message); set.set(true); } }); c.countDown(); } }).start(); assertEquals(1, c.getCount()); assertFalse(c.await(1, TimeUnit.SECONDS)); queue.resize(2); assertTrue(c.await(1, TimeUnit.SECONDS)); assertTrue(set.get()); }
public void resize(int newsize) { if(log.isDebugEnabled()) { log.debug(String.format("Resize queue to %d", newsize)); } final int drained = running.drainTo(temporary); if(log.isDebugEnabled()) { log.debug(String.format("Drained %d elements", drained)); } running.clear(); running = new ArrayBlockingQueue<Transfer>(newsize); this.poll(); }
TransferQueue { public void resize(int newsize) { if(log.isDebugEnabled()) { log.debug(String.format("Resize queue to %d", newsize)); } final int drained = running.drainTo(temporary); if(log.isDebugEnabled()) { log.debug(String.format("Drained %d elements", drained)); } running.clear(); running = new ArrayBlockingQueue<Transfer>(newsize); this.poll(); } }
TransferQueue { public void resize(int newsize) { if(log.isDebugEnabled()) { log.debug(String.format("Resize queue to %d", newsize)); } final int drained = running.drainTo(temporary); if(log.isDebugEnabled()) { log.debug(String.format("Drained %d elements", drained)); } running.clear(); running = new ArrayBlockingQueue<Transfer>(newsize); this.poll(); } TransferQueue();  TransferQueue(final int size); }
TransferQueue { public void resize(int newsize) { if(log.isDebugEnabled()) { log.debug(String.format("Resize queue to %d", newsize)); } final int drained = running.drainTo(temporary); if(log.isDebugEnabled()) { log.debug(String.format("Drained %d elements", drained)); } running.clear(); running = new ArrayBlockingQueue<Transfer>(newsize); this.poll(); } TransferQueue();  TransferQueue(final int size); void add(final Transfer t, final ProgressListener listener); void remove(final Transfer t); void resize(int newsize); }
TransferQueue { public void resize(int newsize) { if(log.isDebugEnabled()) { log.debug(String.format("Resize queue to %d", newsize)); } final int drained = running.drainTo(temporary); if(log.isDebugEnabled()) { log.debug(String.format("Drained %d elements", drained)); } running.clear(); running = new ArrayBlockingQueue<Transfer>(newsize); this.poll(); } TransferQueue();  TransferQueue(final int size); void add(final Transfer t, final ProgressListener listener); void remove(final Transfer t); void resize(int newsize);  }