Package org.apache.synapse.endpoints

Examples of org.apache.synapse.endpoints.LoadbalanceEndpoint


        OMElement loadbalanceElement = epConfig.getFirstChildWithName(
                new QName(SynapseConstants.SYNAPSE_NAMESPACE, "loadbalance"));

        if (loadbalanceElement != null) {

            LoadbalanceEndpoint loadbalanceEndpoint = new LoadbalanceEndpoint();

            // set endpoint name
            OMAttribute name = epConfig.getAttribute(new QName(
                    org.apache.synapse.config.xml.XMLConfigConstants.NULL_NAMESPACE, "name"));

            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. " +
                            "loadbalanceEndpoint element cannot have both member & endpoint " +
                            "child elements";
                    log.error(msg);
                    throw new SynapseException(msg);
                }

                List<Member> members = getMembers(loadbalanceElement);
                loadbalanceEndpoint.setMembers(members);
                algorithm =
                        LoadbalanceAlgorithmFactory.
                                createLoadbalanceAlgorithm2(loadbalanceElement, members);
                loadbalanceEndpoint.startApplicationMembershipTimer();
            }

            if (loadbalanceEndpoint.getChildren() == null &&
                    loadbalanceEndpoint.getMembers() == null) {
                String msg = "Invalid Synapse configuration.\n"
                    + "A LoadbalanceEndpoint must have child elements, but the LoadbalanceEndpoint "
                    + "'" + loadbalanceEndpoint.getName() + "' does not have any child elements.";
                log.error(msg);
                throw new SynapseException(msg);
            }
           
            // set load balance algorithm
            loadbalanceEndpoint.setAlgorithm(algorithm);

            // set if failover is turned off
            String failover = loadbalanceElement.getAttributeValue(new QName("failover"));
            if (failover != null && failover.equalsIgnoreCase("false")) {
                loadbalanceEndpoint.setFailover(false);
            }

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


        SendMediator send2 = (SendMediator) factory.createMediator(config2, new Properties());

        assertTrue("Top level endpoint should be a load balance endpoint.",
                send2.getEndpoint() instanceof LoadbalanceEndpoint);

        LoadbalanceEndpoint endpoint = (LoadbalanceEndpoint) send2.getEndpoint();
        List addresses = endpoint.getChildren();
        assertEquals("There should be 3 leaf level address endpoints", addresses.size(), 3);

        assertTrue("Leaf level endpoints should be address endpoints",
                addresses.get(0) instanceof AddressEndpoint);
        assertTrue("Leaf level endpoints should be address endpoints",
View Full Code Here

        SendMediator send2 = (SendMediator) factory.createMediator(config2, new Properties());

        assertTrue("Top level endpoint should be a load balance endpoint.",
                send2.getEndpoint() instanceof LoadbalanceEndpoint);

        LoadbalanceEndpoint loadbalanceEndpoint = (LoadbalanceEndpoint) send2.getEndpoint();

        List children = loadbalanceEndpoint.getChildren();
        assertEquals("Top level endpoint should have 2 child endpoints.", children.size(), 2);

        assertTrue("First child should be a address endpoint",
                children.get(0) instanceof AddressEndpoint);
View Full Code Here

            new AtomicInteger(18), new AtomicInteger(5),
            new AtomicInteger(4), new AtomicInteger(2),
            new AtomicInteger(1)};

    public void testInitialization () {
        LoadbalanceEndpoint endpoint = createLoadBalanceEndpoint();

        LoadbalanceAlgorithm algo = endpoint.getAlgorithm();

        assert algo instanceof WeightedRRLCAlgorithm;                   
        WeightedRRLCAlgorithm algorithm = (WeightedRRLCAlgorithm) algo;

        assertEquals(6 + 5 + 3 + 2 + 1, algorithm.getTotalWeight());
View Full Code Here

        assertEquals(2, algorithm.getRoundsPerRecalculation());
    }

    public void testNextEndpoint() {
        MessageContext messageContext = createMessageContext();
        LoadbalanceEndpoint endpoint = createLoadBalanceEndpoint();

        String []firstTwoRoundsExpected = {
                "6", "6", "6", "6", "6", "6", "5", "5", "5", "5", "5", "3", "3", "3", "2", "2", "1",
                "6", "6", "6", "6", "6", "6", "5", "5", "5", "5", "5", "3", "3", "3", "2", "2", "1"};

        LoadbalanceAlgorithm algo = endpoint.getAlgorithm();

        String []firstTwoRoundsResults = new String[34];
        for (int i = 0; i < 34; i++) {
            Endpoint epr = algo.getNextEndpoint(messageContext, null);
            if (epr instanceof AddressEndpoint) {
View Full Code Here

            assertEquals(secondTwoRoundsExpected[i], secondTwoRoundsResults[i]);
        }
    }

    private LoadbalanceEndpoint createLoadBalanceEndpoint() {
        LoadbalanceEndpoint loadbalanceEndpoint = new LoadbalanceEndpoint();
        List<Endpoint> endpoints = createEndpoints();
        WeightedRRLCAlgorithm algorithm = new WeightedRRLCAlgorithm();

        MediatorProperty property = new MediatorProperty();
        property.setName(WeightedRRLCAlgorithm.LB_WEIGHTED_RRLC_ROUNDS_PER_RECAL);
        property.setValue("2");
        loadbalanceEndpoint.addProperty(property);       

        algorithm.setEndpoints(endpoints);
        algorithm.setLoadBalanceEndpoint(loadbalanceEndpoint);

        loadbalanceEndpoint.setChildren(endpoints);
        loadbalanceEndpoint.setAlgorithm(algorithm);

        SynapseEnvironment env = new Axis2SynapseEnvironment(
                new ConfigurationContext(new AxisConfiguration()), new SynapseConfiguration());
        loadbalanceEndpoint.init(env);
        return loadbalanceEndpoint;
    }
View Full Code Here

        fac = OMAbstractFactory.getOMFactory();
        OMElement endpointElement
                = fac.createOMElement("endpoint", SynapseConstants.SYNAPSE_OMNAMESPACE);
       
        LoadbalanceEndpoint loadbalanceEndpoint = (LoadbalanceEndpoint) endpoint;

        // serialize the parameters
        serializeProperties(loadbalanceEndpoint, endpointElement);

        serializeCommonAttributes(endpoint,endpointElement);

        OMElement loadbalanceElement
                = fac.createOMElement("loadbalance", SynapseConstants.SYNAPSE_OMNAMESPACE);
        endpointElement.addChild(loadbalanceElement);

        loadbalanceElement.addAttribute(XMLConfigConstants.LOADBALANCE_ALGORITHM,
                                        loadbalanceEndpoint.getAlgorithm().getClass().getName(),
                                        null);

        // set if failover is turned off in the endpoint
        if (!loadbalanceEndpoint.isFailover()) {
            loadbalanceElement.addAttribute("failover", "false", null);
        }

        // Serialize endpoint elements which are children of the loadbalance element
        if (loadbalanceEndpoint.getChildren() != null) {
            for (Endpoint childEndpoint : loadbalanceEndpoint.getChildren()) {
                loadbalanceElement.addChild(EndpointSerializer.getElementFromEndpoint(childEndpoint));
            }

        } else {
            for (Member member : loadbalanceEndpoint.getMembers()) {
                OMElement memberEle = fac.createOMElement(
                        "member", SynapseConstants.SYNAPSE_OMNAMESPACE, loadbalanceElement);
                memberEle.addAttribute(fac.createOMAttribute(
                        "hostName", null, member.getHostName()));
                memberEle.addAttribute(fac.createOMAttribute(
View Full Code Here

        fac = OMAbstractFactory.getOMFactory();
        OMElement endpointElement
                = fac.createOMElement("endpoint", SynapseConstants.SYNAPSE_OMNAMESPACE);
       
        LoadbalanceEndpoint loadbalanceEndpoint = (LoadbalanceEndpoint) endpoint;

        serializeCommonAttributes(endpoint,endpointElement);

        OMElement loadbalanceElement
                = fac.createOMElement("loadbalance", SynapseConstants.SYNAPSE_OMNAMESPACE);
        endpointElement.addChild(loadbalanceElement);

        loadbalanceElement.addAttribute(XMLConfigConstants.LOADBALANCE_ALGORITHM,
                                        loadbalanceEndpoint.getAlgorithm().getClass().getName(),
                                        null);

        // set if failover is turned off in the endpoint
        if (!loadbalanceEndpoint.isFailover()) {
            loadbalanceElement.addAttribute("failover", "false", null);
        }

        // Serialize endpoint elements which are children of the loadbalance element
        if (loadbalanceEndpoint.getChildren() != null) {
            for (Endpoint childEndpoint : loadbalanceEndpoint.getChildren()) {
                loadbalanceElement.addChild(EndpointSerializer.getElementFromEndpoint(childEndpoint));
            }

        } else {
            for (Member member : loadbalanceEndpoint.getMembers()) {
                OMElement memberEle = fac.createOMElement(
                        "member", SynapseConstants.SYNAPSE_OMNAMESPACE, loadbalanceElement);
                memberEle.addAttribute(fac.createOMAttribute(
                        "hostName", null, member.getHostName()));
                memberEle.addAttribute(fac.createOMAttribute(
View Full Code Here

        SendMediator send2 = (SendMediator) factory.createMediator(config2, new Properties());

        assertTrue("Top level endpoint should be a load balance endpoint.",
                send2.getEndpoint() instanceof LoadbalanceEndpoint);

        LoadbalanceEndpoint endpoint = (LoadbalanceEndpoint) send2.getEndpoint();
        List addresses = endpoint.getChildren();
        assertEquals("There should be 3 leaf level address endpoints", addresses.size(), 3);

        assertTrue("Leaf level endpoints should be address endpoints",
                addresses.get(0) instanceof AddressEndpoint);
        assertTrue("Leaf level endpoints should be address endpoints",
View Full Code Here

        SendMediator send2 = (SendMediator) factory.createMediator(config2, new Properties());

        assertTrue("Top level endpoint should be a load balance endpoint.",
                send2.getEndpoint() instanceof LoadbalanceEndpoint);

        LoadbalanceEndpoint loadbalanceEndpoint = (LoadbalanceEndpoint) send2.getEndpoint();

        List children = loadbalanceEndpoint.getChildren();
        assertEquals("Top level endpoint should have 2 child endpoints.", children.size(), 2);

        assertTrue("First child should be a address endpoint",
                children.get(0) instanceof AddressEndpoint);
View Full Code Here

TOP

Related Classes of org.apache.synapse.endpoints.LoadbalanceEndpoint

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.