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

Implementation of the latest stable Netty4 version #902

Merged
merged 46 commits into from
May 30, 2020
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
a92b73d
Revert Netty to 4.0.29
valib Oct 27, 2015
56784ff
Updated Netty to 4.0.32
valib Oct 27, 2015
65b4457
Merge branch 'Netty4' into Implement_Netty4
valib May 26, 2016
e62dccc
Fixed MPEG1 video format detection.
valib May 26, 2016
93ea1fa
Update to the latest Netty 4 version
valib May 26, 2016
094bf84
Merge remote-tracking branch 'origin/master' into Netty4
valib May 27, 2016
57bba40
Merge remote-tracking branch 'origin/master' into Netty4
valib May 29, 2016
d7f01ff
Merge remote-tracking branch 'origin/master' into Netty4
valib Jun 3, 2016
229dfb2
Updated Netty implementation
valib Jun 3, 2016
83278c1
Update the Netty implementation continues
valib Jun 3, 2016
6d3ca77
Removed unused import
valib Jun 3, 2016
e59b629
Check subtitles only once to speed up browsing
valib Jun 4, 2016
624bcd7
Some change
valib Jun 4, 2016
6404bf9
Merge remote-tracking branch 'origin/master' into Netty4
valib Jun 5, 2016
b83228e
Updated Netty to 4.1.1
SubJunk Jun 16, 2016
4c63734
Keep doing Cling searches
SubJunk Jun 16, 2016
68ff002
Formatting
SubJunk Jun 16, 2016
d194dbc
Merge branch 'master' of github.com:UniversalMediaServer/UniversalMed…
SubJunk Jun 17, 2016
f550c65
Merge branch 'FixPanasonicTVUPnPDetection' of github.com:UniversalMed…
SubJunk Jun 17, 2016
b47d3c6
Merge branch 'master' of github.com:UniversalMediaServer/UniversalMed…
SubJunk Jun 19, 2016
533ae3d
Update netty
valib Aug 20, 2017
dfda046
Merge branch 'master' into Netty4
valib Aug 20, 2017
f7c167c
Fixed merging
valib Aug 20, 2017
094d9d5
Add the 'end of content' marker for chunked transfer based on #987
valib Aug 22, 2017
10f4d11
Fixed bug reported by @sami32 and cleans up RequestHandlerV2 based on
valib Aug 29, 2017
767309c
Merge branch 'master' into Netty4
valib Aug 29, 2017
0a0c8ed
Update Netty version and fix some bugs
valib Aug 31, 2017
e2361af
Merge branch 'master' into Netty4
valib Sep 1, 2017
efc48f0
Merge branch 'master' into Netty4
SubJunk Jun 4, 2018
86ad84e
Updated to latest Netty version
SubJunk Jun 11, 2018
c4fd770
Merge branch 'master' into Netty4
valib Jun 11, 2018
74383e2
Merge remote-tracking branch 'origin/master' into NETTY4
valib Oct 10, 2018
b624e8a
Update to the latest Netty version
valib Oct 10, 2018
c419244
Bump Netty
SubJunk Feb 11, 2020
93db2c5
Merge remote-tracking branch 'origin/master' into Netty4
valib Feb 12, 2020
fb2c6fd
Update
valib Feb 12, 2020
25cb767
update
valib Feb 13, 2020
bc584f2
Removed old code
SubJunk Feb 14, 2020
e4d9757
Log if stream is chunked
valib Feb 14, 2020
e12a1f6
Merge branch 'master' into Netty4
valib Feb 14, 2020
b667c28
Merge branch 'master' into Netty4
valib Feb 23, 2020
a01ca4a
Merge branch 'master' into Netty4
valib May 3, 2020
5976a7c
fix merging
valib May 3, 2020
a3f2f3d
Updated to the latest version
valib May 28, 2020
a604e0a
Merge remote-tracking branch 'origin/master' into Netty4
valib May 28, 2020
f196c98
Update src/main/java/net/pms/network/RequestHandlerV2.java
valib May 29, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty</artifactId> <!-- Use 'netty-all' for 4.0 or above -->
<version>3.10.6.Final</version>
<artifactId>netty-all</artifactId>
<version>4.1.50.Final</version>
<scope>compile</scope>
</dependency>

