jetty-9 finished refactor for oneconnector and configuration pluggability

This commit is contained in:
Greg Wilkins 2012-09-13 10:00:44 +10:00
parent a41b6e32ac
commit c709981aa5
11 changed files with 46 additions and 25 deletions

View File

@ -87,7 +87,7 @@ public class ManyConnectors
HTTPSPDYServerConnectionFactory spdy3 = new HTTPSPDYServerConnectionFactory(3,config,push);
spdy2.setInputBufferSize(8192);
NPNServerConnectionFactory npn = new NPNServerConnectionFactory(http.getProtocol(),spdy2.getProtocol(),spdy3.getProtocol());
NPNServerConnectionFactory npn = new NPNServerConnectionFactory(spdy3.getProtocol(),spdy2.getProtocol(),http.getProtocol());
npn.setDefaultProtocol(http.getProtocol());
npn.setInputBufferSize(1024);

View File

@ -421,6 +421,9 @@ public class SslConnection extends AbstractConnection
if (a.getInputBufferSize()<_sslEngine.getSession().getApplicationBufferSize());
a.setInputBufferSize(_sslEngine.getSession().getApplicationBufferSize());
}
connection.onOpen();
super.setConnection(connection);
}

View File

@ -324,9 +324,9 @@ public abstract class AbstractConnector extends AggregateLifeCycle implements Co
public void setDefaultProtocol(String defaultProtocol)
{
if(isRunning())
throw new IllegalStateException(getState());
_defaultProtocol = defaultProtocol.toLowerCase();
if (isRunning())
_defaultConnectionFactory=getConnectionFactory(_defaultProtocol);
}
@Override

View File

@ -86,8 +86,6 @@ public class SslConnectionFactory extends AbstractConnectionFactory
Connection connection = next.newConnection(connector, decrypted_endp);
decrypted_endp.setConnection(connection);
connection.onOpen();
return sslConnection;
}

View File

