LoadbalanceEndpoint loadbalanceEndpoint = new LoadbalanceEndpoint(); loadbalanceEndpoint.setName(name.getAttributeValue()); loadbalanceEndpoint.setChildren(endpoints); algorithm = LoadbalanceAlgorithmFactory. 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); loadbalanceEndpoint.setAlgorithm(algorithm); loadbalanceEndpoint.setFailover(false);
loadbalanceEndpoint.getAlgorithm().getClass().getName(), null); if (!loadbalanceEndpoint.isFailover()) { loadbalanceElement.addAttribute("failover", "false", null); if (loadbalanceEndpoint.isBuildMessageAtt()) { loadbalanceElement .addAttribute(XMLConfigConstants.BUILD_MESSAGE, Boolean.toString(loadbalanceEndpoint.isBuildMessageAtt()), null); if (loadbalanceEndpoint.getChildren() != null) { for (Endpoint childEndpoint : loadbalanceEndpoint.getChildren()) { loadbalanceElement.addChild(EndpointSerializer.getElementFromEndpoint(childEndpoint)); for (Member member : loadbalanceEndpoint.getMembers()) { OMElement memberEle = fac.createOMElement( "member", SynapseConstants.SYNAPSE_OMNAMESPACE, loadbalanceElement);
private void sendMessage(MessageContext synCtx) { logSetter(); if (log.isDebugEnabled()) { log.debug("Sending using Load-balance " + toString()); if (getContext().isState(EndpointContext.ST_OFF)) { informFailure(synCtx, SynapseConstants.ENDPOINT_LB_NONE_READY, "Loadbalance endpoint : " + getName() != null ? getName() : SynapseConstants.ANONYMOUS_ENDPOINT + " - is inactive"); return; endpoint = getNextChild(synCtx); evaluateProperties(synCtx); buildMessage(synCtx); buildMessage(synCtx); synCtx.pushFaultHandler(faultHandler); sendToApplicationMember(synCtx, to, faultHandler); } else { String msg = "Loadbalance endpoint : " + (getName() != null ? getName() : SynapseConstants.ANONYMOUS_ENDPOINT) + " - no ready child endpoints"; log.warn(msg); informFailure(synCtx, SynapseConstants.ENDPOINT_LB_NONE_READY, msg);
/** * If this endpoint is in inactive state, checks if all immediate child endpoints are still * failed. If so returns false. If at least one child endpoint is in active state, sets this * endpoint's state to active and returns true. As this a sessionless load balancing endpoint * having one active child endpoint is enough to consider this as active. * * @return true if active. false otherwise. */ public boolean readyToSend() { for (Endpoint endpoint : getChildren()) { if (endpoint.readyToSend()) { if (log.isDebugEnabled()) { log.debug("Load-balance " + this.toString() + " has at least one endpoint at ready state"); } return true; } } log.warn("Load-balance " + this.toString() + " has no endpoints at ready state to process message"); return false; }
/** * If this endpoint is in inactive state, checks if all immediate child endpoints are still * failed. If so returns false. If at least one child endpoint is in active state, sets this * endpoint's state to active and returns true. As this a sessionless load balancing endpoint * having one active child endpoint is enough to consider this as active. * * @return true if active. false otherwise. */ public boolean readyToSend() { if (getContext().isState(EndpointContext.ST_OFF)) { return false; } for (Endpoint endpoint : getChildren()) { if (endpoint.readyToSend()) { if (log.isDebugEnabled()) { log.debug("Load-balance " + this.toString() + " has at least one endpoint at ready state"); } return true; } } log.warn("Load-balance " + this.toString() + " has no endpoints at ready state to process message"); return false; }
public void send(MessageContext synCtx) { log.debug("Sending using Load-balance " + toString()); endpoint = getNextChild(synCtx); evaluateProperties(synCtx); synCtx.pushFaultHandler(faultHandler); sendToApplicationMember(synCtx, to, faultHandler); } else { String msg = "Loadbalance endpoint : " + (getName() != null ? getName() : SynapseConstants.ANONYMOUS_ENDPOINT) + " - no ready child endpoints"; log.warn(msg); informFailure(synCtx, SynapseConstants.ENDPOINT_LB_NONE_READY, msg);
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; }
@Override public void init(SynapseEnvironment synapseEnvironment) { ConfigurationContext cc = ((Axis2SynapseEnvironment) synapseEnvironment).getAxis2ConfigurationContext(); if (!initialized) { super.init(synapseEnvironment); if (algorithmContext == null) { algorithmContext = new AlgorithmContext(isClusteringEnabled, cc, getName()); } // Initialize the SAL Sessions if already has not been initialized. SALSessions salSessions = SALSessions.getInstance(); if (!salSessions.isInitialized()) { salSessions.initialize(isClusteringEnabled, cc); } } log.info("Dynamic load balance endpoint initialized"); }
List children = loadbalanceEndpoint.getChildren(); assertEquals("Top level endpoint should have 2 child endpoints.", children.size(), 2);
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()); assertEquals(0, algorithm.getTotalConnections()); assertEquals(0, algorithm.getEndpointCursor()); assertEquals(2, algorithm.getRoundsPerRecalculation()); }
@Override public void init(SynapseEnvironment synapseEnvironment) { ConfigurationContext cc = ((Axis2SynapseEnvironment) synapseEnvironment).getAxis2ConfigurationContext(); if (!initialized) { super.init(synapseEnvironment); if (algorithmContext == null) { algorithmContext = new AlgorithmContext(isClusteringEnabled, cc, getName()); } // Initialize the SAL Sessions if already has not been initialized. SALSessions salSessions = SALSessions.getInstance(); if (!salSessions.isInitialized()) { salSessions.initialize(isClusteringEnabled, cc); } } log.info("Dynamic load balance endpoint initialized"); }
List addresses = endpoint.getChildren(); assertEquals("There should be 3 leaf level address endpoints", addresses.size(), 3);
"6", "6", "6", "6", "6", "6", "5", "5", "5", "5", "5", "3", "3", "3", "2", "2", "1"}; LoadbalanceAlgorithm algo = endpoint.getAlgorithm();
LoadbalanceEndpoint loadbalanceEndpoint = new LoadbalanceEndpoint(); loadbalanceEndpoint.setName(name.getAttributeValue()); loadbalanceEndpoint.setChildren(endpoints); algorithm = LoadbalanceAlgorithmFactory. 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); loadbalanceEndpoint.setAlgorithm(algorithm); loadbalanceEndpoint.setFailover(false); loadbalanceEndpoint.setBuildMessageAttAvailable(true); if (JavaUtils.isTrueExplicitly(buildMessageAtt)) { loadbalanceEndpoint.setBuildMessageAtt(true);
loadbalanceEndpoint.getAlgorithm().getClass().getName(), null); if (!loadbalanceEndpoint.isFailover()) { loadbalanceElement.addAttribute("failover", "false", null); if (loadbalanceEndpoint.getChildren() != null) { for (Endpoint childEndpoint : loadbalanceEndpoint.getChildren()) { loadbalanceElement.addChild(EndpointSerializer.getElementFromEndpoint(childEndpoint)); for (Member member : loadbalanceEndpoint.getMembers()) { OMElement memberEle = fac.createOMElement( "member", SynapseConstants.SYNAPSE_OMNAMESPACE, loadbalanceElement);
public void init(SynapseEnvironment synapseEnvironment) { ConfigurationContext cc = ((Axis2SynapseEnvironment) synapseEnvironment).getAxis2ConfigurationContext(); if (!initialized) { super.init(synapseEnvironment); // Initialize the SAL Sessions if already has not been initialized. SALSessions salSessions = SALSessions.getInstance(); if (!salSessions.isInitialized()) { salSessions.initialize(isClusteringEnabled, cc); } //For each root level SAL endpoints , all children are registered // This is for cluttering as in clustering only endpoint names are replicated // and it needs way to pick endpoints by name if (isClusteringEnabled && (this.getParentEndpoint() == null || !(this.getParentEndpoint() instanceof SALoadbalanceEndpoint))) { SALSessions.getInstance().registerChildren(this, getChildren()); } } }
List addresses = endpoint.getChildren(); assertEquals("There should be 3 leaf level address endpoints", addresses.size(), 3);
public void init(SynapseEnvironment synapseEnvironment) { ConfigurationContext cc = ((Axis2SynapseEnvironment) synapseEnvironment).getAxis2ConfigurationContext(); if (!initialized) { super.init(synapseEnvironment); // Initialize the SAL Sessions if already has not been initialized. SALSessions salSessions = SALSessions.getInstance(); if (!salSessions.isInitialized()) { salSessions.initialize(isClusteringEnabled, cc); } //For each root level SAL endpoints , all children are registered // This is for cluttering as in clustering only endpoint names are replicated // and it needs way to pick endpoints by name if (isClusteringEnabled && (this.getParentEndpoint() == null || !(this.getParentEndpoint() instanceof SALoadbalanceEndpoint))) { SALSessions.getInstance().registerChildren(this, getChildren()); } } }
List children = loadbalanceEndpoint.getChildren(); assertEquals("Top level endpoint should have 2 child endpoints.", children.size(), 2);