public boolean readyToSend() { if (getContext().isState(EndpointContext.ST_OFF)) { return false; } for (Endpoint endpoint : getChildren()) { if (endpoint.readyToSend()) { currentEndpoint = endpoint; return true; } } return false; }
@Override public boolean readyToSend(){ if (getContext().isState(EndpointContext.ST_OFF)) { return false; } for(Endpoint endpoint : getChildren()){ if(endpoint.readyToSend()){ if (log.isDebugEnabled()) { log.debug("Recipient List " + this.toString() + " has at least one endpoint at ready state"); } return true; } } return false; }
/** * Is the endpoint considered to be in the given state? * @param state the state to consider * @return true if all endpoints in a group are of the given state, or if a leaf endpoint is in the given state */ public boolean isEndpointInState(int state) { if (endpoint.getChildren() != null) { int count = 0, total = 0; for (Endpoint e : endpoint.getChildren()) { if (e.getContext().isState(state)) { count++; } total++; } return count == total; } else if (endpoint.getContext() != null) { return endpoint.getContext().isState(state); } return false; }
/** * Is the endpoint considered to be in the given state? * @param state the state to consider * @return true if all endpoints in a group are of the given state, or if a leaf endpoint is in the given state */ public boolean isEndpointInState(int state) { if (endpoint.getChildren() != null) { int count = 0, total = 0; for (Endpoint e : endpoint.getChildren()) { if (e.getContext().isState(state)) { count++; } total++; } return count == total; } else if (endpoint.getContext() != null) { return endpoint.getContext().isState(state); } return false; }
/** * Return the number of active children for this endpoint * @return the number of active children for this endpoint * @throws Exception */ public int getActiveChildren() throws Exception { if (endpoint.getChildren() == null) { return 0; } else { int activeCount = 0; for (Endpoint e : endpoint.getChildren()) { if (e.getContext().isState(EndpointContext.ST_ACTIVE)) { activeCount++; } } return activeCount; } }
/** * 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; }
/** * Return the number of active children for this endpoint * @return the number of active children for this endpoint * @throws Exception */ public int getActiveChildren() throws Exception { if (endpoint.getChildren() == null) { return 0; } else { int activeCount = 0; for (Endpoint e : endpoint.getChildren()) { if (e.getContext().isState(EndpointContext.ST_ACTIVE)) { activeCount++; } } return activeCount; } }
/** * Is a leaf level endpoint active? For a group endpoint this means at least one is active * @return true if at least one is active in a group endpoint; for a leaf - if it is currently active * @throws Exception */ public boolean isActive() throws Exception { if (endpoint.getChildren() != null) { return getActiveChildren() > 0; } else if (endpoint.getContext() != null) { return endpoint.getContext().isState(EndpointContext.ST_ACTIVE); } return false; }
/** * Is a leaf level endpoint active? For a group endpoint this means at least one is active * @return true if at least one is active in a group endpoint; for a leaf - if it is currently active * @throws Exception */ public boolean isActive() throws Exception { if (endpoint.getChildren() != null) { return getActiveChildren() > 0; } else if (endpoint.getContext() != null) { return endpoint.getContext().isState(EndpointContext.ST_ACTIVE); } return false; }
public void sendMessage(MessageContext synCtx) { logSetter(); if (log.isDebugEnabled()) { log.debug("Sending using Recipient List " + toString()); } if (getContext().isState(EndpointContext.ST_OFF)) { informFailure(synCtx, SynapseConstants.ENDPOINT_RL_NONE_READY, "RecipientList endpoint : " + getName() != null ? getName() : SynapseConstants.ANONYMOUS_ENDPOINT + " - is inactive"); return; } List<Endpoint> children = getChildren(); //Service child endpoints if (children != null && !children.isEmpty()) { sendToEndpointList(synCtx, children); } //Service member elements if specified else if (members != null && !members.isEmpty()) { sendToApplicationMembers(synCtx); } else if (dynamicEnpointSet != null) { sendToDynamicMembers(synCtx); } else { String msg = "No child endpoints nor member elements available"; log.error(msg); throw new SynapseException(msg); } }
/** * Asserts if the the endpoint view correctly returns the number of active child endpoints included in the * endpoint associated with the view. * * @throws Exception if an error occurs while accessing child endpoints */ public void testGetActiveChildren() throws Exception { //Assert with children AbstractEndpoint endpoint = createMockEndPoint(5); Mockito.when(endpoint.getChildren().get(0).getContext().isState(EndpointContext.ST_ACTIVE)).thenReturn(true); Mockito.when(endpoint.getChildren().get(1).getContext().isState(EndpointContext.ST_ACTIVE)).thenReturn(false); Mockito.when(endpoint.getChildren().get(2).getContext().isState(EndpointContext.ST_ACTIVE)).thenReturn(true); Mockito.when(endpoint.getChildren().get(3).getContext().isState(EndpointContext.ST_ACTIVE)).thenReturn(false); Mockito.when(endpoint.getChildren().get(4).getContext().isState(EndpointContext.ST_ACTIVE)).thenReturn(true); EndpointView endpointView = new EndpointView("endpoint", endpoint); Assert.assertEquals("Incorrect active children count", 3, endpointView.getActiveChildren()); //Assert when endpoint has no children EndpointView endpointViewWithoutChildren = createMockEndPointView(0); Assert.assertEquals("Incorrect active children count", 0, endpointViewWithoutChildren.getActiveChildren()); }
/** * Tests if the endpoint view correctly returns the suspended state with and without the presence of children * endpoints. The endpoint view should be suspended if and only if all child endpoints are suspended. * * @throws Exception if an error occurs while accessing the state of the endpoint view */ public void testIsSuspended() throws Exception { AbstractEndpoint endpoint = createMockEndPoint(2); EndpointView endpointView = new EndpointView("endpoint", endpoint); Mockito.when(endpoint.getChildren().get(0).getContext().isState(EndpointContext.ST_SUSPENDED)).thenReturn(true); Assert.assertFalse("Endpoint view is suspended with active child endpoints", endpointView.isSuspended()); Mockito.when(endpoint.getChildren().get(1).getContext().isState(EndpointContext.ST_SUSPENDED)).thenReturn(true); Assert.assertTrue("Endpoint view is not suspended with all child endpoints being suspended", endpointView.isSuspended()); endpoint = createMockEndPoint(0); endpointView = new EndpointView("endpoint", endpoint); Mockito.when(endpoint.getContext().isState(EndpointContext.ST_SUSPENDED)).thenReturn(true); Assert.assertTrue("Endpoint view is not suspended", endpointView.isSuspended()); Mockito.when(endpoint.getContext().isState(EndpointContext.ST_SUSPENDED)).thenReturn(false); Assert.assertFalse("Endpoint view is suspended", endpointView.isSuspended()); }
/** * Tests if the endpoint view correctly returns the switched off state with and without the presence of children * endpoints. The endpoint view should be switched if and only if all child endpoints are switched off. * * @throws Exception if an error occurs while accessing the state of the endpoint view */ public void testIsSwitchedOff() throws Exception { AbstractEndpoint endpoint = createMockEndPoint(2); EndpointView endpointView = new EndpointView("endpoint", endpoint); Mockito.when(endpoint.getChildren().get(0).getContext().isState(EndpointContext.ST_OFF)).thenReturn(true); Assert.assertFalse("Endpoint view switched off with active child endpoints", endpointView.isSwitchedOff()); Mockito.when(endpoint.getChildren().get(1).getContext().isState(EndpointContext.ST_OFF)).thenReturn(true); Assert.assertTrue("Endpoint view is not switched off with all child endpoints being switched off", endpointView.isSwitchedOff()); endpoint = createMockEndPoint(0); endpointView = new EndpointView("endpoint", endpoint); Mockito.when(endpoint.getContext().isState(EndpointContext.ST_OFF)).thenReturn(true); Assert.assertTrue("Endpoint view is not switched off", endpointView.isSwitchedOff()); Mockito.when(endpoint.getContext().isState(EndpointContext.ST_OFF)).thenReturn(false); Assert.assertFalse("Endpoint view is swtiched off", endpointView.isSwitchedOff()); }
/** * Tests if the endpoint view correctly returns the active state with and without the presence of children * endpoints. The endpoint should be inactive if and only if all child endpoints are inactive. * * @throws Exception if an error occurs while accessing the active children of the endpoint view */ public void testIsActive() throws Exception { AbstractEndpoint endpoint = createMockEndPoint(3); EndpointView endpointView = new EndpointView("endpoint", endpoint); Mockito.when(endpoint.getChildren().get(2).getContext().isState(EndpointContext.ST_ACTIVE)).thenReturn(true); Assert.assertTrue("Endpoint view is not active with active child endpoint", endpointView.isActive()); endpoint = createMockEndPoint(0); EndpointContext endpointContext = Mockito.mock(EndpointContext.class); Mockito.when(endpoint.getContext()).thenReturn(endpointContext); endpointView = new EndpointView("endpoint", endpoint); Mockito.when(endpoint.getContext().isState(EndpointContext.ST_ACTIVE)).thenReturn(true); Assert.assertTrue("Endpoint view is not active", endpointView.isActive()); Mockito.when(endpoint.getContext().isState(EndpointContext.ST_ACTIVE)).thenReturn(false); Assert.assertFalse("Endpoint is active", endpointView.isActive()); }
/** * Tests if the endpoint view correctly returns the timed out state with and without the presence of children * endpoints. The endpoint view should be timed out if and only if all child endpoints are timed out. * * @throws Exception if an error occurs while accessing the state of the endpoint view */ public void testIsTimedout() throws Exception { AbstractEndpoint endpoint = createMockEndPoint(2); EndpointView endpointView = new EndpointView("endpoint", endpoint); Mockito.when(endpoint.getChildren().get(0).getContext().isState(EndpointContext.ST_TIMEOUT)).thenReturn(true); Assert.assertFalse("Endpoint view is timed out with active child endpoints", endpointView.isTimedout()); Mockito.when(endpoint.getChildren().get(1).getContext().isState(EndpointContext.ST_TIMEOUT)).thenReturn(true); Assert.assertTrue("Endpoint view is not timed out with all child endpoints being timed out", endpointView.isTimedout()); endpoint = createMockEndPoint(0); endpointView = new EndpointView("endpoint", endpoint); Mockito.when(endpoint.getContext().isState(EndpointContext.ST_TIMEOUT)).thenReturn(true); Assert.assertTrue("Endpoint view is not timed out", endpointView.isTimedout()); Mockito.when(endpoint.getContext().isState(EndpointContext.ST_TIMEOUT)).thenReturn(false); Assert.assertFalse("Endpoint view is timed out", endpointView.isTimedout()); }
if (getContext().isState(EndpointContext.ST_OFF)) { informFailure(synCtx, SynapseConstants.ENDPOINT_LB_NONE_READY, "Loadbalance endpoint : " + getName() != null ? getName() : SynapseConstants.ANONYMOUS_ENDPOINT + " - is inactive");
if (getContext().isState(EndpointContext.ST_OFF)) { informFailure(synCtx, SynapseConstants.ENDPOINT_LB_NONE_READY, "Loadbalance endpoint : " + getName() != null ? getName() : SynapseConstants.ANONYMOUS_ENDPOINT + " - is inactive");
if (getContext().isState(EndpointContext.ST_OFF)) { informFailure(synCtx, SynapseConstants.ENDPOINT_FO_NONE_READY, "Failover endpoint : " + getName() != null ? getName() : SynapseConstants.ANONYMOUS_ENDPOINT + " - is inactive");