private DistributedMemberLock getPrimaryLock(boolean createDLS) {
    synchronized (this) {
      if (primaryLock == null) {
        DistributedLockService dls = DistributedLockService
            .getServiceNamed(PartitionedRegionHelper.PARTITION_LOCK_SERVICE_NAME);
        if (dls == null) {
          if (!createDLS || getProxyBucketRegion().getCache().isClosed()) {
            return null; // cache closure has destroyed the DLS
          }
          try { // TODO: call GemFireCache#getPartitionedRegionLockService
            dls = DLockService.create(PartitionedRegionHelper.PARTITION_LOCK_SERVICE_NAME,
                getAdvisee().getSystem(), true, true);
          } catch (IllegalArgumentException e) {
            // indicates that the DLS is already created
            dls = DistributedLockService
                .getServiceNamed(PartitionedRegionHelper.PARTITION_LOCK_SERVICE_NAME);
            if (dls == null) {
              // another thread destroyed DLS after this thread called create
              return null; // ok, caller will loop if necessary
            }
          }
          // TODO: we need a good NotConnectedException to replace
          // IllegalStateException and ShutdownException
          // perhaps: DistributedSystemUnavailableException
          catch (IllegalStateException | DistributedSystemDisconnectedException e) {
            // create still throws IllegalStateException if isDisconnecting is true
            return null;
          } // this would certainly prevent us from creating a DLS... messy

        }
        primaryLock = new DistributedMemberLock(dls, getAdvisee().getName(),
            DistributedMemberLock.NON_EXPIRING_LEASE,
            DistributedMemberLock.LockReentryPolicy.PREVENT_SILENTLY);
      }
      return primaryLock;
    }
  }
Lazily gets the lock for acquiring primary lock. Caller must handle null. If DLS, Cache, or
DistributedSystem are shutting down then null will be returned. If DLS does not yet exist and
createDLS is false then null will be returned.

@param createDLS true will create DLS if it does not exist
@return distributed lock indicating primary member or null
geode-core/src/main/java/org/apache/geode/internal/cache/BucketAdvisor.java