javax.jcr.lock.Lock.isLive()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(189)

本文整理了Java中javax.jcr.lock.Lock.isLive()方法的一些代码示例,展示了Lock.isLive()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Lock.isLive()方法的具体详情如下:
包路径:javax.jcr.lock.Lock
类名称:Lock
方法名:isLive

Lock.isLive介绍

[英]Returns true if this Lock object represents a lock that is currently in effect. If this lock has been unlocked either explicitly or due to an implementation-specific limitation (like a timeout) then it returns false. Note that this method is intended for those cases where one is holding a Lock Java object and wants to find out whether the lock (the JCR-level entity that is attached to the lockable node) that this object originally represented still exists. For example, a timeout or explicit unlock will remove a lock from a node but the Lock Java object corresponding to that lock may still exist, and in that case its isLive method will return false.
[中]如果此Lock对象表示当前有效的锁,则返回true。如果此锁已明确解锁或由于特定于实现的限制(如超时)而解锁,则它将返回false。请注意,此方法适用于持有LockJava对象并希望确定该对象最初表示的锁(附加到可锁定节点的JCR级别实体)是否仍然存在的情况。例如,超时或显式unlock将从节点移除锁,但与该锁对应的LockJava对象可能仍然存在,在这种情况下,其isLive方法将返回false

代码示例

代码示例来源:origin: org.onehippo.cms7/hippo-repository-engine

@Override
public boolean isLive() throws RepositoryException {
  synchronized (session) {
    return lock.isLive();
  }
}

代码示例来源:origin: net.adamcin.oakpal/oakpal-core

@Override
public boolean isLive() throws RepositoryException {
  return delegate.isLive();
}

代码示例来源:origin: apache/jackrabbit

/** {@inheritDoc} */
public boolean isLive() throws RepositoryException, RemoteException {
  return lock.isLive();
}

代码示例来源:origin: apache/jackrabbit

/**
 * @see ActiveLock#isExpired()
 */
public boolean isExpired() {
  try {
    return !lock.isLive();
  } catch (RepositoryException e) {
    log.error("Unexpected error: " + e.getMessage());
    return false;
  }
}

代码示例来源:origin: org.apache.jackrabbit/jackrabbit-ocm

public boolean isLive()  {
  try
  {
    return lock.isLive();
  }
  catch (javax.jcr.RepositoryException e)
  {
    throw new RepositoryException(e);
  }
}

代码示例来源:origin: apache/jackrabbit

/**
 * Test {@link javax.jcr.lock.Lock#isLive()}.
 */
public void testIsLive() throws RepositoryException {
  assertTrue("Lock.isLive must be true.", lock.isLive());
}

代码示例来源:origin: org.apache/jackrabbit-ocm

public boolean isLive()  {
  try
  {
    return lock.isLive();
  }
  catch (javax.jcr.RepositoryException e)
  {
    throw new RepositoryException(e);
  }
}

代码示例来源:origin: apache/jackrabbit

/**
 * Test if Lock is properly released.
 * 
 * @throws RepositoryException
 */
public void testUnlock() throws RepositoryException {
  // release the lock
  lockMgr.unlock(lockedNode.getPath());
  
  // assert: lock must not be alive
  assertFalse("lock must not be alive", lock.isLive());
}

代码示例来源:origin: apache/jackrabbit

/**
 * Test refresh
 */
public void testRefresh() throws Exception {
  // create new node
  Node n = testRootNode.addNode(nodeName1, testNodeType);
  ensureMixinType(n, mixLockable);
  testRootNode.getSession().save();
  // lock node and get lock token
  Lock lock = n.lock(false, true);
  // assert: lock must be alive
  assertTrue("lock must be alive", lock.isLive());
  // assert: refresh must succeed
  lock.refresh();
  // unlock node
  n.unlock();
  // assert: lock must not be alive
  assertFalse("lock must not be alive", lock.isLive());
}

代码示例来源:origin: apache/jackrabbit

/**
 * Test refresh
 */
public void testRefreshNotLive() throws Exception {
  // create new node
  Node n = testRootNode.addNode(nodeName1, testNodeType);
  ensureMixinType(n, mixLockable);
  testRootNode.getSession().save();
  // lock node and get lock token
  Lock lock = n.lock(false, true);
  // assert: lock must be alive
  assertTrue("lock must be alive", lock.isLive());
  // unlock node
  n.unlock();
  // assert: lock must not be alive
  assertFalse("lock must not be alive", lock.isLive());
  // refresh
  try {
    lock.refresh();
    fail("Refresh on a lock that is not alive must fail");
  } catch (LockException e) {
    // success
  }
}

代码示例来源:origin: apache/jackrabbit

/**
 * Test {@link javax.jcr.lock.Lock#getSecondsRemaining()} 
 */
public void testGetSecondsRemaining() throws RepositoryException {
  if (lock.isLive()) {
    assertTrue("Seconds remaining must be a positive long.", lock.getSecondsRemaining() > 0);            
  } else {
    assertTrue("Seconds remaining must be a negative long.", lock.getSecondsRemaining() < 0);
  }
}

代码示例来源:origin: apache/jackrabbit

/**
 * Test locks are released when session logs out
 */
public void testImplicitUnlock() throws RepositoryException,
    NotExecutableException {
  Session other = getHelper().getReadWriteSession();
  try {
    Node testNode = (Node) other.getItem(testRootNode.getPath());
    Node lockedNode = testNode.addNode(nodeName1, testNodeType);
    other.save();
    assertLockable(lockedNode);
    Lock lock = getLockManager(other).lock(lockedNode.getPath(), isDeep(), isSessionScoped(), getTimeoutHint(), getLockOwner());
    other.logout();
    assertFalse(lock.isLive());
  } finally {
    if (other.isLive()) {
      other.logout();
    }
  }
}

