314087 Simplified SelectorManager

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2189 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Greg Wilkins 2010-07-28 13:11:40 +00:00
parent bd272143e2
commit ef9ebf31b6
9 changed files with 315 additions and 424 deletions

View File

@ -1,6 +1,6 @@
jetty-7.2-SNAPSHOT
+ 320264 dupliate mime entry
+ 314087 Simplified SelectorManager
+ 319334 Concurrent, sharable ResourceCache
+ 319370 WebAppClassLoader.Context
+ 319444 Two nulls are appended to log statements from ContextHanler$Context

View File

@ -16,6 +16,7 @@ package org.eclipse.jetty.client;
import java.io.IOException;
import java.net.SocketTimeoutException;
import java.nio.channels.SelectionKey;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@ -43,8 +44,6 @@ class SelectConnector extends AbstractLifeCycle implements HttpClient.Connector,
{
private final HttpClient _httpClient;
private final Manager _selectorManager=new Manager();
private final Timeout _connectTimer = new Timeout();
private final Map<SocketChannel, Timeout.Task> _connectingChannels = new ConcurrentHashMap<SocketChannel, Timeout.Task>();
private SSLContext _sslContext;
private Buffers _sslBuffers;
private boolean _blockingConnect;
@ -81,28 +80,6 @@ class SelectConnector extends AbstractLifeCycle implements HttpClient.Connector,
{
super.doStart();
_connectTimer.setDuration(_httpClient.getConnectTimeout());
_connectTimer.setNow();
_httpClient._threadPool.dispatch(new Runnable()
{
public void run()
{
while (isRunning())
{
_connectTimer.tick(System.currentTimeMillis());
try
{
Thread.sleep(200);
}
catch (InterruptedException x)
{
Thread.currentThread().interrupt();
break;
}
}
}
});
_selectorManager.start();
final boolean direct=_httpClient.getUseDirectBuffers();
@ -151,23 +128,31 @@ class SelectConnector extends AbstractLifeCycle implements HttpClient.Connector,
@Override
protected void doStop() throws Exception
{
_connectTimer.cancelAll();
_selectorManager.stop();
}
/* ------------------------------------------------------------ */
public void startConnection( HttpDestination destination )
throws IOException
{
try
{
SocketChannel channel = SocketChannel.open();
Address address = destination.isProxied() ? destination.getProxy() : destination.getAddress();
channel.configureBlocking( false );
channel.configureBlocking( true );
channel.socket().setTcpNoDelay(true);
channel.socket().setSoTimeout(_httpClient.getConnectTimeout());
channel.connect(address.toSocketAddress());
channel.configureBlocking(false);
channel.socket().setSoTimeout((int)_httpClient.getTimeout());
_selectorManager.register( channel, destination );
ConnectTimeout connectTimeout = new ConnectTimeout(channel, destination);
_connectTimer.schedule(connectTimeout);
_connectingChannels.put(channel, connectTimeout);
}
catch(IOException ex)
{
destination.onConnectionFailed(ex);
}
}
/* ------------------------------------------------------------ */
@ -191,12 +176,6 @@ class SelectConnector extends AbstractLifeCycle implements HttpClient.Connector,
/* ------------------------------------------------------------ */
class Manager extends SelectorManager
{
@Override
protected SocketChannel acceptChannel(SelectionKey key) throws IOException
{
throw new IllegalStateException();
}
@Override
public boolean dispatch(Runnable task)
{
@ -230,12 +209,6 @@ class SelectConnector extends AbstractLifeCycle implements HttpClient.Connector,
@Override
protected SelectChannelEndPoint newEndPoint(SocketChannel channel, SelectSet selectSet, SelectionKey key) throws IOException
{
// We're connected, cancel the connect timeout
Timeout.Task connectTimeout = _connectingChannels.remove(channel);
if (connectTimeout != null)
connectTimeout.cancel();
Log.debug("Channels with connection pending: {}", _connectingChannels.size());
// key should have destination at this point (will be replaced by endpoint after this call)
HttpDestination dest=(HttpDestination)key.attachment();
@ -278,19 +251,6 @@ class SelectConnector extends AbstractLifeCycle implements HttpClient.Connector,
return sslEngine;
}
/* ------------------------------------------------------------ */
/* (non-Javadoc)
* @see org.eclipse.io.nio.SelectorManager#connectionFailed(java.nio.channels.SocketChannel, java.lang.Throwable, java.lang.Object)
*/
@Override
protected void connectionFailed(SocketChannel channel, Throwable ex, Object attachment)
{
if (attachment instanceof HttpDestination)
((HttpDestination)attachment).onConnectionFailed(ex);
else
super.connectionFailed(channel,ex,attachment);
}
}
private class ConnectTimeout extends Timeout.Task
@ -307,7 +267,6 @@ class SelectConnector extends AbstractLifeCycle implements HttpClient.Connector,
@Override
public void expired()
{
_connectingChannels.remove(channel);
if (channel.isConnectionPending())
{
Log.debug("Channel {} timed out while connecting, closing it", channel);

View File

@ -343,6 +343,7 @@ public class HttpExchangeTest extends TestCase
{
ContentExchange httpExchange=new ContentExchange()
{
};
//httpExchange.setURL(_scheme+"localhost:"+_port+"/");
httpExchange.setURL(_scheme+"localhost:"+_port);
@ -371,7 +372,7 @@ public class HttpExchangeTest extends TestCase
try
{
Thread.sleep(250);
Thread.sleep(25);
}
catch (InterruptedException e)
{

View File

@ -31,10 +31,15 @@ import org.eclipse.jetty.util.log.Log;
/**
* An Endpoint that can be scheduled by {@link SelectorManager}.
*/
public class SelectChannelEndPoint extends ChannelEndPoint implements Runnable, AsyncEndPoint, ConnectedEndPoint
public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPoint, ConnectedEndPoint
{
private final SelectorManager.SelectSet _selectSet;
private final SelectorManager _manager;
private final Runnable _handler = new Runnable()
{
public void run() { handle(); }
};
private volatile Connection _connection;
private boolean _dispatched = false;
private boolean _redispatched = false;
@ -179,7 +184,7 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements Runnable,
_redispatched=true;
else
{
_dispatched = _manager.dispatch(this);
_dispatched = _manager.dispatch(_handler);
if(!_dispatched)
{
Log.warn("Dispatched Failed!");
@ -491,7 +496,7 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements Runnable,
/* ------------------------------------------------------------ */
/*
*/
public void run()
private void handle()
{
boolean dispatched=true;
try

View File

@ -106,6 +106,7 @@ public abstract class SelectorManager extends AbstractLifeCycle
{
return _selectSet[i];
}
/* ------------------------------------------------------------ */
/** Register a channel
* @param channel
@ -128,6 +129,29 @@ public abstract class SelectorManager extends AbstractLifeCycle
}
}
/* ------------------------------------------------------------ */
/** Register a channel
* @param channel
* @param att Attached Object
*/
public void register(SocketChannel channel)
{
// The ++ increment here is not atomic, but it does not matter.
// so long as the value changes sometimes, then connections will
// be distributed over the available sets.
int s=_set++;
s=s%_selectSets;
SelectSet[] sets=_selectSet;
if (sets!=null)
{
SelectSet set=sets[s];
set.addChange(channel);
set.wakeup();
}
}
/* ------------------------------------------------------------ */
/** Register a {@link ServerSocketChannel}
* @param acceptChannel
@ -193,14 +217,6 @@ public abstract class SelectorManager extends AbstractLifeCycle
sets[acceptorID].doSelect();
}
/* ------------------------------------------------------------ */
/**
* @param key the selection key
* @return the SocketChannel created on accept
* @throws IOException
*/
protected abstract SocketChannel acceptChannel(SelectionKey key) throws IOException;
/* ------------------------------------------------------------------------------- */
public abstract boolean dispatch(Runnable task);
@ -265,13 +281,6 @@ public abstract class SelectorManager extends AbstractLifeCycle
*/
protected abstract SelectChannelEndPoint newEndPoint(SocketChannel channel, SelectorManager.SelectSet selectSet, SelectionKey sKey) throws IOException;
/* ------------------------------------------------------------------------------- */
protected void connectionFailed(SocketChannel channel,Throwable ex,Object attachment)
{
Log.warn(ex+","+channel+","+attachment);
Log.debug(ex);
}
/* ------------------------------------------------------------------------------- */
public void dump()
{
@ -291,7 +300,7 @@ public abstract class SelectorManager extends AbstractLifeCycle
}
}
set.addChange(new ChangeTask(){
set.addChange(new Runnable(){
public void run()
{
set.dump();
@ -313,7 +322,6 @@ public abstract class SelectorManager extends AbstractLifeCycle
private Selector _selector;
private int _nextSet;
private volatile Thread _selecting;
private int _jvmBug;
private int _selects;
@ -347,9 +355,9 @@ public abstract class SelectorManager extends AbstractLifeCycle
}
/* ------------------------------------------------------------ */
public void addChange(Object point)
public void addChange(Object change)
{
_changes.add(point);
_changes.add(change);
}
/* ------------------------------------------------------------ */
@ -360,7 +368,7 @@ public abstract class SelectorManager extends AbstractLifeCycle
else if (att instanceof EndPoint)
addChange(att);
else
addChange(new ChangeSelectableChannel(channel,att));
addChange(new ChannelAndAttachment(channel,att));
}
/* ------------------------------------------------------------ */
@ -389,53 +397,29 @@ public abstract class SelectorManager extends AbstractLifeCycle
SelectChannelEndPoint endpoint = (SelectChannelEndPoint)change;
endpoint.doUpdateKey();
}
else if (change instanceof Runnable)
{
dispatch((Runnable)change);
}
else if (change instanceof ChangeSelectableChannel)
else if (change instanceof ChannelAndAttachment)
{
// finish accepting/connecting this connection
final ChangeSelectableChannel asc = (ChangeSelectableChannel)change;
final ChannelAndAttachment asc = (ChannelAndAttachment)change;
final SelectableChannel channel=asc._channel;
final Object att = asc._attachment;
if ((channel instanceof SocketChannel) && ((SocketChannel)channel).isConnected())
{
SelectionKey key = channel.register(selector,SelectionKey.OP_READ,att);
SelectChannelEndPoint endpoint = createEndPoint((SocketChannel)channel,key);
key.attach(endpoint);
endpoint.schedule();
}
else if (channel.isOpen())
{
channel.register(selector,SelectionKey.OP_CONNECT,att);
}
}
else if (change instanceof SocketChannel)
{
// Newly registered channel
final SocketChannel channel=(SocketChannel)change;
if (channel.isConnected())
{
SelectionKey key = channel.register(selector,SelectionKey.OP_READ,null);
SelectChannelEndPoint endpoint = createEndPoint(channel,key);
key.attach(endpoint);
endpoint.schedule();
}
else if (channel.isOpen())
else if (change instanceof Runnable)
{
channel.register(selector,SelectionKey.OP_CONNECT,null);
}
}
else if (change instanceof ServerSocketChannel)
{
ServerSocketChannel channel = (ServerSocketChannel)change;
channel.register(getSelector(),SelectionKey.OP_ACCEPT);
}
else if (change instanceof ChangeTask)
{
((ChangeTask)change).run();
dispatch((Runnable)change);
}
else
throw new IllegalArgumentException(change.toString());
@ -449,19 +433,15 @@ public abstract class SelectorManager extends AbstractLifeCycle
}
}
long retry_next;
// Do and instant select to see if any connections can be handled.
int selected=selector.selectNow();
_selects++;
long now=System.currentTimeMillis();
_timeout.setNow(now);
retry_next=_timeout.getTimeToNext();
// workout how low to wait in select
long wait = _changes.size()==0?__IDLE_TICK:0L;
if (wait > 0 && retry_next >= 0 && wait > retry_next)
wait = retry_next;
// Do the select.
if (wait > 0)
// if no immediate things to do
if (selected==0)
{
// If we are in pausing mode
if (_pausing)
@ -474,13 +454,130 @@ public abstract class SelectorManager extends AbstractLifeCycle
{
Log.ignore(e);
}
now=System.currentTimeMillis();
}
// workout how long to wait in select
_timeout.setNow(now);
long to_next_timeout=_timeout.getTimeToNext();
long wait = _changes.size()==0?__IDLE_TICK:0L;
if (wait > 0 && to_next_timeout >= 0 && wait > to_next_timeout)
wait = to_next_timeout;
// If we should wait with a select
if (wait>0)
{
long before=now;
int selected=selector.select(wait);
selected=selector.select(wait);
_selects++;
now = System.currentTimeMillis();
_timeout.setNow(now);
_selects++;
checkJvmBugs(before, now, wait, selected);
}
}
// have we been destroyed while sleeping
if (_selector==null || !selector.isOpen())
return;
// Look for things to do
for (SelectionKey key: selector.selectedKeys())
{
try
{
if (!key.isValid())
{
key.cancel();
SelectChannelEndPoint endpoint = (SelectChannelEndPoint)key.attachment();
if (endpoint != null)
endpoint.doUpdateKey();
continue;
}
Object att = key.attachment();
if (att instanceof SelectChannelEndPoint)
{
((SelectChannelEndPoint)att).schedule();
}
else
{
// Wrap readable registered channel in an endpoint
SocketChannel channel = (SocketChannel)key.channel();
SelectChannelEndPoint endpoint = createEndPoint(channel,key);
key.attach(endpoint);
if (key.isReadable())
endpoint.schedule();
}
key = null;
}
catch (CancelledKeyException e)
{
Log.ignore(e);
}
catch (Exception e)
{
if (isRunning())
Log.warn(e);
else
Log.ignore(e);
if (key != null && !(key.channel() instanceof ServerSocketChannel) && key.isValid())
key.cancel();
}
}
// Everything always handled
selector.selectedKeys().clear();
now=System.currentTimeMillis();
_timeout.setNow(now);
Task task = _timeout.expired();
while (task!=null)
{
if (task instanceof Runnable)
dispatch((Runnable)task);
task = _timeout.expired();
}
// Idle tick
if (now-_idleTick>__IDLE_TICK)
{
_idleTick=now;
final long idle_now=((_lowResourcesConnections>0 && selector.keys().size()>_lowResourcesConnections))
?(now+_maxIdleTime-_lowResourcesMaxIdleTime)
:now;
dispatch(new Runnable()
{
public void run()
{
for (SelectChannelEndPoint endp:_endPoints.keySet())
{
endp.checkIdleTimestamp(idle_now);
}
}
});
}
}
catch (CancelledKeyException e)
{
Log.ignore(e);
}
finally
{
_selecting=null;
}
}
/* ------------------------------------------------------------ */
private void checkJvmBugs(long before, long now, long wait, int selected)
throws IOException
{
Selector selector = _selector;
if (selector==null)
return;
// Look for JVM bugs over a monitor period.
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6403933
@ -556,16 +653,8 @@ public abstract class SelectorManager extends AbstractLifeCycle
else
addChange(channel,attachment);
}
Selector old_selector=_selector;
_selector.close();
_selector=new_selector;
try
{
old_selector.close();
}
catch(Exception e)
{
Log.ignore(e);
}
return;
}
}
@ -622,164 +711,6 @@ public abstract class SelectorManager extends AbstractLifeCycle
_busyKey=busy;
}
}
else
{
selector.selectNow();
_selects++;
}
// have we been destroyed while sleeping
if (_selector==null || !selector.isOpen())
return;
// Look for things to do
for (SelectionKey key: selector.selectedKeys())
{
try
{
if (!key.isValid())
{
key.cancel();
SelectChannelEndPoint endpoint = (SelectChannelEndPoint)key.attachment();
if (endpoint != null)
endpoint.doUpdateKey();
continue;
}
Object att = key.attachment();
if (att instanceof SelectChannelEndPoint)
{
((SelectChannelEndPoint)att).schedule();
}
else if (key.isAcceptable())
{
SocketChannel channel = acceptChannel(key);
if (channel==null)
continue;
channel.configureBlocking(false);
// TODO make it reluctant to leave 0
_nextSet=++_nextSet%_selectSet.length;
// Is this for this selectset
if (_nextSet==_setID)
{
// bind connections to this select set.
SelectionKey cKey = channel.register(_selectSet[_nextSet].getSelector(), SelectionKey.OP_READ);
SelectChannelEndPoint endpoint=_selectSet[_nextSet].createEndPoint(channel,cKey);
cKey.attach(endpoint);
if (endpoint != null)
endpoint.schedule();
}
else
{
// nope - give it to another.
_selectSet[_nextSet].addChange(channel);
_selectSet[_nextSet].wakeup();
}
}
else if (key.isConnectable())
{
// Complete a connection of a registered channel
SocketChannel channel = (SocketChannel)key.channel();
boolean connected=false;
try
{
connected=channel.finishConnect();
}
catch(Exception e)
{
connectionFailed(channel,e,att);
}
finally
{
if (connected)
{
key.interestOps(SelectionKey.OP_READ);
SelectChannelEndPoint endpoint = createEndPoint(channel,key);
key.attach(endpoint);
endpoint.schedule();
}
else
{
key.cancel();
}
}
}
else
{
// Wrap readable registered channel in an endpoint
SocketChannel channel = (SocketChannel)key.channel();
SelectChannelEndPoint endpoint = createEndPoint(channel,key);
key.attach(endpoint);
if (key.isReadable())
endpoint.schedule();
}
key = null;
}
catch (CancelledKeyException e)
{
Log.ignore(e);
}
catch (Exception e)
{
if (isRunning())
Log.warn(e);
else
Log.ignore(e);
if (key != null && !(key.channel() instanceof ServerSocketChannel) && key.isValid())
key.cancel();
}
}
// Everything always handled
selector.selectedKeys().clear();
_timeout.setNow(now);
Task task = _timeout.expired();
while (task!=null)
{
if (task instanceof Runnable)
dispatch((Runnable)task);
else
task.expired();
task = _timeout.expired();
}
// Idle tick
if (now-_idleTick>__IDLE_TICK)
{
_idleTick=now;
final long idle_now=((_lowResourcesConnections>0 && selector.keys().size()>_lowResourcesConnections))
?(now+_maxIdleTime-_lowResourcesMaxIdleTime)
:now;
dispatch(new Runnable()
{
public void run()
{
for (SelectChannelEndPoint endp:_endPoints.keySet())
{
endp.checkIdleTimestamp(idle_now);
}
}
});
}
}
catch (CancelledKeyException e)
{
Log.ignore(e);
}
finally
{
_selecting=null;
}
}
/* ------------------------------------------------------------ */
public SelectorManager getManager()
@ -802,6 +733,8 @@ public abstract class SelectorManager extends AbstractLifeCycle
*/
public void scheduleTimeout(Timeout.Task task, long timeoutMs)
{
if (!(task instanceof Runnable))
throw new IllegalArgumentException("!Runnable");
_timeout.schedule(task, timeoutMs);
}
@ -911,22 +844,16 @@ public abstract class SelectorManager extends AbstractLifeCycle
}
/* ------------------------------------------------------------ */
private static class ChangeSelectableChannel
private static class ChannelAndAttachment
{
final SelectableChannel _channel;
final Object _attachment;
public ChangeSelectableChannel(SelectableChannel channel, Object attachment)
public ChannelAndAttachment(SelectableChannel channel, Object attachment)
{
super();
_channel = channel;
_attachment = attachment;
}
}
/* ------------------------------------------------------------ */
private interface ChangeTask
{
public void run();
}
}

