CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-io-cdap-cdap--cdap-common

CDAP Common provides core common utilities and abstractions for the CDAP (Cask Data Application Platform) ecosystem including exception handling, service management, configuration, HTTP utilities, metadata management, security abstractions, discovery services, and various utility classes that are shared across CDAP components.

Pending
Overview
Eval results
Files

services.mddocs/

Service Framework

Service management utilities built on Google Guava's Service interface, providing lifecycle management with timeout handling and error recovery.

Capabilities

Service Management Utilities

Core utilities for managing service lifecycles with timeout control and error handling.

/**
 * Utilities for service management and coordination
 */
public class Services {
    /**
     * Attempts to start the passed in service with timeout
     * @param service The service to start
     * @param timeout The duration to wait for the service to start
     * @param timeoutUnit The time unit used for the timeout parameter
     * @throws TimeoutException If the service can not be started before the specified timeout
     * @throws InterruptedException If the service is interrupted while trying to start
     * @throws ExecutionException If an exception occurs while trying to start the service
     */
    public static void startAndWait(Service service, long timeout, TimeUnit timeoutUnit)
        throws TimeoutException, InterruptedException, ExecutionException;
    
    /**
     * Attempts to start the passed in service with timeout and custom error message
     * @param service The service to start
     * @param timeout The duration to wait for the service to start
     * @param timeoutUnit The time unit used for the timeout parameter
     * @param timeoutErrorMessage An optional error message to display if starting the service times out
     * @throws TimeoutException If the service can not be started before the specified timeout
     * @throws InterruptedException If the service is interrupted while trying to start
     * @throws ExecutionException If an exception occurs while trying to start the service
     */
    public static void startAndWait(Service service, long timeout, TimeUnit timeoutUnit,
        String timeoutErrorMessage)
        throws TimeoutException, InterruptedException, ExecutionException;
}

Usage Examples:

import io.cdap.cdap.common.service.Services;
import com.google.common.util.concurrent.Service;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.InterruptedException;
import java.util.concurrent.ExecutionException;

// Start a service with timeout
try {
    Services.startAndWait(myService, 30, TimeUnit.SECONDS);
    System.out.println("Service started successfully");
} catch (TimeoutException e) {
    System.err.println("Service failed to start within 30 seconds");
} catch (InterruptedException e) {
    System.err.println("Service start was interrupted");
} catch (ExecutionException e) {
    System.err.println("Service start failed: " + e.getCause().getMessage());
}

// Start service with custom timeout message
try {
    Services.startAndWait(
        authenticationService, 
        60, 
        TimeUnit.SECONDS,
        "Authentication service failed to start within expected time"
    );
} catch (TimeoutException e) {
    // Custom error message will be logged
    System.err.println("Custom timeout handling");
}

Retry Strategies

Configurable retry strategies for resilient service operations.

/**
 * Interface for retry strategies
 */
public interface RetryStrategy {
    /**
     * Returns the next retry delay in milliseconds, or -1 if no more retries
     * @param failureCount Number of consecutive failures
     * @param startTime Time when the operation first started (in milliseconds)
     * @return Delay in milliseconds before next retry, or -1 to stop retrying
     */
    long nextRetry(int failureCount, long startTime);
}

/**
 * Common retry strategy implementations
 */
public class RetryStrategies {
    /**
     * No retry strategy - fail immediately
     */
    public static RetryStrategy noRetry();
    
    /**
     * Fixed delay retry strategy
     */
    public static RetryStrategy fixedDelay(long delay, TimeUnit timeUnit);
    
    /**
     * Exponential backoff retry strategy
     */
    public static RetryStrategy exponentialDelay(long initialDelay, long maxDelay, TimeUnit timeUnit);
    
    /**
     * Limited retry strategy that stops after max attempts
     */
    public static RetryStrategy limit(RetryStrategy delegate, int maxAttempts);
    
    /**
     * Time-limited retry strategy
     */
    public static RetryStrategy timeLimit(RetryStrategy delegate, long maxElapsedTime, TimeUnit timeUnit);
}

/**
 * Utility class for executing operations with retry logic
 */
public class Retries {
    /**
     * Call a supplier with retry logic
     */
    public static <V> V callWithRetries(Supplier<V> supplier, RetryStrategy retryStrategy) 
        throws Exception;
    
    /**
     * Call a callable with retry logic, handling specific exception types
     */
    public static <V> V callWithRetries(Callable<V> callable, RetryStrategy retryStrategy, 
        Class<? extends Exception>... retryableExceptions) throws Exception;
    
    /**
     * Run a runnable with retry logic
     */
    public static void runWithRetries(Runnable runnable, RetryStrategy retryStrategy) 
        throws Exception;
}

Service Base Classes

Abstract base classes for implementing common service patterns.

/**
 * Abstract base class for services with retry logic on start failure
 */
public abstract class AbstractRetryableScheduledService extends AbstractScheduledService {
    protected AbstractRetryableScheduledService(RetryStrategy retryStrategy);
    
    @Override
    protected final void startUp() throws Exception;
    
    /**
     * Subclasses implement this method for actual startup logic
     */
    protected abstract void doStartUp() throws Exception;
}

/**
 * Service decorator that retries start failures
 */
public class RetryOnStartFailureService extends AbstractService {
    public RetryOnStartFailureService(Service delegate, RetryStrategy retryStrategy);
    
    @Override
    protected void doStart();
    
    @Override
    protected void doStop();
}

/**
 * Service with command port support for remote management
 */
public abstract class CommandPortService extends AbstractService {
    protected CommandPortService(String serviceName, int commandPort);
    
    /**
     * Get the command port for this service
     */
    public int getCommandPort();
    
    /**
     * Handle a command received on the command port
     */
    protected abstract String handleCommand(String command);
}

Service Discovery Integration

Integration components for service discovery and registration.

/**
 * Service that integrates with service discovery
 */
public class ServiceDiscoverable extends AbstractService {
    public ServiceDiscoverable(String serviceName, 
                              InetSocketAddress bindAddress,
                              DiscoveryService discoveryService);
    
    @Override
    protected void doStart();
    
    @Override
    protected void doStop();
    
    /**
     * Get the discoverable for this service
     */
    public Discoverable getDiscoverable();
}

Install with Tessl CLI

npx tessl i tessl/maven-io-cdap-cdap--cdap-common

docs

configuration.md

exceptions.md

http.md

index.md

io.md

logging.md

network.md

security.md

services.md

utilities.md

tile.json