private DistributedLockService initializeDistributedLockService(String dlsName) { DistributedLockService lockService = DistributedLockService.getServiceNamed(dlsName); if (lockService == null) { lockService = DistributedLockService.create(dlsName, this.cache.getDistributedSystem()); } return lockService; }
public boolean lockSharedConfiguration() { return this.sharedConfigLockingService.lock(SHARED_CONFIG_LOCK_NAME, -1, -1); }
@Override public void releaseTieLock() { if (holdingTieLock) { distributedLockService.unlock("PERSISTENCE_" + regionPath); holdingTieLock = false; } }
/** * Destroys the GatewaySender distributed lock service when closing the cache. Caller must be * synchronized on this GemFireCache. */ private void destroyGatewaySenderLockService() { if (DistributedLockService.getServiceNamed(AbstractGatewaySender.LOCK_SERVICE_NAME) != null) { try { DistributedLockService.destroy(AbstractGatewaySender.LOCK_SERVICE_NAME); } catch (IllegalArgumentException ignore) { // DistributedSystem.disconnect may have already destroyed the DLS } } }
private DistributedLockService getLockService() { return DistributedLockService .getServiceNamed(PartitionedRegionHelper.PARTITION_LOCK_SERVICE_NAME); }
@Test public void locksAreReleasedDuringDisconnect() { assertThat(lockService.lock("MyLock", 0, -1)).isTrue(); assertThat(lockService.isHeldByCurrentThread("MyLock")).isTrue(); ((InternalDistributedSystem) system).setIsDisconnectThread(); lockService.unlock("MyLock"); assertThat(lockService.isHeldByCurrentThread("MyLock")).isFalse(); } }
public boolean volunteerForPrimary() { if (logger.isDebugEnabled()) { logger.debug("Sender : {} is volunteering for Primary ", this.sender.getId()); } if (advisePrimaryGatewaySender() == null) { if (!adviseEldestGatewaySender()) { if (logger.isDebugEnabled()) { logger.debug( "Sender {} is not the eldest in the system. Giving preference to eldest sender to become primary...", this.sender); } return false; } if (logger.isDebugEnabled()) { logger.debug("Sender : {} no Primary available. So going to acquire distributed lock", this.sender); } this.lockService.lock(this.lockToken, 10000, -1); return this.lockService.isHeldByCurrentThread(this.lockToken); } return false; }
/** * Return the DistributedLockService associated with this Region. This method will lazily create * that service the first time it is invoked on this region. */ public DistributedLockService getLockService() { synchronized (this.dlockMonitor) { String dlsName = getFullPath(); if (this.dlockService == null) { this.dlockService = DistributedLockService.getServiceNamed(dlsName); if (this.dlockService == null) { // region destroy will destroy dls and manual freeResources only this.dlockService = DLockService.create(getFullPath(), getSystem(), true, false, false); } // handle is-lock-grantor region attribute... if (this.isLockGrantor) { this.dlockService.becomeLockGrantor(); } if (logger.isDebugEnabled()) { logger.debug("LockService for {} is using LockLease={}, LockTimeout={}", dlsName, getCache().getLockLease(), getCache().getLockTimeout()); } } return this.dlockService; } }
if (interruptible) { gotLock = getLockService().lockInterruptibly(this.key, waitInterval, getLockLeaseForLock()); } else { gotLock = getLockService().lock(this.key, waitInterval, getLockLeaseForLock());
@Override public void unlock() { try { ReplyProcessor21.forceSevereAlertProcessing(); getLockService().unlock(this.key); if (!DistributedRegion.this.entries.containsKey(this.key)) { getLockService().freeResources(this.key); } } catch (IllegalStateException ex) { lockCheckReadiness(); throw ex; } finally { ReplyProcessor21.unforceSevereAlertProcessing(); } }
@Before public void setup() { Properties properties = new Properties(); properties.put(ConfigurationProperties.LOCATORS, ""); properties.put(ConfigurationProperties.MCAST_PORT, "0"); system = DistributedSystem.connect(properties); lockService = DistributedLockService.create("Test Lock Service", system); }
/** * Destroys the PartitionedRegion distributed lock service when closing the cache. Caller must be * synchronized on this GemFireCache. */ private void destroyPartitionedRegionLockService() { try { DistributedLockService.destroy(PartitionedRegionHelper.PARTITION_LOCK_SERVICE_NAME); } catch (IllegalArgumentException ignore) { // DistributedSystem.disconnect may have already destroyed the DLS } }
@Override public DistributedLockService getDLS() { InternalCache cache = getCache(); DistributedLockService dls = DistributedLockService.getServiceNamed(AUTO_BALANCER_LOCK_SERVICE_NAME); if (dls == null) { if (logger.isDebugEnabled()) { logger.debug("Creating DistributeLockService"); } dls = DLockService.create(AUTO_BALANCER_LOCK_SERVICE_NAME, cache.getInternalDistributedSystem(), true, true, true); } return dls; }
DistributedLockService.destroy(getSenderAdvisor().getDLockServiceName()); } catch (IllegalArgumentException e) {
private DistributedLockService getLockService(DistributionManager dm) { DistributedLockService dls = DistributedLockService.getServiceNamed(LOCK_SERVICE_NAME); if (dls == null) { synchronized (LOCK_SYNC) { dls = DistributedLockService.getServiceNamed(LOCK_SERVICE_NAME); if (dls == null) { // Create the DistributedLockService dls = DistributedLockService.create(LOCK_SERVICE_NAME, dm.getSystem()); } } } Assert.assertTrue(dls != null); return dls; } }
protected DistributedLockService getLockService() { if (this.dls != null) { return this.dls; } synchronized (this.dlsLock) { if (this.dls == null) { try { this.dls = DLockService.create(LOCK_SERVICE_NAME, this.cache.getInternalDistributedSystem(), true /* distributed */, true /* destroyOnDisconnect */, true /* automateFreeResources */); } catch (IllegalArgumentException e) { this.dls = DistributedLockService.getServiceNamed(LOCK_SERVICE_NAME); if (this.dls == null) { throw e; } } } return this.dls; } }
/** * Grab the PartitionedRegionID Lock, this MUST be done in a try block since it may throw an * exception * * @return true if the lock was acquired */ private static boolean grabPRIDLock(final DistributedLockService lockService) { final boolean isDebugEnabled = logger.isDebugEnabled(); boolean ownership = false; int n = 0; while (!ownership) { if (isDebugEnabled) { logger.debug("grabPRIDLock: Trying to get the dlock in allPartitionedRegions for {}: {}", PartitionedRegionHelper.MAX_PARTITIONED_REGION_ID, (n + 1)); } ownership = lockService.lock(PartitionedRegionHelper.MAX_PARTITIONED_REGION_ID, VM_OWNERSHIP_WAIT_TIME, -1); } return ownership; }
public void unlockSharedConfiguration() { this.sharedConfigLockingService.unlock(SHARED_CONFIG_LOCK_NAME); }