Git Product home page Git Product logo

foldright / auto-pipeline Goto Github PK

View Code? Open in Web Editor NEW
136.0 6.0 29.0 1.08 MB

๐Ÿš€ auto-pipeline is a source code generator that auto generate the component's pipeline.

Home Page: https://foldright.io/auto-pipeline/

License: Apache License 2.0

Kotlin 65.03% Java 28.35% Shell 6.62%
auto-pipeline auto annotation-processor java codegen code-generator codegenerator chain-of-responsibility pipeline

auto-pipeline's Introduction

auto-pipeline ๐Ÿš€

Github Workflow Build Status Github Workflow Build Status Coverage Status Java support License Maven Central GitHub release GitHub Stars GitHub Forks GitHub issues GitHub Contributors GitHub repo size gitpod: Ready to Code

auto-pipeline is a source code generator that auto generate the component's pipeline. Help you to keep your project smaller, simpler, and more extensible. ๐Ÿ’ก

auto-pipeline is an annotation-processor for Pipeline generation, which is inspired by Google's Auto. โค๏ธ

for more information, please check out the auto-pipeline documents.

quick examples

below is a brief introduction. please check the examples project, and it's test cases for details.

quick start

auto-pipeline require java 8 or above.

0. add auto-pipeline dependencies

for maven project:

<dependencies>
    <!--
        the auto-pipeline annotation processor will generate
          the pipeline classes for the interface.
        annotation processor dependency should be "provided" scope,
          because it's only needed at compile time.
    -->
    <dependency>
        <groupId>com.foldright.auto-pipeline</groupId>
        <artifactId>auto-pipeline-processor</artifactId>
        <version>0.3.0</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

for gradle project:

/*
 * 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")

/*
 * 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'

auto-pipeline has published to maven central, click here to find the latest version.

1. using @AutoPipeline to auto generate pipeline for your interface

annotate @AutoPipeline to your interface, and auto-pipeline will generate some java files for the interface at compile time.

let's check the ConfigSource as an example:

given an interface named ConfigSource, the ConfigSource has the get() method, input a string as key and output a string as the value. like this:

public interface ConfigSource {
    String get(String key);
}

say, we want ConfigSource#get() has some extensibility, so we decide to apply the chain of responsibility pattern to it for extensibility.

Now it's auto-pipeline's turn to play a role, we simply add @AutoPipelin to ConfigSource๏ผš

@AutoPipeline
public interface ConfigSource {
    String get(String key);
}

auto-pipeline-processor will auto generate pipeline java files for ConfigSource into subpackage pipeline when compiled:

  • ConfigSourceHandler
    the responsibility interface we want to implement for extensibility
  • ConfigSourcePipeline
    the chain
  • ConfigSourceHandlerContext
  • AbstractConfigSourceHandlerContext
  • DefaultConfigSourceHandlerContext

2. implementing your handler for pipeline

we can implement MapConfigSourceHandler and SystemConfigSourceHandler (they are all in the ConfigSource handler example):

public class MapConfigSourceHandler implements ConfigSourceHandler {
    private final Map<String, String> map;

    public MapConfigSourceHandler(Map<String, String> 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);
    }
}

3. use the pipeline

create a ConfigSourcePipeline by composing ConfigSourceHandlers which can ben an entrance of the ConfigSource:

Map<String, String> mapConfig = new HashMap<String, String>();
mapConfig.put("hello", "world");
ConfigSourceHandler mapConfigSourceHandler = new MapConfigSourceHandler(mapConfig);

ConfigSource pipeline = new ConfigSourcePipeline()
        .addLast(mapConfigSourceHandler)
        .addLast(SystemConfigSourceHandler.INSTANCE);

now, we can use the pipeline.get(...) to invoke the chain! ๐ŸŽ‰

pipeline.get("hello");
// get value "world"
// from mapConfig / mapConfigSourceHandler

pipeline.get("java.specification.version")
// get value "1.8"
// from system properties / SystemConfigSourceHandler

check the runnable test case for details.

License

Apache License 2.0

auto-pipeline's People

Contributors

dependabot[bot] avatar oldratlee avatar zavakid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

auto-pipeline's Issues

support duplexing pipeline

Implement a two-way pipeline to solve request/response-like scenarios.

e.g.

interface RequestOperation {
    Future invoke(Request request, RpcContext ctx)
}

interface ResponseOperation {
    Future onResponse(Request request, Response response, RpcContext ctx)
}


interface RPCHandler extends RequestOperation, ResponseOperation {
}

after apply @AutoPipeline to RPCHandler (we need to add some metadata for auto-pipeline) :

  • invoke method will start from head to tail
  • while onResponse will start from tail to head
  • may be invoke and onResponse operation will in separate interfaces, and some handler can just implement one of the interfaces
  • auto-pipeline will auto detect whether the handler is duplexing or not, and will call or skip the handler adaptively

Retain annotations of my interface like @NotNull in generated classes.

Hi, when using autopipeline, I encountered a little difficulty about using annotation.

The annotations in my interface like @NotNull cannot be retained in the generated classes (including the implementations of my interface and the Handler interface), which makes it impossible for me to constrain the Handler implementations at the interface level.
code sample:

@AutoPipeline
public interface ConfigSource {
    @NotNull
    String get(@NotNull String key);
}

// I hope the implementations of ConfigSourceHandler can also be constrained by @NotNull.
public class ConfigSourceHandlerImpl implements ConfigSourceHandler {
    @Override
    public String get(String key, ConfigSourceHandlerContext configSourceHandlerContext) {
        return null;
    }
}

support IntelliJ auto-pipeline plugin

When using @Autopipeline, I found that classes such as HandlerContext/Pipeline are generated only after compiling the code, which is not smooth enough for the developer experience.For readers who open the project for the first time, he will find various compilation warnings, which will confuse which classes showing red warnings are where.

IntelliJ lombok plugin does just that. For example, after adding the @Setting annotation to the class, the developer can use the set method immediately

Looking forward to the birth of IntelliJ autopipeline plugin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.