| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
package org.apache.camel.bam; |
| 18 |
|
|
| 19 |
|
import java.util.Date; |
| 20 |
|
|
| 21 |
|
import org.apache.camel.Endpoint; |
| 22 |
|
import org.apache.camel.Expression; |
| 23 |
|
import org.apache.camel.Processor; |
| 24 |
|
import org.apache.camel.Route; |
| 25 |
|
import org.apache.camel.bam.model.ActivityState; |
| 26 |
|
import org.apache.camel.bam.model.ProcessInstance; |
| 27 |
|
import org.apache.camel.bam.rules.ActivityRules; |
| 28 |
|
import org.apache.camel.builder.ProcessorFactory; |
| 29 |
|
import org.apache.camel.impl.EventDrivenConsumerRoute; |
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
public class ActivityBuilder implements ProcessorFactory { |
| 35 |
|
private ProcessBuilder processBuilder; |
| 36 |
|
private Endpoint endpoint; |
| 37 |
|
private ActivityRules activityRules; |
| 38 |
|
private Expression correlationExpression; |
| 39 |
|
|
| 40 |
4 |
public ActivityBuilder(ProcessBuilder processBuilder, Endpoint endpoint) { |
| 41 |
4 |
this.processBuilder = processBuilder; |
| 42 |
4 |
this.endpoint = endpoint; |
| 43 |
4 |
this.activityRules = new ActivityRules(processBuilder); |
| 44 |
4 |
this.activityRules.setActivityName(endpoint.getEndpointUri()); |
| 45 |
4 |
} |
| 46 |
|
|
| 47 |
|
public Endpoint getEndpoint() { |
| 48 |
4 |
return endpoint; |
| 49 |
|
} |
| 50 |
|
|
| 51 |
|
public Processor createProcessor() throws Exception { |
| 52 |
4 |
return processBuilder.createActivityProcessor(this); |
| 53 |
|
} |
| 54 |
|
|
| 55 |
|
public Route createRoute() throws Exception { |
| 56 |
4 |
Processor processor = createProcessor(); |
| 57 |
4 |
if (processor == null) { |
| 58 |
0 |
throw new IllegalArgumentException("No processor created for ActivityBuilder: " + this); |
| 59 |
|
} |
| 60 |
4 |
return new EventDrivenConsumerRoute(getEndpoint(), processor); |
| 61 |
|
} |
| 62 |
|
|
| 63 |
|
|
| 64 |
|
|
| 65 |
|
public ActivityBuilder correlate(Expression correlationExpression) { |
| 66 |
4 |
this.correlationExpression = correlationExpression; |
| 67 |
4 |
return this; |
| 68 |
|
} |
| 69 |
|
|
| 70 |
|
public ActivityBuilder name(String name) { |
| 71 |
4 |
activityRules.setActivityName(name); |
| 72 |
4 |
return this; |
| 73 |
|
} |
| 74 |
|
|
| 75 |
|
|
| 76 |
|
|
| 77 |
|
|
| 78 |
|
public TimeExpression starts() { |
| 79 |
2 |
return new TimeExpression(this, ActivityLifecycle.Started) { |
| 80 |
2 |
public Date evaluate(ProcessInstance instance, ActivityState state) { |
| 81 |
0 |
return state.getTimeStarted(); |
| 82 |
|
} |
| 83 |
|
}; |
| 84 |
|
} |
| 85 |
|
|
| 86 |
|
|
| 87 |
|
|
| 88 |
|
|
| 89 |
|
public TimeExpression completes() { |
| 90 |
2 |
return new TimeExpression(this, ActivityLifecycle.Completed) { |
| 91 |
2 |
public Date evaluate(ProcessInstance instance, ActivityState state) { |
| 92 |
6 |
return state.getTimeCompleted(); |
| 93 |
|
} |
| 94 |
|
}; |
| 95 |
|
} |
| 96 |
|
|
| 97 |
|
|
| 98 |
|
|
| 99 |
|
public Expression getCorrelationExpression() { |
| 100 |
4 |
return correlationExpression; |
| 101 |
|
} |
| 102 |
|
|
| 103 |
|
public ActivityRules getActivityRules() { |
| 104 |
8 |
return activityRules; |
| 105 |
|
} |
| 106 |
|
|
| 107 |
|
public ProcessBuilder getProcessBuilder() { |
| 108 |
4 |
return processBuilder; |
| 109 |
|
} |
| 110 |
|
} |