1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.camel.component.timer; |
18 |
|
|
19 |
|
import java.net.URI; |
20 |
|
import java.net.URISyntaxException; |
21 |
|
import java.util.Date; |
22 |
|
import java.util.Map; |
23 |
|
|
24 |
|
import org.apache.camel.Consumer; |
25 |
|
import org.apache.camel.Processor; |
26 |
|
import org.apache.camel.Producer; |
27 |
|
import org.apache.camel.RuntimeCamelException; |
28 |
|
import org.apache.camel.component.bean.BeanExchange; |
29 |
|
import org.apache.camel.impl.DefaultEndpoint; |
30 |
|
import org.apache.camel.util.IntrospectionSupport; |
31 |
|
import org.apache.camel.util.URISupport; |
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
15 |
public class TimerEndpoint extends DefaultEndpoint<BeanExchange> { |
39 |
|
|
40 |
|
private final TimerComponent component; |
41 |
|
private final String timerName; |
42 |
|
private Date time; |
43 |
3 |
private long period = -1; |
44 |
3 |
private long delay = -1; |
45 |
|
private boolean fixedRate; |
46 |
3 |
private boolean daemon = true; |
47 |
|
|
48 |
|
|
49 |
|
public TimerEndpoint(String fullURI, TimerComponent component, String timerPartURI) throws URISyntaxException { |
50 |
3 |
super(fullURI, component); |
51 |
3 |
this.component = component; |
52 |
|
|
53 |
|
|
54 |
3 |
URI u = new URI(timerPartURI); |
55 |
3 |
Map options = URISupport.parseParamters(u); |
56 |
3 |
IntrospectionSupport.setProperties(this, options); |
57 |
3 |
this.timerName = u.getPath(); |
58 |
|
|
59 |
3 |
} |
60 |
|
|
61 |
|
public Producer<BeanExchange> createProducer() throws Exception { |
62 |
0 |
throw new RuntimeCamelException("Cannot produce to a TimerEndpoint: " + getEndpointUri()); |
63 |
|
} |
64 |
|
|
65 |
|
public Consumer<BeanExchange> createConsumer(Processor processor) throws Exception { |
66 |
3 |
return new TimerConsumer(this, processor); |
67 |
|
} |
68 |
|
|
69 |
|
public BeanExchange createExchange() { |
70 |
15 |
return new BeanExchange(getContext()); |
71 |
|
} |
72 |
|
|
73 |
|
public TimerComponent getComponent() { |
74 |
6 |
return component; |
75 |
|
} |
76 |
|
|
77 |
|
public String getTimerName() { |
78 |
3 |
return timerName; |
79 |
|
} |
80 |
|
|
81 |
|
public boolean isDaemon() { |
82 |
3 |
return daemon; |
83 |
|
} |
84 |
|
|
85 |
|
public void setDaemon(boolean daemon) { |
86 |
0 |
this.daemon = daemon; |
87 |
0 |
} |
88 |
|
|
89 |
|
public long getDelay() { |
90 |
3 |
return delay; |
91 |
|
} |
92 |
|
|
93 |
|
public void setDelay(long delay) { |
94 |
3 |
this.delay = delay; |
95 |
3 |
} |
96 |
|
|
97 |
|
public boolean isFixedRate() { |
98 |
3 |
return fixedRate; |
99 |
|
} |
100 |
|
|
101 |
|
public void setFixedRate(boolean fixedRate) { |
102 |
3 |
this.fixedRate = fixedRate; |
103 |
3 |
} |
104 |
|
|
105 |
|
public long getPeriod() { |
106 |
3 |
return period; |
107 |
|
} |
108 |
|
|
109 |
|
public void setPeriod(long period) { |
110 |
3 |
this.period = period; |
111 |
3 |
} |
112 |
|
|
113 |
|
public Date getTime() { |
114 |
3 |
return time; |
115 |
|
} |
116 |
|
|
117 |
|
public void setTime(Date time) { |
118 |
0 |
this.time = time; |
119 |
0 |
} |
120 |
|
|
121 |
|
public boolean isSingleton() { |
122 |
3 |
return true; |
123 |
|
} |
124 |
|
|
125 |
|
} |