View File

@ -90,60 +90,56 @@ public class SslSelectChannelEndPoint extends SelectChannelEndPoint
if (_debug) __log.debug(_session+" channel="+channel);
}
int _outCount;
/* ------------------------------------------------------------ */
private void needOutBuffer()
{
if (_outNIOBuffer==null)
{
synchronized (this)
{
_outCount++;
if (_outNIOBuffer==null)
_outNIOBuffer=(NIOBuffer)_buffers.getBuffer(_session.getPacketBufferSize());
}
}
}
/* ------------------------------------------------------------ */
private void needInBuffer()
{
if (_inNIOBuffer==null)
{
synchronized (this)
{
if(_inNIOBuffer==null)
_inNIOBuffer=(NIOBuffer)_buffers.getBuffer(_session.getPacketBufferSize());
}
}
}
/* ------------------------------------------------------------ */
private void freeOutBuffer()
{
if (_outNIOBuffer!=null && _outNIOBuffer.length()==0)
{
synchronized (this)
{
if (_outNIOBuffer!=null && _outNIOBuffer.length()==0)
if (--_outCount<=0 && _outNIOBuffer!=null && _outNIOBuffer.length()==0)
{
_buffers.returnBuffer(_outNIOBuffer);
_outNIOBuffer=null;
_outCount=0;
}
}
}
int _inCount;
/* ------------------------------------------------------------ */
private void needInBuffer()
{
synchronized (this)
{
_inCount++;
if(_inNIOBuffer==null)
_inNIOBuffer=(NIOBuffer)_buffers.getBuffer(_session.getPacketBufferSize());
}
}
/* ------------------------------------------------------------ */
private void freeInBuffer()
{
if (_inNIOBuffer!=null && _inNIOBuffer.length()==0)
{
synchronized (this)
{
if (_inNIOBuffer!=null && _inNIOBuffer.length()==0)
if (--_inCount<=0 &&_inNIOBuffer!=null && _inNIOBuffer.length()==0)
{
_buffers.returnBuffer(_inNIOBuffer);
_inNIOBuffer=null;
}
_inCount=0;
}
}
}
@ -184,10 +180,10 @@ public class SslSelectChannelEndPoint extends SelectChannelEndPoint
long end=System.currentTimeMillis()+((SocketChannel)_channel).socket().getSoTimeout();
try
{
if (isBufferingOutput())
while (isOpen() && isBufferingOutput()&& System.currentTimeMillis()<end)
{
flush();
while (isOpen() && isBufferingOutput() && System.currentTimeMillis()<end)
if (isBufferingOutput())
{
Thread.sleep(100); // TODO non blocking
flush();
@ -198,14 +194,11 @@ public class SslSelectChannelEndPoint extends SelectChannelEndPoint
loop: while (isOpen() && !(_engine.isInboundDone() && _engine.isOutboundDone()) && System.currentTimeMillis()<end)
{
if (isBufferingOutput())
{
flush();
while (isOpen() && isBufferingOutput() && System.currentTimeMillis()<end)
{
Thread.sleep(100); // TODO non blocking
flush();
}
if (isBufferingOutput())
Thread.sleep(100);
}
if (_debug) __log.debug(_session+" closing "+_engine.getHandshakeStatus());
@ -252,6 +245,8 @@ public class SslSelectChannelEndPoint extends SelectChannelEndPoint
ByteBuffer out_buffer=_outNIOBuffer.getByteBuffer();
try
{
if (_outNIOBuffer.length()>0)
flush();
_outNIOBuffer.compact();
int put=_outNIOBuffer.putIndex();
out_buffer.position(put);
@ -271,9 +266,10 @@ public class SslSelectChannelEndPoint extends SelectChannelEndPoint
}
}
}
catch (InterruptedException e)
catch (Exception e)
{
Log.ignore(e);
Log.debug(e);
super.close();
}
}

View File

@ -411,13 +411,6 @@ public class ProxyHandler extends HandlerWrapper
private class Manager extends SelectorManager
{
@Override
protected SocketChannel acceptChannel(SelectionKey key) throws IOException
{
// This is a client-side selector manager
throw new IllegalStateException();
}
@Override
protected SelectChannelEndPoint newEndPoint(SocketChannel channel, SelectSet selectSet, SelectionKey selectionKey) throws IOException
{

View File

@ -67,19 +67,6 @@ public class SelectChannelConnector extends AbstractNIOConnector
private final SelectorManager _manager = new SelectorManager()
{
@Override
protected SocketChannel acceptChannel(SelectionKey key) throws IOException
{
// TODO handle max connections
SocketChannel channel = ((ServerSocketChannel)key.channel()).accept();
if (channel==null)
return null;
channel.configureBlocking(false);
Socket socket = channel.socket();
configure(socket);
return channel;
}
@Override
public boolean dispatch(Runnable task)
{
@ -212,9 +199,6 @@ public class SelectChannelConnector extends AbstractNIOConnector
if (_localPort<=0)
throw new IOException("Server channel not bound");
// Set to non blocking mode
_acceptChannel.configureBlocking(false);
}
}
}
@ -287,8 +271,32 @@ public class SelectChannelConnector extends AbstractNIOConnector
_manager.setLowResourcesMaxIdleTime(getLowResourcesMaxIdleTime());
_manager.start();
open();
_manager.register(_acceptChannel);
super.doStart();
// start a thread to accept new connections
_manager.dispatch(new Runnable()
{
public void run()
{
final ServerSocketChannel server=_acceptChannel;
while (isRunning() && _acceptChannel==server && server.isOpen())
{
try
{
SocketChannel channel = server.accept();
channel.configureBlocking(false);
Socket socket = channel.socket();
configure(socket);
_manager.register(channel);
}
catch(IOException e)
{
Log.ignore(e);
}
}
}
});
}
/* ------------------------------------------------------------ */

View File

@ -33,7 +33,7 @@ public class BusySelectChannelServerTest extends HttpServerTestBase
@BeforeClass
public static void init() throws Exception
{
startServer(new SelectChannelConnector()
SelectChannelConnector connector=new SelectChannelConnector()
{
@Override
protected SelectChannelEndPoint newEndPoint(SocketChannel channel, SelectSet selectSet, SelectionKey key) throws IOException
@ -128,6 +128,8 @@ public class BusySelectChannelServerTest extends HttpServerTestBase
}
};
}
});
};
connector.setAcceptors(1);
startServer(connector);
}
}