@Test public void testTryWithResourceNoThrottle() throws Exception { LearnerSnapshotThrottler throttler = new LearnerSnapshotThrottler(1); for (int i = 0; i < 3; i++) { LearnerSnapshot snapshot = throttler.beginSnapshot(false); try { Assert.assertFalse(snapshot.isEssential()); Assert.assertEquals(1, snapshot.getConcurrentSnapshotNumber()); } finally { snapshot.close(); } } }
public LearnerSnapshot beginSnapshot(boolean essential) throws SnapshotThrottleException, InterruptedException { int snapshotNumber; synchronized (snapCountSyncObject) { if (!essential && timeoutMillis > 0 && snapsInProgress >= maxConcurrentSnapshots) { long timestamp = Time.currentElapsedTime(); do { snapCountSyncObject.wait(timeoutMillis); } while (snapsInProgress >= maxConcurrentSnapshots && timestamp + timeoutMillis < Time.currentElapsedTime()); } if (essential || snapsInProgress < maxConcurrentSnapshots) { snapsInProgress++; snapshotNumber = snapsInProgress; } else { throw new SnapshotThrottleException(snapsInProgress + 1, maxConcurrentSnapshots); } } return new LearnerSnapshot(this, snapshotNumber, essential); }
LearnerSnapshotThrottler { public LearnerSnapshot beginSnapshot(boolean essential) throws SnapshotThrottleException, InterruptedException { int snapshotNumber; synchronized (snapCountSyncObject) { if (!essential && timeoutMillis > 0 && snapsInProgress >= maxConcurrentSnapshots) { long timestamp = Time.currentElapsedTime(); do { snapCountSyncObject.wait(timeoutMillis); } while (snapsInProgress >= maxConcurrentSnapshots && timestamp + timeoutMillis < Time.currentElapsedTime()); } if (essential || snapsInProgress < maxConcurrentSnapshots) { snapsInProgress++; snapshotNumber = snapsInProgress; } else { throw new SnapshotThrottleException(snapsInProgress + 1, maxConcurrentSnapshots); } } return new LearnerSnapshot(this, snapshotNumber, essential); } }
LearnerSnapshotThrottler { public LearnerSnapshot beginSnapshot(boolean essential) throws SnapshotThrottleException, InterruptedException { int snapshotNumber; synchronized (snapCountSyncObject) { if (!essential && timeoutMillis > 0 && snapsInProgress >= maxConcurrentSnapshots) { long timestamp = Time.currentElapsedTime(); do { snapCountSyncObject.wait(timeoutMillis); } while (snapsInProgress >= maxConcurrentSnapshots && timestamp + timeoutMillis < Time.currentElapsedTime()); } if (essential || snapsInProgress < maxConcurrentSnapshots) { snapsInProgress++; snapshotNumber = snapsInProgress; } else { throw new SnapshotThrottleException(snapsInProgress + 1, maxConcurrentSnapshots); } } return new LearnerSnapshot(this, snapshotNumber, essential); } LearnerSnapshotThrottler(int maxConcurrentSnapshots,
                                    long timeoutMillis);  LearnerSnapshotThrottler(int maxConcurrentSnapshots); }
LearnerSnapshotThrottler { public LearnerSnapshot beginSnapshot(boolean essential) throws SnapshotThrottleException, InterruptedException { int snapshotNumber; synchronized (snapCountSyncObject) { if (!essential && timeoutMillis > 0 && snapsInProgress >= maxConcurrentSnapshots) { long timestamp = Time.currentElapsedTime(); do { snapCountSyncObject.wait(timeoutMillis); } while (snapsInProgress >= maxConcurrentSnapshots && timestamp + timeoutMillis < Time.currentElapsedTime()); } if (essential || snapsInProgress < maxConcurrentSnapshots) { snapsInProgress++; snapshotNumber = snapsInProgress; } else { throw new SnapshotThrottleException(snapsInProgress + 1, maxConcurrentSnapshots); } } return new LearnerSnapshot(this, snapshotNumber, essential); } LearnerSnapshotThrottler(int maxConcurrentSnapshots,
                                    long timeoutMillis);  LearnerSnapshotThrottler(int maxConcurrentSnapshots); LearnerSnapshot beginSnapshot(boolean essential); void endSnapshot(); }
LearnerSnapshotThrottler { public LearnerSnapshot beginSnapshot(boolean essential) throws SnapshotThrottleException, InterruptedException { int snapshotNumber; synchronized (snapCountSyncObject) { if (!essential && timeoutMillis > 0 && snapsInProgress >= maxConcurrentSnapshots) { long timestamp = Time.currentElapsedTime(); do { snapCountSyncObject.wait(timeoutMillis); } while (snapsInProgress >= maxConcurrentSnapshots && timestamp + timeoutMillis < Time.currentElapsedTime()); } if (essential || snapsInProgress < maxConcurrentSnapshots) { snapsInProgress++; snapshotNumber = snapsInProgress; } else { throw new SnapshotThrottleException(snapsInProgress + 1, maxConcurrentSnapshots); } } return new LearnerSnapshot(this, snapshotNumber, essential); } LearnerSnapshotThrottler(int maxConcurrentSnapshots,
                                    long timeoutMillis);  LearnerSnapshotThrottler(int maxConcurrentSnapshots); LearnerSnapshot beginSnapshot(boolean essential); void endSnapshot();  }