org.apache.axis2.clustering.ClusteringFault Java Examples

The following examples show how to use org.apache.axis2.clustering.ClusteringFault. 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: HelloService.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
public String greet(String name) {
    ServiceContext serviceContext =
            MessageContext.getCurrentMessageContext().getServiceContext();
    serviceContext.setProperty(HELLO_SERVICE_NAME, name);
    try {
        Replicator.replicate(serviceContext, new String[]{HELLO_SERVICE_NAME});
    } catch (ClusteringFault clusteringFault) {
        clusteringFault.printStackTrace();
    }

    if (name != null) {
        return "Hello World, " + name + " !!!";
    } else {
        return "Hello World !!!";
    }
}
 
Example #2
Source File: StatUpdateClusterMessage.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(ConfigurationContext configurationContext) throws ClusteringFault {

    //update the service variable, a boolean variable representing the stat data publishing in the node
    APIManagerAnalyticsConfiguration instanceOfAPIAnalytics = APIManagerAnalyticsConfiguration.getInstance();
    instanceOfAPIAnalytics.setAnalyticsEnabled(statUpdateStatus);

    // Only change Data publishing information only if they are set
    if (receiverUrl != null && !receiverUrl.isEmpty() &&
        user != null && !user.isEmpty() &&
        password != null && !password.isEmpty()) {
        instanceOfAPIAnalytics.setDasReceiverUrlGroups(receiverUrl);
        instanceOfAPIAnalytics.setDasReceiverServerUser(user);
        instanceOfAPIAnalytics.setDasReceiverServerPassword(password);
    }

    if (log.isDebugEnabled()) {
        log.debug("Updated Stat publishing status to : " + statUpdateStatus);
    }

}
 
Example #3
Source File: RemoteTaskManager.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(ConfigurationContext ctx) throws ClusteringFault {
    try {
        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(this.getTenantId(), true);
        TaskManager tm = TasksDSComponent.getTaskService().getTaskManager(
                this.getTaskType());
        if (tm instanceof RemoteTaskManager) {
            this.result = new TaskStatusResult();
            this.result.setRunning(((RemoteTaskManager) tm).isTaskRunning(this
                    .getTaskName()));
        }
    } catch (Exception e) {
        throw new ClusteringFault(e.getMessage(), e);
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}
 
Example #4
Source File: SharedMemorySubscriptionStorage.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
public void addSubscription(Subscription subscription) {
      String topicName = getTopicName(subscription.getTopicName());
      SubscriptionContainer subscriptionsContainer = getTopicSubscriptionCache().get(topicName);

      if (subscriptionsContainer == null){
          subscriptionsContainer = new SubscriptionContainer(topicName);
      }
      
      subscriptionsContainer.getSubscriptionsCache().put(subscription.getId(), subscription);
      getTopicSubscriptionCache().put(topicName, subscriptionsContainer);
      getSubscriptionIDTopicNameCache().put(subscription.getId(), topicName);
      
      //send cluster message to inform other nodes about subscription added to the system, so that everyone can add new one.
      try {
	SharedMemoryCacheUtil.sendAddSubscriptionClusterMessage(topicName, subscription.getId(), 
			subscription.getTenantId(),
			subscription.getTenantDomain());
} catch (ClusteringFault e) {
	//This happen due to hazelcast clustering not setup correctly. subscription cluster will not send to other nodes.
	log.error("Subscription cluster message sending failed",e);
}
  }
 
Example #5
Source File: SubscriptionClusterMessage.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(ConfigurationContext arg0) throws ClusteringFault {

       try {
           PrivilegedCarbonContext.startTenantFlow();
           PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantID);
           PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain);
           PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true);
          
           //get the subscription by adding the 
           SubscriptionContainer subscriptionsContainer = SharedMemorySubscriptionStorage.getTopicSubscriptionCache().get(topicName);

           if (subscriptionsContainer != null){
           	subscriptionsContainer.getSubscriptionsCache().get(subscriptionID);
           	log.info("Subscription ID: "+subscriptionID+" for the topic: "+topicName+" is received.");
           }          

       }
       finally{
           PrivilegedCarbonContext.endTenantFlow();
       }
}
 
Example #6
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 #7
Source File: HelloService.java    From product-ei with Apache License 2.0 6 votes vote down vote up
public String greet(String name) {
    ServiceContext serviceContext =
            MessageContext.getCurrentMessageContext().getServiceContext();
    serviceContext.setProperty(HELLO_SERVICE_NAME, name);
    try {
        Replicator.replicate(serviceContext, new String[]{HELLO_SERVICE_NAME});
    } catch (ClusteringFault clusteringFault) {
        clusteringFault.printStackTrace();
    }

    if (name != null) {
        return "Hello World, " + name + " !!!";
    } else {
        return "Hello World !!!";
    }
}
 
