Skip to content
This repository was archived by the owner on Jul 18, 2024. It is now read-only.

Commit 45d1a65

Browse files
committed
Implement j.u.c.Flow/AsyncIterator adapters
Adds a bridge from AsyncIterator to j.u.c.Flow introduced in Java 9. To keep compatibility with Java8, async-util now provides two dependencies, asyncutil and asyncflow which includes the adapters (and requires jdk9). To enable this, both packages are compiled with jdk9, but asyncutil has jdk8 compliance.
1 parent addda99 commit 45d1a65

File tree

82 files changed

+1868
-24
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+1868
-24
lines changed

.travis.yml

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
language: java
2-
3-
jdk:
4-
- oraclejdk8
2+
sudo: false
3+
dist: trusty
4+
jdk: oraclejdk9
5+
addons:
6+
apt:
7+
packages:
8+
- oracle-java9-installer

asyncutil-flow/.settings/org.eclipse.jdt.core.prefs

+371
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
cleanup.add_default_serial_version_id=false
2+
cleanup.add_generated_serial_version_id=false
3+
cleanup.add_missing_annotations=true
4+
cleanup.add_missing_deprecated_annotations=true
5+
cleanup.add_missing_methods=false
6+
cleanup.add_missing_nls_tags=false
7+
cleanup.add_missing_override_annotations=true
8+
cleanup.add_missing_override_annotations_interface_methods=true
9+
cleanup.add_serial_version_id=false
10+
cleanup.always_use_blocks=true
11+
cleanup.always_use_parentheses_in_expressions=false
12+
cleanup.always_use_this_for_non_static_field_access=true
13+
cleanup.always_use_this_for_non_static_method_access=false
14+
cleanup.convert_to_enhanced_for_loop=true
15+
cleanup.correct_indentation=false
16+
cleanup.format_source_code=true
17+
cleanup.format_source_code_changes_only=false
18+
cleanup.make_local_variable_final=true
19+
cleanup.make_parameters_final=true
20+
cleanup.make_private_fields_final=true
21+
cleanup.make_type_abstract_if_missing_method=false
22+
cleanup.make_variable_declarations_final=true
23+
cleanup.never_use_blocks=false
24+
cleanup.never_use_parentheses_in_expressions=true
25+
cleanup.organize_imports=true
26+
cleanup.qualify_static_field_accesses_with_declaring_class=false
27+
cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
28+
cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
29+
cleanup.qualify_static_member_accesses_with_declaring_class=true
30+
cleanup.qualify_static_method_accesses_with_declaring_class=false
31+
cleanup.remove_private_constructors=true
32+
cleanup.remove_trailing_whitespaces=true
33+
cleanup.remove_trailing_whitespaces_all=true
34+
cleanup.remove_trailing_whitespaces_ignore_empty=false
35+
cleanup.remove_unnecessary_casts=true
36+
cleanup.remove_unnecessary_nls_tags=true
37+
cleanup.remove_unused_imports=true
38+
cleanup.remove_unused_local_variables=false
39+
cleanup.remove_unused_private_fields=true
40+
cleanup.remove_unused_private_members=false
41+
cleanup.remove_unused_private_methods=true
42+
cleanup.remove_unused_private_types=true
43+
cleanup.sort_members=false
44+
cleanup.sort_members_all=false
45+
cleanup.use_blocks=true
46+
cleanup.use_blocks_only_for_return_and_throw=false
47+
cleanup.use_parentheses_in_expressions=false
48+
cleanup.use_this_for_non_static_field_access=true
49+
cleanup.use_this_for_non_static_field_access_only_if_necessary=false
50+
cleanup.use_this_for_non_static_method_access=true
51+
cleanup.use_this_for_non_static_method_access_only_if_necessary=true
52+
cleanup_profile=_Cleversafe
53+
cleanup_settings_version=2
54+
eclipse.preferences.version=1
55+
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
56+
formatter_profile=_Cleversafe
57+
formatter_settings_version=12
58+
instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true
59+
org.eclipse.jdt.ui.ignorelowercasenames=true
60+
org.eclipse.jdt.ui.importorder=java;javax;org;com;
61+
org.eclipse.jdt.ui.javadoc=false
62+
org.eclipse.jdt.ui.ondemandthreshold=99
63+
org.eclipse.jdt.ui.staticondemandthreshold=99
64+
org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\n * @return the ${bare_field_name}\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\n * @param ${param} the ${bare_field_name} to set\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\n * ${tags}\n */</template><template autoinsert\="true" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/**\n * \n */</template><template autoinsert\="false" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\n * ${tags}\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\n * \n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\n * ${tags}\n */</template><template autoinsert\="true" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/* (non-Javadoc)\n * ${see_to_overridden}\n */</template><template autoinsert\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\n * ${tags}\n * ${see_to_target}\n */</template><template autoinsert\="false" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">/* \n* Copyright (c) IBM Corporation 2017. All Rights Reserved.\n* Project name\: java-async-util\n* This project is licensed under the Apache License 2.0, see LICENSE.\n*/\n\n${package_declaration}\n\n${type_declaration}\n\n</template><template autoinsert\="false" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\n</template><template autoinsert\="true" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\n${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates>
65+
sp_cleanup.add_default_serial_version_id=true
66+
sp_cleanup.add_generated_serial_version_id=false
67+
sp_cleanup.add_missing_annotations=true
68+
sp_cleanup.add_missing_deprecated_annotations=true
69+
sp_cleanup.add_missing_methods=false
70+
sp_cleanup.add_missing_nls_tags=false
71+
sp_cleanup.add_missing_override_annotations=true
72+
sp_cleanup.add_serial_version_id=false
73+
sp_cleanup.always_use_blocks=true
74+
sp_cleanup.always_use_parentheses_in_expressions=false
75+
sp_cleanup.always_use_this_for_non_static_field_access=true
76+
sp_cleanup.always_use_this_for_non_static_method_access=false
77+
sp_cleanup.convert_to_enhanced_for_loop=false
78+
sp_cleanup.correct_indentation=false
79+
sp_cleanup.format_source_code=true
80+
sp_cleanup.format_source_code_changes_only=false
81+
sp_cleanup.make_local_variable_final=true
82+
sp_cleanup.make_parameters_final=true
83+
sp_cleanup.make_private_fields_final=true
84+
sp_cleanup.make_type_abstract_if_missing_method=false
85+
sp_cleanup.make_variable_declarations_final=true
86+
sp_cleanup.never_use_blocks=false
87+
sp_cleanup.never_use_parentheses_in_expressions=true
88+
sp_cleanup.on_save_use_additional_actions=true
89+
sp_cleanup.organize_imports=true
90+
sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
91+
sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
92+
sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
93+
sp_cleanup.qualify_static_member_accesses_with_declaring_class=true
94+
sp_cleanup.qualify_static_method_accesses_with_declaring_class=true
95+
sp_cleanup.remove_private_constructors=true
96+
sp_cleanup.remove_trailing_whitespaces=false
97+
sp_cleanup.remove_trailing_whitespaces_all=true
98+
sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
99+
sp_cleanup.remove_unnecessary_casts=true
100+
sp_cleanup.remove_unnecessary_nls_tags=false
101+
sp_cleanup.remove_unused_imports=true
102+
sp_cleanup.remove_unused_local_variables=false
103+
sp_cleanup.remove_unused_private_fields=true
104+
sp_cleanup.remove_unused_private_members=false
105+
sp_cleanup.remove_unused_private_methods=true
106+
sp_cleanup.remove_unused_private_types=true
107+
sp_cleanup.sort_members=false
108+
sp_cleanup.sort_members_all=false
109+
sp_cleanup.use_blocks=false
110+
sp_cleanup.use_blocks_only_for_return_and_throw=false
111+
sp_cleanup.use_parentheses_in_expressions=false
112+
sp_cleanup.use_this_for_non_static_field_access=true
113+
sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=false
114+
sp_cleanup.use_this_for_non_static_method_access=true
115+
sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true

