Package org.apache.synapse.endpoints.algorithms

Examples of org.apache.synapse.endpoints.algorithms.LoadbalanceAlgorithm


            if (name != null) {
                loadbalanceEndpoint.setName(name.getAttributeValue());
            }

            LoadbalanceAlgorithm algorithm = null;

            // set endpoints or members
            if (loadbalanceElement.getFirstChildWithName(XMLConfigConstants.ENDPOINT_ELT) != null) {
                if(loadbalanceElement.
                        getChildrenWithName((MEMBER)).hasNext()){
                    String msg =
                            "Invalid Synapse configuration. " +
                            "child elements";
                    log.error(msg);
                    throw new SynapseException(msg);
                }
                List<Endpoint> endpoints
                        = getEndpoints(loadbalanceElement, loadbalanceEndpoint, properties);
                loadbalanceEndpoint.setChildren(endpoints);
                algorithm =
                        LoadbalanceAlgorithmFactory.
                                createLoadbalanceAlgorithm(loadbalanceElement, endpoints);
                algorithm.setLoadBalanceEndpoint(loadbalanceEndpoint);
            } else if (loadbalanceElement.getFirstChildWithName(MEMBER) != null) {
                if(loadbalanceElement.
                        getChildrenWithName((XMLConfigConstants.ENDPOINT_ELT)).hasNext()){
                    String msg =
                            "Invalid Synapse configuration. " +
View Full Code Here


                                                                 "value")).trim();
                        lbProperties.put(propName, propValue);
                    }

                    // Set load balance algorithm
                    LoadbalanceAlgorithm algorithm =
                            LoadbalanceAlgorithmFactory.
                                    createLoadbalanceAlgorithm(loadbalanceElement, null);
                    lbMembershipHandler.init(lbProperties, algorithm);
                    loadbalanceEndpoint.setLoadBalanceMembershipHandler(lbMembershipHandler);
                } catch (Exception e) {
View Full Code Here

            List<Endpoint> endpoints = getEndpoints(loadbalanceElement,
                    loadbalanceEndpoint, properties);
            loadbalanceEndpoint.setChildren(endpoints);

            // set load balance algorithm
            LoadbalanceAlgorithm algorithm = LoadbalanceAlgorithmFactory.
                    createLoadbalanceAlgorithm(loadbalanceElement, endpoints);
            loadbalanceEndpoint.setAlgorithm(algorithm);

            // process the parameters
            processProperties(loadbalanceEndpoint, epConfig);
View Full Code Here

    private static Log log = LogFactory.getLog(LoadbalanceAlgorithmFactory.class);

    public static LoadbalanceAlgorithm createLoadbalanceAlgorithm(OMElement loadbalanceElement, List endpoints) {

        //default algorithm is round robin
        LoadbalanceAlgorithm algorithm = new RoundRobin(endpoints);

        OMAttribute policyAttribute = loadbalanceElement.getAttribute(new QName(null,
                XMLConfigConstants.LOADBALANCE_POLICY));
        OMAttribute algoAttribute = loadbalanceElement.getAttribute(new QName(null,
                XMLConfigConstants.LOADBALANCE_ALGORITHM));

        if (policyAttribute != null && algoAttribute != null) {
            String msg = "You cannot specify both the 'policy' & 'algorithm' in the configuration. " +
                         "It is sufficient to provide only the 'algorithm'.";
            log.fatal(msg); // We cannot continue execution. Hence it is logged at fatal level
            throw new SynapseException(msg);
        }

        if (algoAttribute != null) {
            String algorithmStr = algoAttribute.getAttributeValue().trim();
            try {
                algorithm = (LoadbalanceAlgorithm) Class.forName(algorithmStr).newInstance();
                algorithm.setEndpoints(endpoints);
            } catch (Exception e) {
                String msg = "Cannot instantiate LoadbalanceAlgorithm implementation class " +
                             algorithmStr;
                log.fatal(msg, e); // We cannot continue execution. Hence it is logged at fatal level
                throw new SynapseException(msg, e);
View Full Code Here

        return algorithm;
    }

    public static LoadbalanceAlgorithm createLoadbalanceAlgorithm2(OMElement loadbalanceElement,
                                                                   List<Member> members) {
        LoadbalanceAlgorithm algorithm = createLoadbalanceAlgorithm(loadbalanceElement, null);
        algorithm.setApplicationMembers(members);
        return algorithm;
    }
View Full Code Here

*/
public class LoadbalanceAlgorithmFactory {

    public static LoadbalanceAlgorithm createLoadbalanceAlgorithm(OMElement loadbalanceElement, ArrayList endpoints) {

        LoadbalanceAlgorithm algorithm = null;

        String algorithmName = "roundRobin";
        OMAttribute algoAttribute = loadbalanceElement.getAttribute(new QName(null, XMLConfigConstants.ALGORITHM_NAME));
        if(algoAttribute != null) {
            algorithmName = algoAttribute.getAttributeValue();
View Full Code Here

    }

    public Member getNextApplicationMember(String host) {
        DomainAlgorithmContext domainAlgorithmContext = getDomainAlgorithmContext(host);
        String lbDomain = domainAlgorithmContext.getDomain();
        LoadbalanceAlgorithm algorithm = domainAlgorithmContext.getAlgorithm();
        GroupManagementAgent groupMgtAgent = clusteringAgent.getGroupManagementAgent(lbDomain);
        if(groupMgtAgent == null){
            String msg =
                    "A LoadBalanceEventHandler has not been specified in the axis2.xml " +
                    "file for the domain " + lbDomain + " for host " + host;
            log.error(msg);
            throw new SynapseException(msg);
        }
        algorithm.setApplicationMembers(groupMgtAgent.getMembers());
        AlgorithmContext context = domainAlgorithmContext.getAlgorithmContext();
        return algorithm.getNextApplicationMember(context);
    }
View Full Code Here

                                                                 "value")).trim();
                        lbProperties.put(propName, propValue);
                    }

                    // Set load balance algorithm
                    LoadbalanceAlgorithm algorithm =
                            LoadbalanceAlgorithmFactory.
                                    createLoadbalanceAlgorithm(loadbalanceElement, null);
                    lbMembershipHandler.init(lbProperties, algorithm);
                    loadbalanceEndpoint.setLoadBalanceMembershipHandler(lbMembershipHandler);
                } catch (Exception e) {
View Full Code Here

        // here we have to pass tenant id to get domain from hostContext
        String domain = hostContext.getDomainFromTenantId(tenantId);
        String subDomain = hostContext.getSubDomainFromTenantId(tenantId);

        LoadbalanceAlgorithm algorithm = hostContext.getAlgorithm();
        GroupManagementAgent groupMgtAgent = clusteringAgent.getGroupManagementAgent(domain, subDomain);
       
        if (groupMgtAgent == null) {
          String tenantDomain;
            try {
              tenantDomain = ConfigHolder.getInstance().getRealmService().getTenantManager().getDomain(tenantId);
            } catch (UserStoreException ignore) {
              tenantDomain = ""+tenantId;
            }
         
            String msg =
                    "No Group Management Agent found for the domain: " + domain + ", subDomain: "
                        + subDomain + ", host: " + host+ " and for tenant: "
                        +  tenantDomain;
            log.error(msg);
            throw new SynapseException(msg);
        }
        algorithm.setApplicationMembers(groupMgtAgent.getMembers());
        AlgorithmContext context = hostContext.getAlgorithmContext();
        return algorithm.getNextApplicationMember(context);
    }
View Full Code Here

            log.error(msg, e);
            throw new TenantAwareLoadBalanceEndpointException(msg, e);
        }


        LoadbalanceAlgorithm algorithm = null;
        try {
            OMElement payload = AXIOMUtil.stringToOM(generatePayLoad());
            algorithm =
                    LoadbalanceAlgorithmFactory.
                            createLoadbalanceAlgorithm(payload, null);
View Full Code Here

TOP

Related Classes of org.apache.synapse.endpoints.algorithms.LoadbalanceAlgorithm

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.