Example #8
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 #9
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 #10
Source File: PolicySearchCacheInvalidationClusteringMessage.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(ConfigurationContext configurationContext) throws ClusteringFault {

    if (log.isDebugEnabled()) {
        log.debug("Received PolicySearchCacheInvalidationClusteringMessage.");
    }
    // We need to clear our local policy search cache of the corresponding tenant based on the received cluster
    // message from other node.
    int tenantIdInThreadLocalContext = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
    try{
        // Clear local cache for the tenant domain included with the cluster message.
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, true);

        EntitlementEngine.getInstance().getPolicySearch().getPolicySearchCache().clearCache();
        if (log.isDebugEnabled()) {
            log.debug("Local policy search cache is cleared for the tenant: "
                    + IdentityTenantUtil.getTenantDomain(tenantId) + ".");
        }
    } finally {
        // Switch back to the original tenant domain used in this thread local context.
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantIdInThreadLocalContext, true);
    }
}
 
Example #11
Source File: HelloService.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
public String greet(String name) {
    ServiceContext serviceContext =
            MessageContext.getCurrentMessageContext().getServiceContext();
    serviceContext.setProperty(HELLO_SERVICE_NAME, name);
    try {
        Replicator.replicate(serviceContext, new String[]{HELLO_SERVICE_NAME});
    } catch (ClusteringFault clusteringFault) {
        clusteringFault.printStackTrace();
    }

    if (name != null) {
        return "Hello World, " + name + " !!!";
    } else {
        return "Hello World !!!";
    }
}
 
Example #12
Source File: VirtualHostAddRequest.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(ConfigurationContext configurationContext) throws ClusteringFault {
    URLMappingHolder.getInstance().
           putUrlMappingForApplication(hostName, uri);
   Host host = VirtualHostClusterUtil.addHostToEngine(this.hostName);
    try {
        Context context = DataHolder.getInstance().getCarbonTomcatService().addWebApp(host, "/", this.webappPath);
        log.info("Deployed webapp on host: " + context);
        URLMappingHolder.getInstance().putUrlMappingForApplication(hostName, uri);
    } catch (CarbonTomcatException e) {
        log.error("error while adding web app to virtual host through cluster", e);
    }
}
 
Example #13
Source File: ServiceMappingDeleteRequest.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(ConfigurationContext configurationContext) throws ClusteringFault {
    URLMappingHolder urlMappingHolder = URLMappingHolder.getInstance();
    if(urlMappingHolder.isUrlMappingExists(mapping)) {
        urlMappingHolder.removeUrlMappingMap(mapping);
    }
    log.info("mapping removed to service:***********: " + mapping);
}
 
Example #14
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);
}
 
Example #15
Source File: PrivatePaaSBasedMembershipScheme.java    From product-private-paas with Apache License 2.0 5 votes vote down vote up
@Override
public void init() throws ClusteringFault {
    try {
        nwConfig.getJoin().getMulticastConfig().setEnabled(false);
        nwConfig.getJoin().getAwsConfig().setEnabled(false);
        TcpIpConfig tcpIpConfig = nwConfig.getJoin().getTcpIpConfig();
        tcpIpConfig.setEnabled(true);

        Parameter clusterIdsParameter = getParameter(PARAMETER_NAME_CLUSTER_IDS);
        if(clusterIdsParameter == null) {
            throw new RuntimeException(PARAMETER_NAME_CLUSTER_IDS + " parameter not found");
        }
        String clusterIds = (String)clusterIdsParameter.getValue();
        String[] clusterIdArray = clusterIds.split(",");

        if (!waitForTopologyInitialization()) return;

        try {
            TopologyManager.acquireReadLock();
            for (String clusterId : clusterIdArray) {
                org.apache.stratos.messaging.domain.topology.Cluster cluster =
                        TopologyManager.getTopology().getCluster(clusterId);
                if (cluster == null) {
                    throw new RuntimeException("Cluster not found in topology: [cluster-id]" + clusterId);
                }

                log.info("Reading members of cluster: [cluster-id] " + clusterId);
                for (org.apache.stratos.messaging.domain.topology.Member member : cluster.getMembers()) {
                    tcpIpConfig.addMember(member.getDefaultPrivateIP());
                    log.info("Member added to cluster configuration: [member-ip] " + member.getDefaultPrivateIP());
                }
            }
        } finally {
            TopologyManager.releaseReadLock();
        }
    } catch (Throwable t) {
        log.error("Could not initialize stratos membership scheme", t);
    }
}
 
Example #16
Source File: KubernetesMembershipScheme.java    From product-private-paas with Apache License 2.0 5 votes vote down vote up
protected String getParameterValue(String parameterName, String defaultValue) throws ClusteringFault {
    Parameter kubernetesServicesParam = getParameter(parameterName);
    if (kubernetesServicesParam == null) {
        if (defaultValue == null) {
            throw new ClusteringFault(parameterName + " parameter not found");
        } else {
            return defaultValue;
        }
    }
    return (String) kubernetesServicesParam.getValue();
}
 
