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 */
017package org.apache.camel.model;
018
019import javax.xml.bind.annotation.XmlAccessType;
020import javax.xml.bind.annotation.XmlAccessorType;
021import javax.xml.bind.annotation.XmlTransient;
022import javax.xml.bind.annotation.XmlType;
023
024import org.apache.camel.processor.loadbalancer.LoadBalancer;
025import org.apache.camel.spi.Metadata;
026
027/**
028 * Balances message processing among a number of nodes
029 */
030@Metadata(label = "eip,routing")
031@XmlType(name = "loadBalancer")
032@XmlAccessorType(XmlAccessType.FIELD)
033@SuppressWarnings("rawtypes")
034public class LoadBalancerDefinition extends IdentifiedType {
035    @XmlTransient
036    private LoadBalancer loadBalancer;
037    @XmlTransient
038    private String loadBalancerTypeName;
039
040    public LoadBalancerDefinition() {
041    }
042
043    public LoadBalancerDefinition(LoadBalancer loadBalancer) {
044        this.loadBalancer = loadBalancer;
045    }
046
047    protected LoadBalancerDefinition(String loadBalancerTypeName) {
048        this.loadBalancerTypeName = loadBalancerTypeName;
049    }
050
051    /**
052     * Maximum number of outputs, as some load balancers only support 1
053     * processor
054     */
055    public int getMaximumNumberOfOutputs() {
056        return Integer.MAX_VALUE;
057    }
058
059    /**
060     * Allows derived classes to customize the load balancer
061     */
062    public void configureLoadBalancer(LoadBalancer loadBalancer) {
063    }
064
065    public LoadBalancer getLoadBalancer() {
066        return loadBalancer;
067    }
068
069    public void setLoadBalancer(LoadBalancer loadBalancer) {
070        this.loadBalancer = loadBalancer;
071    }
072
073    public String getLoadBalancerTypeName() {
074        return loadBalancerTypeName;
075    }
076
077    @Override
078    public String toString() {
079        if (loadBalancer != null) {
080            return loadBalancer.toString();
081        } else {
082            return loadBalancerTypeName;
083        }
084    }
085}