org.apache.ignite.internal.processors.cache

## Class GridCachePreloaderAdapter

- java.lang.Object
- - org.apache.ignite.internal.processors.cache.GridCachePreloaderAdapter

All Implemented Interfaces:
  GridCachePreloader

Direct Known Subclasses:
  GridDhtPreloader

    public class GridCachePreloaderAdapter
    extends Object
    implements GridCachePreloader

Adapter for preloading which always assumes that preloading finished.

### Field Summary

Fields
`protected GridCacheSharedContext` `ctx`
`protected CacheGroupContext` `grp`
`protected IgniteLogger` `log` Logger.

### Constructor Summary

Constructors
Constructor and Description
`GridCachePreloaderAdapter(CacheGroupContext grp)`

### Method Summary

All Methods Instance Methods Concrete Methods
`Runnable` `addAssignments(GridDhtPreloaderAssignments assignments, boolean forcePreload, long rebalanceId, Runnable next, @Nullable GridCompoundFuture<Boolean,Boolean> forcedRebFut)` Adds assignments to preloader.
`long` `batchesPrefetchCount()` The number of batches generated by supply node at rebalancing procedure start.
`int` `batchSize()` The supply message size in bytes to be loaded within a single rebalance batch.
`void` `dumpDebugInfo()` Dumps debug information.
`IgniteInternalFuture<Boolean>` `forceRebalance()` Force Rebalance process.
`GridDhtPreloaderAssignments` `generateAssignments(GridDhtPartitionExchangeId exchId, GridDhtPartitionsExchangeFuture exchFut)`
`void` `handleDemandMessage(int idx, UUID id, GridDhtPartitionDemandMessage d)` Handles Demand message.
`void` `handleSupplyMessage(UUID id, GridDhtPartitionSupplyMessage s)` Handles Supply message.
`boolean` `needForceKeys()`
`void` `onInitialExchangeComplete(@Nullable Throwable err)` Callback by exchange manager when initial partition exchange is complete.
`void` `onKernalStop()` Kernal stop callback.
`void` `onReconnected()` Client reconnected callback.
`void` `onTopologyChanged(GridDhtPartitionsExchangeFuture lastFut)`
`void` `pause()` Pause preloader.
`IgniteInternalFuture<Boolean>` `rebalanceFuture()`
`boolean` `rebalanceRequired(AffinityTopologyVersion rebTopVer, GridDhtPartitionsExchangeFuture exchFut)`
`GridDhtFuture<Object>` `request(GridCacheContext ctx, Collection<KeyCacheObject> keys, AffinityTopologyVersion topVer)` Requests that preloader sends the request for the key.
`GridDhtFuture<Object>` `request(GridCacheContext ctx, GridNearAtomicAbstractUpdateRequest req, AffinityTopologyVersion topVer)` Requests that preloader sends the request for the key.
`void` `resume()` Resume preloader.
`void` `start()` Starts preloading.
`IgniteInternalFuture<Object>` `startFuture()`
`IgniteInternalFuture<?>` `syncFuture()`
`long` `throttle()` Time in milliseconds to wait between rebalance messages to avoid overloading of CPU or network.
`long` `timeout()` Rebalance timeout for supply and demand messages in milliseconds.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### grp

    protected final CacheGroupContext grp

#### ctx

    protected final GridCacheSharedContext ctx

#### log

    protected final IgniteLogger log

Logger.

### Constructor Detail

#### GridCachePreloaderAdapter

    public GridCachePreloaderAdapter(CacheGroupContext grp)

Parameters:
  `grp` - Cache group.

### Method Detail

#### start

    public void start()
               throws IgniteCheckedException

Starts preloading.

Specified by:
  `start` in interface `GridCachePreloader`
Throws:
  `IgniteCheckedException` - If start failed.

#### onKernalStop

    public void onKernalStop()

Kernal stop callback.

Specified by:
  `onKernalStop` in interface `GridCachePreloader`

#### forceRebalance

    public IgniteInternalFuture<Boolean> forceRebalance()

Force Rebalance process.

Specified by:
  `forceRebalance` in interface `GridCachePreloader`

#### needForceKeys

    public boolean needForceKeys()

Specified by:
  `needForceKeys` in interface `GridCachePreloader`
Returns:
  `true` if there is no need to force keys preloading (e.g. rebalancing has been completed).

#### onReconnected

    public void onReconnected()

Client reconnected callback.

Specified by:
  `onReconnected` in interface `GridCachePreloader`

#### startFuture

    public IgniteInternalFuture<Object> startFuture()

Specified by:
  `startFuture` in interface `GridCachePreloader`
Returns:
  Future which will complete when preloader is safe to use.

#### syncFuture

    public IgniteInternalFuture<?> syncFuture()

Specified by:
  `syncFuture` in interface `GridCachePreloader`
Returns:
  Future which will complete when preloading is finished.

#### rebalanceFuture

    public IgniteInternalFuture<Boolean> rebalanceFuture()

Specified by:
  `rebalanceFuture` in interface `GridCachePreloader`
Returns:
  Future which will complete when preloading finishes on current topology. Future result is `true` in case rebalancing successfully finished at current topology. Future result is `false` in case rebalancing cancelled or finished with missed partitions and will be restarted at current or pending topology.

#### handleSupplyMessage

    public void handleSupplyMessage(UUID id,
                                    GridDhtPartitionSupplyMessage s)

Handles Supply message.

Specified by:
  `handleSupplyMessage` in interface `GridCachePreloader`
Parameters:
  `id` - Node Id.
  `s` - Supply message.

#### handleDemandMessage

    public void handleDemandMessage(int idx,
                                    UUID id,
                                    GridDhtPartitionDemandMessage d)

