-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Event bus streaming mockup 2 #4712
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
Draft
vietj
wants to merge
1
commit into
master
Choose a base branch
from
event-bus-streaming-mockup-2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
87 changes: 0 additions & 87 deletions
87
src/main/generated/io/vertx/core/net/ConnectOptionsConverter.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /* | ||
| * Copyright (c) 2011-2021 Contributors to the Eclipse Foundation | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the Eclipse Public License 2.0 which is available at | ||
| * http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
| * which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
| */ | ||
| package io.vertx.core.eventbus; | ||
|
|
||
| import io.vertx.codegen.annotations.VertxGen; | ||
| import io.vertx.core.Handler; | ||
|
|
||
| @VertxGen | ||
| public interface MessageStream { | ||
|
|
||
| void handler(Handler<Message<String>> handler); | ||
|
|
||
| void endHandler(Handler<Void> handler); | ||
|
|
||
| void write(String msg); | ||
|
|
||
| void end(); | ||
|
|
||
| } | ||
50 changes: 50 additions & 0 deletions
50
src/main/java/io/vertx/core/eventbus/impl/ClientStream.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package io.vertx.core.eventbus.impl; | ||
|
|
||
| import io.vertx.core.Handler; | ||
| import io.vertx.core.Promise; | ||
| import io.vertx.core.eventbus.Message; | ||
| import io.vertx.core.eventbus.MessageStream; | ||
| import io.vertx.core.impl.ContextInternal; | ||
|
|
||
| import java.util.concurrent.TimeoutException; | ||
|
|
||
| class ClientStream extends StreamBase implements Handler<Long> { | ||
|
|
||
| private final Promise<MessageStream> promise2; | ||
| private final long timeoutID; | ||
|
|
||
| public ClientStream(EventBusImpl eventBus, String sourceAddress, ContextInternal ctx, Promise<MessageStream> promise2) { | ||
| super(sourceAddress, ctx, eventBus, sourceAddress, true); | ||
| this.promise2 = promise2; | ||
| this.timeoutID = ctx.setTimer(3_000, this); | ||
| } | ||
|
|
||
| @Override | ||
| public void handle(Long event) { | ||
| unregister(); | ||
| promise2.fail(new TimeoutException()); | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean doReceive(Message msg) { | ||
| if (msg.body() instanceof SynFrame) { | ||
| if (context.owner().cancelTimer(timeoutID)) { | ||
| base = (MessageImpl) msg; | ||
| SynFrame syn = (SynFrame) msg.body(); | ||
| remoteAddress = syn.src; | ||
| promise2.complete(this); | ||
| } | ||
| return true; | ||
| } else { | ||
| if (base != null) { | ||
| return super.doReceive(msg); | ||
| } else { | ||
| if (context.owner().cancelTimer(timeoutID)) { | ||
| unregister(); | ||
| promise2.fail(new IllegalStateException()); | ||
| } | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package io.vertx.core.eventbus.impl; | ||
|
|
||
| import io.netty.util.CharsetUtil; | ||
| import io.vertx.core.buffer.Buffer; | ||
| import io.vertx.core.eventbus.MessageCodec; | ||
|
|
||
| class FinFrame implements Frame { | ||
|
|
||
| public static final MessageCodec<FinFrame, FinFrame> CODEC = new MessageCodec<>() { | ||
| @Override | ||
| public void encodeToWire(Buffer buffer, FinFrame synFrame) { | ||
| byte[] strBytes = synFrame.addr.getBytes(CharsetUtil.UTF_8); | ||
| buffer.appendInt(strBytes.length); | ||
| buffer.appendBytes(strBytes); | ||
| } | ||
|
|
||
| @Override | ||
| public FinFrame decodeFromWire(int pos, Buffer buffer) { | ||
| int length = buffer.getInt(pos); | ||
| pos += 4; | ||
| byte[] bytes = buffer.getBytes(pos, pos + length); | ||
| String src = new String(bytes, CharsetUtil.UTF_8); | ||
| return new FinFrame(src); | ||
| } | ||
|
|
||
| @Override | ||
| public FinFrame transform(FinFrame finFrame) { | ||
| return finFrame; | ||
| } | ||
|
|
||
| @Override | ||
| public String name() { | ||
| return "frame.fin"; | ||
| } | ||
|
|
||
| @Override | ||
| public byte systemCodecID() { | ||
| return 19; | ||
| } | ||
| }; | ||
|
|
||
| final String addr; | ||
|
|
||
| public FinFrame(String addr) { | ||
| this.addr = addr; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| package io.vertx.core.eventbus.impl; | ||
|
|
||
| public interface Frame { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| package io.vertx.core.eventbus.impl; | ||
|
|
||
| import io.vertx.core.Handler; | ||
| import io.vertx.core.MultiMap; | ||
| import io.vertx.core.eventbus.DeliveryOptions; | ||
| import io.vertx.core.eventbus.Message; | ||
| import io.vertx.core.eventbus.MessageStream; | ||
| import io.vertx.core.impl.ContextInternal; | ||
|
|
||
| class StreamBase extends HandlerRegistration implements MessageStream { | ||
|
|
||
| MessageImpl base; | ||
| private Handler<Message<String>> handler; | ||
| private Handler<Void> endHandler; | ||
| final String localAddress; | ||
| String remoteAddress; | ||
| private boolean halfClosed; | ||
|
|
||
| StreamBase(String localAddress, ContextInternal context, EventBusImpl bus, String address, boolean src) { | ||
| super(context, bus, address, src); | ||
| this.localAddress = localAddress; | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean doReceive(Message msg) { | ||
| if (msg.body() instanceof FinFrame) { | ||
| Handler<Void> h = endHandler; | ||
| if (h != null) { | ||
| h.handle(null); | ||
| } | ||
| if (halfClosed) { | ||
| unregister(); | ||
| } else { | ||
| halfClosed = true; | ||
| } | ||
| return true; | ||
| } else { | ||
| Handler<Message<String>> h = handler; | ||
| if (h != null) { | ||
| h.handle(msg); | ||
| } | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| protected void dispatch(Message msg, ContextInternal context, Handler handler) { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void handler(Handler<Message<String>> handler) { | ||
| this.handler = handler; | ||
| } | ||
|
|
||
| @Override | ||
| public void endHandler(Handler<Void> handler) { | ||
| this.endHandler = handler; | ||
| } | ||
|
|
||
| @Override | ||
| public void write(String body) { | ||
| MessageImpl msg = base.createReply(body, new DeliveryOptions()); | ||
| bus.sendOrPub(context, msg, new DeliveryOptions(), context.promise()); | ||
| } | ||
|
|
||
| @Override | ||
| public void end() { | ||
| MessageImpl msg = base.createReply(new FinFrame(remoteAddress), new DeliveryOptions()); | ||
| bus.sendOrPub(context, msg, new DeliveryOptions(), context.promise()); | ||
| if (halfClosed) { | ||
| unregister(); | ||
| } else { | ||
| halfClosed = true; | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.