List of usage examples for java.util.concurrent.locks ReentrantLock ReentrantLock
public ReentrantLock()
From source file:org.craftercms.engine.service.context.SiteContextManager.java
public SiteContextManager() { lock = new ReentrantLock(); contextRegistry = new ConcurrentHashMap<>(); }
From source file:info.pancancer.arch3.worker.CollectingLogOutputStream.java
/** * Get all the lines concatenated into a single string, with \n between each line. * //from w ww. j a va2 s . 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:org.excalibur.discovery.service.p2p.DiscoveryServiceImpl.java
public DiscoveryServiceImpl(Overlay overlay) { this.overlay_ = checkNotNull(overlay); mapper = new JsonJaxbObjectMapper(); lock_ = new ReentrantLock(); }
From source file:com.eatnumber1.util.cglib.EnhancerUtils.java
@NotNull public static <T, D extends T> T synchronize(@NotNull Class<T> type, @NotNull D delegate) { return synchronize(type, delegate, new ReentrantLock()); }
From source file:org.commonjava.util.partyline.BinaryFileTest.java
@Test public void shouldReadBinaryFile() throws IOException, InterruptedException { List<String> failures = new ArrayList<>(); File binaryFile = temp.newFile("binary-file.bin"); ReentrantLock lock = new ReentrantLock(); JoinableFile jf = new JoinableFile(binaryFile, new LockOwner(binaryFile.getAbsolutePath(), name.getMethodName(), LockLevel.write), true); OutputStream jos = jf.getOutputStream(); InputStream actual = jf.joinStream(); ByteArrayOutputStream written = new ByteArrayOutputStream(); writeBinaryFile(jos, written);/*w ww . jav a2 s .c om*/ int pos = 0; int exp, act; ByteArrayInputStream expected = new ByteArrayInputStream(written.toByteArray()); while ((exp = expected.read()) != -1) { act = actual.read(); pos++; if (act != exp) { failures.add(String.format("Failure at position %d. Expected %d, got %d", pos, exp, act)); } } if (!failures.isEmpty()) { fail("Failures: " + failures); } }
From source file:com.ebay.myriad.scheduler.MyriadScheduler.java
@Inject public MyriadScheduler(final MyriadConfiguration cfg, final SchedulerState schedulerState) { this.driverOperationLock = new ReentrantLock(); this.schedulerState = schedulerState; }
From source file:org.ops4j.pax.web.extender.whiteboard.internal.HttpServiceTracker.java
/** * Tracks Http Services./* ww w . j ava 2 s .co m*/ * * @param bundleContext a bundle context; mandatory */ public HttpServiceTracker(final BundleContext bundleContext) { super(validateBundleContext(bundleContext), HttpService.class.getName(), null); m_listeners = new ArrayList<HttpServiceListener>(); lock = new ReentrantLock(); }
From source file:com.eatnumber1.util.cglib.EnhancerUtils.java
@NotNull public static <T, D extends T> T synchronize(@NotNull ConstructorDescriptor<T> descriptor, @NotNull D delegate) {// w w w . j a v a2s .com return synchronize(descriptor, delegate, new ReentrantLock()); }
From source file:com.qut.middleware.saml2.identifier.impl.IdentifierGeneratorImpl.java
public IdentifierGeneratorImpl(IdentifierCache cache) { if (cache == null) { throw new IllegalArgumentException("identifier cache cannot be null."); //$NON-NLS-1$ }/* w w w . ja v a2 s. c om*/ this.cache = cache; this.lock = new ReentrantLock(); try { /* Attempt to get the specified RNG instance */ this.random = SecureRandom.getInstance(this.RNG); } catch (NoSuchAlgorithmException nsae) { this.logger.error(Messages.getString("IdentifierGeneratorImpl.13")); //$NON-NLS-1$ this.logger.debug(nsae.getLocalizedMessage(), nsae); this.random = new SecureRandom(); } this.random.setSeed(System.currentTimeMillis()); }
From source file:info.pancancer.arch3.worker.WorkflowRunner.java
/** * Get the stdout of the running command. * * @return/*from w w w. j a v a 2 s. c om*/ */ public String getStdOut() { String s; Lock lock = new ReentrantLock(); lock.lock(); try { this.outputStream.flush(); s = this.outputStream.getAllLinesAsString(); } finally { lock.unlock(); } return s; }