【发布时间】:2017-03-29 14:24:35
【问题描述】:
我正在使用 Camel File 组件来消费一个文件,如下所示:
<from uri="file:myDir?noop=true&filter=myFilter&scheduler=quartz2&scheduler.cron={{schedule}}/>
源位置是只读的。 Camel File documentation 说,默认情况下它不会使用读锁。
但是,我在运行此代码时遇到了权限被拒绝异常。
端点[file://myFile?filter=myFilter&idempotent=true&noop=true&scheduler=quartz2&scheduler.cron={{mySchedule}} 无法开始处理文件:GenericFile[myDir\myFile] 由于:访问 被拒绝。原因:[java.io.IOException - 访问被拒绝]
堆栈跟踪 java.io.IOException:权限被拒绝 java.io.UnixFileSystem.createFileExclusively(Native Method)[:1.8.0_66] 在 java.io.File.createNewFile(File.java:1012)[:1.8.0_66] 在 org.apache.camel.util.FileUtil.createNewFile(FileUtil.java:587)[org.apache.camel:camel-core:2.15.1.redhat-621090 com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4.2] 在 org.apache.camel.component.file.strategy.MarkerFileExclusiveReadLockStrategy.acquireExclusiveReadLock(MarkerFileExclusiveReadLockStrategy.java:71)[org.apache.camel:camel-core:2.15.1.redhat-621090 com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4.2] 在 org.apache.camel.component.file.strategy.GenericFileProcessStrategySupport.begin(GenericFileProcessStrategySupport.java:49)[org.apache.camel:camel-core:2.15.1.redhat-621090 com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4.2] 在 org.apache.camel.component.file.strategy.GenericFileRenameProcessStrategy.begin(GenericFileRenameProcessStrategy.java:35)[org.apache.camel:camel-core:2.15.1.redhat-621090 com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4.2] 在 org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:352)[org.apache.camel:camel-core:2.15.1.redhat-621090 com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4.2] 在 org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:211)[org.apache.camel:camel-core:2.15.1.redhat-621090 com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4.2] 在 org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:175)[org.apache.camel:camel-core:2.15.1.redhat-621090 com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4.2] 在 org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:174)[org.apache.camel:camel-core:2.15.1.redhat-621090 com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4.2] 在 org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:101)[org.apache.camel:camel-core:2.15.1.redhat-621090 com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4.2] 在 org.apache.camel.pollconsumer.quartz2.QuartzScheduledPollConsumerJob.execute(QuartzScheduledPollConsumerJob.java:59)[org.apache.camel:camel-quartz2:2.15.1.redhat-621090] 在 org.quartz.core.JobRunShell.run(JobRunShell.java:202)[org.quartz-scheduler:quartz:2.2.1] 在 org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)[org.quartz-scheduler:quartz:2.2.1]
从堆栈跟踪看来,camel 正在尝试创建 readLock,并且由于缺少权限而导致异常。
所以,我的问题是
- 为什么骆驼使用锁,即使读锁的默认值为none
- 如果这是预期行为,如何从我没有写入权限的只读位置使用文件?
更新
我尝试按照其中一个答案的建议将readLockMarkingFile 设置为false,但这并没有解决问题。所以,我明确地将readLock 设置为none。现在,它正在工作。不知道,为什么 readLock 默认不是 none 文档中提到的。
【问题讨论】:
标签: java apache-camel readonly jbossfuse file-read