Use asynchttpclient instead

This commit is contained in:
md_5 2013-03-20 19:10:59 +11:00
parent 8827feacfb
commit 27d454524f
3 changed files with 18 additions and 22 deletions

View File

@ -26,9 +26,9 @@
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.eclipse.jetty</groupId> <groupId>com.ning</groupId>
<artifactId>jetty-client</artifactId> <artifactId>async-http-client</artifactId>
<version>9.0.0.v20130308</version> <version>1.7.12</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -2,6 +2,7 @@ package net.md_5.bungee.api;
import net.md_5.bungee.api.plugin.PluginManager; import net.md_5.bungee.api.plugin.PluginManager;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.ning.http.client.AsyncHttpClient;
import java.io.File; import java.io.File;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.Collection; import java.util.Collection;
@ -14,7 +15,6 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.connection.Server; import net.md_5.bungee.api.connection.Server;
import net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.api.scheduler.TaskScheduler; import net.md_5.bungee.api.scheduler.TaskScheduler;
import org.eclipse.jetty.client.HttpClient;
public abstract class ProxyServer public abstract class ProxyServer
{ {
@ -246,5 +246,5 @@ public abstract class ProxyServer
* *
* @return * @return
*/ */
public abstract HttpClient getHttpClient(); public abstract AsyncHttpClient getHttpClient();
} }

View File

@ -2,6 +2,10 @@ package net.md_5.bungee;
import net.md_5.bungee.scheduler.BungeeScheduler; import net.md_5.bungee.scheduler.BungeeScheduler;
import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.ning.http.client.AsyncHttpClient;
import com.ning.http.client.AsyncHttpClientConfig;
import com.ning.http.client.providers.netty.NettyAsyncHttpProvider;
import com.ning.http.client.providers.netty.NettyAsyncHttpProviderConfig;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelException; import io.netty.channel.ChannelException;
@ -21,10 +25,8 @@ import java.util.Map;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -48,8 +50,6 @@ import net.md_5.bungee.config.YamlConfig;
import net.md_5.bungee.netty.PipelineUtils; import net.md_5.bungee.netty.PipelineUtils;
import net.md_5.bungee.packet.DefinedPacket; import net.md_5.bungee.packet.DefinedPacket;
import net.md_5.bungee.packet.PacketFAPluginMessage; import net.md_5.bungee.packet.PacketFAPluginMessage;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
/** /**
* Main BungeeCord proxy class. * Main BungeeCord proxy class.
@ -77,7 +77,7 @@ public class BungeeCord extends ProxyServer
* Thread pools. * Thread pools.
*/ */
public final ScheduledExecutorService executors = new ScheduledThreadPoolExecutor( 8, new ThreadFactoryBuilder().setNameFormat( "Bungee Pool Thread #%1$d" ).build() ); public final ScheduledExecutorService executors = new ScheduledThreadPoolExecutor( 8, new ThreadFactoryBuilder().setNameFormat( "Bungee Pool Thread #%1$d" ).build() );
public final MultithreadEventLoopGroup eventLoops = new NioEventLoopGroup( 8, new ThreadFactoryBuilder().setNameFormat( "Netty IO Thread #%1$d" ).build() ); public final MultithreadEventLoopGroup eventLoops = new NioEventLoopGroup( 0, new ThreadFactoryBuilder().setNameFormat( "Netty IO Thread #%1$d" ).build() );
/** /**
* locations.yml save thread. * locations.yml save thread.
*/ */
@ -113,7 +113,10 @@ public class BungeeCord extends ProxyServer
@Getter @Getter
private final TaskScheduler scheduler = new BungeeScheduler(); private final TaskScheduler scheduler = new BungeeScheduler();
@Getter @Getter
private final HttpClient httpClient = new HttpClient(); private final AsyncHttpClient httpClient = new AsyncHttpClient(
new NettyAsyncHttpProvider(
new AsyncHttpClientConfig.Builder().setAsyncHttpClientProviderConfig(
new NettyAsyncHttpProviderConfig().addProperty( NettyAsyncHttpProviderConfig.BOSS_EXECUTOR_SERVICE, executors ) ).setExecutorService( executors ).build() ) );
{ {
@ -183,9 +186,9 @@ public class BungeeCord extends ProxyServer
@Override @Override
public void start() throws Exception public void start() throws Exception
{ {
httpClient.setExecutor( executors ); httpClient.prepareGet( "http://www.ning.com/" ).execute().get();
httpClient.start(); httpClient.prepareGet( "http://www.ning.com/" ).execute().get();
httpClient.GET( "http://isup.me/" );
pluginsFolder.mkdir(); pluginsFolder.mkdir();
pluginManager.loadPlugins( pluginsFolder ); pluginManager.loadPlugins( pluginsFolder );
config.load(); config.load();
@ -249,14 +252,7 @@ public class BungeeCord extends ProxyServer
{ {
this.isRunning = false; this.isRunning = false;
try httpClient.close();
{
getLogger().info( "Stopping HTTP client" );
httpClient.stop();
} catch ( Exception ex )
{
getLogger().severe( "Could not stop HTTP client" );
}
executors.shutdown(); executors.shutdown();
stopListeners(); stopListeners();