List of usage examples for java.util.concurrent.locks Lock lock
lock
From source file:org.mule.util.queue.DualRandomAccessFileQueueStoreDelegate.java
@Override public synchronized void doClear() { Lock lock = filesLock.readLock(); lock.lock(); try {/*from w w w . j a v a 2 s . c o m*/ randomAccessFileQueueStore1.clear(); randomAccessFileQueueStore2.clear(); } finally { lock.unlock(); } }
From source file:org.mule.util.queue.DualRandomAccessFileQueueStoreDelegate.java
private void delete() { Lock lock = filesLock.writeLock(); lock.lock(); try {/* w w w . j a va 2s. c o m*/ randomAccessFileQueueStore1.delete(); randomAccessFileQueueStore2.delete(); queueControlDataFile.delete(); } finally { lock.unlock(); } }
From source file:org.mule.util.queue.DualRandomAccessFileQueueStoreDelegate.java
@Override protected boolean doAddAll(Collection<? extends Serializable> items) { Lock lock = filesLock.readLock(); lock.lock(); try {/*from ww w . jav a 2s . com*/ for (Serializable item : items) { add(item); } } finally { lock.unlock(); } return true; }
From source file:org.mule.util.queue.DualRandomAccessFileQueueStoreDelegate.java
/** * {@inheritDoc}//from w ww . ja va2 s. c o m */ @Override public void dispose() { Lock lock = filesLock.writeLock(); lock.lock(); try { doClose(); delete(); } finally { lock.unlock(); } }
From source file:org.mule.util.queue.DualRandomAccessFileQueueStoreDelegate.java
@Override public boolean contains(Serializable value) { Lock lock = filesLock.readLock(); lock.lock(); try {/*from w w w. j a va 2 s. c om*/ final RawDataSelector dataSelector = createDataSelector(value); if (!randomAccessFileQueueStore1.contains(dataSelector)) { return randomAccessFileQueueStore2.contains(dataSelector); } } finally { lock.unlock(); } return true; }
From source file:org.mule.util.queue.DualRandomAccessFileQueueStoreDelegate.java
@Override protected Serializable getFirst() throws InterruptedException { if (isEmpty()) { return null; }/*from w w w.j a v a 2s . c o m*/ Lock lock = filesLock.readLock(); lock.lock(); byte[] bytes; try { if (readFile.isEmpty()) { readFile.clear(); switchReadFile(); } bytes = readFile.getFirst(); } finally { lock.unlock(); } return deserialize(bytes); }
From source file:net.gbmb.collector.RecordController.java
private void addRecord(String cid, CollectionRecord record) throws CollectionStateException { Lock lock = hazelcast.getLock(cid); lock.lock(); try {// ww w . ja va2 s. c om Collection collection = collectionMap.get(cid); if (collection == null) { throw new CollectionStateException("Collection not existing"); } else if (collection.getState() != CollectionState.COLLECTING) { throw new CollectionStateException(collection.getState(), "Collection not in collecting state"); } else { collectionRecords.put(cid, record); } } finally { lock.unlock(); } }
From source file:org.jasig.maven.notice.LicenseLookupHelper.java
protected LicenseLookup loadLicenseLookup(Unmarshaller unmarshaller, String licenseLookupFile, URL licenseLookupUrl, Lock lock, boolean create) throws MojoFailureException { final String licenseLookupKey = licenseLookupUrl.toString(); lock.lock(); try {/*from ww w . j a v a 2 s . c om*/ //Look in the cache to see if the lookup file has already been parsed LicenseLookup licenseLookup = LICENSE_LOOKUP_CACHE.get(licenseLookupKey); if (licenseLookup != null) { logger.info("Loading license lookup mappings from '" + licenseLookupUrl + "' (cached)"); return licenseLookup; } //Cache miss, check if we should parse the file, return null if not if (!create) { return null; } logger.info("Loading license lookup mappings from '" + licenseLookupUrl + "'"); InputStream lookupStream = null; try { lookupStream = licenseLookupUrl.openStream(); licenseLookup = (LicenseLookup) unmarshaller.unmarshal(lookupStream); LICENSE_LOOKUP_CACHE.put(licenseLookupKey, licenseLookup); return licenseLookup; } catch (IOException e) { throw new MojoFailureException( "Failed to read '" + licenseLookupFile + "' from '" + licenseLookupUrl + "'", e); } catch (JAXBException e) { throw new MojoFailureException( "Failed to parse '" + licenseLookupFile + "' from '" + licenseLookupUrl + "'", e); } finally { IOUtils.closeQuietly(lookupStream); } } finally { lock.unlock(); } }
From source file:net.gbmb.collector.RecordController.java
@RequestMapping(value = "/records/{cid}/end", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE) public void endCollection(final @PathVariable("cid") String cid) throws CollectionStateException { Lock lock = hazelcast.getLock(cid); lock.lock(); try {/*from w w w .j a va2 s .co m*/ Collection collection = collectionMap.get(cid); if (collection == null) { // not existing collection throw new CollectionStateException("Collection not existing"); } else if (collection.getState() == CollectionState.ENDED) { throw new CollectionStateException("Collection already ended"); } // mark collection ended markCollectionEnded(collection); } finally { lock.unlock(); } // post treatment on collection: push // done outside of lock pushQueue.offer(cid); }
From source file:org.mule.util.queue.DualRandomAccessFileQueueStoreDelegate.java
private void switchWriteFileIfFull() { if (writeFile.getLength() >= MAXIMUM_QUEUE_FILE_SIZE_IN_BYTES) { Lock lock = filesLock.writeLock(); lock.lock(); try {/*from w w w . j a v a 2 s . c o m*/ if (writeFile.getLength() >= MAXIMUM_QUEUE_FILE_SIZE_IN_BYTES) { if (randomAccessFileQueueStore1.getLength() >= MAXIMUM_QUEUE_FILE_SIZE_IN_BYTES && randomAccessFileQueueStore2.getLength() >= MAXIMUM_QUEUE_FILE_SIZE_IN_BYTES) { return; } if (logger.isDebugEnabled()) { logger.debug( "switching write file. Random 1 size: " + randomAccessFileQueueStore1.getLength() + " , Random 2 size: " + randomAccessFileQueueStore2.getLength()); } writeFile = (writeFile == randomAccessFileQueueStore1 ? randomAccessFileQueueStore2 : randomAccessFileQueueStore1); queueControlDataFile.writeControlData(writeFile.getFile(), readFile.getFile()); } } finally { lock.unlock(); } } }