| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
package org.apache.camel.processor; |
| 19 |
|
|
| 20 |
|
import org.apache.camel.Endpoint; |
| 21 |
|
import org.apache.camel.Exchange; |
| 22 |
|
import org.apache.camel.Processor; |
| 23 |
|
import org.apache.camel.Producer; |
| 24 |
|
import org.apache.camel.Service; |
| 25 |
|
import org.apache.camel.impl.ServiceSupport; |
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
public class SendProcessor extends ServiceSupport implements Processor, Service { |
| 31 |
|
private Endpoint destination; |
| 32 |
|
private Producer producer; |
| 33 |
|
|
| 34 |
50 |
public SendProcessor(Endpoint destination) { |
| 35 |
50 |
this.destination = destination; |
| 36 |
50 |
} |
| 37 |
|
|
| 38 |
|
protected void doStop() throws Exception { |
| 39 |
38 |
if (producer != null) { |
| 40 |
|
try { |
| 41 |
38 |
producer.stop(); |
| 42 |
|
} |
| 43 |
|
finally { |
| 44 |
38 |
producer = null; |
| 45 |
38 |
} |
| 46 |
|
} |
| 47 |
38 |
} |
| 48 |
|
|
| 49 |
|
protected void doStart() throws Exception { |
| 50 |
39 |
this.producer = destination.createProducer(); |
| 51 |
39 |
} |
| 52 |
|
|
| 53 |
|
public void process(Exchange exchange) throws Exception { |
| 54 |
40 |
if (producer == null) { |
| 55 |
1 |
throw new IllegalStateException("No producer, this processor has not been started!"); |
| 56 |
|
} |
| 57 |
39 |
producer.process(exchange); |
| 58 |
39 |
} |
| 59 |
|
|
| 60 |
|
public Endpoint getDestination() { |
| 61 |
7 |
return destination; |
| 62 |
|
} |
| 63 |
|
|
| 64 |
|
@Override |
| 65 |
|
public String toString() { |
| 66 |
91 |
return "sendTo(" + destination + ")"; |
| 67 |
|
} |
| 68 |
|
} |