Update to latest netty, fix event bus bug, comment and rework PacketDecoder to new netty for better performance

This commit is contained in:
md_5
2013-05-14 18:32:17 +10:00
parent 21a354fa75
commit b25c81daf3
5 changed files with 42 additions and 13 deletions

View File

@@ -84,7 +84,7 @@ public class BungeeCord extends ProxyServer
* Thread pools.
*/
public final ScheduledThreadPoolExecutor executors = new BungeeThreadPool( new ThreadFactoryBuilder().setNameFormat( "Bungee Pool Thread #%1$d" ).build() );
public final MultithreadEventLoopGroup eventLoops = new NioEventLoopGroup( 0, new ThreadFactoryBuilder().setNameFormat( "Netty IO Thread #%1$d" ).build() );
public final MultithreadEventLoopGroup eventLoops = new NioEventLoopGroup( NioEventLoopGroup.DEFAULT_EVENT_LOOP_THREADS, new ThreadFactoryBuilder().setNameFormat( "Netty IO Thread #%1$d" ).build() );
/**
* locations.yml save thread.
*/

View File

@@ -1,6 +1,7 @@
package net.md_5.bungee.netty;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.MessageBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;
import lombok.AllArgsConstructor;
@@ -25,13 +26,29 @@ public class PacketDecoder extends ReplayingDecoder<Void>
private int protocol;
@Override
protected byte[] decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception
protected void decode(ChannelHandlerContext ctx, ByteBuf in, MessageBuf<Object> out) throws Exception
{
int startIndex = in.readerIndex();
PacketReader.readPacket( in, protocol );
byte[] buf = new byte[ in.readerIndex() - startIndex ];
in.readerIndex( startIndex );
in.readBytes( buf, 0, buf.length );
return buf;
// While we have enough data
while ( true )
{
// Store our start index
int startIndex = in.readerIndex();
// Run packet through framer
PacketReader.readPacket( in, protocol );
// If we got this far, it means we have formed a packet, so lets grab the end index
int endIndex = in.readerIndex();
// Allocate a buffer big enough for all bytes we have read
byte[] buf = new byte[ endIndex - startIndex ];
// Go back to start index
in.readerIndex( startIndex );
// Drain all the bytes into our buffer
in.readBytes( buf, 0, buf.length );
// Jump back to the end of this packet
in.readerIndex( endIndex );
// Checkpoint our state incase we don't have enough data for another packet
checkpoint();
// Store our decoded message
out.add( buf );
}
}
}