+1. Will include comments for such code segment..

Thanks,
Reka

On Sat, Feb 7, 2015 at 6:43 PM, Imesh Gunaratne <im...@apache.org> wrote:

> As I found we have written above logic to check availability of one
> cluster and assume that all the other clusters have been initialized
> because of the Application Clusters created event.
>
> IMO if we are writing such logic we need to add some comments describing
> the assumptions. Otherwise it would be difficult for others to understand.
>
> Thanks
>
> On Sat, Feb 7, 2015 at 3:44 PM, Imesh Gunaratne <im...@apache.org> wrote:
>
>> 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
>>
>
>
>
> --
> Imesh Gunaratne
>
> Technical Lead, WSO2
> Committer & PMC Member, Apache Stratos
>



-- 
Reka Thirunavukkarasu
Senior Software Engineer,
WSO2, Inc.:http://wso2.com,
Mobile: +94776442007

Reply via email to