Merge branch 'jetty-9' of ssh://git.eclipse.org/gitroot/jetty/org.eclipse.jetty.project into jetty-9

This commit is contained in:
Joakim Erdfelt 2012-07-18 11:51:38 -07:00
commit 964fa9325a
14 changed files with 169 additions and 235 deletions

View File

@ -7,31 +7,31 @@ public abstract class AbstractEndPoint implements EndPoint
private final long _created=System.currentTimeMillis();
private final InetSocketAddress _local;
private final InetSocketAddress _remote;
private volatile int _maxIdleTime;
private volatile long _maxIdleTime;
private volatile long _idleTimestamp=System.currentTimeMillis();
protected AbstractEndPoint(InetSocketAddress local,InetSocketAddress remote)
{
_local=local;
_remote=remote;
}
@Override
public long getCreatedTimeStamp()
{
return _created;
}
@Override
public int getMaxIdleTime()
public long getMaxIdleTime()
{
return _maxIdleTime;
}
@Override
public void setMaxIdleTime(int timeMs)
public void setMaxIdleTime(long timeMs)
{
_maxIdleTime=timeMs;
}
@ -61,12 +61,7 @@ public abstract class AbstractEndPoint implements EndPoint
{
_idleTimestamp=System.currentTimeMillis();
}
/* ------------------------------------------------------------ */
public void onClose()
{
}
/* ------------------------------------------------------------ */
@Override
public String toString()
@ -79,5 +74,5 @@ public abstract class AbstractEndPoint implements EndPoint
isOpen(),
isOutputShutdown());
}
}

View File

@ -21,7 +21,7 @@ public class AsyncByteArrayEndPoint extends ByteArrayEndPoint implements AsyncEn
private AsyncConnection _connection;
private final TimerTask _checkTimeout=new TimeoutTask(this);
private final ReadInterest _readInterest = new ReadInterest()
{
@Override
@ -30,18 +30,18 @@ public class AsyncByteArrayEndPoint extends ByteArrayEndPoint implements AsyncEn
if (_closed)
throw new ClosedChannelException();
return _in==null || BufferUtil.hasContent(_in);
}
}
};
private final WriteFlusher _writeFlusher = new WriteFlusher(this)
{
@Override
protected void onIncompleteFlushed()
{
{
// Don't need to do anything here as takeOutput does the signalling.
}
};
public AsyncByteArrayEndPoint(Timer timer)
{
super();
@ -85,7 +85,7 @@ public class AsyncByteArrayEndPoint extends ByteArrayEndPoint implements AsyncEn
super.setOutput(out);
_writeFlusher.completeWrite();
}
@Override
public void reset()
{
@ -117,7 +117,7 @@ public class AsyncByteArrayEndPoint extends ByteArrayEndPoint implements AsyncEn
{
_connection=connection;
}
public void checkReadWriteTimeout(long now)
{
synchronized (this)
@ -136,7 +136,7 @@ public class AsyncByteArrayEndPoint extends ByteArrayEndPoint implements AsyncEn
if (isOutputShutdown())
close();
notIdle();
TimeoutException timeout = new TimeoutException("idle "+idleForMs+"ms");
_readInterest.failed(timeout);
_writeFlusher.failed(timeout);
@ -146,22 +146,26 @@ public class AsyncByteArrayEndPoint extends ByteArrayEndPoint implements AsyncEn
}
}
@Override
public void onOpen()
{
}
@Override
public void onClose()
{
_checkTimeout.cancel();
super.onClose();
}
private static class TimeoutTask extends TimerTask
{
final WeakReference<AsyncByteArrayEndPoint> _endp;
TimeoutTask(AsyncByteArrayEndPoint endp)
{
_endp=new WeakReference<AsyncByteArrayEndPoint>(endp);
}
@Override
public void run()
{
@ -172,5 +176,5 @@ public class AsyncByteArrayEndPoint extends ByteArrayEndPoint implements AsyncEn
endp.checkReadWriteTimeout(System.currentTimeMillis());
}
};
}

View File

