Package net.shibboleth.idp.consent.logic.impl

# Class CounterStorageKeyFunction

java.lang.Object
net.shibboleth.shared.component.AbstractInitializableComponent
net.shibboleth.idp.consent.logic.impl.CounterStorageKeyFunction

All Implemented Interfaces:
  `Function<Pair<ProfileRequestContext,List<String>>,List<String>>`, `Component`, `DestructableComponent`, `InitializableComponent`

public class CounterStorageKeyFunction extends AbstractInitializableComponent implements Function<Pair<ProfileRequestContext,List<String>>,List<String>>
Function to order storage keys by least-used and oldest first during pruning of storage records. For every storage key supplied as input, this function attempts to lookup the number of times the flow corresponding to the storage key has been executed. As such, this function depends on the `UpdateCounter` action being executed prior to this function.

## Field Summary

Fields
Modifier and Type
Field
Description
`private Function<ProfileRequestContext,ProfileInterceptorContext>`
`interceptorContextlookupStrategy`
Strategy used to find the `ProfileInterceptorContext` from the `ProfileRequestContext`.
`private final org.slf4j.Logger`
`log`
Class logger.
`private Function<ProfileRequestContext,String>`
`storageContextLookupStrategy`
Strategy used to determine the storage storageContext.

## Constructor Summary

Constructors
Constructor
Description
`CounterStorageKeyFunction()`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`List<String>`
`apply(Pair<ProfileRequestContext,List<String>> input)`
`protected String`
`getCounterStorageKey(String storageKey)`
Get the storage key for the storage record whose value is a counter.
`protected String`
`getStorageContext(ProfileRequestContext profileRequestContext)`
Get the storage context by applying the storage context lookup strategy to the profile request context.
`protected Long`
`getStorageKeyCounter(StorageService storageService, String storageContext, String storageKey)`
Get the counter for the given storage key.
`protected Map<String,Long>`
`getStorageKeyCounters(ProfileRequestContext profileRequestContext, List<String> storageKeys)`
Get the map of storage keys to counters.
`protected StorageService`
`getStorageService(ProfileRequestContext profileRequestContext)`
Get the storage service from the flow descriptor of the profile interceptor context.
`void`
`setInterceptorContextLookupStrategy(Function<ProfileRequestContext,ProfileInterceptorContext> strategy)`
Set the profile interceptor context lookup strategy.
`void`
`setStorageContextLookupStrategy(Function<ProfileRequestContext,String> strategy)`
Set the storage context lookup strategy.

### Methods inherited from class net.shibboleth.shared.component.AbstractInitializableComponent

`checkComponentActive, checkSetterPreconditions, destroy, doDestroy, doInitialize, ifDestroyedThrowDestroyedComponentException, ifInitializedThrowUnmodifiabledComponentException, ifNotInitializedThrowUninitializedComponentException, initialize, isDestroyed, isInitialized`

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

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

### Methods inherited from interface java.util.function.Function

`andThen, compose`

## Field Details

### log

@Nonnull private final org.slf4j.Logger log
Class logger.

### interceptorContextlookupStrategy

@Nonnull private Function<ProfileRequestContext,ProfileInterceptorContext> interceptorContextlookupStrategy
Strategy used to find the `ProfileInterceptorContext` from the `ProfileRequestContext`.

### storageContextLookupStrategy

@Nonnull private Function<ProfileRequestContext,String> storageContextLookupStrategy
Strategy used to determine the storage storageContext.

## Constructor Details

### CounterStorageKeyFunction

public CounterStorageKeyFunction()
Constructor.

## Method Details

### setInterceptorContextLookupStrategy

public void setInterceptorContextLookupStrategy(@Nonnull Function<ProfileRequestContext,ProfileInterceptorContext> strategy)
Set the profile interceptor context lookup strategy.

Parameters:
  `strategy` - the profile interceptor context lookup strategy

### setStorageContextLookupStrategy

public void setStorageContextLookupStrategy(@Nonnull Function<ProfileRequestContext,String> strategy)
Set the storage context lookup strategy.

Parameters:
  `strategy` - the storage context lookup strategy

### getStorageService

@Nonnull protected StorageService getStorageService(@Nonnull ProfileRequestContext profileRequestContext)
Get the storage service from the flow descriptor of the profile interceptor context. The profile interceptor context is retrieved by applying the profile interceptor context lookup strategy to the profile request context. The storage service is retrieved from the flow descriptor of the last interceptor flow which was attempted.

Parameters:
  `profileRequestContext` - the profile request context
Returns:
  the storage service
Throws:
  `ConstraintViolationException` - if the lookup strategy returns `null`, the interceptor flow descriptor is `null`, or the storage service is `null`

### getStorageContext

@Nonnull protected String getStorageContext(@Nonnull ProfileRequestContext profileRequestContext)
Get the storage context by applying the storage context lookup strategy to the profile request context.

Parameters:
  `profileRequestContext` - the profile request context
Returns:
  the storage context
Throws:
  `ConstraintViolationException` - if the lookup strategy returns `null`

### getCounterStorageKey

@Nonnull protected String getCounterStorageKey(@Nonnull String storageKey)
Get the storage key for the storage record whose value is a counter.

Parameters:
  `storageKey` - the storage key
Returns:
  the storage key for the storage record whose value is a counter

### getStorageKeyCounter

@Nullable protected Long getStorageKeyCounter(@Nonnull StorageService storageService, @Nonnull String storageContext, @Nonnull String storageKey) throws IOException
Get the counter for the given storage key.

Parameters:
  `storageService` - the storage service
  `storageContext` - the storage context
  `storageKey` - the storage key
Returns:
  the counter for the given storage key
Throws:
  `IOException` - if a storage service error occurs
  `NumberFormatException` - if the storage record value cannot be parsed as an integer

### getStorageKeyCounters

@Nonnull protected Map<String,Long> getStorageKeyCounters(@Nonnull ProfileRequestContext profileRequestContext, @Nonnull List<String> storageKeys)
Get the map of storage keys to counters.

Parameters:
  `profileRequestContext` - the profile request context
  `storageKeys` - the storage keys
Returns:
  map of storage keys to counters

### apply

@Nullable public List<String> apply(@Nullable Pair<ProfileRequestContext,List<String>> input)

Specified by:
  `apply` in interface `Function<Pair<ProfileRequestContext,List<String>>,List<String>>`