Search in sources :

Example 1 with ClusteringMessage

use of org.apache.axis2.clustering.ClusteringMessage in project carbon-apimgt by wso2.

the class TenantLoadMessageSenderTest method testSendTenantRegistryLoadMessage.

@Test
public void testSendTenantRegistryLoadMessage() throws ClusteringFault {
    ClusteringAgent clusteringAgent = PowerMockito.mock(ClusteringAgent.class);
    ClusteringMessage request = new TenantLoadMessage(1, "a.com");
    ClusteringCommand command = PowerMockito.mock(ClusteringCommand.class);
    List<ClusteringCommand> commandList = new ArrayList<ClusteringCommand>();
    commandList.add(command);
    PowerMockito.when(clusteringAgent.sendMessage(request, true)).thenReturn(commandList);
    tenantLoadMessageSender.sendTenantLoadMessage(clusteringAgent, 1, "a.com", 1);
}
Also used : ClusteringCommand(org.apache.axis2.clustering.ClusteringCommand) ClusteringMessage(org.apache.axis2.clustering.ClusteringMessage) ArrayList(java.util.ArrayList) ClusteringAgent(org.apache.axis2.clustering.ClusteringAgent) TenantLoadMessage(org.wso2.carbon.apimgt.impl.message.clustering.TenantLoadMessage) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with ClusteringMessage

use of org.apache.axis2.clustering.ClusteringMessage in project carbon-apimgt by wso2.

the class TenantLoadMessageSender method sendTenantLoadMessage.

/**
 * Send the {@link TenantLoadMessage} message
 *
 * @param clusteringAgent {@link ClusteringAgent} object
 * @param tenantId        tenant id
 * @param tenantDomain    tenant domain
 * @param retryCount      retry count if cluster message sending fails
 * @throws ClusteringFault id cluster message sending fails
 */
void sendTenantLoadMessage(ClusteringAgent clusteringAgent, int tenantId, String tenantDomain, int retryCount) throws ClusteringFault {
    // need to re-try if the initial message fails.
    int numberOfRetries = 0;
    ClusteringMessage request = new TenantLoadMessage(tenantId, tenantDomain);
    while (numberOfRetries < retryCount) {
        try {
            clusteringAgent.sendMessage(request, true);
            log.info("Sent [" + request.toString() + "]");
            break;
        } catch (ClusteringFault e) {
            numberOfRetries++;
            if (numberOfRetries < retryCount) {
                log.warn("Could not send TenantRegistryLoadMessage for tenant " + tenantId + ". Retry will be attempted in 2s. Request: " + request, e);
            } else {
                // cluster message sending failed, throw
                throw e;
            }
            try {
                Thread.sleep(2000);
            } catch (InterruptedException ignored) {
            }
        }
    }
}
Also used : ClusteringMessage(org.apache.axis2.clustering.ClusteringMessage) TenantLoadMessage(org.wso2.carbon.apimgt.impl.message.clustering.TenantLoadMessage) ClusteringFault(org.apache.axis2.clustering.ClusteringFault)

Aggregations

ClusteringMessage (org.apache.axis2.clustering.ClusteringMessage)2 TenantLoadMessage (org.wso2.carbon.apimgt.impl.message.clustering.TenantLoadMessage)2 ArrayList (java.util.ArrayList)1 ClusteringAgent (org.apache.axis2.clustering.ClusteringAgent)1 ClusteringCommand (org.apache.axis2.clustering.ClusteringCommand)1 ClusteringFault (org.apache.axis2.clustering.ClusteringFault)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1