code: public CloseableDataStore getDataStore(URI location, String apiKey, MetricRegistry metricRegistry)
              throws IOException {
          String id = LocationUtil.getDataStoreIdentifier(location, apiKey);
          CloseableDataStore dataStore = null;
          while (dataStore == null) {
              // Get the cached DataStore if it exists
              DataStoreMonitor dataStoreMonitor = _dataStoreByLocation.get(id);
              if (dataStoreMonitor == null || (dataStore = dataStoreMonitor.getDataStore()) == null) {
                  // Either the value wasn't cached or the cached value was closed before the reference count could
                  // be incremented.  Create a new DataStore and cache it.
                  CloseableDataStore unmonitoredDataStore;
                  switch (LocationUtil.getLocationType(location)) {
                      case EMO_HOST_DISCOVERY:
                          unmonitoredDataStore = createDataStoreWithHostDiscovery(location, apiKey, metricRegistry);
                          break;
                      case EMO_URL:
                          unmonitoredDataStore = createDataStoreWithUrl(location, apiKey, metricRegistry);
                          break;
                      default:
                          throw new IllegalArgumentException("Location does not use a data store: " + location);
                  }
  
                  dataStoreMonitor = new DataStoreMonitor(id, unmonitoredDataStore);
  
                  if (_dataStoreByLocation.putIfAbsent(id, dataStoreMonitor) != null) {
                      // Race condition; close the created DataStore and try again
                      dataStoreMonitor.closeNow();
                  } else {
                      // New data store was cached; return the value
                      dataStore = dataStoreMonitor.getDataStore();
                  }
              }
          }
  
          return dataStore;
      }
docs: Returns a DataStore for a given location.  If a cached instance already exists its reference count is incremented
  and returned, otherwise a new instance is created and cached.