Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
FileEndpoint |
|
| 0.0;0 |
1 | /** |
|
2 | * |
|
3 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
4 | * contributor license agreements. See the NOTICE file distributed with |
|
5 | * this work for additional information regarding copyright ownership. |
|
6 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
7 | * (the "License"); you may not use this file except in compliance with |
|
8 | * the License. You may obtain a copy of the License at |
|
9 | * |
|
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
11 | * |
|
12 | * Unless required by applicable law or agreed to in writing, software |
|
13 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15 | * See the License for the specific language governing permissions and |
|
16 | * limitations under the License. |
|
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 | * @version $Revision: 523016 $ |
|
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 | * @return a Producer |
|
48 | * @throws Exception |
|
49 | 0 | * @see org.apache.camel.Endpoint#createProducer() |
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 | * @param file |
|
58 | 0 | * @return a Consumer |
59 | * @throws Exception |
|
60 | * @see org.apache.camel.Endpoint#createConsumer(org.apache.camel.Processor) |
|
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 | * @param file |
|
70 | * @return a FileExchange |
|
71 | * @see org.apache.camel.Endpoint#createExchange() |
|
72 | */ |
|
73 | public FileExchange createExchange(File file) { |
|
74 | 0 | return new FileExchange(getContext(), file); |
75 | } |
|
76 | 0 | |
77 | /** |
|
78 | * @return an Exchange |
|
79 | * @see org.apache.camel.Endpoint#createExchange() |
|
80 | */ |
|
81 | public FileExchange createExchange() { |
|
82 | 0 | return createExchange(this.file); |
83 | } |
|
84 | 0 | |
85 | 0 | /** |
86 | * @return the executor |
|
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 | * @param executor the executor to set |
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 | } |