@ -17,7 +17,7 @@ import org.eclipse.jetty.util.FutureCallback;
* some inefficiencies.
* <p>
* This class will frequently be used in conjunction with some of the utility
* implementations of {@link Callback}, such as {@link FutureCallback} and
* implementations of {@link Callback}, such as {@link FutureCallback} and
* {@link ExecutorCallback}. Examples are:
* <h3>Blocking Read</h3>
* A FutureCallback can be used to block until an endpoint is ready to be filled
@ -40,21 +40,21 @@ import org.eclipse.jetty.util.FutureCallback;
* }
* public void onFailed(String context,Throwable cause) {...}
* });</pre></blockquote>
* The executor callback can also be customized to not dispatch in some circumstances when
* The executor callback can also be customized to not dispatch in some circumstances when
* it knows it can use the callback thread and does not need to dispatch.
*
*
* <h3>Blocking Write</h3>
* The write contract is that the callback complete is not called until all data has been
* The write contract is that the callback complete is not called until all data has been
* written or there is a failure. For blocking this looks like:
*
*
* <blockquote><pre>
* FutureCallback<String> future = new FutureCallback<>();
* endpoint.write("ContextObj",future,headerBuffer,contentBuffer);
* String context = future.get(); // This blocks
* </pre></blockquote>
*
*
* <h3>Dispatched Write</h3>
* Note also that multiple buffers may be passed in write so that gather writes
* Note also that multiple buffers may be passed in write so that gather writes
* can be done:
* <blockquote><pre>
* endpoint.write("ContextObj",new ExecutorCallback<String>(executor)
@ -66,7 +66,7 @@ import org.eclipse.jetty.util.FutureCallback;
* }
* public void onFailed(String context,Throwable cause) {...}
* },headerBuffer,contentBuffer);</pre></blockquote>
*
*
*/
public interface AsyncEndPoint extends EndPoint
{
@ -83,7 +83,7 @@ public interface AsyncEndPoint extends EndPoint
/* ------------------------------------------------------------ */
/** Asynchronous write operation.
* <p>
* This method performs {@link #flush(ByteBuffer...)} operation(s) and do a callback when all the data
* This method performs {@link #flush(ByteBuffer...)} operation(s) and do a callback when all the data
* has been flushed or an error occurs.
* @param context Context to return via the callback
* @param callback The callback to call when an error occurs or we are readable.
@ -102,7 +102,8 @@ public interface AsyncEndPoint extends EndPoint
AsyncConnection getAsyncConnection();
void setAsyncConnection(AsyncConnection connection);
void onOpen();
void onClose();
}

View File

@ -116,13 +116,13 @@ public interface EndPoint
* extraordinary handling takes place.
* @return the max idle time in ms or if ms <= 0 implies an infinite timeout
*/
int getMaxIdleTime();
long getMaxIdleTime();
/* ------------------------------------------------------------ */
/** Set the max idle time.
* @param timeMs the max idle time in MS. Timeout <= 0 implies an infinite timeout
*/
void setMaxIdleTime(int timeMs);
void setMaxIdleTime(long timeMs);

View File

@ -60,7 +60,7 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements Runnable,
return false;
}
};
/* ------------------------------------------------------------ */
private final WriteFlusher _writeFlusher = new WriteFlusher(this)
{
@ -73,7 +73,7 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements Runnable,
};
/* ------------------------------------------------------------ */
public SelectChannelEndPoint(SocketChannel channel, ManagedSelector selectSet, SelectionKey key, int maxIdleTime) throws IOException
public SelectChannelEndPoint(SocketChannel channel, ManagedSelector selectSet, SelectionKey key, long maxIdleTime) throws IOException
{
super(channel);
_manager = selectSet.getManager();
@ -97,7 +97,7 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements Runnable,
{
_writeFlusher.write(context,callback,buffers);
}
/* ------------------------------------------------------------ */
@Override
public AsyncConnection getAsyncConnection()
@ -171,7 +171,7 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements Runnable,
public void checkReadWriteTimeout(long now)
{
synchronized (this)
{
{
if (isOutputShutdown() || _readInterest.isInterested() || _writeFlusher.isWriting())
{
long idleTimestamp = getIdleTimestamp();
@ -196,7 +196,7 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements Runnable,
}
}
/* ------------------------------------------------------------ */
@Override
protected void shutdownInput()
@ -204,7 +204,7 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements Runnable,
super.shutdownInput();
updateKey();
}
/* ------------------------------------------------------------ */
/**
* Updates selection key. This method schedules a call to doUpdateKey to do the keyChange
@ -327,6 +327,11 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements Runnable,
updateKey();
}
@Override
public void onOpen()
{
}
/* ------------------------------------------------------------ */
@Override
public void onClose()

View File

@ -51,6 +51,7 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
private final ManagedSelector[] _selectSets;
private long _selectSetIndex;
private volatile long _maxIdleTime;
protected SelectorManager()
{
@ -62,12 +63,19 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
this._selectSets = new ManagedSelector[selectors];
}
/**
* @return the max idle time
*/
protected abstract int getMaxIdleTime();
protected long getMaxIdleTime()
{
return _maxIdleTime;
}
public void setMaxIdleTime(long maxIdleTime)
{
_maxIdleTime = maxIdleTime;
}
protected abstract void execute(Runnable task);
/**
@ -139,18 +147,27 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
/**
* @param endpoint the endPoint being opened
*/
protected abstract void endPointOpened(AsyncEndPoint endpoint);
protected void endPointOpened(AsyncEndPoint endpoint)
{
endpoint.getAsyncConnection().onOpen();
}
/**
* @param endpoint the endPoint being closed
*/
protected abstract void endPointClosed(AsyncEndPoint endpoint);
protected void endPointClosed(AsyncEndPoint endpoint)
{
endpoint.getAsyncConnection().onClose();
endpoint.onClose();
}
/**
* @param endpoint the endPoint being upgraded
* @param oldConnection the previous connection
*/
protected abstract void endPointUpgraded(AsyncEndPoint endpoint,AsyncConnection oldConnection);
protected void endPointUpgraded(AsyncEndPoint endpoint, AsyncConnection oldConnection)
{
}
/**
* @param channel the socket channel

View File

@ -1,11 +1,5 @@
package org.eclipse.jetty.io;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
@ -30,42 +24,25 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class SelectChannelEndPointTest
{
protected volatile AsyncEndPoint _lastEndp;
protected ServerSocketChannel _connector;
protected QueuedThreadPool _threadPool = new QueuedThreadPool();
private int maxIdleTimeout = 600000; // TODO: use smaller value
protected SelectorManager _manager = new SelectorManager()
{
@Override
protected int getMaxIdleTime()
{
return maxIdleTimeout;
}
@Override
protected void execute(Runnable task)
{
_threadPool.execute(task);
}
@Override
protected void endPointClosed(AsyncEndPoint endpoint)
{
}
@Override
protected void endPointOpened(AsyncEndPoint endpoint)
{
endpoint.getAsyncConnection().onOpen();
}
@Override
protected void endPointUpgraded(AsyncEndPoint endpoint, AsyncConnection oldConnection)
{
}
@Override
public AsyncConnection newConnection(SocketChannel channel, AsyncEndPoint endpoint, Object attachment)
{
@ -81,6 +58,9 @@ public class SelectChannelEndPointTest
return endp;
}
};
{
_manager.setMaxIdleTime(600000); // TODO: use smaller value
}
// Must be volatile or the test may fail spuriously
protected volatile int _blockAt=0;
@ -350,12 +330,12 @@ public class SelectChannelEndPointTest
_blockAt=10;
clientOutputStream.write("12345678".getBytes("UTF-8"));
clientOutputStream.flush();
while(_lastEndp==null);
_lastEndp.setMaxIdleTime(10*specifiedTimeout);
Thread.sleep((11*specifiedTimeout)/10);
long start=System.currentTimeMillis();
try
{
@ -367,7 +347,7 @@ public class SelectChannelEndPointTest
int elapsed = Long.valueOf(System.currentTimeMillis() - start).intValue();
Assert.assertThat("Expected timeout", elapsed, greaterThanOrEqualTo(3*specifiedTimeout/4));
}
// write remaining characters
clientOutputStream.write("90ABCDEF".getBytes("UTF-8"));
clientOutputStream.flush();
@ -538,13 +518,13 @@ public class SelectChannelEndPointTest
//if (latch.getCount()%1000==0)
// System.out.println(writes-latch.getCount());
latch.countDown();
}
}
catch(Throwable e)
{
long now = System.currentTimeMillis();
System.err.println("count="+count);
System.err.println("latch="+latch.getCount());
@ -552,7 +532,7 @@ public class SelectChannelEndPointTest
System.err.println("last="+(now-last));
System.err.println("endp="+_lastEndp);
System.err.println("conn="+_lastEndp.getAsyncConnection());
e.printStackTrace();
}
}
@ -581,7 +561,7 @@ public class SelectChannelEndPointTest
Assert.fail();
last=latch.getCount();
}
assertEquals(0,latch.getCount());
}

View File

@ -7,7 +7,6 @@ import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLSocket;
@ -32,38 +31,14 @@ public class SslConnectionTest
protected volatile AsyncEndPoint _lastEndp;
protected ServerSocketChannel _connector;
protected QueuedThreadPool _threadPool = new QueuedThreadPool();
private int maxIdleTimeout = 600000; // TODO: use smaller value
protected SelectorManager _manager = new SelectorManager()
{
@Override
protected int getMaxIdleTime()
{
return maxIdleTimeout;
}
@Override
protected void execute(Runnable task)
{
_threadPool.execute(task);
}
@Override
protected void endPointClosed(AsyncEndPoint endpoint)
{
}
@Override
protected void endPointOpened(AsyncEndPoint endpoint)
{
// System.err.println("endPointOpened");
endpoint.getAsyncConnection().onOpen();
}
@Override
protected void endPointUpgraded(AsyncEndPoint endpoint, AsyncConnection oldConnection)
{
}
@Override
public AsyncConnection newConnection(SocketChannel channel, AsyncEndPoint endpoint, Object attachment)
{
@ -89,12 +64,15 @@ public class SslConnectionTest
return endp;
}
};
{
_manager.setMaxIdleTime(600000); // TODO: use smaller value
}
// Must be volatile or the test may fail spuriously
protected volatile int _blockAt=0;
private volatile int _writeCount=1;
@BeforeClass
public static void initSslEngine() throws Exception
{
@ -147,7 +125,7 @@ public class SslConnectionTest
{
// System.err.println("onClose");
}
@Override
public synchronized void onFillable()
{
@ -171,7 +149,7 @@ public class SslConnectionTest
}
// System.err.println(BufferUtil.toDetailString(_in));
// Write everything
int l=_in.remaining();
if (l>0)
@ -181,7 +159,7 @@ public class SslConnectionTest
blockingWrite.get();
// System.err.println("wrote "+l);
}
// are we done?
if (endp.isInputShutdown())
{
@ -216,7 +194,7 @@ public class SslConnectionTest
public void testHelloWorld() throws Exception
{
//Log.getRootLogger().setDebugEnabled(true);
// Log.getRootLogger().setDebugEnabled(true);
Socket client = newClient();
// System.err.println("client="+client);
@ -225,24 +203,24 @@ public class SslConnectionTest
SocketChannel server = _connector.accept();
server.configureBlocking(false);
_manager.accept(server);
client.getOutputStream().write("HelloWorld".getBytes("UTF-8"));
// System.err.println("wrote");
byte[] buffer = new byte[1024];
int len = client.getInputStream().read(buffer);
// System.err.println(new String(buffer,0,len,"UTF-8"));
client.close();
}
@Test
@Ignore
public void testNasty() throws Exception
{
//Log.getRootLogger().setDebugEnabled(true);
// Log.getRootLogger().setDebugEnabled(true);
final Socket client = newClient();
// System.err.println("client="+client);
@ -251,7 +229,7 @@ public class SslConnectionTest
SocketChannel server = _connector.accept();
server.configureBlocking(false);
_manager.accept(server);
new Thread()
{
public void run()
@ -277,7 +255,7 @@ public class SslConnectionTest
}
}
}.start();
for (int i=0;i<100000;i++)
{
client.getOutputStream().write(("HelloWorld "+i+"\n").getBytes("UTF-8"));
@ -285,10 +263,10 @@ public class SslConnectionTest
if (i%1000==0)
Thread.sleep(10);
}
Thread.sleep(20000);
client.close();
}

View File

@ -131,7 +131,7 @@ public abstract class AbstractConnector extends AggregateLifeCycle implements Co
{
return _byteBufferPool;
}
/* ------------------------------------------------------------ */
public void setByteBufferPool(ByteBufferPool byteBufferPool)
{
@ -174,7 +174,7 @@ public abstract class AbstractConnector extends AggregateLifeCycle implements Co
public void open() throws IOException
{
}
/* ------------------------------------------------------------ */
public void close() throws IOException
{
@ -185,13 +185,13 @@ public abstract class AbstractConnector extends AggregateLifeCycle implements Co
{
return -1;
}
/* ------------------------------------------------------------ */
/**
* @return Returns the maxIdleTime.
*/
@Override
public int getMaxIdleTime()
public long getMaxIdleTime()
{
return _maxIdleTime;
}
@ -278,10 +278,10 @@ public abstract class AbstractConnector extends AggregateLifeCycle implements Co
if (_name==null)
_name = (getHost() == null?"0.0.0.0":getHost()) + ":" + getPort();
// open listener port
open();
_name=_name+"/"+getLocalPort();
super.doStart();
@ -316,7 +316,7 @@ public abstract class AbstractConnector extends AggregateLifeCycle implements Co
if (thread != null)
thread.interrupt();
}
int i=_name.lastIndexOf("/");
if (i>0)
_name=_name.substring(0,i);
@ -437,8 +437,6 @@ public abstract class AbstractConnector extends AggregateLifeCycle implements Co
/* ------------------------------------------------------------ */
protected void connectionOpened(AsyncConnection connection)
{
// TODO: should we dispatch the call to onOpen() to another thread ?
connection.onOpen();
_stats.connectionOpened();
}
@ -453,9 +451,6 @@ public abstract class AbstractConnector extends AggregateLifeCycle implements Co
/* ------------------------------------------------------------ */
protected void connectionClosed(AsyncConnection connection)
{
// TODO: should we dispatch the call to onClose() to another thread ?
connection.onClose();
long duration = System.currentTimeMillis() - connection.getEndPoint().getCreatedTimeStamp();
// TODO: remove casts to HttpConnection
int requests = (connection instanceof HttpConnection)?((HttpConnection)connection).getHttpChannel().getRequests():0;

View File

@ -4,11 +4,11 @@
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// The Eclipse Public License is available at
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// You may elect to redistribute this code under either of these licenses.
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.server;
@ -21,47 +21,47 @@ import org.eclipse.jetty.util.component.LifeCycle;
/** HTTP Connector.
* Implementations of this interface provide connectors for the HTTP protocol.
* A connector receives requests (normally from a socket) and calls the
* A connector receives requests (normally from a socket) and calls the
* handle method of the Handler object. These operations are performed using
* threads from the ThreadPool set on the connector.
*
*
* When a connector is registered with an instance of Server, then the server
* will set itself as both the ThreadPool and the Handler. Note that a connector
* can be used without a Server if a thread pool and handler are directly provided.
*
*
*/
public interface Connector extends LifeCycle
{
{
/* ------------------------------------------------------------ */
/**
* @return the name of the connector. Defaults to the HostName:port
*/
String getName();
/* ------------------------------------------------------------ */
Server getServer();
/* ------------------------------------------------------------ */
Executor findExecutor();
Executor findExecutor();
/* ------------------------------------------------------------ */
Executor getExecutor();
Executor getExecutor();
/* ------------------------------------------------------------ */
ByteBufferPool getByteBufferPool();
ByteBufferPool getByteBufferPool();
/* ------------------------------------------------------------ */
/**
* @return Max Idle time for connections in milliseconds
*/
int getMaxIdleTime();
long getMaxIdleTime();
/* ------------------------------------------------------------ */
/**
* @return the underlying socket, channel, buffer etc. for the connector.
*/
Object getTransport();
/* ------------------------------------------------------------ */
Statistics getStatistics();
@ -69,28 +69,28 @@ public interface Connector extends LifeCycle
{
/* ------------------------------------------------------------ */
/**
* Opens the connector
* Opens the connector
* @throws IOException
*/
void open() throws IOException;
/* ------------------------------------------------------------ */
void close();
/* ------------------------------------------------------------ */
/**
* @return The hostname representing the interface to which
* @return The hostname representing the interface to which
* this connector will bind, or null for all interfaces.
*/
String getHost();
/* ------------------------------------------------------------ */
/**
* @return The configured port for the connector or 0 if any available
* port may be used.
*/
int getPort();
/* ------------------------------------------------------------ */
/**
* @return The actual port the connector is listening on or
@ -98,20 +98,20 @@ public interface Connector extends LifeCycle
*/
int getLocalPort();
}
interface Statistics extends LifeCycle
{
/* ------------------------------------------------------------ */
/**
/**
* @return True if statistics collection is turned on.
*/
boolean getStatsOn();
/* ------------------------------------------------------------ */
/** Reset statistics.
*/
void statsReset();
/* ------------------------------------------------------------ */
/**
* @return Get the number of messages received by this connector
@ -119,7 +119,7 @@ public interface Connector extends LifeCycle
* is undefined.
*/
public int getMessagesIn();
/* ------------------------------------------------------------ */
/**
* @return Get the number of messages sent by this connector
@ -127,7 +127,7 @@ public interface Connector extends LifeCycle
* is undefined.
*/
public int getMessagesOut();
/* ------------------------------------------------------------ */
/**
* @return Get the number of bytes received by this connector
@ -135,7 +135,7 @@ public interface Connector extends LifeCycle
* is undefined.
*/
public int getBytesIn();
/* ------------------------------------------------------------ */
/**
* @return Get the number of bytes sent by this connector
@ -151,42 +151,42 @@ public interface Connector extends LifeCycle
public long getConnectionsDurationTotal();
/* ------------------------------------------------------------ */
/**
/**
* @return Number of connections accepted by the server since
* statsReset() called. Undefined if setStatsOn(false).
*/
public int getConnections() ;
/* ------------------------------------------------------------ */
/**
/**
* @return Number of connections currently open that were opened
* since statsReset() called. Undefined if setStatsOn(false).
*/
public int getConnectionsOpen() ;
/* ------------------------------------------------------------ */
/**
/**
* @return Maximum number of connections opened simultaneously
* since statsReset() called. Undefined if setStatsOn(false).
*/
public int getConnectionsOpenMax() ;
/* ------------------------------------------------------------ */
/**
/**
* @return Maximum duration in milliseconds of an open connection
* since statsReset() called. Undefined if setStatsOn(false).
*/
public long getConnectionsDurationMax();
/* ------------------------------------------------------------ */
/**
/**
* @return Mean duration in milliseconds of open connections
* since statsReset() called. Undefined if setStatsOn(false).
*/
public double getConnectionsDurationMean() ;
/* ------------------------------------------------------------ */
/**
/**
* @return Standard deviation of duration in milliseconds of
* open connections since statsReset() called. Undefined if
* setStatsOn(false).
@ -194,28 +194,28 @@ public interface Connector extends LifeCycle
public double getConnectionsDurationStdDev() ;
/* ------------------------------------------------------------ */
/**
/**
* @return Mean number of messages received per connection
* since statsReset() called. Undefined if setStatsOn(false).
*/
public double getConnectionsMessagesInMean() ;
/* ------------------------------------------------------------ */
/**
/**
* @return Standard Deviation of number of messages received per connection
* since statsReset() called. Undefined if setStatsOn(false).
*/
public double getConnectionsMessagesInStdDev() ;
/* ------------------------------------------------------------ */
/**
/**
* @return Maximum number of messages received per connection
* since statsReset() called. Undefined if setStatsOn(false).
*/
public int getConnectionsMessagesInMax();
/* ------------------------------------------------------------ */
/**
/**
* @return Timestamp stats were started at.
*/
public long getStatsOnMs();

View File

@ -39,7 +39,7 @@ public class LocalHttpConnector extends HttpConnector
{
setMaxIdleTime(30000);
}
/* ------------------------------------------------------------ */
@Override
public Object getTransport()
@ -70,7 +70,7 @@ public class LocalHttpConnector extends HttpConnector
{
LOG.debug("getResponses");
Phaser phaser=_executor._phaser;
int phase = phaser.register(); // the corresponding arrival will be done by the acceptor thread when it takes
int phase = phaser.register(); // the corresponding arrival will be done by the acceptor thread when it takes
LocalEndPoint request = new LocalEndPoint();
request.setInput(requestsBuffer);
_connects.add(request);
@ -80,7 +80,7 @@ public class LocalHttpConnector extends HttpConnector
/* ------------------------------------------------------------ */
/**
* Execute a request and return the EndPoint through which
* Execute a request and return the EndPoint through which
* responses can be received.
* @param rawRequest
* @return
@ -88,7 +88,7 @@ public class LocalHttpConnector extends HttpConnector
public LocalEndPoint executeRequest(String rawRequest)
{
Phaser phaser=_executor._phaser;
int phase = phaser.register(); // the corresponding arrival will be done by the acceptor thread when it takes
int phase = phaser.register(); // the corresponding arrival will be done by the acceptor thread when it takes
LocalEndPoint endp = new LocalEndPoint();
endp.setInput(BufferUtil.toBuffer(rawRequest,StringUtil.__UTF8_CHARSET));
_connects.add(endp);
@ -106,7 +106,7 @@ public class LocalHttpConnector extends HttpConnector
connectionOpened(connection);
_executor._phaser.arriveAndDeregister(); // arrive for the register done in getResponses
}
/* ------------------------------------------------------------ */
@Override
protected void doStart() throws Exception
@ -141,14 +141,14 @@ public class LocalHttpConnector extends HttpConnector
{
return false;
}
};
final Executor _executor;
LocalExecutor(Executor e)
{
_executor=e;
}
@Override
public void execute(final Runnable task)
{
@ -167,7 +167,7 @@ public class LocalHttpConnector extends HttpConnector
{
_phaser.arriveAndDeregister();
}
}
}
});
}
}
@ -176,7 +176,7 @@ public class LocalHttpConnector extends HttpConnector
public class LocalEndPoint extends AsyncByteArrayEndPoint
{
private CountDownLatch _closed = new CountDownLatch(1);
LocalEndPoint()
{
super(getTimer());
@ -204,7 +204,6 @@ public class LocalHttpConnector extends HttpConnector
public void onClose()
{
super.onClose();
connectionClosed(getAsyncConnection());
_closed.countDown();
}
@ -237,5 +236,5 @@ public class LocalHttpConnector extends HttpConnector
}
}
}
}
}
}

