List of usage examples for java.util.concurrent.locks Lock lock
lock
From source file:info.pancancer.arch3.worker.CollectingLogOutputStream.java
/** * Get all the lines concatenated into a single string, with \n between each line. * /*w w w . j a v a 2s. co m*/ * @return */ public String getAllLinesAsString() { Lock lock = new ReentrantLock(); lock.lock(); // TODO: Add functionality to allow other join characters besides \n ? (not urgent) String allTheLines = StringUtils.join(this.lines, "\n"); lock.unlock(); return allTheLines; }
From source file:info.pancancer.arch3.worker.CollectingLogOutputStream.java
/** * Get the last *n* lines in the log.//from w ww . j av a 2 s . co m * * @param n * - The number of lines to get. * @return A list of strings. */ public List<String> getLastNLines(int n) { Lock lock = new ReentrantLock(); lock.lock(); List<String> nlines = new ArrayList<String>(n); int start, end; end = this.lines.size(); start = Math.max(0, this.lines.size() - n); if (end > start && start >= 0) { nlines = this.lines.subList(start, end); } lock.unlock(); return nlines; }
From source file:org.mule.transport.ConcurrentWorkTracker.java
public List<Runnable> pendingWorks() { Lock lock = registryLock.readLock(); try {//w w w . ja v a 2 s. c om lock.lock(); return Collections.unmodifiableList(works); } finally { lock.unlock(); } }
From source file:org.mule.transport.ConcurrentWorkTracker.java
@Override public void dispose() { Lock lock = registryLock.writeLock(); try {// w ww .j a va 2 s . c om lock.lock(); works.clear(); } finally { lock.unlock(); } }
From source file:com.civprod.util.concurrent.locks.CompositeLock.java
@Override public void lock() { for (Lock curLock : interLocks) { curLock.lock(); } }
From source file:com.crossover.trial.weather.metrics.impl.DropwizardMetricsService.java
@Override public void clear() { Lock write = registryLock.readLock(); write.lock(); try {//w ww . jav a 2 s . c om registry = new MetricRegistry(); } finally { write.unlock(); } }
From source file:com.crossover.trial.weather.metrics.impl.DropwizardMetricsService.java
@Override public void markRequest(IATA iata, double radius) { Assert.isTrue(iata != null, "iata is required"); Lock read = registryLock.readLock(); read.lock(); try {/*from w ww. j av a2 s.c o m*/ registry.meter(iata.getCode()).mark(); registry.histogram("radius").update(Double.valueOf(radius).intValue() / 10); } finally { read.unlock(); } }
From source file:org.mule.security.oauth.DefaultRefreshTokenManager.java
/** * {@inheritDoc} This implementation uses a lock to guarantee that no refresh * token is consumed more than once//from www . ja v a 2 s. c om * * @see org.mule.security.oauth.RefreshTokenManager#refreshToken(org.mule.security.oauth.OAuth2Adapter, * java.lang.String) */ @Override public void refreshToken(OAuth2Adapter adapter, String accessTokenId) throws Exception { if (StringUtils.isEmpty(accessTokenId)) { throw new IllegalArgumentException("Cannot refresh a blank accessTokenId"); } String id = String.format("%s:%s:%s", this.getClass().getCanonicalName(), adapter.getName(), accessTokenId); Lock lock = this.muleContext.getLockFactory().createLock(id); lock.lock(); try { if (!this.getRefreshedTokens().contains(id)) { adapter.refreshAccessToken(accessTokenId); this.getRefreshedTokens().store(id, true); } } finally { lock.unlock(); } }
From source file:com.lithium.flow.shell.sshj.SshjShore.java
@Override @Nonnull/* w w w . j a v a 2 s. co m*/ public Shell getShell(@Nonnull Login login) throws IOException { checkNotNull(login); Sshj client = new Sshj(config, access.getPrompt()); Lock lock = locks.getUnchecked(login.getHost()); lock.lock(); try { Shell shell = new SshjShell(client, login); shells.add(shell); return new DecoratedShell(shell) { @Override public void close() throws IOException { shells.remove(shell); super.close(); } }; } finally { lock.unlock(); } }
From source file:com.crossover.trial.weather.metrics.impl.DropwizardMetricsService.java
@Override public MetricsReport<Meter, HistogramSnapshotDTO> buildReport() { Lock read = registryLock.readLock(); read.lock(); try {/* w w w . j a v a 2 s. c om*/ MetricsReport.Builder<Meter, HistogramSnapshotDTO> builder = new MetricsReport.Builder<Meter, HistogramSnapshotDTO>() .withRadiusFrequency(new HistogramSnapshotDTO(registry.histogram("radius"))).withDataSize( dataPointRepository.countTotalMeasurementsInLastTimeWindow(timestamp().minusDays(1))); registry.getMeters().entrySet().stream().forEach(entry -> { Airport airport = airportRepository.findOne(IATA.valueOf(entry.getKey())); if (airport == null) registry.remove(entry.getKey()); else { Meter meter = registry.meter(entry.getKey()); if (meter != null) builder.withAirportMetric(airport, meter); } }); return builder.build(); } finally { read.unlock(); } }