提交 7914eb31 编写于 作者: J Jia Zhai 提交者: xiaolong.ran

make some method of ManagedLedger public (#5472)

Some of the ManagedLedger methods, such as hasMoreEntries/getPreviousPosition/getNextValidPosition, are protected. This change try to make them public.
These methods are useful when user want to do some advanced operation in Data Processing.

(cherry picked from commit 89e3f30d)
上级 4f247a41
...@@ -208,7 +208,7 @@ public class ManagedLedgerImpl implements ManagedLedger, CreateCallback { ...@@ -208,7 +208,7 @@ public class ManagedLedgerImpl implements ManagedLedger, CreateCallback {
} }
// define boundaries for position based seeks and searches // define boundaries for position based seeks and searches
enum PositionBound { public enum PositionBound {
startIncluded, startExcluded startIncluded, startExcluded
} }
...@@ -1724,7 +1724,7 @@ public class ManagedLedgerImpl implements ManagedLedger, CreateCallback { ...@@ -1724,7 +1724,7 @@ public class ManagedLedgerImpl implements ManagedLedger, CreateCallback {
return mbean; return mbean;
} }
boolean hasMoreEntries(PositionImpl position) { public boolean hasMoreEntries(PositionImpl position) {
PositionImpl lastPos = lastConfirmedEntry; PositionImpl lastPos = lastConfirmedEntry;
boolean result = position.compareTo(lastPos) <= 0; boolean result = position.compareTo(lastPos) <= 0;
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
...@@ -2622,7 +2622,7 @@ public class ManagedLedgerImpl implements ManagedLedger, CreateCallback { ...@@ -2622,7 +2622,7 @@ public class ManagedLedgerImpl implements ManagedLedger, CreateCallback {
* specifies whether or not to include the start position in calculating the distance * specifies whether or not to include the start position in calculating the distance
* @return the new position that is n entries ahead * @return the new position that is n entries ahead
*/ */
PositionImpl getPositionAfterN(final PositionImpl startPosition, long n, PositionBound startRange) { public PositionImpl getPositionAfterN(final PositionImpl startPosition, long n, PositionBound startRange) {
long entriesToSkip = n; long entriesToSkip = n;
long currentLedgerId; long currentLedgerId;
long currentEntryId; long currentEntryId;
...@@ -2690,7 +2690,7 @@ public class ManagedLedgerImpl implements ManagedLedger, CreateCallback { ...@@ -2690,7 +2690,7 @@ public class ManagedLedgerImpl implements ManagedLedger, CreateCallback {
* the current position * the current position
* @return the previous position * @return the previous position
*/ */
PositionImpl getPreviousPosition(PositionImpl position) { public PositionImpl getPreviousPosition(PositionImpl position) {
if (position.getEntryId() > 0) { if (position.getEntryId() > 0) {
return PositionImpl.get(position.getLedgerId(), position.getEntryId() - 1); return PositionImpl.get(position.getLedgerId(), position.getEntryId() - 1);
} }
...@@ -2752,15 +2752,15 @@ public class ManagedLedgerImpl implements ManagedLedger, CreateCallback { ...@@ -2752,15 +2752,15 @@ public class ManagedLedgerImpl implements ManagedLedger, CreateCallback {
} }
} }
boolean ledgerExists(long ledgerId) { public boolean ledgerExists(long ledgerId) {
return ledgers.get(ledgerId) != null; return ledgers.get(ledgerId) != null;
} }
Long getNextValidLedger(long ledgerId) { public Long getNextValidLedger(long ledgerId) {
return ledgers.ceilingKey(ledgerId + 1); return ledgers.ceilingKey(ledgerId + 1);
} }
PositionImpl getNextValidPosition(final PositionImpl position) { public PositionImpl getNextValidPosition(final PositionImpl position) {
PositionImpl nextPosition = position.getNext(); PositionImpl nextPosition = position.getNext();
while (!isValidPosition(nextPosition)) { while (!isValidPosition(nextPosition)) {
Long nextLedgerId = ledgers.ceilingKey(nextPosition.getLedgerId() + 1); Long nextLedgerId = ledgers.ceilingKey(nextPosition.getLedgerId() + 1);
...@@ -2772,7 +2772,7 @@ public class ManagedLedgerImpl implements ManagedLedger, CreateCallback { ...@@ -2772,7 +2772,7 @@ public class ManagedLedgerImpl implements ManagedLedger, CreateCallback {
return nextPosition; return nextPosition;
} }
PositionImpl getFirstPosition() { public PositionImpl getFirstPosition() {
Long ledgerId = ledgers.firstKey(); Long ledgerId = ledgers.firstKey();
if (ledgerId == null) { if (ledgerId == null) {
return null; return null;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册