001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.camel.model.loadbalancer;
018
019 import javax.xml.bind.annotation.XmlAccessType;
020 import javax.xml.bind.annotation.XmlAccessorType;
021 import javax.xml.bind.annotation.XmlElement;
022 import javax.xml.bind.annotation.XmlRootElement;
023
024 import org.apache.camel.model.language.ExpressionDefinition;
025 import org.apache.camel.processor.loadbalancer.LoadBalancer;
026
027 /**
028 * Represents an XML <sticky/> element
029 */
030 @XmlRootElement(name = "sticky")
031 @XmlAccessorType(XmlAccessType.FIELD)
032 public class StickyLoadBalanceStrategy extends LoadBalancerDefinition {
033 @XmlElement(required = true, name = "expression", type = ExpressionDefinition.class)
034 private ExpressionDefinition expressionType;
035 @XmlElement(required = false, name = "loadBalancer", type = LoadBalancerDefinition.class)
036 private LoadBalancerDefinition loadBalancerType;
037
038 public StickyLoadBalanceStrategy() {
039 super("org.apache.camel.processor.loadbalancer.StickyLoadBalancer");
040 }
041
042 public StickyLoadBalanceStrategy(ExpressionDefinition expressionType) {
043 this();
044 this.expressionType = expressionType;
045 }
046
047 public StickyLoadBalanceStrategy(ExpressionDefinition expressionType, LoadBalancerDefinition loadBalancerType) {
048 this();
049 this.expressionType = expressionType;
050 this.loadBalancerType = loadBalancerType;
051 }
052
053 public void setExpressionType(ExpressionDefinition expressionType) {
054 this.expressionType = expressionType;
055 }
056
057 public ExpressionDefinition getExpressionType() {
058 return expressionType;
059 }
060
061 public void setLoadBalancerType(LoadBalancerDefinition loadBalancerType) {
062 this.loadBalancerType = loadBalancerType;
063 }
064
065 public LoadBalancerDefinition getLoadBalancerType() {
066 return loadBalancerType;
067 }
068
069 @Override
070 protected void configureLoadBalancer(LoadBalancer loadBalancer) {
071 ExpressionDefinition expression = getExpressionType();
072 if (expression != null) {
073 setProperty(loadBalancer, "correlationExpression", expression);
074 }
075 LoadBalancerDefinition type = getLoadBalancerType();
076 if (type != null) {
077 setProperty(loadBalancer, "loadBalancer", type);
078 }
079 }
080
081 @Override
082 public String toString() {
083 return "StickyLoadBalanceStrategy[" + expressionType + ", " + loadBalancerType + "]";
084 }
085 }