代码示例来源:origin: apache/jackrabbit

assertFalse(msg, lock.isLive());
assertFalse(msg, lockedNode.isLocked());
assertFalse(msg, lockMgr.isLocked(lockedNode.getPath()));
assertTrue(msg, lock.isLive());
assertTrue(msg, lockedNode.isLocked());
assertTrue(msg, lockMgr.isLocked(lockedNode.getPath()));

代码示例来源:origin: apache/jackrabbit

/**
 * If a locked nodes is unlocked again, any Lock instance retrieved by
 * another session must change the lock-status. Similarly, the previously
 * locked node must not be marked locked any more.
 */
public void testUnlockByOtherSession() throws RepositoryException {
  Node ln2 = (Node) otherSession.getItem(lockedNode.getPath());
  Lock l2 = ln2.getLock();
  lockedNode.unlock();
  assertFalse("Lock must be informed if Node is unlocked.", l2.isLive());
}

代码示例来源:origin: apache/jackrabbit

/**
 * Test correct behaviour of {@link javax.jcr.lock.Lock} inside a
 * transaction.
 * @throws Exception
 */
public void testLockBehaviour2() throws Exception {
  // add node that is both lockable and referenceable, save
  Node n = testRootNode.addNode(nodeName1);
  n.addMixin(mixLockable);
  n.addMixin(mixReferenceable);
  testRootNode.save();
  Lock lock = n.lock(false, true);
  // get user transaction object, start
  UserTransaction utx = new UserTransactionImpl(superuser);
  utx.begin();
  // verify lock is live
  assertTrue("Lock live", lock.isLive());
  // unlock
  n.unlock();
  // verify lock is no longer live
  assertFalse("Lock not live", lock.isLive());
  // rollback
  utx.rollback();
  // verify lock is live again
  assertTrue("Lock live", lock.isLive());
}

代码示例来源:origin: apache/jackrabbit

/**
 * Test correct behaviour of {@link javax.jcr.lock.Lock} inside a
 * transaction.
 * @throws Exception
 */
public void testLockBehaviour() throws Exception {
  // add node that is both lockable and referenceable, save
  Node n = testRootNode.addNode(nodeName1);
  n.addMixin(mixLockable);
  n.addMixin(mixReferenceable);
  testRootNode.save();
  // get user transaction object, start and lock node
  UserTransaction utx = new UserTransactionImpl(superuser);
  utx.begin();
  Lock lock = n.lock(false, true);
  // verify lock is live
  assertTrue("Lock live", lock.isLive());
  // rollback
  utx.rollback();
  // verify lock is not live anymore
  assertFalse("Lock not live", lock.isLive());
}

代码示例来源:origin: apache/jackrabbit

public void testLogoutHasNoEffect() throws Exception {
  // create a second session session. since logout of the 'superuser'
  // will cause all inherited tear-down to fail
  Node testRoot2 = (Node) otherSession.getItem(testRootNode.getPath());
  Node lockedNode2 = testRoot2.addNode(nodeName2, testNodeType);
  lockedNode2.addMixin(mixLockable);
  testRoot2.save();
  Lock lock2 = lockedNode2.lock(false, isSessionScoped());
  // force reloading of the testroot in order to be aware of the
  // locked node added by another session
  testRootNode.refresh(false);
  Node n2 = (Node) superuser.getItem(lockedNode2.getPath());
  try {
    String lockToken = lock2.getLockToken();
    otherSession.removeLockToken(lockToken);
    superuser.addLockToken(lockToken);
    otherSession.logout();
    assertTrue("After logout a open-scoped node must still be locked.", lock2.isLive());
    assertTrue("After logout a open-scoped node must still be locked.", n2.isLocked());
  } finally {
    n2.unlock();
  }
}

代码示例来源:origin: ModeShape/modeshape

@Test
@FixFor( "MODE-2633" )
public void shouldExpireOpenScopedLocks() throws Exception {
  // Create a new lockable node
  Node node = session.getRootNode().addNode("test");
  node.addMixin("mix:lockable");
  session.save();
  
  // Lock the node
  JcrLockManager lockManager = session.getWorkspace().getLockManager();
  lockManager.lock(node.getPath(), false, false, 1, null);
  assertTrue(node.isLocked());
  
  // Wait enough time for the lock to be expired
  Thread.sleep(TimeUnit.SECONDS.toMillis(2));
  
  // The old lock should still be there even though it's expired 
  assertFalse(node.isLocked());
  assertFalse(lockManager.getLock(node.getPath()).isLive());
  
  // Check that a new lock can be obtained
  lockManager.lock(node.getPath(), false, false, 10, null);
  assertTrue(node.isLocked());
}

代码示例来源:origin: apache/jackrabbit

assertFalse(lock2.isLive());
assertFalse(n2.isLocked());
assertFalse(n2.hasProperty(jcrLockOwner));

代码示例来源:origin: ModeShape/modeshape

@Test
@FixFor( "MODE-2642" )
public void shouldLockNodeWithinTransaction() throws Exception {
  Node node = session.getRootNode().addNode("test");
  node.addMixin("mix:lockable");
  session.save();
  
  startTransaction();
  JcrLockManager lockManager = session.getWorkspace().getLockManager();
  Lock lock = lockManager.lock(node.getPath(), false, false, Long.MAX_VALUE, null);
  assertTrue(lock.isLive());
  assertTrue("Node should be locked", node.isLocked());
  commitTransaction();
  assertTrue(node.isLocked());
}

相关文章