Hi Reka,

Would you mind explaining the logic in this method? It is difficult to
understand the statements highlighted in yellow. If we are trying to check
whether all clusters have been initialized in an application, why do we
return true if one of the service clusters exists?

public static boolean allClustersInitialized(Application application) {
    boolean allClustersInitialized = false;
    for (ClusterDataHolder holder : application.getClusterDataRecursively()) {
        TopologyManager.acquireReadLockForCluster(holder.getServiceType(),
                holder.getClusterId());

        try {
            Topology topology = TopologyManager.getTopology();
            if (topology != null) {
                Service service = topology.getService(holder.getServiceType());
                if (service != null) {
                    if (service.clusterExists(holder.getClusterId())) {
                        allClustersInitialized = true;
                        return allClustersInitialized;
                    } else {
                        if (log.isDebugEnabled()) {
                            log.debug("[Cluster] " +
holder.getClusterId() + " is not found in " +
                                    "the Topology");
                        }
                        allClustersInitialized = false;
                    }
                } else {
                    if (log.isDebugEnabled()) {
                        log.debug("Service is null in the
CompleteTopologyEvent");
                    }
                }
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Topology is null in the CompleteTopologyEvent");
                }
            }
        } finally {
            TopologyManager.releaseReadLockForCluster(holder.getServiceType(),
                    holder.getClusterId());
        }
    }
    return allClustersInitialized;
}

Thanks



-- 
Imesh Gunaratne

Technical Lead, WSO2
Committer & PMC Member, Apache Stratos

Reply via email to