View File

@ -70,7 +70,7 @@ public class SelectChannelConnector extends HttpConnector implements NetConnecto
this(Math.max(1,(Runtime.getRuntime().availableProcessors())/4),
Math.max(1,(Runtime.getRuntime().availableProcessors())/4));
}
/* ------------------------------------------------------------ */
public SelectChannelConnector(int acceptors, int selectors)
{
@ -78,7 +78,7 @@ public class SelectChannelConnector extends HttpConnector implements NetConnecto
_manager=new ConnectorSelectorManager(selectors);
addBean(_manager,true);
}
/* ------------------------------------------------------------ */
@Override
@ -210,7 +210,6 @@ public class SelectChannelConnector extends HttpConnector implements NetConnecto
/* ------------------------------------------------------------------------------- */
protected void endPointClosed(AsyncEndPoint endpoint)
{
endpoint.onClose();
connectionClosed(endpoint.getAsyncConnection());
}
@ -237,15 +236,16 @@ public class SelectChannelConnector extends HttpConnector implements NetConnecto
findExecutor().execute(task);
}
@Override
protected int getMaxIdleTime()
@Override
protected long getMaxIdleTime()
{
return SelectChannelConnector.this.getMaxIdleTime();
}
@Override
protected void endPointClosed(AsyncEndPoint endpoint)
{
super.endPointClosed(endpoint);
SelectChannelConnector.this.endPointClosed(endpoint);
}
@ -253,6 +253,7 @@ public class SelectChannelConnector extends HttpConnector implements NetConnecto
protected void endPointOpened(AsyncEndPoint endpoint)
{
// TODO handle max connections and low resources
super.endPointOpened(endpoint);
connectionOpened(endpoint.getAsyncConnection());
}

