org.keycloak.models.sessions.infinispan.remotestore

## Class RemoteCacheSessionsLoader

- java.lang.Object
- - org.keycloak.models.sessions.infinispan.remotestore.RemoteCacheSessionsLoader

- All Implemented Interfaces:
    Serializable, SessionLoader<RemoteCacheSessionsLoaderContext,SessionLoader.WorkerContext,SessionLoader.WorkerResult>

      public class RemoteCacheSessionsLoader
      extends Object
      implements SessionLoader<RemoteCacheSessionsLoaderContext,SessionLoader.WorkerContext,SessionLoader.WorkerResult>, Serializable

  Author:
    Marek Posolda
  See Also:
    Serialized Form

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface org.keycloak.models.sessions.infinispan.initializer.SessionLoader

      `SessionLoader.LoaderContext, SessionLoader.WorkerContext, SessionLoader.WorkerResult`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `RemoteCacheSessionsLoader(String cacheName, int sessionsPerSegment)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `afterAllSessionsLoaded(BaseCacheInitializer initializer)` Callback triggered on cluster coordinator once it recognize that all sessions were successfully loaded
    `RemoteCacheSessionsLoaderContext` | `computeLoaderContext(KeycloakSession session)` Will be triggered just once on cluster coordinator node to count the number of segments and other context data specific to whole computation.
    `SessionLoader.WorkerContext` | `computeWorkerContext(RemoteCacheSessionsLoaderContext loaderCtx, int segment, int workerId, SessionLoader.WorkerResult previousResult)` Compute the worker context for current iteration
    `SessionLoader.WorkerResult` | `createFailedWorkerResult(RemoteCacheSessionsLoaderContext loaderContext, SessionLoader.WorkerContext workerContext)` Called when it's not possible to compute current iteration and load session for some reason (EG.
    `protected org.infinispan.Cache` | `getCache(KeycloakSession session)`
    `protected int` | `getIspnSegmentsCount(org.infinispan.client.hotrod.RemoteCache remoteCache)`
    `protected Set<Integer>` | `getMyIspnSegments(int segment, RemoteCacheSessionsLoaderContext ctx)`
    `protected org.infinispan.client.hotrod.RemoteCache` | `getRemoteCache(KeycloakSession session)`
    `void` | `init(KeycloakSession session)` Will be triggered just once on cluster coordinator node to perform some generic initialization tasks (Eg.
    `boolean` | `isFinished(BaseCacheInitializer initializer)` This will be called on nodes to check if loading is finished.
    `SessionLoader.WorkerResult` | `loadSessions(KeycloakSession session, RemoteCacheSessionsLoaderContext loaderContext, SessionLoader.WorkerContext ctx)` Will be called on all cluster nodes to load the specified page.
    `String` | `toString()`

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

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

- - ### Constructor Detail

    - #### RemoteCacheSessionsLoader

          public RemoteCacheSessionsLoader(String cacheName,
                                           int sessionsPerSegment)

  - ### Method Detail

    - #### init

          public void init(KeycloakSession session)

      Description copied from interface: `SessionLoader`
      Will be triggered just once on cluster coordinator node to perform some generic initialization tasks (Eg. update DB before starting load). NOTE: This shouldn't be used for the initialization of loader instance itself!
      Specified by:
        `init` in interface `SessionLoader<RemoteCacheSessionsLoaderContext,SessionLoader.WorkerContext,SessionLoader.WorkerResult>`

    - #### computeLoaderContext

          public RemoteCacheSessionsLoaderContext computeLoaderContext(KeycloakSession session)

      Description copied from interface: `SessionLoader`
      Will be triggered just once on cluster coordinator node to count the number of segments and other context data specific to whole computation. Each segment will be then later computed in one "worker" task This method could be expensive to call, so the "computed" loaderContext object is passed among workers/loaders and needs to be serializable
      Specified by:
        `computeLoaderContext` in interface `SessionLoader<RemoteCacheSessionsLoaderContext,SessionLoader.WorkerContext,SessionLoader.WorkerResult>`
      Returns:

    - #### getIspnSegmentsCount

          protected int getIspnSegmentsCount(org.infinispan.client.hotrod.RemoteCache remoteCache)

    - #### computeWorkerContext

          public SessionLoader.WorkerContext computeWorkerContext(RemoteCacheSessionsLoaderContext loaderCtx,
                                                                  int segment,
                                                                  int workerId,
                                                                  SessionLoader.WorkerResult previousResult)

      Description copied from interface: `SessionLoader`
      Compute the worker context for current iteration
      Specified by:
        `computeWorkerContext` in interface `SessionLoader<RemoteCacheSessionsLoaderContext,SessionLoader.WorkerContext,SessionLoader.WorkerResult>`
      Parameters:
        `loaderCtx` - global loader context
        `segment` - the current segment (page) to compute
        `workerId` - ID of worker for current worker iteration. Usually the number 0-8 (with single cluster node)
        `previousResult` - last workerResult from previous computation. Can be empty list in case of the operation is triggered for the 1st time
      Returns:

    - #### createFailedWorkerResult

          public SessionLoader.WorkerResult createFailedWorkerResult(RemoteCacheSessionsLoaderContext loaderContext,
                                                                     SessionLoader.WorkerContext workerContext)

      Description copied from interface: `SessionLoader`
      Called when it's not possible to compute current iteration and load session for some reason (EG. infinispan not yet fully initialized)
      Specified by:
        `createFailedWorkerResult` in interface `SessionLoader<RemoteCacheSessionsLoaderContext,SessionLoader.WorkerContext,SessionLoader.WorkerResult>`
      Returns:

    - #### loadSessions

          public SessionLoader.WorkerResult loadSessions(KeycloakSession session,
                                                         RemoteCacheSessionsLoaderContext loaderContext,
                                                         SessionLoader.WorkerContext ctx)

      Description copied from interface: `SessionLoader`
      Will be called on all cluster nodes to load the specified page.
      Specified by:
        `loadSessions` in interface `SessionLoader<RemoteCacheSessionsLoaderContext,SessionLoader.WorkerContext,SessionLoader.WorkerResult>`
        `loaderContext` - global loaderContext object, which was already computed before
        `ctx` - for current iteration
      Returns:

    - #### getMyIspnSegments

          protected Set<Integer> getMyIspnSegments(int segment,
                                                   RemoteCacheSessionsLoaderContext ctx)

    - #### isFinished

          public boolean isFinished(BaseCacheInitializer initializer)

      Description copied from interface: `SessionLoader`
      This will be called on nodes to check if loading is finished. It allows loader to notify that loading is finished for some reason.
      Specified by:
        `isFinished` in interface `SessionLoader<RemoteCacheSessionsLoaderContext,SessionLoader.WorkerContext,SessionLoader.WorkerResult>`
      Returns:

    - #### afterAllSessionsLoaded

          public void afterAllSessionsLoaded(BaseCacheInitializer initializer)

      Description copied from interface: `SessionLoader`
      Callback triggered on cluster coordinator once it recognize that all sessions were successfully loaded
      Specified by:
        `afterAllSessionsLoaded` in interface `SessionLoader<RemoteCacheSessionsLoaderContext,SessionLoader.WorkerContext,SessionLoader.WorkerResult>`

    - #### getCache

          protected org.infinispan.Cache getCache(KeycloakSession session)

    - #### getRemoteCache

          protected org.infinispan.client.hotrod.RemoteCache getRemoteCache(KeycloakSession session)

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

Copyright © 2020 JBoss by Red Hat. All rights reserved.