<commit_before>package com.cloud.hypervisor.xen.resource;

import java.util.HashMap;

import org.apache.log4j.Logger;

import com.cloud.utils.Pair;
import com.cloud.vm.VirtualMachine.State;

 
public class XenServerPoolVms {
    private static final Logger s_logger = Logger.getLogger(XenServerPoolVms.class);
    private HashMap<String/* clusterId */, HashMap<String/* vm name */, Pair<String/* host uuid */, State/* vm state */>>> _cluster_vms = 
        new HashMap<String, HashMap<String, Pair<String, State>>>();

    public HashMap<String, Pair<String, State>> getClusterVmState(String clusterId){
        HashMap<String, Pair<String, State>> _vms= _cluster_vms.get(clusterId);
        if (_vms==null) {
            HashMap<String, Pair<String, State>> vmStates =  new HashMap<String, Pair<String, State>>();
            _cluster_vms.put(clusterId, vmStates);
            return vmStates;
        }
        else return _vms;
    }
    
    public void clear(String clusterId){
        HashMap<String, Pair<String, State>> _vms= getClusterVmState(clusterId);
        _vms.clear();
    }
    
    public State getState(String clusterId, String name){
        HashMap<String, Pair<String, State>> vms = getClusterVmState(clusterId);
        Pair<String, State> pv = vms.get(name);
        return pv == null ? State.Stopped : pv.second(); // if a VM is absent on the cluster, it is effectively in stopped state.
    }<commit_msg>bug 13473: fixed the concurrent access to vms hashmap<commit_after>package com.cloud.hypervisor.xen.resource;

import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;
import java.util.concurrent.ConcurrentHashMap;
import com.cloud.utils.Pair;
import com.cloud.vm.VirtualMachine.State;

 
public class XenServerPoolVms {
    private static final Logger s_logger = Logger.getLogger(XenServerPoolVms.class);
    private final Map<String/* clusterId */, HashMap<String/* vm name */, Pair<String/* host uuid */, State/* vm state */>>> _cluster_vms =
         new ConcurrentHashMap<String, HashMap<String, Pair<String, State>>>();


    public HashMap<String, Pair<String, State>> getClusterVmState(String clusterId){
        HashMap<String, Pair<String, State>> _vms= _cluster_vms.get(clusterId);
        if (_vms==null) {
            HashMap<String, Pair<String, State>> vmStates =  new HashMap<String, Pair<String, State>>();
            _cluster_vms.put(clusterId, vmStates);
            return vmStates;
        }
        else return _vms;
    }
    
    public void clear(String clusterId){
        HashMap<String, Pair<String, State>> _vms= getClusterVmState(clusterId);
        _vms.clear();
    }
    
    public State getState(String clusterId, String name){
        HashMap<String, Pair<String, State>> vms = getClusterVmState(clusterId);
        Pair<String, State> pv = vms.get(name);
        return pv == null ? State.Stopped : pv.second(); // if a VM is absent on the cluster, it is effectively in stopped state.
    }
{'fraction_non_alphanumeric': 0.11871227364185111, 'fraction_numerical': 0.002347417840375587, 'mean_word_length': 3.412721893491124, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4440939', 'n_tokens_mistral': 913, 'n_tokens_neox': 892, 'n_words': 231}