Java Code Examples for org.apache.axis2.clustering.ClusteringAgent#sendMessage()

The following examples show how to use org.apache.axis2.clustering.ClusteringAgent#sendMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PolicySearchCache.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Send out policy status change notification to other nodes.
 *
 * @param clusterMessage
 * @param isSync
 */
private void sendClusterMessage(ClusteringMessage clusterMessage, boolean isSync) {
    try {
        if (log.isDebugEnabled()) {
            log.debug("Sending cluster message to all other nodes");
        }
        ClusteringAgent clusteringAgent = EntitlementConfigHolder.getInstance().getConfigurationContextService()
                .getServerConfigContext().getAxisConfiguration().getClusteringAgent();
        if (clusteringAgent != null) {
            clusteringAgent.sendMessage(clusterMessage, isSync);
        } else {
            log.error("Clustering Agent not available.");
        }
    } catch (ClusteringFault clusteringFault) {
        log.error("Error while sending cluster message", clusteringFault);
    }
}
 
Example 2
Source File: PolicyCache.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Send out policy status change notification to other nodes.
 *
 * @param clusterMessage
 * @param isSync
 */
private void sendClusterMessage(PolicyStatusClusterMessage clusterMessage, boolean isSync) {
    try {
        if (log.isDebugEnabled()) {
            log.debug("Sending policy status change cluster message to all other nodes");
        }

        ClusteringAgent clusteringAgent = EntitlementConfigHolder.getInstance()
                .getConfigurationContextService()
                .getServerConfigContext()
                .getAxisConfiguration()
                .getClusteringAgent();

        if (clusteringAgent != null) {
            clusteringAgent.sendMessage(clusterMessage, isSync);
        } else {
            log.error("Clustering Agent not available.");
        }
    } catch (ClusteringFault clusteringFault) {
        log.error("Error while sending policy status change cluster message", clusteringFault);
    }
}
 
Example 3
Source File: OpenIDAssociationReplicationManager.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
private void replicateAssociationInfo(AssociationClusterMessage associationInfoData) {
    if (log.isDebugEnabled()) {
        log.debug("Starting to replicate association : " + associationInfoData.getAssociation().getHandle());
    }

    ClusteringAgent agent = IdentityProviderServiceComponent.getConfigContext().getAxisConfiguration().getClusteringAgent();
    if (log.isDebugEnabled()) {
        log.debug("Clustering Agent: " + agent);
    }

    if (agent != null) {
        try {
            agent.sendMessage(associationInfoData, true);
        } catch (ClusteringFault e) {
            log.error("Unable to send cluster message :" + e.getMessage(), e);
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Completed replicating association : " + associationInfoData.getAssociation().getHandle());
    }
}
 
Example 4
Source File: VirtualHostClusterUtil.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
public static Boolean addServiceMappingToCluster(String mapping, String epr) throws AxisFault {
    Boolean isMappingAdded = false;
    try {
        ClusteringAgent agent = getClusteringAgent();
        if(agent != null) {
            agent.sendMessage(new ServiceMappingAddRequest(mapping, epr), true);
            isMappingAdded = true;
        }
        if (log.isDebugEnabled()) {
            log.debug("sent cluster command to to get Active tenants on cluster");
        }
    } catch (AxisFault f) {
        String msg = "Error in getting active tenant by cluster commands";
        log.error(msg, f);
        throw new AxisFault(msg);
    }
    return isMappingAdded;
}
 
Example 5
Source File: VirtualHostClusterUtil.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
public static Boolean addVirtualHostsToCluster(String hostName, String uri, String webappPath) throws AxisFault {
    Boolean isMappingAdded = false;
    try {
        ClusteringAgent agent = getClusteringAgent();
        if(agent != null) {
            agent.sendMessage(new VirtualHostAddRequest(hostName, uri, webappPath), true);
            isMappingAdded = true;
        }
        if (log.isDebugEnabled()) {
            log.debug("sent cluster command to to get Active tenants on cluster");
        }
    } catch (AxisFault f) {
        String msg = "Error in getting active tenant by cluster commands";
        log.error(msg, f);
        throw new AxisFault(msg);
    }
    return isMappingAdded;
}
 
Example 6
Source File: VirtualHostClusterUtil.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
public static Boolean deleteServiceMappingToCluster(String mapping) throws AxisFault {
    Boolean isMappingAdded = false;
    try {
        ClusteringAgent agent = getClusteringAgent();
        if(agent != null) {
            agent.sendMessage(new ServiceMappingDeleteRequest(mapping), true);
            isMappingAdded = true;
        }
        if (log.isDebugEnabled()) {
            log.debug("sent cluster command to to get Active tenants on cluster");
        }
    } catch (AxisFault f) {
        String msg = "Error in getting active tenant by cluster commands";
        log.error(msg, f);
        throw new AxisFault(msg);
    }
    return isMappingAdded;
}
 
Example 7
Source File: VirtualHostClusterUtil.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
public static Boolean deleteVirtualHostsToCluster(String hostName) throws AxisFault {
    Boolean isMappingAdded = false;
    try {
        ClusteringAgent agent = getClusteringAgent();
        if(agent != null) {
            agent.sendMessage(new VirtualHostDeleteMapping(hostName), true);
            isMappingAdded = true;
        }
        if (log.isDebugEnabled()) {
            log.debug("sent cluster command to to get Active tenants on cluster");
        }
    } catch (AxisFault f) {
        String msg = "Error in getting active tenant by cluster commands";
        log.error(msg, f);
        throw new AxisFault(msg);
    }
    return isMappingAdded;
}
 
Example 8
Source File: DataSourceRepository.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
private void notifyClusterDSChange(String dsName) throws DataSourceException {
	if (log.isDebugEnabled()) {
		log.debug("Notifying cluster DS change: " + dsName);
	}
	ConfigurationContextService configCtxService = DataSourceServiceComponent.
	        getConfigContextService();
	if (configCtxService == null) {
		throw new DataSourceException("ConfigurationContextService not available " +
				"for notifying the cluster");
	}
	ConfigurationContext configCtx = configCtxService.getServerConfigContext();
	ClusteringAgent agent = configCtx.getAxisConfiguration().getClusteringAgent();
	if (log.isDebugEnabled()) {
		log.debug("Clustering Agent: " + agent);
	}
	if (agent != null) {
		DataSourceStatMessage msg = new DataSourceStatMessage();
		msg.setTenantId(this.getTenantId());
		msg.setDsName(dsName);
		try {
			agent.sendMessage(msg, true);
		} catch (ClusteringFault e) {
			throw new DataSourceException("Error in sending out cluster message: " +
					e.getMessage(), e);
		}
	}
}
 
Example 9
Source File: SSOSessionManager.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
public void sendSessionInvalidationClusterMessage(String sessionIndex) {

        SessionClusterMessage clusterMessage = new SessionClusterMessage();
        clusterMessage.setMessageId(UUID.randomUUID());
        clusterMessage.setSessionIndex(sessionIndex);

        ClusteringAgent clusteringAgent = SAML2SSOAuthFEDataHolder.getInstance()
                .getConfigurationContextService().getServerConfigContext().getAxisConfiguration()
                .getClusteringAgent();

        if (clusteringAgent != null) {
            int numberOfRetries = 0;

            while (numberOfRetries < 60) {
                try {
                    clusteringAgent.sendMessage(clusterMessage, true);
                    log.info("Sent [" + clusterMessage + "]");
                    break;
                } catch (ClusteringFault e) {
                    numberOfRetries++;

                    if (numberOfRetries < 60) {
                        log.warn(
                                "Could not send SSOSessionInvalidationClusterMessage. Retry will be attempted in 2s. Request: "
                                        + clusterMessage, e);
                    } else {
                        log.error(
                                "Could not send SSOSessionInvalidationClusterMessage. Several retries failed. Request:"
                                        + clusterMessage, e);
                    }

                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException ignored) {
                    }
                }
            }
        }
    }
 
