コード例 #1
0
 /**
  * Parse the {@link LockingStrategy} selection and make it a constructor argument.
  *
  * @param element The {@link org.w3c.dom.Element} being parsed.
  * @param builder The {@link org.springframework.beans.factory.support.BeanDefinitionBuilder}
  *     being used to construct the {@link
  *     org.springframework.beans.factory.config.BeanDefinition}.
  */
 private void parseLockingStrategy(Element element, GenericBeanDefinition builder) {
   if (element.hasAttribute(LOCK_MANAGER_ATTRIBUTE)) {
     String lockManager = element.getAttribute(LOCK_MANAGER_ATTRIBUTE);
     builder
         .getConstructorArgumentValues()
         .addIndexedArgumentValue(2, new RuntimeBeanReference(lockManager));
   } else if (element.hasAttribute(LOCKING_STRATEGY_ATTRIBUTE)) {
     LockingStrategy strategy =
         LockingStrategy.valueOf(element.getAttribute(LOCKING_STRATEGY_ATTRIBUTE));
     GenericBeanDefinition lockManager = new GenericBeanDefinition();
     lockManager.setBeanClass(strategy.getLockManagerType());
     builder.getConstructorArgumentValues().addIndexedArgumentValue(2, lockManager);
   }
 }
コード例 #2
0
 /**
  * Test basic acquire/release semantics.
  *
  * @throws Exception On errors.
  */
 @Test
 public void verifyAcquireAndRelease() throws Exception {
   final String appId = "basic";
   final String uniqueId = appId + "-1";
   final LockingStrategy lock =
       newLockTxProxy(appId, uniqueId, JpaTicketRegistryProperties.DEFAULT_LOCK_TIMEOUT);
   try {
     assertTrue(lock.acquire());
     assertEquals(uniqueId, getOwner(appId));
     lock.release();
     assertNull(getOwner(appId));
   } catch (final Exception e) {
     logger.debug("testAcquireAndRelease produced an error", e);
     fail("testAcquireAndRelease failed");
   }
 }
コード例 #3
0
 /** Verify non-reentrant behavior. */
 @Test
 public void verifyNonReentrantBehavior() {
   final String appId = "reentrant";
   final String uniqueId = appId + "-1";
   final LockingStrategy lock =
       newLockTxProxy(appId, uniqueId, JpaTicketRegistryProperties.DEFAULT_LOCK_TIMEOUT);
   try {
     assertTrue(lock.acquire());
     assertEquals(uniqueId, getOwner(appId));
     assertFalse(lock.acquire());
     lock.release();
     assertNull(getOwner(appId));
   } catch (final Exception e) {
     logger.debug("testNonReentrantBehavior produced an error", e);
     fail("testNonReentrantBehavior failed.");
   }
 }
コード例 #4
0
 @Override
 public Boolean call() throws Exception {
   try {
     return lock.acquire();
   } catch (final Exception e) {
     logger.debug("{} failed to acquire lock", lock, e);
     return false;
   }
 }
コード例 #5
0
 /**
  * Test lock expiration.
  *
  * @throws Exception On errors.
  */
 @Test
 public void verifyLockExpiration() throws Exception {
   final String appId = "expquick";
   final String uniqueId = appId + "-1";
   final LockingStrategy lock = newLockTxProxy(appId, uniqueId, "1");
   try {
     assertTrue(lock.acquire());
     assertEquals(uniqueId, getOwner(appId));
     assertFalse(lock.acquire());
     Thread.sleep(1500);
     assertTrue(lock.acquire());
     assertEquals(uniqueId, getOwner(appId));
     lock.release();
     assertNull(getOwner(appId));
   } catch (final Exception e) {
     logger.debug("testLockExpiration produced an error", e);
     fail("testLockExpiration failed");
   }
 }
コード例 #6
0
 @Override
 public Boolean call() throws Exception {
   try {
     lock.release();
     return true;
   } catch (final Exception e) {
     logger.debug("{} failed to release lock", lock, e);
     return false;
   }
 }