### Create and Use ConfigSourcePipeline Source: https://github.com/foldright/auto-pipeline/blob/main/docs/docs/tutorial-basics/01-quick-start.md This snippet shows how to instantiate a ConfigSourcePipeline by adding ConfigSourceHandlers. It then demonstrates how to use the pipeline to retrieve configuration values from different sources like a map and system properties. ```java public class Main { public static void main(String[] args) { Map mapConfig = new HashMap(); mapConfig.put("hello", "world"); ConfigSourceHandler mapConfigSourceHandler = new MapConfigSourceHandler(mapConfig); ConfigSource pipeline = new ConfigSourcePipeline() .addLast(mapConfigSourceHandler) .addLast(SystemConfigSourceHandler.INSTANCE); pipeline.get("hello"); // get value "world" // from mapConfig / mapConfigSourceHandler pipeline.get("java.specification.version"); // get value "1.8" // from system properties / SystemConfigSourceHandler } } ``` -------------------------------- ### Implement ConfigSource Handler (Java) Source: https://github.com/foldright/auto-pipeline/blob/main/docs/docs/tutorial-basics/01-quick-start.md Implement the generated `ConfigSourceHandler` interface to define specific business logic for the pipeline. This example shows how to implement handlers for retrieving configuration values from a map or system properties. ```java public class MapConfigSourceHandler implements ConfigSourceHandler { private final Map map; public MapConfigSourceHandler(Map map) { this.map = map; } @Override public String get(String key, ConfigSourceHandlerContext context) { String value = map.get(key); if (StringUtils.isNotBlank(value)) { return value; } return context.get(key); } } ``` ```java public class SystemConfigSourceHandler implements ConfigSourceHandler { public static final SystemConfigSourceHandler INSTANCE = new SystemConfigSourceHandler(); @Override public String get(String key, ConfigSourceHandlerContext context) { String value = System.getProperty(key); if (StringUtils.isNotBlank(value)) { return value; } return context.get(key); } } ``` -------------------------------- ### Using the Generated ConfigSource Pipeline Source: https://github.com/foldright/auto-pipeline/blob/main/README.md This Java code illustrates how to create and use the pipeline generated by Auto-Pipeline. It involves instantiating handlers, composing them using the `addLast` method on the `ConfigSourcePipeline`, and then invoking the `get` method on the pipeline. ```java Map mapConfig = new HashMap(); mapConfig.put("hello", "world"); ConfigSourceHandler mapConfigSourceHandler = new MapConfigSourceHandler(mapConfig); ConfigSource pipeline = new ConfigSourcePipeline() .addLast(mapConfigSourceHandler) .addLast(SystemConfigSourceHandler.INSTANCE); pipeline.get("hello"); // get value "world" // from mapConfig / mapConfigSourceHandler pipeline.get("java.specification.version") // get value "1.8" // from system properties / SystemConfigSourceHandler ``` -------------------------------- ### Define Extensible Interface with @AutoPipeline (Java) Source: https://github.com/foldright/auto-pipeline/blob/main/docs/docs/tutorial-basics/01-quick-start.md Define a Java interface and annotate it with `@AutoPipeline` to enable the 'chain of responsibility' pattern. The annotation processor will automatically generate pipeline-related classes in a 'pipeline' subpackage. ```java @AutoPipeline // add @AutoPipeline here! public interface ConfigSource { String get(String key); } ``` -------------------------------- ### Add Auto-Pipeline Dependency (Maven, Gradle) Source: https://github.com/foldright/auto-pipeline/blob/main/docs/docs/tutorial-basics/01-quick-start.md Add the Auto-Pipeline dependency to your project's build configuration. This ensures the annotation processor is available during compilation. The scope should be 'provided' as it's only needed at compile time. ```xml com.foldright.auto-pipeline auto-pipeline-processor 0.3.0 provided ``` ```kotlin // the auto-pipeline annotation will be used in your interface type compileOnly("com.foldright.auto-pipeline:auto-pipeline-annotations:0.3.0") // the auto-pipeline annotation processor will generate the pipeline classes for the interface. // use "annotationProcessor" scope because it's only needed at annotation processing time. annotationProcessor("com.foldright.auto-pipeline:auto-pipeline-processor:0.3.0") ``` ```groovy compileOnly 'com.foldright.auto-pipeline:auto-pipeline-annotations:0.3.0' annotationProcessor 'com.foldright.auto-pipeline:auto-pipeline-processor:0.3.0' ``` -------------------------------- ### Load Balancer Pipeline for Node Selection Source: https://context7.com/foldright/auto-pipeline/llms.txt Implements a load balancing pipeline in Java that filters and selects nodes. It uses the `@AutoPipeline` annotation for generating pipeline interfaces. The example includes handlers for filtering available nodes and selecting a random node from the available subset. ```java import com.foldright.auto.pipeline.AutoPipeline; import java.util.List; import java.util.stream.Collectors; @AutoPipeline public interface LoadBalancer { T choose(List nodes); } public interface Node { boolean isAvailable(); } // Filter available nodes public class AvailableLoadBalancerHandler implements LoadBalancerHandler { @Override public T choose(List nodes, LoadBalancerHandlerContext context) { List available = nodes.stream() .filter(Node::isAvailable) .collect(Collectors.toList()); if (available.isEmpty()) { return null; } return context.choose(available); } } // Select random node from available public class RandomLoadBalancerHandler implements LoadBalancerHandler { @Override public T choose(List nodes, LoadBalancerHandlerContext context) { if (nodes.isEmpty()) { return null; } return nodes.get((int) (Math.random() * nodes.size())); } } // Build load balancer pipeline LoadBalancer lb = new LoadBalancerPipeline() .addLast(new AvailableLoadBalancerHandler()) .addLast(new RandomLoadBalancerHandler()); // Use with custom node type class Server implements Node { private final String host; private boolean available; public Server(String host, boolean available) { this.host = host; this.available = available; } public boolean isAvailable() { return available; } public String getHost() { return host; } } List servers = Arrays.asList( new Server("server1", true), new Server("server2", false), new Server("server3", true) ); Server selected = lb.choose(servers); // Returns server1 or server3 ``` -------------------------------- ### Build and Use Basic Pipeline with Handlers (Java) Source: https://context7.com/foldright/auto-pipeline/llms.txt Demonstrates how to create and use a simple configuration pipeline. It defines two handlers, `MapConfigSourceHandler` and `SystemConfigSourceHandler`, and then constructs a `ConfigSourcePipeline` by adding these handlers sequentially. The pipeline is used to retrieve configuration values. ```java import com.foldright.examples.config.ConfigSource; import com.foldright.examples.config.pipeline.*; import com.foldright.examples.config.handler.*; import java.util.HashMap; import java.util.Map; // Define handlers public class MapConfigSourceHandler implements ConfigSourceHandler { private final Map map; public MapConfigSourceHandler(Map map) { this.map = map; } @Override public String get(String key, ConfigSourceHandlerContext context) { String value = map.get(key); if (value != null && !value.isEmpty()) { return value; } // Delegate to next handler in chain return context.get(key); } } public class SystemConfigSourceHandler implements ConfigSourceHandler { public static final SystemConfigSourceHandler INSTANCE = new SystemConfigSourceHandler(); @Override public String get(String key, ConfigSourceHandlerContext context) { String value = System.getProperty(key); if (value != null && !value.isEmpty()) { return value; } return context.get(key); } } // Build and use pipeline Map config = new HashMap<>(); config.put("app.name", "MyApp"); config.put("app.version", "1.0.0"); ConfigSource pipeline = new ConfigSourcePipeline() .addLast(new MapConfigSourceHandler(config)) .addLast(SystemConfigSourceHandler.INSTANCE); // Query configuration - checks map first, then system properties String appName = pipeline.get("app.name"); // Returns "MyApp" String javaHome = pipeline.get("java.home"); // Returns system property String notFound = pipeline.get("nonexistent.key"); // Returns null ``` -------------------------------- ### Implementing Handlers for ConfigSource Pipeline Source: https://github.com/foldright/auto-pipeline/blob/main/README.md These Java snippets show how to implement custom handlers for the `ConfigSource` pipeline. Each handler adds specific logic, such as retrieving values from a map or system properties, before potentially delegating to the next handler in the chain. ```java public class MapConfigSourceHandler implements ConfigSourceHandler { private final Map map; public MapConfigSourceHandler(Map map) { this.map = map; } @Override public String get(String key, ConfigSourceHandlerContext context) { String value = map.get(key); if (StringUtils.isNotBlank(value)) { return value; } return context.get(key); } } public class SystemConfigSourceHandler implements ConfigSourceHandler { public static final SystemConfigSourceHandler INSTANCE = new SystemConfigSourceHandler(); @Override public String get(String key, ConfigSourceHandlerContext context) { String value = System.getProperty(key); if (StringUtils.isNotBlank(value)) { return value; } return context.get(key); } } ``` -------------------------------- ### Add auto-pipeline Gradle Dependency (Kotlin DSL) Source: https://github.com/foldright/auto-pipeline/blob/main/README.md This snippet demonstrates how to add auto-pipeline dependencies for a Gradle project using the Kotlin DSL. It includes the annotation for interface use and the annotation processor for code generation, both with appropriate scopes. ```groovy /* * Gradle Kotlin DSL */ // the auto-pipeline annotation will be used in your interface type compileOnly("com.foldright.auto-pipeline:auto-pipeline-annotations:0.3.0") // the auto-pipeline annotation processor will generate the pipeline classes for the interface. // use "annotationProcessor" scope because it's only needed at annotation processing time. annotationProcessor("com.foldright.auto-pipeline:auto-pipeline-processor:0.3.0") ``` -------------------------------- ### Add auto-pipeline Gradle Dependency (Groovy DSL) Source: https://github.com/foldright/auto-pipeline/blob/main/README.md This snippet shows how to add auto-pipeline dependencies for a Gradle project using the Groovy DSL. It specifies the annotation for interface usage and the annotation processor for code generation, utilizing the correct compilation scopes. ```groovy /* * Gradle Groovy DSL */ compileOnly 'com.foldright.auto-pipeline:auto-pipeline-annotations:0.3.0' annotationProcessor 'com.foldright.auto-pipeline:auto-pipeline-processor:0.3.0' ``` -------------------------------- ### Annotating Interface for Auto-Pipeline Source: https://github.com/foldright/auto-pipeline/blob/main/README.md This snippet demonstrates how to annotate a Java interface with `@AutoPipeline` to enable the auto-pipeline processor to generate a pipeline implementation. The processor will create related pipeline classes in a subpackage. ```java public interface ConfigSource { String get(String key); } @AutoPipeline public interface ConfigSource { String get(String key); } ``` -------------------------------- ### Interactive Button with React in MDX - JavaScript Source: https://github.com/foldright/auto-pipeline/blob/main/docs/blog/2021-08-01-mdx-blog-post.mdx This snippet showcases how to embed interactive React components directly within MDX blog posts. It uses a simple JavaScript event handler to display an alert when a button is clicked. No external dependencies are required beyond React itself, which is standard for Docusaurus. ```js ``` -------------------------------- ### Add auto-pipeline Maven Dependency Source: https://github.com/foldright/auto-pipeline/blob/main/README.md This snippet shows how to add the auto-pipeline annotation processor as a compile-time dependency in a Maven project. It should be configured with the 'provided' scope as it's only required during compilation. ```xml com.foldright.auto-pipeline auto-pipeline-processor 0.3.0 provided ``` -------------------------------- ### Generated Auto-Pipeline Classes for Interface Extension Source: https://context7.com/foldright/auto-pipeline/llms.txt Illustrates the Java code automatically generated by the auto-pipeline annotation processor. It includes handler interfaces, context interfaces, and pipeline classes to implement the Chain of Responsibility pattern. ```java // Given this interface: @AutoPipeline public interface ConfigSource { String get(String key); } // The processor generates: // Handler interface - implement this for extensibility public interface ConfigSourceHandler { String get(String key, ConfigSourceHandlerContext context); } // Context interface - passed to handlers for chain control public interface ConfigSourceHandlerContext { String get(String key); } // Pipeline class - main entry point for building chains public class ConfigSourcePipeline implements ConfigSource { public ConfigSourcePipeline addFirst(ConfigSourceHandler handler) { /* ... */ } public ConfigSourcePipeline addLast(ConfigSourceHandler handler) { /* ... */ } public ConfigSourcePipeline remove(ConfigSourceHandler handler) { /* ... */ } @Override public String get(String key) { // Executes handler chain } } // Abstract context implementation public abstract class AbstractConfigSourceHandlerContext implements ConfigSourceHandlerContext { // Base implementation with chain navigation logic } // Default context implementation public class DefaultConfigSourceHandlerContext extends AbstractConfigSourceHandlerContext { // Concrete implementation used internally } ``` -------------------------------- ### Gradle Dependency Configuration for Auto-Pipeline Source: https://context7.com/foldright/auto-pipeline/llms.txt Configure auto-pipeline dependencies in a Gradle project using both Kotlin DSL and Groovy DSL. Dependencies are set to 'compileOnly' and 'annotationProcessor' configurations. ```groovy // Kotlin DSL dependencies { compileOnly("com.foldright.auto-pipeline:auto-pipeline-annotations:0.3.0") annotationProcessor("com.foldright.auto-pipeline:auto-pipeline-processor:0.3.0") } ``` ```groovy // Groovy DSL dependencies { compileOnly 'com.foldright.auto-pipeline:auto-pipeline-annotations:0.3.0' annotationProcessor 'com.foldright.auto-pipeline:auto-pipeline-processor:0.3.0' } ``` -------------------------------- ### Annotate Interface for Auto Pipeline Generation (Java) Source: https://context7.com/foldright/auto-pipeline/llms.txt Marks a Java interface to indicate that the auto-pipeline annotation processor should generate pipeline components for it. This is the primary annotation used to initiate the pipeline generation process. ```java package com.example; import com.foldright.auto.pipeline.AutoPipeline; @AutoPipeline public interface ConfigSource { String get(String key); } ``` -------------------------------- ### Bidirectional Pipeline for RPC Request/Response Handling Source: https://context7.com/foldright/auto-pipeline/llms.txt Implements a bidirectional pipeline for RPC services using Java. Handlers can process requests in the forward direction and responses in the backward direction. It utilizes `RPCHandler` and `RPCPipeline` for defining and executing the pipeline, allowing information to be added to both requests and responses. ```java import com.foldright.examples.duplexing.pipeline.*; import com.foldright.examples.duplexing.RPC.*; // Handler that adds information to both request and response public class AddInfoHandler implements RPCHandler { private final String info; public AddInfoHandler(String info) { this.info = info; } @Override public Response request(Request request, RPCHandlerContext context) { request.append(info); // Add info on forward pass return context.request(request); } @Override public void onResponse(Response response, RPCHandlerContext context) { response.append(info); // Add info on reverse pass context.onResponse(response); } } // Terminal handler that creates response public class InvokerHandler implements RPCHandler { @Override public Response request(Request request, RPCHandlerContext context) { Response response = new Response(); onResponse(response, context); return response; } @Override public void onResponse(Response response, RPCHandlerContext context) { context.onResponse(response); } } // Build bidirectional pipeline RPC pipeline = new RPCPipeline() .addLast(new AddInfoHandler("Handler1")) .addLast(new AddInfoHandler("Handler2")) .addLast(new AddInfoHandler("Handler3")) .addLast(new InvokerHandler()); // Execute - request flows forward, response flows backward Request request = new Request(); Response response = pipeline.request(request); // request.infos() == ["Handler1", "Handler2", "Handler3"] // response.infos() == ["Handler3", "Handler2", "Handler1"] ``` -------------------------------- ### Control Pipeline Execution Direction with @PipelineDirection (Java) Source: https://context7.com/foldright/auto-pipeline/llms.txt Illustrates how to use the `@PipelineDirection` annotation to specify the execution flow for methods within an auto-generated pipeline. It shows how to define methods that process data in a forward (head-to-tail) or reverse (tail-to-head) direction. ```java import com.foldright.auto.pipeline.AutoPipeline; import com.foldright.auto.pipeline.PipelineDirection; import static com.foldright.auto.pipeline.PipelineDirection.Direction.REVERSE; @AutoPipeline public interface RPC { // Forward direction: head to tail Response request(Request request); // Reverse direction: tail to head @PipelineDirection(REVERSE) void onResponse(Response response); class Request { private final List infos = new ArrayList<>(); public void append(String info) { infos.add(info); } public List infos() { return Collections.unmodifiableList(infos); } } class Response { private final List infos = new ArrayList<>(); public void append(String info) { infos.add(info); } public List infos() { return Collections.unmodifiableList(infos); } } } ``` -------------------------------- ### Maven Dependency Configuration for Auto-Pipeline Source: https://context7.com/foldright/auto-pipeline/llms.txt Configure auto-pipeline dependencies in a Maven project. Includes 'auto-pipeline-annotations' and 'auto-pipeline-processor' with 'provided' scope, meaning they are needed for compilation but not included in the final artifact. ```xml com.foldright.auto-pipeline auto-pipeline-annotations 0.3.0 provided com.foldright.auto-pipeline auto-pipeline-processor 0.3.0 provided ``` -------------------------------- ### Generic Type Support in Auto Pipeline Source: https://context7.com/foldright/auto-pipeline/llms.txt Enables type-safe operations across different data types within the pipeline using Java generics. The `@AutoPipeline` annotation generates handler interfaces that preserve generic types, facilitating type-safe client calls. This is demonstrated with `Channel` and `ClientCall`. ```java import com.foldright.auto.pipeline.AutoPipeline; @AutoPipeline public interface Channel { ClientCall newCall( MethodDescriptor methodDescriptor, CallOptions callOptions ); } // Generated handler interface preserves generics public class DefaultChannelHandler implements ChannelHandler { @Override public ClientCall newCall( MethodDescriptor methodDescriptor, CallOptions callOptions, ChannelHandlerContext context ) { // Custom implementation return new DefaultClientCall<>(methodDescriptor, callOptions); } } // Use with type safety Channel pipeline = new ChannelPipeline() .addLast(new DefaultChannelHandler()) .addLast(new TransformClientCallHandler()); ClientCall call = pipeline.newCall( MethodDescriptor.create("myMethod", MyRequest.class, MyResponse.class), CallOptions.DEFAULT ); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.