ActivitiEndpoint.java 4.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/* Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.activiti.camel;

import org.activiti.engine.RuntimeService;
import org.apache.camel.*;
import org.apache.camel.impl.DefaultEndpoint;

20 21 22 23 24 25 26 27
/**
 * This class has been modified to be consistent with the changes to CamelBehavior and its implementations. The set of changes
 * significantly increases the flexibility of our Camel integration, as you can either choose one of three "out-of-the-box" modes,
 * or you can choose to create your own. Please reference the comments for the "CamelBehavior" class for more information on the 
 * out-of-the-box implementation class options.  
 * 
 * @author Ryan Johnston (@rjfsu), Tijs Rademakers
 */
28 29
public class ActivitiEndpoint extends DefaultEndpoint {

30

31
  private RuntimeService runtimeService;
32

33
  private ActivitiConsumer activitiConsumer;
34

35
  private boolean copyVariablesToProperties;
36

37
  private boolean copyVariablesToBodyAsMap;
38

39 40 41
  private boolean copyCamelBodyToBody;
  
  private boolean copyVariablesFromProperties;
42

43 44 45
  private boolean copyVariablesFromHeader;
  
  private boolean copyCamelBodyToBodyAsString;
46 47 48 49
  
  private long timeout = 5000;
  
  private int timeResolution = 100;
50

51
  public ActivitiEndpoint(String uri, CamelContext camelContext, RuntimeService runtimeService) {
52 53 54
    super();
    setCamelContext(camelContext);
    setEndpointUri(uri);
55 56 57 58 59 60
    this.runtimeService = runtimeService;
  }

  void addConsumer(ActivitiConsumer consumer) {
    if (activitiConsumer != null) {
      throw new RuntimeException("Activit consumer already defined for " + getEndpointUri() + "!");
61
    }
62 63
    activitiConsumer = consumer;
  }
64

65 66 67
  public void process(Exchange ex) throws Exception {
    if (activitiConsumer == null) {
      throw new RuntimeException("Activiti consumer not defined for " + getEndpointUri());
68
    }
69 70
    activitiConsumer.getProcessor().process(ex);
  }
71

72
  public Producer createProducer() throws Exception {
73
    return new ActivitiProducer(this, runtimeService, getTimeout(), getTimeResolution());
74
  }
75

76 77 78
  public Consumer createConsumer(Processor processor) throws Exception {
    return new ActivitiConsumer(this, processor);
  }
79

80 81 82
  public boolean isSingleton() {
    return true;
  }
83

84 85 86 87 88 89 90 91
  public boolean isCopyVariablesToProperties() {
    return copyVariablesToProperties;
  }

  public void setCopyVariablesToProperties(boolean copyVariablesToProperties) {
    this.copyVariablesToProperties = copyVariablesToProperties;
  }

92 93
  public boolean isCopyCamelBodyToBody() {
    return copyCamelBodyToBody;
94 95
  }

96 97
  public void setCopyCamelBodyToBody(boolean copyCamelBodyToBody) {
    this.copyCamelBodyToBody = copyCamelBodyToBody;
98 99
  }

100 101 102 103 104 105 106 107
  public boolean isCopyVariablesToBodyAsMap() {
    return copyVariablesToBodyAsMap;
  }

  public void setCopyVariablesToBodyAsMap(boolean copyVariablesToBodyAsMap) {
    this.copyVariablesToBodyAsMap = copyVariablesToBodyAsMap;
  }
  
108 109 110 111 112 113 114 115
  public boolean isCopyVariablesFromProperties() {
    return copyVariablesFromProperties;
  }

  public void setCopyVariablesFromProperties(boolean copyVariablesFromProperties) {
    this.copyVariablesFromProperties = copyVariablesFromProperties;
  }

116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
  public boolean isCopyVariablesFromHeader() {
    return this.copyVariablesFromHeader;
  }

  public void setCopyVariablesFromHeader(boolean copyVariablesFromHeader) {
    this.copyVariablesFromHeader = copyVariablesFromHeader;
  }
  
  public boolean isCopyCamelBodyToBodyAsString() {
    return copyCamelBodyToBodyAsString;
  }
  
  public void setCopyCamelBodyToBodyAsString(boolean copyCamelBodyToBodyAsString) {
    this.copyCamelBodyToBodyAsString = copyCamelBodyToBodyAsString;
  }
  
132 133 134 135
  @Override
  public boolean isLenientProperties() {
    return true;
  }
136 137 138 139 140 141 142 143
  
  public long getTimeout() {
    return timeout;
  }
  
  public int getTimeResolution() {
    return timeResolution;
  }
144

145
}