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

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

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

Lock.getSecondsRemaining介绍

[英]Returns the number of seconds remaining until this locks times out. If the lock has already timed out, a negative value is returned. If the number of seconds remaining is infinite or unknown, Long.MAX_VALUE is returned.
[中]返回此锁定超时前剩余的秒数。如果锁已超时,则返回负值。如果剩余秒数为无限或未知,则返回Long.MAX_VALUE

代码示例

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

@Override
public long getSecondsRemaining() throws RepositoryException {
  synchronized (session) {
    return lock.getSecondsRemaining();
  }
}

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

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

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

@Override
public long getSecondsRemaining() throws RepositoryException {
  return delegate.getSecondsRemaining();
}

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

/**
 * Calculates the milliseconds of the timeout from
 * {@link javax.jcr.lock.Lock#getSecondsRemaining()}. If the timeout of
 * jcr lock is undefined or infinite {@link #INFINITE_TIMEOUT} is
 * returned.
 *
 * @see ActiveLock#getTimeout()
 */
public long getTimeout() {
  try {
    long to = lock.getSecondsRemaining();
    long reportAs;
    if (to == Long.MAX_VALUE) {
      reportAs = INFINITE_TIMEOUT;
    }
    else if (to / 1000 <= Long.MAX_VALUE / 1000) {
      // expressible as long?
      reportAs = to * 1000;
    }
    else {
      reportAs = INFINITE_TIMEOUT;
    }
    return reportAs;
  } catch (RepositoryException e) {
    return INFINITE_TIMEOUT;
  }
}

代码示例来源: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 {@link javax.jcr.lock.Lock#getSecondsRemaining()}
 */
public void testGetSecondsRemainingAfterUnlock() throws RepositoryException {
  lockMgr.unlock(lockedNode.getPath());
  assertTrue("Lock has been released: seconds remaining must be a negative long.", lock.getSecondsRemaining() < 0);
}

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

long remaining = lock.getSecondsRemaining();
if (remaining <= hint) {
  if (remaining > 0) {
  long secs = lock.getSecondsRemaining();
  assertTrue(
      "A released lock must return a negative number of seconds, was: " + secs,

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

/**
 * Creates a new lock info for the given JCR lock object.
 *
 * @param lock the lock.
 * @param idFactory the id factory.
 * @throws RepositoryException if an error occurs while the node from the
 * given lock or while creating the node id.
 */
private LockInfoImpl(Lock lock, IdFactoryImpl idFactory) throws RepositoryException {
  super(lock.getLockToken(), lock.getLockOwner(), lock.isDeep(),
      lock.isSessionScoped(), lock.getSecondsRemaining(), lock.isLockOwningSession(), 
      idFactory.createNodeId(lock.getNode()));
}

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

/**
 * Creates a new lock info for the given JCR lock object.
 *
 * @param lock the lock.
 * @param idFactory the id factory.
 * @throws RepositoryException if an error occurs while the node from the
 * given lock or while creating the node id.
 */
private LockInfoImpl(Lock lock, IdFactoryImpl idFactory) throws RepositoryException {
  super(lock.getLockToken(), lock.getLockOwner(), lock.isDeep(),
      lock.isSessionScoped(), lock.getSecondsRemaining(), lock.isLockOwningSession(), 
      idFactory.createNodeId(lock.getNode()));
}

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

assertEquals(timeoutHint, l.getSecondsRemaining());
assertTrue(l.isLive());

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

@Test
@FixFor( "MODE-2641" )
public void shouldProvideTimeoutForOpenScopedLocks() throws Exception {
  // Create a new lockable node
  Node node = session.getRootNode().addNode("test");
  node.addMixin("mix:lockable");
  session.save();
  
  String path = node.getPath();
  // Lock the node with an open scoped lock
  int timeout = 2;
  JcrLockManager lockManager = session.getWorkspace().getLockManager();
  Lock lock = lockManager.lock(node.getPath(), false, false, timeout, null);
  assertTrue(node.isLocked());
  long secondsRemaining = lock.getSecondsRemaining();
  assertTrue("Expected a valid value for seconds remaining", secondsRemaining <= timeout && secondsRemaining > 0);
  
  // Look at the same lock from another session
  session.logout();
  session = repository.login();
  lockManager = session.getWorkspace().getLockManager();
  lock = lockManager.getLock(path);
  secondsRemaining = lock.getSecondsRemaining();
  assertTrue("Expected a valid value for seconds remaining", secondsRemaining <= timeout && secondsRemaining > 0);
  
  Thread.sleep(TimeUnit.SECONDS.toMillis(2));
  assertEquals("Expected a negative value because the lock should have expired", Long.MIN_VALUE, lock.getSecondsRemaining());
}

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

@Test
@FixFor( "MODE-2641" ) 
public void shouldNotProvideTimeoutForSessionScopedLocks() throws Exception {
  // Create a new lockable node
  Node node = session.getRootNode().addNode("test");
  node.addMixin("mix:lockable");
  session.save();
  String path = node.getPath();
  
  // Lock the node with a session scoped lock
  int timeout = 2;
  JcrLockManager lockManager = session.getWorkspace().getLockManager();
  Lock lock = lockManager.lock(node.getPath(), false, true, timeout, null);
  assertTrue(node.isLocked());
  assertEquals("Session scoped locks should not have timeout information", Long.MAX_VALUE, lock.getSecondsRemaining());

  JcrSession otherSession = repository.login();
  try {
    lockManager = otherSession.getWorkspace().getLockManager();
    lock = lockManager.getLock(path);
    assertTrue(otherSession.getNode(path).isLocked());
    assertEquals("Session scoped locks should not have timeout information", Long.MAX_VALUE, lock.getSecondsRemaining());
  } finally {
    otherSession.logout();            
  }
}

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

assertEquals(Long.MAX_VALUE, locker2.getWorkspace().getLockManager().getLock("/sessionLockedNode2").getSecondsRemaining());
assertEquals(Long.MAX_VALUE, locker1.getWorkspace().getLockManager().getLock("/sessionLockedNode2").getSecondsRemaining());
assertLocking(reader, "/sessionLockedNode2", true);
assertEquals(Long.MAX_VALUE, locker2.getWorkspace().getLockManager().getLock("/sessionLockedNode2").getSecondsRemaining());

相关文章