@ -31,6 +31,7 @@ import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.spdy.NPNServerConnectionFactory;
import org.eclipse.jetty.spdy.SPDYServerConnector;
import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.http.PushStrategy.None;
import org.eclipse.jetty.util.ssl.SslContextFactory;
public class HTTPSPDYServerConnector extends SelectChannelConnector
@ -54,18 +55,27 @@ public class HTTPSPDYServerConnector extends SelectChannelConnector
{
this(server,new HttpChannelConfig(),sslContextFactory,pushStrategies);
}
public HTTPSPDYServerConnector(Server server, short version, HttpChannelConfig httpChannelConfig, PushStrategy push)
{
super(server,new HTTPSPDYServerConnectionFactory(version,httpChannelConfig,push));
}
public HTTPSPDYServerConnector(Server server, HttpChannelConfig config, SslContextFactory sslContextFactory, Map<Short, PushStrategy> pushStrategies)
{
super(server,AbstractConnectionFactory.getFactories(sslContextFactory,
sslContextFactory==null
?new ConnectionFactory[] {new HttpConnectionFactory(config)}
:new ConnectionFactory[] {new NPNServerConnectionFactory("http/1.1","spdy/3","spdy/2"),
:new ConnectionFactory[] {new NPNServerConnectionFactory("spdy/3","spdy/2","http/1.1"),
new HttpConnectionFactory(config),
new HTTPSPDYServerConnectionFactory(SPDY.V3,new HttpChannelConfig(),getPushStrategy(SPDY.V3, pushStrategies)),
new HTTPSPDYServerConnectionFactory(SPDY.V2,new HttpChannelConfig(),getPushStrategy(SPDY.V2, pushStrategies))}));
if (getConnectionFactory(NPNServerConnectionFactory.class)!=null)
getConnectionFactory(NPNServerConnectionFactory.class).setDefaultProtocol("http/1.1");
}
private static PushStrategy getPushStrategy(short version, Map<Short, PushStrategy> pushStrategies)
{
PushStrategy pushStrategy = pushStrategies.get(version);

View File

@ -93,10 +93,7 @@ public abstract class AbstractHTTPSPDYTest
protected HTTPSPDYServerConnector newHTTPSPDYServerConnector(short version)
{
// For these tests, we need the connector to speak HTTP over SPDY even in non-SSL
HTTPSPDYServerConnector connector = new HTTPSPDYServerConnector(server);
ConnectionFactory defaultFactory = new HTTPSPDYServerConnectionFactory(version,new HttpChannelConfig(), new PushStrategy.None());
connector.addConnectionFactory(defaultFactory);
connector.setDefaultProtocol(defaultFactory.getProtocol()); // TODO I don't think this is right
HTTPSPDYServerConnector connector = new HTTPSPDYServerConnector(server,version,new HttpChannelConfig(), new PushStrategy.None());
return connector;
}

View File

@ -31,6 +31,7 @@ import org.eclipse.jetty.server.ConnectionFactory;
import org.eclipse.jetty.server.HttpChannelConfig;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.spdy.NPNServerConnectionFactory;
import org.eclipse.jetty.spdy.SPDYServerConnector;
import org.eclipse.jetty.spdy.api.DataInfo;
import org.eclipse.jetty.spdy.api.ReplyInfo;
@ -57,10 +58,8 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
@Override
protected HTTPSPDYServerConnector newHTTPSPDYServerConnector(short version)
{
HTTPSPDYServerConnector connector = super.newHTTPSPDYServerConnector(version);
ConnectionFactory defaultFactory = new HTTPSPDYServerConnectionFactory(version,new HttpChannelConfig(), new ReferrerPushStrategy());
connector.addConnectionFactory(defaultFactory);
connector.setDefaultProtocol(defaultFactory.getProtocol()); // TODO I don't think this is right
HTTPSPDYServerConnector connector =
new HTTPSPDYServerConnector(server,version,new HttpChannelConfig(),new ReferrerPushStrategy());
return connector;
}
@ -74,6 +73,11 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
pushStrategy.setReferrerPushPeriod(referrerPushPeriod);
ConnectionFactory defaultFactory = new HTTPSPDYServerConnectionFactory(version,new HttpChannelConfig(), pushStrategy);
connector.addConnectionFactory(defaultFactory);
if (connector.getConnectionFactory(NPNServerConnectionFactory.class)!=null)
connector.getConnectionFactory(NPNServerConnectionFactory.class).setDefaultProtocol(defaultFactory.getProtocol());
else
connector.setDefaultProtocol(defaultFactory.getProtocol());
connector.setDefaultProtocol(defaultFactory.getProtocol()); // TODO I don't think this is right
Fields mainRequestHeaders = createHeadersWithoutReferrer(mainResource);
@ -97,7 +101,10 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
pushStrategy.setReferrerPushPeriod(referrerPushPeriod);
ConnectionFactory defaultFactory = new HTTPSPDYServerConnectionFactory(version,new HttpChannelConfig(), pushStrategy);
connector.addConnectionFactory(defaultFactory);
connector.setDefaultProtocol(defaultFactory.getProtocol()); // TODO I don't think this is right
if (connector.getConnectionFactory(NPNServerConnectionFactory.class)!=null)
connector.getConnectionFactory(NPNServerConnectionFactory.class).setDefaultProtocol(defaultFactory.getProtocol());
else
connector.setDefaultProtocol(defaultFactory.getProtocol());
Fields mainRequestHeaders = createHeadersWithoutReferrer(mainResource);
Session session1 = sendMainRequestAndCSSRequest(address, mainRequestHeaders);

View File

@ -34,21 +34,14 @@ public class NPNServerConnectionFactory extends AbstractConnectionFactory
private final List<String> _protocols;
private String _defaultProtocol;
public NPNServerConnectionFactory()
{
this(new String[0]);
}
/* ------------------------------------------------------------ */
/**
* @param protocols List of supported protocols. The first of these is set as the default protocol
* @param protocols List of supported protocols in priority order
*/
public NPNServerConnectionFactory(String... protocols)
{
super("npn");
_protocols=Arrays.asList(protocols);
if (_protocols.size()>0)
_defaultProtocol=_protocols.get(0);
}
public String getDefaultProtocol()
@ -81,6 +74,10 @@ public class NPNServerConnectionFactory extends AbstractConnectionFactory
}
}
String dft=_defaultProtocol;
if (dft==null)
dft=_protocols.get(0);
return new NextProtoNegoServerConnection((DecryptedEndPoint)endPoint, connector,protocols,_defaultProtocol);
}

View File

@ -40,10 +40,13 @@ public class SPDYServerConnector extends SelectChannelConnector
sslContextFactory==null
?new ConnectionFactory[]{new SPDYServerConnectionFactory(SPDY.V2, listener)}
:new ConnectionFactory[]{
new NPNServerConnectionFactory("http/1.1","spdy/2","spdy/3"),
new NPNServerConnectionFactory("spdy/3","spdy/2","http/1.1"),
new HttpConnectionFactory(),
new SPDYServerConnectionFactory(SPDY.V2, listener),
new SPDYServerConnectionFactory(SPDY.V3, listener)});
if (getConnectionFactory(NPNServerConnectionFactory.class)!=null)
getConnectionFactory(NPNServerConnectionFactory.class).setDefaultProtocol("http/1.1");
}
}

View File

@ -73,6 +73,12 @@ public abstract class AbstractTest
connector.addConnectionFactory(spdy);
connector.setPort(0);
server.addConnector(connector);
if (connector.getConnectionFactory(NPNServerConnectionFactory.class)!=null)
connector.getConnectionFactory(NPNServerConnectionFactory.class).setDefaultProtocol(spdy.getProtocol());
else
connector.setDefaultProtocol(spdy.getProtocol());
server.start();
return new InetSocketAddress("localhost", connector.getLocalPort());
}

View File

@ -189,7 +189,7 @@ public class FlowControlTest extends AbstractTest
}
}
});
DataInfo dataInfo = exchanger.exchange(null, 5, TimeUnit.SECONDS);
checkThatWeAreFlowControlStalled(exchanger);