| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
package org.apache.camel.component.file; |
| 19 |
|
|
| 20 |
|
import org.apache.camel.Component; |
| 21 |
|
import org.apache.camel.Consumer; |
| 22 |
|
import org.apache.camel.Processor; |
| 23 |
|
import org.apache.camel.Producer; |
| 24 |
|
import org.apache.camel.impl.PollingEndpoint; |
| 25 |
|
import org.apache.camel.util.IntrospectionSupport; |
| 26 |
|
|
| 27 |
|
import java.io.File; |
| 28 |
|
import java.util.Map; |
| 29 |
|
import java.util.concurrent.ScheduledExecutorService; |
| 30 |
|
import java.util.concurrent.ScheduledThreadPoolExecutor; |
| 31 |
|
|
| 32 |
0 |
|
| 33 |
|
|
| 34 |
|
|
| 35 |
0 |
public class FileEndpoint extends PollingEndpoint<FileExchange> { |
| 36 |
0 |
private File file; |
| 37 |
0 |
private ScheduledExecutorService executor; |
| 38 |
|
|
| 39 |
|
protected FileEndpoint(File file, String endpointUri, FileComponent component) { |
| 40 |
0 |
super(endpointUri, component); |
| 41 |
0 |
this.file = file; |
| 42 |
0 |
this.executor = component.getExecutorService(); |
| 43 |
0 |
} |
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
0 |
|
| 50 |
|
|
| 51 |
|
public Producer<FileExchange> createProducer() throws Exception { |
| 52 |
0 |
Producer<FileExchange> result = new FileProducer(this); |
| 53 |
0 |
return startService(result); |
| 54 |
|
} |
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
0 |
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
public Consumer<FileExchange> createConsumer(Processor<FileExchange> file) throws Exception { |
| 63 |
0 |
Consumer<FileExchange> result = new FileConsumer(this, file, getExecutor()); |
| 64 |
0 |
configureConsumer(result); |
| 65 |
0 |
return startService(result); |
| 66 |
0 |
} |
| 67 |
|
|
| 68 |
|
|
| 69 |
|
|
| 70 |
|
|
| 71 |
|
|
| 72 |
|
|
| 73 |
|
public FileExchange createExchange(File file) { |
| 74 |
0 |
return new FileExchange(getContext(), file); |
| 75 |
|
} |
| 76 |
0 |
|
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
|
|
| 81 |
|
public FileExchange createExchange() { |
| 82 |
0 |
return createExchange(this.file); |
| 83 |
|
} |
| 84 |
0 |
|
| 85 |
0 |
|
| 86 |
|
|
| 87 |
0 |
|
| 88 |
|
public synchronized ScheduledExecutorService getExecutor() { |
| 89 |
0 |
if (this.executor == null) { |
| 90 |
0 |
this.executor = new ScheduledThreadPoolExecutor(10); |
| 91 |
|
} |
| 92 |
0 |
return executor; |
| 93 |
|
} |
| 94 |
|
|
| 95 |
0 |
|
| 96 |
0 |
|
| 97 |
|
|
| 98 |
|
public synchronized void setExecutor(ScheduledExecutorService executor) { |
| 99 |
0 |
this.executor = executor; |
| 100 |
0 |
} |
| 101 |
|
|
| 102 |
|
public File getFile() { |
| 103 |
0 |
return file; |
| 104 |
|
} |
| 105 |
|
|
| 106 |
|
public boolean isSingleton() { |
| 107 |
0 |
return true; |
| 108 |
|
} |
| 109 |
|
} |