asyncutil-flow/README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# asyncutil-flow
2+
3+
## Introduction
4+
5+
This optional module allows Java 9 users to translate the iteration primitive provided by asyncutil to and from [java.util.Flow constructs](https://docs.oracle.com/javase/9/docs/api/java/util/concurrent/Flow.html). An asyncutil [AsyncIterator](https://pages.github.ibm.com/cs-team-atg/async-util/apidocs/com/ibm/asyncutil/iteration/AsyncIterator.html) can be used as the source for a `Flow.Publisher`, and a `Flow.Publisher` can be consumed via an `AsyncIterator`.
6+
7+
## Downloading
8+
TODO maven instructions
9+
10+
## Comparison to other Flow providers
11+
There are now several options for implementations of Flow. Here are some things to consider when comparing `AsyncIterator` to other implementations, especially RxJava.
12+
13+
### CompletionStage oriented
14+
asyncutil is strictly a Java 8+ library, and is designed with `CompletionStage` in mind. AsyncIterators are naturally constructed from stage producing APIs and always reduce back into stages when actually evaluated. Moreover, these terminal reduction steps take on the familiar form of `Stream` terminal methods. RxJava doesn't target CompletionStages, and is a better choice when supporting older Java releases.
15+
16+
### Iteration vs Reactivity
17+
AsyncIterators excel at being local scope notions for structuring an iterative async computation and getting a `CompletionStage` of the result using a terminal method. It is well suited for concisely expressing an iterative asynchronous computation. Using it to model signals in a reactive style gets messy because you must carefully manage partially evaluating the iterator, which is a more natural fit for RxJava.
18+
19+
### Hot/Cold vs Lazy
20+
In the Rx world there are two choices for an `Observable`. Hot observables usually model sources that already "exist" and are always producing. Subscribers join into the existing stream. Cold observables constructa new stream of production when a subscriber is added.
21+
22+
Instead, an `AsyncIterator` is lazy, which is a constrained form of cold. It can only be consumed once, and production only starts upon consumption. This makes it very natural to model stateful streams, and you can build back to the cold observables model with `Supplier<AsyncIterator>`. Consumption directly includes a notion of completion (consumption is accomplished via terminal methods that return `CompletionStage`), compared to subscription in Rx. AsyncIterators are generally poorly suited for the Hot observable model.
23+
24+
### Constrained scope
25+
AsyncIterators exclusively solve the problem of consumer driven sequential iteration, whereas RxJava provides a wealth of features like Schedulers, Plugins, flexible backpressure, etc. If `AsyncIterator` can sufficiently covers your needs, you may find it easier to work with.

asyncutil-flow/pom.xml

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>com.ibm</groupId>
6+
<artifactId>asyncutil-flow</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>asyncutil-flow</name>
11+
<url>http://maven.apache.org</url>
12+
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
<maven.compiler.source>1.9</maven.compiler.source>
16+
<maven.compiler.target>1.9</maven.compiler.target>
17+
</properties>
18+
19+
<build>
20+
<plugins>
21+
<plugin>
22+
<artifactId>maven-surefire-plugin</artifactId>
23+
<configuration>
24+
<threadCount>1</threadCount>
25+
</configuration>
26+
<version>2.20.1</version>
27+
<dependencies>
28+
<dependency>
29+
<groupId>org.apache.maven.surefire</groupId>
30+
<artifactId>surefire-junit47</artifactId>
31+
<version>2.20.1</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.apache.maven.surefire</groupId>
35+
<artifactId>surefire-testng</artifactId>
36+
<version>2.20.1</version>
37+
</dependency>
38+
</dependencies>
39+
</plugin>
40+
</plugins>
41+
</build>
42+
43+
<reporting>
44+
<plugins>
45+
<plugin>
46+
<groupId>org.apache.maven.plugins</groupId>
47+
<artifactId>maven-javadoc-plugin</artifactId>
48+
<version>2.10.4</version>
49+
</plugin>
50+
</plugins>
51+
</reporting>
52+
53+
<dependencies>
54+
<dependency>
55+
<groupId>com.ibm</groupId>
56+
<artifactId>asyncutil</artifactId>
57+
<version>0.0.1-SNAPSHOT</version>
58+
</dependency>
59+
<dependency>
60+
<groupId>junit</groupId>
61+
<artifactId>junit</artifactId>
62+
<version>4.11</version>
63+
<scope>test</scope>
64+
</dependency>
65+
<dependency>
66+
<groupId>org.testng</groupId>
67+
<artifactId>testng</artifactId>
68+
<version>6.8</version>
69+
<scope>test</scope>
70+
</dependency>
71+
<dependency>
72+
<groupId>org.reactivestreams</groupId>
73+
<artifactId>reactive-streams-tck-flow</artifactId>
74+
<version>1.0.2</version>
75+
<scope>test</scope>
76+
</dependency>
77+
</dependencies>
78+
</project>

0 commit comments

Comments
 (0)