Expand Down
78 changes: 41 additions & 37 deletions src/main/java/net/pms/network/HTTPServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,24 @@
import java.net.*;
import java.nio.channels.ClosedByInterruptException;
import java.nio.channels.ServerSocketChannel;
import java.util.concurrent.Executors;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.stream.ChunkedWriteHandler;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
import net.pms.PMS;
import net.pms.configuration.PmsConfiguration;
import net.pms.newgui.StatusTab.ConnectionState;
import org.apache.commons.lang3.StringUtils;
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelFactory;
import org.jboss.netty.channel.group.ChannelGroup;
import org.jboss.netty.channel.group.DefaultChannelGroup;
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
import org.jboss.netty.util.ThreadNameDeterminer;
import org.jboss.netty.util.ThreadRenamingRunnable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -50,10 +53,10 @@ public class HTTPServer implements Runnable {
private boolean stop;
private Thread runnable;
private InetAddress iafinal;
private ChannelFactory factory;
private Channel channel;
private NetworkInterface networkInterface;
private ChannelGroup group;
private EventLoopGroup bossGroup;
private EventLoopGroup workerGroup;

// XXX not used
@Deprecated
Expand Down Expand Up @@ -111,27 +114,32 @@ public boolean start() throws IOException {
LOGGER.info("Created socket: {}", address);

if (configuration.isHTTPEngineV2()) { // HTTP Engine V2
ThreadRenamingRunnable.setThreadNameDeterminer(ThreadNameDeterminer.CURRENT);
group = new DefaultChannelGroup("HTTPServer");
factory = new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(new NettyBossThreadFactory()),
Executors.newCachedThreadPool(new NettyWorkerThreadFactory())
);

ServerBootstrap bootstrap = new ServerBootstrap(factory);
HttpServerPipelineFactory pipeline = new HttpServerPipelineFactory(group);
bootstrap.setPipelineFactory(pipeline);
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setOption("child.keepAlive", true);
bootstrap.setOption("reuseAddress", true);
bootstrap.setOption("child.reuseAddress", true);
bootstrap.setOption("child.sendBufferSize", 65536);
bootstrap.setOption("child.receiveBufferSize", 65536);
bossGroup = new NioEventLoopGroup(1);
workerGroup = new NioEventLoopGroup();
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap.childOption(ChannelOption.TCP_NODELAY, true)
.childOption(ChannelOption.SO_KEEPALIVE, true)
.option(ChannelOption.SO_REUSEADDR, true)
.childOption(ChannelOption.SO_REUSEADDR, true)
.childOption(ChannelOption.SO_SNDBUF, 65536)
.childOption(ChannelOption.SO_RCVBUF, 65536);
bootstrap.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.localAddress(address)
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast("HttpHandler", new HttpServerCodec())
// eliminate the need to decode http chunks from the client
.addLast("aggregator", new HttpObjectAggregator(64 * 1024))
.addLast("chunkedWriter", new ChunkedWriteHandler())
.addLast("handler", new RequestHandlerV2());
}
});

try {
channel = bootstrap.bind(address);

group.add(channel);
channel = bootstrap.bind().channel();
} catch (Exception e) {
LOGGER.error("Another program is using port " + port + ", which UMS needs.");
LOGGER.error("You can change the port UMS uses on the General Configuration tab.");
Expand Down Expand Up @@ -208,13 +216,9 @@ public void stop() {
}

if (channel != null) { // HTTP Engine V2
if (group != null) {
group.close().awaitUninterruptibly();
}

if (factory != null) {
factory.releaseExternalResources();
}
channel.close().syncUninterruptibly();
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}

NetworkConfiguration.forgetConfiguration();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/pms/network/HttpException.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package net.pms.network;

import org.jboss.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpResponseStatus;

public class HttpException extends Exception {

private static final long serialVersionUID = -4952529888336004924L;
SubJunk marked this conversation as resolved.
Show resolved Hide resolved
private HttpResponseStatus status;

HttpException(HttpResponseStatus status) {
Expand Down
55 changes: 0 additions & 55 deletions src/main/java/net/pms/network/HttpServerPipelineFactory.java

This file was deleted.