Class ServerAffinityProvider

  • All Implemented Interfaces:
    Configurable, ExampleUsageProvider, Reconfigurable<ServerAffinityProviderConfig>, UnboundIDExtension

    @Extensible
    @DirectoryProxyServerExtension(appliesToLocalContent=false,
                                   appliesToRemoteContent=true)
    @ThreadSafety(level=INTERFACE_THREADSAFE)
    public abstract class ServerAffinityProvider
    extends java.lang.Object
    implements UnboundIDExtension, Reconfigurable<ServerAffinityProviderConfig>, ExampleUsageProvider
    This class defines an API that must be implemented by extensions which are used to influence which backend server a client should use in a load-balanced set. The primary purpose is to attempt to ensure that related requests are sent to the same backend server in an attempt to eliminate problems that may result from replication propagation delay (e.g., because of a read immediately after a write), to ensure that repeated accesses to the same data benefit from having the data in-cache, etc. A server affinity provider is called at two points in operation processing:
    • Before using the load-balancing algorithm to select a backend server. If the server affinity provider indicates that there is already an affinity defined for the operation, and the affinity is for a server that has a health check state of AVAILABLE, then the server selected by affinity will be used instead selecting a server with the load-balancing algorithm. If the server affinity provider does not specify which server to use, or if the server selected by the affinity provider does not have a health check state of AVAILABLE, then the load-balancing algorithm will be used to select the server.
    • After an operation has been processed. This may be used to set or update state information that may be used by the next request in a "related" set (where "related" is defined according to whatever logic the affinity provider provides).


    Configuring Server Affinity Providers

    In order to configure a server affinity provider created using this API, use a command like:
          dsconfig create-server-affinity-provider \
               --provider-name "{provider-name}" \
               --type third-party \
               --set enabled:true \
               --set "extension-class:{class-name}" \
               --set "extension-argument:{name=value}"
     
    where "{provider-name}" is the name to use for the server affinity provider instance, "{class-name}" is the fully-qualified name of the Java class that extends com.unboundid.directory.sdk.proxy.api.ServerAffinityProvider, and "{name=value}" represents name-value pairs for any arguments to provide to the server affinity provider. If multiple arguments should be provided to the server affinity provider, then the "--set extension-argument:{name=value}" option should be provided multiple times.
    • Constructor Detail

      • ServerAffinityProvider

        public ServerAffinityProvider()
        Creates a new instance of this server affinity provider. All server affinity provider implementations must include a default constructor, but any initialization should generally be done in the initializeServerAffinityProvider method.
    • Method Detail

      • getExtensionDescription

        public abstract java.lang.String[] getExtensionDescription()
        Retrieves a human-readable description for this extension. Each element of the array that is returned will be considered a separate paragraph in generated documentation.
        Specified by:
        getExtensionDescription in interface UnboundIDExtension
        Returns:
        A human-readable description for this extension, or null or an empty array if no description should be available.
      • defineConfigArguments

        public void defineConfigArguments​(ArgumentParser parser)
                                   throws ArgumentException
        Updates the provided argument parser to define any configuration arguments which may be used by this extension. The argument parser may also be updated to define relationships between arguments (e.g., to specify required, exclusive, or dependent argument sets).
        Specified by:
        defineConfigArguments in interface Configurable
        Parameters:
        parser - The argument parser to be updated with the configuration arguments which may be used by this extension.
        Throws:
        ArgumentException - If a problem is encountered while updating the provided argument parser.
      • initializeServerAffinityProvider

        public void initializeServerAffinityProvider​(ProxyServerContext serverContext,
                                                     ServerAffinityProviderConfig config,
                                                     ArgumentParser parser)
                                              throws LDAPException
        Initializes this server affinity provider.
        Parameters:
        serverContext - A handle to the server context for the Directory Proxy server in which this extension is running.
        config - The general configuration for this server affinity provider.
        parser - The argument parser which has been initialized from the configuration for this server affinity provider.
        Throws:
        LDAPException - If a problem occurs while initializing this server affinity provider.
      • isConfigurationAcceptable

        public boolean isConfigurationAcceptable​(ServerAffinityProviderConfig config,
                                                 ArgumentParser parser,
                                                 java.util.List<java.lang.String> unacceptableReasons)
        Indicates whether the configuration represented by the provided argument parser is acceptable for use by this extension. The parser will have been used to parse any configuration available for this extension, and any automatic validation will have been performed. This method may be used to perform any more complex validation which cannot be performed automatically by the argument parser.
        Specified by:
        isConfigurationAcceptable in interface Reconfigurable<ServerAffinityProviderConfig>
        Parameters:
        config - The general configuration for this extension.
        parser - The argument parser that has been used to parse the proposed configuration for this extension.
        unacceptableReasons - A list to which messages may be added to provide additional information about why the provided configuration is not acceptable.
        Returns:
        true if the configuration in the provided argument parser appears to be acceptable, or false if not.
      • applyConfiguration

        public ResultCode applyConfiguration​(ServerAffinityProviderConfig config,
                                             ArgumentParser parser,
                                             java.util.List<java.lang.String> adminActionsRequired,
                                             java.util.List<java.lang.String> messages)
        Attempts to apply the configuration from the provided argument parser to this extension.
        Specified by:
        applyConfiguration in interface Reconfigurable<ServerAffinityProviderConfig>
        Parameters:
        config - The general configuration for this extension.
        parser - The argument parser that has been used to parse the new configuration for this extension.
        adminActionsRequired - A list to which messages may be added to provide additional information about any additional administrative actions that may be required to apply some of the configuration changes.
        messages - A list to which messages may be added to provide additional information about the processing performed by this method.
        Returns:
        A result code providing information about the result of applying the configuration change. A result of SUCCESS should be used to indicate that all processing completed successfully. Any other result will indicate that a problem occurred during processing.
      • finalizeServerAffinityProvider

        public void finalizeServerAffinityProvider()
        Performs any cleanup which may be necessary when this server affinity provider is to be taken out of service.
      • clearAffinityData

        public abstract void clearAffinityData​(DN lbaDN,
                                               java.util.Map<DN,​BackendServer> backendServers)
        Clears all affinity data associated with the provided list of load-balancing algorithms.
        Parameters:
        lbaDN - The config entry DN of the load-balancing algorithm for which to clear the affinity data. If this is null, then all affinity data for all load-balancing algorithms should be cleared.
        backendServers - The set of backend servers that are associated with the specified load-balancing algorithm.
      • selectServer

        public abstract ServerAffinity selectServer​(DN lbaDN,
                                                    java.util.Map<DN,​BackendServer> backendServers,
                                                    ProxyOperationContext operation)
        Indicates which backend server should be used for the provided operation. It is generally recommended that this method only return a server if the operation matches an affinity that has already been established (via a previous call to the updateAffinity method). If no affinity has been set, then it is recommended that this method return null to allow the load-balancing algorithm to select an appropriate server instead.
        Parameters:
        lbaDN - The config entry DN of the load-balancing algorithm for which to make the determination.
        backendServers - The set of backend servers from which the selection may be made, indexed by the DN of the configuration entry for each server. It will not be null.
        operation - The operation to be processed. It will not be null.
        Returns:
        The backend server for which an affinity is already established, or null if the operation does not match any affinity that has already been established and the appropriate backend server should be selected by the load-balancing algorithm.
      • updateAffinity

        public abstract void updateAffinity​(ProxyOperationContext operation,
                                            DN lbaDN,
                                            BackendServer backendServer)
        Specifies the backend server that was used to process the provided operation, which allows this affinity provider to establish or update any necessary state information that could be used to select the same server for "related" operations that may be processed in the future.
        Parameters:
        operation - The operation that was processed.
        lbaDN - The config entry DN of the load-balancing algorithm with which the backend server is associated.
        backendServer - The backend server that was used to process the operation.
      • toString

        public final java.lang.String toString()
        Retrieves a string representation of this server affinity provider.
        Overrides:
        toString in class java.lang.Object
        Returns:
        A string representation of this server affinity provider.
      • toString

        public abstract void toString​(java.lang.StringBuilder buffer)
        Appends a string representation of this server affinity provider to the provided buffer.
        Parameters:
        buffer - The buffer to which the string representation should be appended.
      • getExamplesArgumentSets

        public java.util.Map<java.util.List<java.lang.String>,​java.lang.String> getExamplesArgumentSets()
        Retrieves a map containing examples of configurations that may be used for this extension. The map key should be a list of sample arguments, and the corresponding value should be a description of the behavior that will be exhibited by the extension when used with that configuration.
        Specified by:
        getExamplesArgumentSets in interface ExampleUsageProvider
        Returns:
        A map containing examples of configurations that may be used for this extension. It may be null or empty if there should not be any example argument sets.