A
- Type parameter of the "range" data.B
- Type parameter of the data.public abstract class TieredRangeFetcher<A extends Comparable<A>,B> extends Object
TieredRangeFetcher
abstracts the concept of
tiered data sources. When data is fetched (via the
fetch(Comparable,Comparable)
method), the TieredRangeFetcher
attempts to retrieve the requested range from the "top" tier of the stack. If
all or a part of the range is not present in the tier, the
TieredRangeFetcher
attempts to fetch the missing portion of the range
from the next tier. Upon successfully fetching the data, the
TieredRangeFetcher
thereafter inserts the fetched data into the top
tier, thus resembling a caching mechanism. The TieredRangeFetcher
is
intended to provide an abstraction for the caching of range data belonging to
a data source that is expensive to call, such as a remote database.Constructor and Description |
---|
TieredRangeFetcher(TieredRangeFetcher<A,B> next)
Creates a
TieredRangeFetcher with the specified next
TieredRangeFetcher that represents the next tier. |
Modifier and Type | Method and Description |
---|---|
SortedMap<A,B> |
fetch(A from,
A to)
|
SortedMap<A,B> |
fetch(A from,
A to,
TieredRangeFetcher<A,B> last)
|
protected abstract void |
insert(A from,
A to,
SortedMap<A,B> data)
|
protected abstract A[] |
range()
Returns the range of the keys present in this TieredFetcher, as an array of
length 2.
|
protected abstract SortedMap<A,B> |
select(A from,
A to)
|
public TieredRangeFetcher(TieredRangeFetcher<A,B> next)
TieredRangeFetcher
with the specified next
TieredRangeFetcher
that represents the next tier.next
- The TieredRangeFetcher
that represents the next tier.public SortedMap<A,B> fetch(A from, A to)
from
- The lower bound of the range, inclusive.to
- The upper bound of the range, exclusive.SortedMap
of data from from
(inclusive) to
to
(exclusive).public SortedMap<A,B> fetch(A from, A to, TieredRangeFetcher<A,B> last)
from
- The lower bound of the range, inclusive.to
- The upper bound of the range, exclusive.last
- The TieredRangeFetcher
representing the previous tier.SortedMap
of data from from
(inclusive) to
to
(exclusive).protected abstract A[] range()
protected abstract SortedMap<A,B> select(A from, A to)
from
- The start of the range, inclusive.to
- The end of the range, exclusive.SortedMap
of data in this TieredRangeFetcher
for
the range between from
and to
.Copyright © 2020 LibJ. All rights reserved.