CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-com-netflix-ribbon--ribbon-core

Client configuration APIs and shared utilities for Netflix's Ribbon IPC library, providing core interfaces for load balancing, fault tolerance, and service discovery capabilities in cloud environments.

Pending
Overview
Eval results
Files

client-framework.mddocs/

Client Framework

Core interfaces and classes for building client applications that can execute requests against remote services with support for load balancing, retry logic, and configuration management.

Capabilities

IClient Interface

The main interface for client implementations that can execute requests.

/**
 * Interface for clients that can execute a single request
 * @param <S> the request type, extending ClientRequest
 * @param <T> the response type, extending IResponse
 */
public interface IClient<S extends ClientRequest, T extends IResponse> {
    /**
     * Executes the request and returns response
     * @param request the request to execute
     * @param requestConfig configuration for this specific request
     * @return the response from the request execution
     * @throws Exception if the request execution fails
     */
    T execute(S request, IClientConfig requestConfig) throws Exception;
}

ClientRequest Class

Immutable object representing a client request with load balancing and retry information.

/**
 * Immutable object representing a common client request suitable for all communication protocols
 */
public class ClientRequest implements Cloneable {
    /**
     * Creates a new empty request
     */
    public ClientRequest();
    
    /**
     * Creates a request with a URI
     * @param uri the target URI for the request
     */
    public ClientRequest(URI uri);
    
    /**
     * Creates a request with URI, load balancer key, and retry flag
     * @param uri the target URI for the request
     * @param loadBalancerKey key used by load balancer for routing decisions
     * @param isRetriable whether this request can be retried on failure
     */
    public ClientRequest(URI uri, Object loadBalancerKey, boolean isRetriable);
    
    /**
     * Copy constructor
     * @param request the request to copy
     */
    public ClientRequest(ClientRequest request);
    
    /**
     * Returns the request URI
     * @return the URI of this request
     */
    public URI getUri();
    
    /**
     * Returns the load balancer key
     * @return the load balancer key, or null if not set
     */
    public Object getLoadBalancerKey();
    
    /**
     * Returns true if the request is retriable
     * @return true if this request can be retried on failure
     */
    public boolean isRetriable();
    
    /**
     * Creates new request with different URI
     * @param newURI the new URI for the request
     * @return a new ClientRequest with the specified URI
     */
    public ClientRequest replaceUri(URI newURI);
}

Usage Examples:

import com.netflix.client.ClientRequest;
import java.net.URI;

// Basic request
URI serviceUri = URI.create("http://my-service/api/users");
ClientRequest request = new ClientRequest(serviceUri);

// Request with load balancer key (e.g., user ID for sticky sessions)
ClientRequest stickyRequest = new ClientRequest(
    serviceUri, 
    "user123",  // load balancer key
    true        // is retriable
);

// Create modified request with new URI
URI newUri = URI.create("http://my-service/api/users/123");
ClientRequest modifiedRequest = request.replaceUri(newUri);

IResponse Interface

Interface defining the contract for response objects returned by client implementations.

/**
 * Response interface for the client framework
 */
public interface IResponse extends Closeable {
    /**
     * Returns the response payload
     * @return the response payload object
     * @throws ClientException if there's an error accessing the payload
     */
    Object getPayload() throws ClientException;
    
    /**
     * Checks if response has payload
     * @return true if the response contains a payload
     */
    boolean hasPayload();
    
    /**
     * Returns true if response is successful
     * @return true if the response indicates success
     */
    boolean isSuccess();
    
    /**
     * Returns the request URI that generated this response
     * @return the original request URI
     */
    URI getRequestedURI();
    
    /**
     * Returns response headers
     * @return map of response headers
     */
    Map<String, ?> getHeaders();
}

IClientConfigAware Interface

Interface for components that need access to client configuration for initialization.

/**
 * Interface for components that need access to client configuration
 */
public interface IClientConfigAware {
    /**
     * Initialize with client configuration
     * @param clientConfig the configuration to use for initialization
     */
    default void initWithNiwsConfig(IClientConfig clientConfig);
    
    /**
     * Initialize with client configuration and factory
     * @param clientConfig the configuration to use
     * @param factory factory for creating additional objects
     */
    default void initWithNiwsConfig(IClientConfig clientConfig, Factory factory);
    
    /**
     * Factory interface for creating objects with configuration
     */
    interface Factory {
        /**
         * Creates an object of the specified type using configuration
         * @param type the type of object to create
         * @param config the configuration to use
         * @return the created object
         * @throws InstantiationException if object cannot be instantiated
         * @throws IllegalAccessException if object constructor is not accessible
         * @throws ClassNotFoundException if the specified type class is not found
         */
        Object create(String type, IClientConfig config) 
            throws InstantiationException, IllegalAccessException, ClassNotFoundException;
    }
}

Utils Class

Utility class providing common operations for client framework.

/**
 * Utility class for common operations
 */
public class Utils {
    /**
     * Searches for specific throwable types in exception cause chain
     * @param throwableToSearchIn the exception to search through
     * @param throwableToSearchFor collection of exception types to find
     * @return true if any of the specified throwable types are found in the cause chain
     */
    public static boolean isPresentAsCause(
        Throwable throwableToSearchIn, 
        Collection<Class<? extends Throwable>> throwableToSearchFor
    );
}

VipAddressResolver Interface

Interface for resolving VIP (Virtual IP) addresses, which are logical names for target server farms.

/**
 * Interface for resolving VIP addresses (logical names for target server farms)
 */
public interface VipAddressResolver {
    /**
     * Resolves a VIP address using client configuration
     * @param vipAddress the VIP address to resolve
     * @param niwsClientConfig client configuration containing resolution context
     * @return the resolved address
     */
    String resolve(String vipAddress, IClientConfig niwsClientConfig);
}

Usage Examples:

import com.netflix.client.*;
import com.netflix.client.config.IClientConfig;

// Example client implementation
public class MyHttpClient implements IClient<ClientRequest, MyHttpResponse> {
    private final IClientConfig config;
    
    public MyHttpClient(IClientConfig config) {
        this.config = config;
    }
    
    @Override
    public MyHttpResponse execute(ClientRequest request, IClientConfig requestConfig) 
            throws Exception {
        // Implementation would handle HTTP request execution
        // using the request URI, load balancer key, etc.
        
        URI uri = request.getUri();
        Object lbKey = request.getLoadBalancerKey();
        boolean canRetry = request.isRetriable();
        
        // Execute HTTP request and return response
        return new MyHttpResponse(/* response data */);
    }
}

// Example response implementation
public class MyHttpResponse implements IResponse {
    private final Object payload;
    private final boolean success;
    private final URI requestUri;
    private final Map<String, String> headers;
    
    @Override
    public Object getPayload() throws ClientException {
        return payload;
    }
    
    @Override
    public boolean hasPayload() {
        return payload != null;
    }
    
    @Override
    public boolean isSuccess() {
        return success;
    }
    
    @Override
    public URI getRequestedURI() {
        return requestUri;
    }
    
    @Override
    public Map<String, ?> getHeaders() {
        return headers;
    }
    
    @Override
    public void close() throws IOException {
        // Clean up resources if needed
    }
}

Install with Tessl CLI

npx tessl i tessl/maven-com-netflix-ribbon--ribbon-core

docs

client-framework.md

configuration.md

exceptions.md

index.md

retry-handlers.md

ssl-support.md

tile.json