View File

@ -287,22 +287,6 @@ public class SPDYClient
return result;
}
@Override
protected void endPointOpened(AsyncEndPoint endpoint)
{
}
@Override
protected void endPointUpgraded(AsyncEndPoint endpoint, AsyncConnection oldConnection)
{
}
@Override
protected void endPointClosed(AsyncEndPoint endpoint)
{
endpoint.getAsyncConnection().onClose();
}
@Override
public AsyncConnection newConnection(final SocketChannel channel, AsyncEndPoint endPoint, Object attachment)
{

View File

@ -21,7 +21,6 @@ import java.nio.channels.SocketChannel;
import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.atomic.AtomicReference;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLException;
@ -51,36 +50,12 @@ public class WebSocketClientSelectorManager extends SelectorManager
this.executor = executor;
}
@Override
protected void endPointClosed(AsyncEndPoint endpoint)
{
endpoint.getAsyncConnection().onClose();
}
@Override
protected void endPointOpened(AsyncEndPoint endpoint)
{
}
@Override
protected void endPointUpgraded(AsyncEndPoint endpoint, AsyncConnection oldConnection)
{
// TODO Investigate role of this with websocket
}
@Override
protected void execute(Runnable task)
{
// TODO Auto-generated method stub
}
@Override
protected int getMaxIdleTime()
{
return 0;
}
public SslContextFactory getSslContextFactory()
{
return sslContextFactory;