001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.camel.component.file; 018 019 import org.apache.camel.Exchange; 020 021 /** 022 * Strategy for acquiring exclusive read locks for files to be consumed. After 023 * granting the read lock it is realeased, we just want to make sure that when 024 * we start consuming the file its not currently in progress of being written by 025 * third party. 026 * <p/> 027 * Camel supports out of the box the following strategies: 028 * <ul> 029 * <li>GenericFileRenameExclusiveReadLockStrategy waiting until its possible to 030 * rename the file.</li> 031 * <li>NewFileLockExclusiveReadLockStrategy acquiring a RW file lock for the duration 032 * of the processing.</li> 033 * <li>NewMarkerFileExclusiveReadLockStrategy using a marker file for acquiring 034 * read lock.</li> 035 * </ul> 036 */ 037 public interface GenericFileExclusiveReadLockStrategy<T> { 038 039 /** 040 * Acquires exclusive read lock to the file. 041 * 042 * @param operations generic file operations 043 * @param file the file 044 * @param exchange the exchange 045 * @return <tt>true</tt> if read lock was acquired. If <tt>false</tt> Camel 046 * will skip the file and try it on the next poll 047 * @throws Exception can be thrown in case of errors 048 */ 049 boolean acquireExclusiveReadLock(GenericFileOperations<T> operations, GenericFile<T> file, Exchange exchange) throws Exception; 050 051 /** 052 * Releases the exclusive read lock granted by the <tt>acquireExclusiveReadLock</tt> method. 053 * 054 * @param operations generic file operations 055 * @param file the file 056 * @param exchange the exchange 057 * @throws Exception can be thrown in case of errors 058 */ 059 void releaseExclusiveReadLock(GenericFileOperations<T> operations, GenericFile<T> file, Exchange exchange) throws Exception; 060 061 /** 062 * Sets an optional timeout period. 063 * <p/> 064 * If the readlock could not be granted within the timeperiod then the wait is stopped and the 065 * <tt>acquireExclusiveReadLock</tt> method returns <tt>false</tt>. 066 * 067 * @param timeout period in millis 068 */ 069 void setTimeout(long timeout); 070 071 }