Example #17
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 #18
Source File: TenantLoadMessageSenderTest.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Test(expected = ClusteringFault.class)
public void testSendTenantRegistryLoadMessageFail() throws ClusteringFault {
    ClusteringAgent clusteringAgent = PowerMockito.mock(ClusteringAgent.class);
    ClusteringCommand command = PowerMockito.mock(ClusteringCommand.class);
    List<ClusteringCommand> commandList = new ArrayList<ClusteringCommand>();
    commandList.add(command);
    ClusteringFault clusteringFault = PowerMockito.mock(ClusteringFault.class);
    PowerMockito.when(clusteringAgent.sendMessage(Matchers.any(TenantLoadMessage.class), Matchers.anyBoolean())).
            thenThrow(clusteringFault);
    tenantLoadMessageSender.sendTenantLoadMessage(clusteringAgent, 1, "a.com", 2);
}
 
Example #19
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 #20
Source File: TenantLoadMessageSenderTest.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #21
Source File: TenantLoadMessageTest.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecuteMessage() throws ClusteringFault {
    System.setProperty(APIConstants.ENABLE_TENANT_LOAD_NOTIFICATION, "true");
    PowerMockito.mockStatic(APIUtil.class);
    PowerMockito.doNothing().when(APIUtil.class);
    tenantLoadMessage.execute(new ConfigurationContext(new AxisConfiguration()));
}
 
Example #22
Source File: HelloService.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public String greet(String name) {
    ServiceContext serviceContext = MessageContext.getCurrentMessageContext().getServiceContext();
    serviceContext.setProperty(HELLO_SERVICE_NAME, name);
    try {
        Replicator.replicate(serviceContext, new String[] { HELLO_SERVICE_NAME });
    } catch (ClusteringFault clusteringFault) {
        clusteringFault.printStackTrace();
    }

    if (name != null) {
        return "Hello World, " + name + " !!!";
    } else {
        return "Hello World !!!";
    }
}
 
Example #23
Source File: TenantLoadMessageSender.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Override
public void notifyTenantLoad() {
    ClusteringAgent clusteringAgent = getClusteringAgent();
    // if clustering is not enabled, the clusteringAgent should be null
    if (clusteringAgent != null) {
        int tenantId = getTenantId();
        String tenantDomain = getTenantDomain();
        try {
            sendTenantLoadMessage(clusteringAgent, tenantId, tenantDomain, 60);
        } catch (ClusteringFault e) {
            log.error("Could not send TenantLoadMessage for tenant domain: " + tenantDomain + ", tenant " + "id: "
                    + tenantId + ". Several retries failed.", e);
        }
    }
}
 
Example #24
Source File: TenantLoadMessage.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(ConfigurationContext configurationContext) throws ClusteringFault {
    if (!isEnabled()) {
        log.debug("Tenant Load Notifications are disabled");
        return;
    }

    if (log.isDebugEnabled()) {
        log.debug("Executing cluster message " + this.toString());
    }
    APIUtil.loadTenantConfig(tenantDomain);
}
 
Example #25
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 #26
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 #27
Source File: SessionClusterMessage.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(ConfigurationContext configurationContext) throws ClusteringFault {
    if (log.isDebugEnabled()) {
        log.debug("Executing the received cluster message with session index:"+sessionIndex);
    }
    SAMLSSORelyingPartyObject.ssho.handleClusterLogout(sessionIndex);

}
 
Example #28
Source File: SessionClusterMessage.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(ConfigurationContext configurationContext) throws ClusteringFault {

    SSOSessionManager sessionManager = SSOSessionManager.getInstance();
    HttpSession session = sessionManager.getSession(sessionIndex);

    if (session != null) {
        sessionManager.handleLogout(sessionIndex);
    }
}
 
Example #29
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 #30
Source File: AssociationClusterMessage.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(ConfigurationContext configCtx) throws ClusteringFault {
    OpenIDAssociationReplicationManager associationReplicationManager = OpenIDAssociationReplicationManager.getPersistenceManager();
    Association association = getAssociation();
    if(isRemove()){
        if (log.isDebugEnabled()) {
            log.debug("Removing association : " + association.getHandle() + " during the replication replication");
        }

        if(associationReplicationManager.isExistingSession(association.getHandle())) {
            if (log.isDebugEnabled()) {
                log.debug("Association : " + association.getHandle() + " does exist");
            }
            associationReplicationManager.getAssociationMap().remove(association.getHandle());
            if (log.isDebugEnabled()) {
                log.debug("Removed association : " + association.getHandle() + " during the replication replication");
            }
        }
        else {
            if (log.isDebugEnabled()) {
                log.debug("Association : " + association.getHandle() + " does not exist. Cannot remove association");
            }
        }
    }
    else{
        if (log.isDebugEnabled()) {
            log.debug("Adding new association : " + association.getHandle() + " during the replication replication");
        }
        associationReplicationManager.getAssociationMap().put(association.getHandle(), association);
        if (log.isDebugEnabled()) {
            log.debug("Added new association : " + association.getHandle() + " during the replication replication");
        }
    }
}