示例#1
0
文件: Log.java 项目: AbacusHu/OpenDJ
 /**
  * Returns a cursor that allows to retrieve the records from this log. The starting position is
  * defined by the provided key, cursor matching strategy and cursor positioning strategy.
  *
  * @param key Key to use as a start position for the cursor. If key is {@code null}, cursor will
  *     point at the first record of the log.
  * @param matchingStrategy Cursor key matching strategy.
  * @param positionStrategy The cursor positioning strategy.
  * @return a cursor on the log records, which is never {@code null}
  * @throws ChangelogException If the cursor can't be created.
  */
 public RepositionableCursor<K, V> getCursor(
     final K key,
     final KeyMatchingStrategy matchingStrategy,
     final PositionStrategy positionStrategy)
     throws ChangelogException {
   if (key == null) {
     return getCursor();
   }
   AbortableLogCursor<K, V> cursor = null;
   sharedLock.lock();
   try {
     if (isClosed) {
       return new EmptyCursor<>();
     }
     cursor = new AbortableLogCursor<>(this, new InternalLogCursor<K, V>(this));
     final boolean isSuccessfullyPositioned =
         cursor.positionTo(key, matchingStrategy, positionStrategy);
     // Allow for cursor re-initialization after exhaustion in case of
     // LESS_THAN_OR_EQUAL_TO_KEY ands GREATER_THAN_OR_EQUAL_TO_KEY strategies
     if (isSuccessfullyPositioned || matchingStrategy != EQUAL_TO_KEY) {
       registerCursor(cursor);
       return cursor;
     } else {
       StaticUtils.close(cursor);
       return new EmptyCursor<>();
     }
   } catch (ChangelogException e) {
     StaticUtils.close(cursor);
     throw e;
   } finally {
     sharedLock.unlock();
   }
 }
示例#2
0
文件: Log.java 项目: AbacusHu/OpenDJ
 /**
  * Returns a cursor that allows to retrieve the records from this log, starting at the first
  * position.
  *
  * @return a cursor on the log records, which is never {@code null}
  * @throws ChangelogException If the cursor can't be created.
  */
 public RepositionableCursor<K, V> getCursor() throws ChangelogException {
   AbortableLogCursor<K, V> cursor = null;
   sharedLock.lock();
   try {
     if (isClosed) {
       return new EmptyCursor<>();
     }
     cursor = new AbortableLogCursor<>(this, new InternalLogCursor<K, V>(this));
     cursor.positionTo(null, null, null);
     registerCursor(cursor);
     return cursor;
   } catch (ChangelogException e) {
     StaticUtils.close(cursor);
     throw e;
   } finally {
     sharedLock.unlock();
   }
 }