auto-async

A Library to generate async interface

License

License

Categories

Categories

Net Auto Application Layer Libs Code Generators
GroupId

GroupId

net.vakilla
ArtifactId

ArtifactId

auto-async
Last Version

Last Version

1.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

auto-async
A Library to generate async interface
Project URL

Project URL

https://github.com/YanXs/auto-async
Source Code Management

Source Code Management

https://github.com/YanXs/auto-async

Download auto-async

How to add to project

<!-- https://jarcasting.com/artifacts/net.vakilla/auto-async/ -->
<dependency>
    <groupId>net.vakilla</groupId>
    <artifactId>auto-async</artifactId>
    <version>1.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/net.vakilla/auto-async/
implementation 'net.vakilla:auto-async:1.0.2'
// https://jarcasting.com/artifacts/net.vakilla/auto-async/
implementation ("net.vakilla:auto-async:1.0.2")
'net.vakilla:auto-async:jar:1.0.2'
<dependency org="net.vakilla" name="auto-async" rev="1.0.2">
  <artifact name="auto-async" type="jar" />
</dependency>
@Grapes(
@Grab(group='net.vakilla', module='auto-async', version='1.0.2')
)
libraryDependencies += "net.vakilla" % "auto-async" % "1.0.2"
[net.vakilla/auto-async "1.0.2"]

Dependencies

compile (2)

Group / Artifact Type Version
com.google.auto.service : auto-service jar 1.0-rc3
com.squareup : javapoet jar 1.7.0

Project Modules

There are no modules declared in this project.

auto-async

auto-async是一个基于java APT自动生成异步接口和Facade抽象实现类的库

Download

Maven

<dependency>
    <groupId>net.vakilla</groupId>
    <artifactId>auto-async</artifactId>
    <version>1.0.2</version>
</dependency>

or Gradle

compile 'net.vakilla:auto-async:1.0.2'

使用方法

  • Example 1: 生成异步接口
@AutoAsync
public interface SimpleService {

    String echo(String message);

    @Asyncable
    List<Complex> complex(Map<String, List<Date>> map);
}

自动生成接口

@AutoGenerated("net.vakilla.auto.async.processor.AutoAsyncProcessor")
public interface Unified_SimpleService extends SimpleService {
  ListenableFuture<List<Complex>> async_complex(Map<String, List<Date>> map);
}
  • Example 2: 生成异步接口和抽象实现类
@AutoAsync(generateFacade = true)
public interface SimpleService {

    String echo(String message);

    @Asyncable
    List<Complex> complex(Map<String, List<Date>> map);
}

自动生成接口

@AutoGenerated(
    generateFacade = true,
    value = "net.vakilla.auto.async.processor.AutoAsyncProcessor"
)
public interface Unified_SimpleService extends SimpleService {
  ListenableFuture<List<Complex>> async_complex(Map<String, List<Date>> map);
}

自动生成抽象实现类

@AutoGenerated("net.vakilla.auto.async.processor.AutoGeneratedProcessor")
public abstract class Facade_Unified_SimpleService implements Unified_SimpleService {
  public ListenableFuture<List<Complex>> async_complex(Map<String, List<Date>> map) {
    return null;
  }
}

依赖

<dependency>
    <groupId>com.google.auto.service</groupId>
    <artifactId>auto-service</artifactId>
    <version>1.0-rc3</version>
</dependency>

<dependency>
    <groupId>com.squareup</groupId>
    <artifactId>javapoet</artifactId>
    <version>1.7.0</version>
</dependency>

注意事项

  • 生成的异步接口基于guava的ListenableFuture
  • 生成代码使用javapoet库,没有检查方法返回类型,如果方法标记了@Asyncable就会扫描生成异步方法,即使原本的返回类型是Future。 所以,可以使用AutoAsync的strict模式(strict = true),这样会检查方法的返回类型是不是Future或者子类,如果是会报错
    strict模式会影响编译的效率,默认是不开启的,使用时注意不要在返回类型是Future的方法上添加@Asyncable注解

Versions

Version
1.0.2
1.0.1
1.0.0