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>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
<version>9.0.0.v20130308</version>
<groupId>com.ning</groupId>
<artifactId>async-http-client</artifactId>
<version>1.7.12</version>
<scope>compile</scope>
</dependency>
<dependency>

View File

@ -2,6 +2,7 @@ package net.md_5.bungee.api;
import net.md_5.bungee.api.plugin.PluginManager;
import com.google.common.base.Preconditions;
import com.ning.http.client.AsyncHttpClient;
import java.io.File;
import java.net.InetSocketAddress;
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.plugin.Plugin;
import net.md_5.bungee.api.scheduler.TaskScheduler;
import org.eclipse.jetty.client.HttpClient;
public abstract class ProxyServer
{
@ -246,5 +246,5 @@ public abstract class ProxyServer
*
* @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 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.channel.Channel;
import io.netty.channel.ChannelException;
@ -21,10 +25,8 @@ import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
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.packet.DefinedPacket;
import net.md_5.bungee.packet.PacketFAPluginMessage;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
/**
* Main BungeeCord proxy class.
@ -77,7 +77,7 @@ public class BungeeCord extends ProxyServer
* Thread pools.
*/
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.
*/
@ -113,7 +113,10 @@ public class BungeeCord extends ProxyServer
@Getter
private final TaskScheduler scheduler = new BungeeScheduler();
@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
public void start() throws Exception
{
httpClient.setExecutor( executors );
httpClient.start();
httpClient.GET( "http://isup.me/" );
httpClient.prepareGet( "http://www.ning.com/" ).execute().get();
httpClient.prepareGet( "http://www.ning.com/" ).execute().get();
pluginsFolder.mkdir();
pluginManager.loadPlugins( pluginsFolder );
config.load();
@ -249,14 +252,7 @@ public class BungeeCord extends ProxyServer
{
this.isRunning = false;
try
{
getLogger().info( "Stopping HTTP client" );
httpClient.stop();
} catch ( Exception ex )
{
getLogger().severe( "Could not stop HTTP client" );
}
httpClient.close();
executors.shutdown();
stopListeners();