-
Notifications
You must be signed in to change notification settings - Fork 357
Using RxNetty for tcp transport #101
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5edfdbf
Using RxNetty for tcp transport
NiteshKant a8fce8f
Merge branch 'master' of https://github.com/ReactiveSocket/reactiveso…
NiteshKant c61a53a
Merge branch 'master' of https://github.com/ReactiveSocket/reactiveso…
NiteshKant 6372600
Review comments
NiteshKant 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
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
20 changes: 20 additions & 0 deletions
20
reactivesocket-examples/src/main/resources/log4j.properties
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,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 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
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 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,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 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,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 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,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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll add a charset in another commit ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Steve - I'm looking out for the EBCDIC users of the world