Package com.privatechain.core.mempool
Class TimestampBasedPrioritizer
java.lang.Object
com.privatechain.core.mempool.TimestampBasedPrioritizer
- All Implemented Interfaces:
TransactionPrioritizer,Serializable,Comparator<Transaction>
public final class TimestampBasedPrioritizer
extends Object
implements TransactionPrioritizer, Serializable
Orders transactions by submission timestamp in ascending order (oldest first / FIFO).
This prioritizer is the default used when no explicit prioritizer is configured
via BlockchainConfig.Builder.transactionPrioritizer(TransactionPrioritizer).
It favors transactions that have been waiting longest, which provides a fair,
predictable ordering suitable for development and testing (FR-MEMPOOL-03).
Ordering contract
- A transaction with an earlier timestamp sorts before one with a later timestamp (ascending / the lowest timestamp = highest priority in the queue).
- When two transactions share the same timestamp, their UUID natural order is used as a stable tiebreaker to ensure deterministic sorting.
nulltimestamps are treated asLong.MAX_VALUE(lowest priority), which guards against NPEs from partially-constructed objects.
- Since:
- 1.0.0
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintcompare(Transaction t1, Transaction t2) Compares two transactions by their submission timestamps.toString()Returns a human-readable name for this prioritizer.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Constructor Details
-
TimestampBasedPrioritizer
public TimestampBasedPrioritizer()
-
-
Method Details
-
compare
Compares two transactions by their submission timestamps.Returns a negative integer if
t1should be selected beforet2(i.e.,t1has an earlier timestamp).Returns a positive integer if
t1should be selected aftert2(i.e.,t1has a newer timestamp).If both transections has a same timestamp then we compare their transections id.
Returns a negative integer if
t1.getId()is less thant2.getId()Returns a positive integer if
t1.getId()is greater thant2.getId()- Specified by:
comparein interfaceComparator<Transaction>- Specified by:
comparein interfaceTransactionPrioritizer- Parameters:
t1- the first transaction (non-null)t2- the second transaction (non-null)- Returns:
- negative if
t1sorts first, positive ift2sorts first
-
toString
Returns a human-readable name for this prioritizer.
-