Skip to content
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

Don't share pipeline state in fields of the FileChunkedStrategy instance #319

Merged
merged 2 commits into from
Apr 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/main/java/reactor/ipc/netty/NettyOutbound.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,7 @@ default NettyOutbound sendFile(Path file, long position, long count) {
default NettyOutbound sendFileChunked(Path file, long position, long count) {
Objects.requireNonNull(file);
final FileChunkedStrategy strategy = getFileChunkedStrategy();
final boolean needChunkedWriteHandler = context().channel().pipeline().get(NettyPipeline.ChunkedWriter) == null;
if (needChunkedWriteHandler) {
strategy.preparePipeline(context());
}
strategy.preparePipeline(context());

return then(Mono.using(() -> FileChannel.open(file, StandardOpenOption.READ),
fc -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package reactor.ipc.netty.channel.data;

import java.io.RandomAccessFile;

import io.netty.handler.stream.ChunkedWriteHandler;
import reactor.ipc.netty.NettyContext;
import reactor.ipc.netty.NettyPipeline;
Expand All @@ -35,8 +33,6 @@
*/
public abstract class AbstractFileChunkedStrategy<T> implements FileChunkedStrategy<T> {

boolean addHandler;

/**
* {@inheritDoc}
* <p>
Expand All @@ -49,10 +45,7 @@ public abstract class AbstractFileChunkedStrategy<T> implements FileChunkedStrat
*/
@Override
public final void preparePipeline(NettyContext context) {
this.addHandler = context.channel()
.pipeline()
.get(NettyPipeline.ChunkedWriter) == null;
if (addHandler) {
if (!hasChunkedWriter(context)) {
boolean hasReactiveBridge = context.channel()
.pipeline()
.get(NettyPipeline.ReactiveBridge) != null;
Expand All @@ -72,6 +65,12 @@ public final void preparePipeline(NettyContext context) {
}
}

private boolean hasChunkedWriter(NettyContext context) {
return context.channel()
.pipeline()
.get(NettyPipeline.ChunkedWriter) != null;
}

/**
* {@inheritDoc}
* <p>
Expand All @@ -82,7 +81,7 @@ public final void preparePipeline(NettyContext context) {
*/
@Override
public final void cleanupPipeline(NettyContext context) {
if (addHandler) {
if (hasChunkedWriter(context)) {
context.channel()
.pipeline()
.remove(NettyPipeline.ChunkedWriter);
Expand Down