Handles Demand message.

Specified by:
  `handleDemandMessage` in interface `GridCachePreloader`
Parameters:
  `idx` - Index.
  `id` - Node Id.
  `d` - Demand message.

#### request

    public GridDhtFuture<Object> request(GridCacheContext ctx,
                                         Collection<KeyCacheObject> keys,
                                         AffinityTopologyVersion topVer)

Requests that preloader sends the request for the key.

Specified by:
  `request` in interface `GridCachePreloader`
Parameters:
  `ctx` - Cache context.
  `keys` - Keys to request.
  `topVer` - Topology version, `-1` if not required.
Returns:
  Future to complete when all keys are preloaded.

#### request

    public GridDhtFuture<Object> request(GridCacheContext ctx,
                                         GridNearAtomicAbstractUpdateRequest req,
                                         AffinityTopologyVersion topVer)

Requests that preloader sends the request for the key.

Specified by:
  `request` in interface `GridCachePreloader`
Parameters:
  `ctx` - Cache context.
  `req` - Message with keys to request.
  `topVer` - Topology version, `-1` if not required.
Returns:
  Future to complete when all keys are preloaded.

#### onInitialExchangeComplete

    public void onInitialExchangeComplete(@Nullable
                                          @Nullable Throwable err)

Callback by exchange manager when initial partition exchange is complete.

Specified by:
  `onInitialExchangeComplete` in interface `GridCachePreloader`
Parameters:
  `err` - Error, if any happened on initial exchange.

#### rebalanceRequired

    public boolean rebalanceRequired(AffinityTopologyVersion rebTopVer,
                                     GridDhtPartitionsExchangeFuture exchFut)

Specified by:
  `rebalanceRequired` in interface `GridCachePreloader`
Parameters:
  `rebTopVer` - Previous rebalance topology version or `NONE` if there is no info.
  `exchFut` - Completed exchange future.
Returns:
  `True` if rebalance should be started (previous will be interrupted).

#### generateAssignments

    public GridDhtPreloaderAssignments generateAssignments(GridDhtPartitionExchangeId exchId,
                                                           GridDhtPartitionsExchangeFuture exchFut)

Specified by:
  `generateAssignments` in interface `GridCachePreloader`
Parameters:
  `exchId` - Exchange ID.
  `exchFut` - Completed exchange future. Can be `null` if forced or reassigned generation occurs.
Returns:
  Partition assignments which will be requested from supplier nodes.

#### addAssignments

    public Runnable addAssignments(GridDhtPreloaderAssignments assignments,
                                   boolean forcePreload,
                                   long rebalanceId,
                                   Runnable next,
                                   @Nullable
                                   @Nullable GridCompoundFuture<Boolean,Boolean> forcedRebFut)

Adds assignments to preloader.

Specified by:
  `addAssignments` in interface `GridCachePreloader`
Parameters:
  `assignments` - Assignments to add.
  `forcePreload` - `True` if preload requested by `ForceRebalanceExchangeTask`.
  `rebalanceId` - Rebalance id created by exchange thread.
  `next` - Runnable responsible for cache rebalancing chain.
  `forcedRebFut` - External future for forced rebalance.
Returns:
  Rebalancing runnable.

#### onTopologyChanged

    public void onTopologyChanged(GridDhtPartitionsExchangeFuture lastFut)

Specified by:
  `onTopologyChanged` in interface `GridCachePreloader`
Parameters:
  `lastFut` - Last future.

#### dumpDebugInfo

    public void dumpDebugInfo()

Dumps debug information.

Specified by:
  `dumpDebugInfo` in interface `GridCachePreloader`

#### pause

    public void pause()

Pause preloader.

Specified by:
  `pause` in interface `GridCachePreloader`

#### resume

    public void resume()

Resume preloader.

Specified by:
  `resume` in interface `GridCachePreloader`

#### timeout

    public long timeout()

Rebalance timeout for supply and demand messages in milliseconds.

The `IgniteConfiguration.getRebalanceTimeout()` will be used by default. If an Ignite's configuration value is not provided than the `CacheConfiguration.getRebalanceTimeout()` will be used instead.

Specified by:
  `timeout` in interface `GridCachePreloader`
Returns:
  Rebalance message timeout in milliseconds.

#### batchesPrefetchCount

    public long batchesPrefetchCount()

The number of batches generated by supply node at rebalancing procedure start.

The `IgniteConfiguration.getRebalanceBatchesPrefetchCount()` will be used by default. If an Ignite's configuration value is not provided than the `CacheConfiguration.getRebalanceBatchesPrefetchCount()` will be used instead.

Specified by:
  `batchesPrefetchCount` in interface `GridCachePreloader`
Returns:
  The number of batches prefetch count.

#### throttle

    public long throttle()

Time in milliseconds to wait between rebalance messages to avoid overloading of CPU or network.

The `IgniteConfiguration.getRebalanceThrottle()` will be used by default. If an Ignite's configuration value is not provided than the `CacheConfiguration.getRebalanceThrottle()` will be used instead.

Specified by:
  `throttle` in interface `GridCachePreloader`
Returns:
  Time in milliseconds to wait between rebalance messages, `0` to disable throttling.

#### batchSize

    public int batchSize()

The supply message size in bytes to be loaded within a single rebalance batch.

The `IgniteConfiguration.getRebalanceBatchSize()` will be used by default. If an Ignite's configuration value is not provided than the `CacheConfiguration.getRebalanceBatchSize()` will be used instead.

Specified by:
  `batchSize` in interface `GridCachePreloader`
Returns:
  Rebalance message size in bytes.

${current.year} Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Database and Caching Platform | : ver. 2.8.1
Release Date | : May 21 2020