Example 10
Source File: SAMLSSORelyingPartyObject.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
public void sendSessionInvalidationClusterMessage(String sessionIndex) {

        SessionClusterMessage clusterMessage = new SessionClusterMessage();
        clusterMessage.setMessageId(UUID.randomUUID());
        clusterMessage.setSessionIndex(sessionIndex);
        ClusteringAgent clusteringAgent = SSOHostObjectDataHolder.getInstance()
                .getConfigurationContextService().getServerConfigContext().getAxisConfiguration()
                .getClusteringAgent();
        if (clusteringAgent != null) {
            int numberOfRetries = 0;
            while (numberOfRetries < 60) {
                try {
                    clusteringAgent.sendMessage(clusterMessage, true);
                    log.info("Sent [" + clusterMessage + "]");
                    break;
                } catch (ClusteringFault e) {
                    numberOfRetries++;
                    if (numberOfRetries < 60) {
                        log.warn(
                                "Could not send SSOSessionInvalidationClusterMessage. Retry will be attempted in 2s. Request: "
                                        + clusterMessage, e);
                    } else {
                        log.error("Could not send SSOSessionInvalidationClusterMessage. Several retries failed. Request:"
                                + clusterMessage, e);
                    }
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException ignored) {
                    }
                }
            }
        }
    }
 
Example 11
Source File: TenantLoadMessageSender.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * 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) {
            }
        }
    }
}
 
Example 12
Source File: RemoteTaskManager.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
private TaskState getTaskStateFromLocalCluster(String taskName) throws TaskException {
    /* first check local server */
    if (this.isTaskRunning(taskName)) {
        return TaskState.BLOCKED;
    }
    ClusteringAgent agent = this.getClusteringAgent();
    if (agent == null) {
        return TaskState.UNKNOWN;
    }
    TaskStatusMessage msg = new TaskStatusMessage();
    msg.setTaskName(taskName);
    msg.setTaskType(this.getTaskType());
    msg.setTenantId(this.getTenantId());
    try {
        List<ClusteringCommand> result = agent.sendMessage(msg, true);
        TaskStatusResult status;
        for (ClusteringCommand entry : result) {
            status = (TaskStatusResult) entry;
            if (status.isRunning()) {
                return TaskState.BLOCKED;
            }
        }
        return TaskState.NORMAL;
    } catch (ClusteringFault e) {
        throw new TaskException(e.getMessage(), Code.UNKNOWN, e);
    }
}
 
Example 13
Source File: SharedMemoryCacheUtil.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
/**
    * This is to send clusterMessage to inform other nodes about subscription added to the system, so that everyone can add new one.
    * @param topicName
    * @param subsciptionID
    * @param tenantID
    * @param tenantName
    * @throws ClusteringFault
    */
public static void sendAddSubscriptionClusterMessage(String topicName,String subsciptionID, 
		int tenantID, String tenantName) throws ClusteringFault{
	ConfigurationContextService configContextService = (ConfigurationContextService) PrivilegedCarbonContext
			.getThreadLocalCarbonContext().getOSGiService(ConfigurationContextService.class);
	ConfigurationContext configContext = configContextService.getServerConfigContext();
	ClusteringAgent agent = configContext.getAxisConfiguration().getClusteringAgent();

	agent.sendMessage(new SubscriptionClusterMessage(topicName,subsciptionID,tenantID, tenantName), false);
}