| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
package org.apache.camel.processor; |
| 18 |
|
|
| 19 |
|
import org.apache.camel.Endpoint; |
| 20 |
|
import org.apache.camel.Exchange; |
| 21 |
|
import org.apache.camel.Processor; |
| 22 |
|
import org.apache.camel.Producer; |
| 23 |
|
import org.apache.camel.Service; |
| 24 |
|
import org.apache.camel.impl.ServiceSupport; |
| 25 |
|
import org.apache.commons.logging.Log; |
| 26 |
|
import org.apache.commons.logging.LogFactory; |
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
public class SendProcessor extends ServiceSupport implements Processor, Service { |
| 32 |
3 |
private static final transient Log LOG = LogFactory.getLog(SendProcessor.class); |
| 33 |
|
private Endpoint destination; |
| 34 |
|
private Producer producer; |
| 35 |
|
|
| 36 |
315 |
public SendProcessor(Endpoint destination) { |
| 37 |
315 |
if (destination == null) { |
| 38 |
0 |
throw new IllegalArgumentException("Endpoint cannot be null!"); |
| 39 |
|
} |
| 40 |
315 |
this.destination = destination; |
| 41 |
315 |
} |
| 42 |
|
|
| 43 |
|
protected void doStop() throws Exception { |
| 44 |
267 |
if (producer != null) { |
| 45 |
|
try { |
| 46 |
267 |
producer.stop(); |
| 47 |
|
} finally { |
| 48 |
267 |
producer = null; |
| 49 |
267 |
} |
| 50 |
|
} |
| 51 |
267 |
} |
| 52 |
|
|
| 53 |
|
protected void doStart() throws Exception { |
| 54 |
276 |
this.producer = destination.createProducer(); |
| 55 |
276 |
} |
| 56 |
|
|
| 57 |
|
public void process(Exchange exchange) throws Exception { |
| 58 |
327 |
if (producer == null) { |
| 59 |
0 |
if (isStopped()) { |
| 60 |
0 |
LOG.warn("Ignoring exchange sent after processor is stopped: " + exchange); |
| 61 |
0 |
} else { |
| 62 |
0 |
throw new IllegalStateException("No producer, this processor has not been started!"); |
| 63 |
|
} |
| 64 |
|
} else { |
| 65 |
327 |
producer.process(exchange); |
| 66 |
|
} |
| 67 |
327 |
} |
| 68 |
|
|
| 69 |
|
public Endpoint getDestination() { |
| 70 |
27 |
return destination; |
| 71 |
|
} |
| 72 |
|
|
| 73 |
|
@Override |
| 74 |
|
public String toString() { |
| 75 |
366 |
return "sendTo(" + destination + ")"; |
| 76 |
|
} |
| 77 |
|
} |