Code example for BlockingQueue

Methods: contains, offer

0
	 
	private static final BlockingQueue<File> collection = new LinkedBlockingQueue<File>(10);
 
	public synchronized static Maybe<File> reserve(final File outputFile) {
		log.info("Reserving file '{}'.", outputFile.getName());
		if (!collection.contains(outputFile) && collection.offer(outputFile)) {
			log.debug("Reserved file '{}'.", outputFile.getName());
			return Maybe.just(outputFile);
		} 
		log.debug("File '{}' is still reserved.", outputFile.getName());
		return Maybe.nothing(); 
	} 
 
	public static boolean release(final File inputFile) {
		return collection.remove(inputFile);
	} 
 
	public synchronized static int numberOfReservedFiles() { 
		return collection.size();
	}