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);
}
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) {
}
}
}
}
Aggregations