-
Notifications
You must be signed in to change notification settings - Fork 534
Provide a transparent Flow bridge #394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Can you do it with Gradle? Also there is an asymmetry problem here: if RS implements |
public class FlowVsRS {
interface FlowPublisher {
}
interface RSPublisher extends FlowPublisher {
}
public static void flowAPI(FlowPublisher src) {
}
public static void rsAPI(RSPublisher src) {
}
public static void main(String[] args) {
flowAPI(new FlowPublisher() { });
flowAPI(new RSPublisher() { });
rsAPI(new RSPublisher() { });
rsAPI(new FlowPublisher() { }); // <-------- compilation error, incompatible types
}
} |
No problems in doing it with Gradle if it is needed. Yes, the trick helps when say I need to provide a API that returns e.g. a Publisher, not when the API consumes a Publisher as you've shown. public class FlowVsRS2 {
interface FlowPublisher {
}
interface RSPublisher extends FlowPublisher {
}
public static RSPublisher uniqueAPI() {
return new RSPublisher() {};
}
public static void main(String[] args) {
RSPublisher rs = uniqueApi();
FlowPublisher flow = uniqueApi();
// flow accepts a FlowSubscriber
}
} Having a Also, creating a So, it does not cover all cases, but it seems useful in many cases. |
Yes, the second difficulty is having two Therefore, I'm not convinced combining Flow and RS interfaces is worth it. I find the current route of using the bridge or natively implementing Flow API instead of RS more approachable. If we had a structural type system, such as TypeScript, we wouldn't even need a bridge. However, it's up to the project leads to decide. |
I'd think having explicit conversions is much better if the "implicit" coercions aren't bijective. |
@viktorklang -> I don't think bijection would be a problem here, if
Use case 1: you have a JDK8 project:
Use case 2: you have a JDK9 project:
Notice that in this scenario there is no class that implements e.g. The only issue is that no build system currently supports multi-release JAR-s (in other words: you have to assemble it manually). I'm working on a Gradle plugin for Jigsaw, and I'm thinking about adding such a support, but the work hasn't started yet. |
That's not how multi release jars work or are intended to be used. It would not, and will not work, because mr-jars are strictly a runtime thing, and can not allow something to compile or not compile. Compilation always happens against the "main" class; thus it is not possible to make code that "oh yeah, compiles and works only on jdk9", e.g. such assignment: It's not about "no build tool supports it", it is "this is not the intended use case and will not work", not in javac, not in any other build system. Please read my write-up about what mr-jars can, and cannot, do http://kto.so/2017/09/30/the-practical-truth-about-multi-release-jars/ I'm also going to publish an reactive-streams specific post / guide very soon, so that'll explain the various ways that don't work in reality. |
@ktoso -> I've already found your blog post. Good explanation. |
I've gotten in touch with Alan from Oracle to discuss this deeper,; I'll report back as my findings may have been incorrect - due to testing on an exploded jar on classpath instead proper jar. I'll let you know and update the blog post. |
Yeah @ktoso, when compiling a Java 9 project, you can assign a IntelliJ is giving me errors, but the test is run correctly by surefire. |
There's now a converter lib in master, we're discussing naming over here: #401 |
I've done some tests using the Java 9 multi-release JAR feature and created this project. It produces a JAR with a copy of the 4 interfaces but, as you can see from the tests, those interfaces implement the
Flow.xxx
equivalent when using the jar with a Java 9 JVM, while they just implementorg.reactivestreams.xxx
when running on Java 8. A similar approach can be used also for Java 6 if needed.I'm planning to add such interfaces to Apache Camel, but I know there are many other libraries that want to do something similar, in order to be compatible with any version of Java.
Have you considered adding something similar directly in this repo, maybe in the flow-bridge project?
I can help with the implementation.
The text was updated successfully, but these errors were encountered: