-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using RxNetty for tcp transport (#101)
* Using RxNetty for tcp transport Current TCP transport implementation lacks a few critical features around insights and network flow control. Since RxNetty already has these features, it makes sense to use it. * Merge branch 'master' of https://github.com/ReactiveSocket/reactivesocket-java into rxnetty # Conflicts: # reactivesocket-examples/src/main/java/io/reactivesocket/examples/EchoClient.java # reactivesocket-transport-tcp/src/main/java/io/reactivesocket/transport/tcp/client/ClientTcpDuplexConnection.java # reactivesocket-transport-tcp/src/main/java/io/reactivesocket/transport/tcp/client/TcpReactiveSocketConnector.java * Review comments Also updated to rxnetty-0.5.2-rc.3
- Loading branch information
1 parent
59a4ebe
commit 023bb54
Showing
26 changed files
with
750 additions
and
909 deletions.
There are no files selected for viewing
This file contains 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 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
20 changes: 20 additions & 0 deletions
20
reactivesocket-examples/src/main/resources/log4j.properties
This file contains 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,20 @@ | ||
# | ||
# Copyright 2015 Netflix, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
log4j.rootLogger=INFO, stdout | ||
|
||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender | ||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout | ||
log4j.appender.stdout.layout.ConversionPattern=%c %d{dd MMM yyyy HH:mm:ss,SSS} %5p [%t] (%F:%L) - %m%n |
This file contains 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 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
38 changes: 0 additions & 38 deletions
38
...ivesocket-transport-tcp/src/examples/java/io/reactivesocket/transport/tcp/EchoServer.java
This file was deleted.
Oops, something went wrong.
68 changes: 0 additions & 68 deletions
68
...et-transport-tcp/src/examples/java/io/reactivesocket/transport/tcp/EchoServerHandler.java
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
...et-transport-tcp/src/examples/java/io/reactivesocket/transport/tcp/HttpServerHandler.java
This file was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
...ocket-transport-tcp/src/main/java/io/reactivesocket/transport/tcp/ObserverSubscriber.java
This file contains 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,46 @@ | ||
/* | ||
* Copyright 2016 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package io.reactivesocket.transport.tcp; | ||
|
||
import io.reactivesocket.Frame; | ||
import io.reactivesocket.rx.Observer; | ||
import rx.Subscriber; | ||
|
||
public class ObserverSubscriber extends Subscriber<Frame> { | ||
|
||
private final Observer<Frame> o; | ||
|
||
public ObserverSubscriber(Observer<Frame> o) { | ||
this.o = o; | ||
} | ||
|
||
@Override | ||
public void onCompleted() { | ||
o.onComplete(); | ||
} | ||
|
||
@Override | ||
public void onError(Throwable e) { | ||
o.onError(e); | ||
} | ||
|
||
@Override | ||
public void onNext(Frame frame) { | ||
o.onNext(frame); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...transport-tcp/src/main/java/io/reactivesocket/transport/tcp/ReactiveSocketFrameCodec.java
This file contains 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,63 @@ | ||
/* | ||
* Copyright 2016 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package io.reactivesocket.transport.tcp; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import io.netty.buffer.Unpooled; | ||
import io.netty.channel.ChannelDuplexHandler; | ||
import io.netty.channel.ChannelHandlerContext; | ||
import io.netty.channel.ChannelPromise; | ||
import io.netty.util.ReferenceCountUtil; | ||
import io.reactivesocket.Frame; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
/** | ||
* A Codec that aids reading and writing of ReactiveSocket {@link Frame}s. | ||
*/ | ||
public class ReactiveSocketFrameCodec extends ChannelDuplexHandler { | ||
|
||
private final MutableDirectByteBuf buffer = new MutableDirectByteBuf(Unpooled.buffer(0)); | ||
private final Frame frame = Frame.allocate(buffer); | ||
|
||
@Override | ||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { | ||
if (msg instanceof ByteBuf) { | ||
try { | ||
buffer.wrap((ByteBuf) msg); | ||
frame.wrap(buffer, 0); | ||
ctx.fireChannelRead(frame); | ||
} finally { | ||
ReferenceCountUtil.release(msg); | ||
} | ||
} else { | ||
super.channelRead(ctx, msg); | ||
} | ||
} | ||
|
||
@Override | ||
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { | ||
if (msg instanceof Frame) { | ||
ByteBuffer src = ((Frame)msg).getByteBuffer(); | ||
ByteBuf toWrite = ctx.alloc().buffer(src.remaining()).writeBytes(src); | ||
ctx.write(toWrite, promise); | ||
} else { | ||
super.write(ctx, msg, promise); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...ransport-tcp/src/main/java/io/reactivesocket/transport/tcp/ReactiveSocketLengthCodec.java
This file contains 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,28 @@ | ||
/* | ||
* Copyright 2016 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package io.reactivesocket.transport.tcp; | ||
|
||
import io.netty.handler.codec.LengthFieldBasedFrameDecoder; | ||
import org.agrona.BitUtil; | ||
|
||
public class ReactiveSocketLengthCodec extends LengthFieldBasedFrameDecoder { | ||
|
||
public ReactiveSocketLengthCodec() { | ||
super(Integer.MAX_VALUE, 0, BitUtil.SIZE_OF_INT, -1 * BitUtil.SIZE_OF_INT, 0); | ||
} | ||
} |
Oops, something went wrong.