use of org.eclipse.jetty.util.thread.Scheduler in project dropwizard by dropwizard.
the class HttpConnectorFactory method build.
@Override
public Connector build(Server server, MetricRegistry metrics, String name, ThreadPool threadPool) {
final HttpConfiguration httpConfig = buildHttpConfiguration();
final HttpConnectionFactory httpConnectionFactory = buildHttpConnectionFactory(httpConfig);
final Scheduler scheduler = new ScheduledExecutorScheduler();
final ByteBufferPool bufferPool = buildBufferPool();
return buildConnector(server, scheduler, bufferPool, name, threadPool, new Jetty93InstrumentedConnectionFactory(httpConnectionFactory, metrics.timer(httpConnections())));
}
use of org.eclipse.jetty.util.thread.Scheduler in project jetty.project by eclipse.
the class HTTP2ClientConnectionFactory method newConnection.
@Override
public Connection newConnection(EndPoint endPoint, Map<String, Object> context) throws IOException {
HTTP2Client client = (HTTP2Client) context.get(CLIENT_CONTEXT_KEY);
ByteBufferPool byteBufferPool = (ByteBufferPool) context.get(BYTE_BUFFER_POOL_CONTEXT_KEY);
Executor executor = (Executor) context.get(EXECUTOR_CONTEXT_KEY);
Scheduler scheduler = (Scheduler) context.get(SCHEDULER_CONTEXT_KEY);
Session.Listener listener = (Session.Listener) context.get(SESSION_LISTENER_CONTEXT_KEY);
@SuppressWarnings("unchecked") Promise<Session> promise = (Promise<Session>) context.get(SESSION_PROMISE_CONTEXT_KEY);
Generator generator = new Generator(byteBufferPool);
FlowControlStrategy flowControl = client.getFlowControlStrategyFactory().newFlowControlStrategy();
HTTP2ClientSession session = new HTTP2ClientSession(scheduler, endPoint, generator, listener, flowControl);
Parser parser = new Parser(byteBufferPool, session, 4096, 8192);
HTTP2ClientConnection connection = new HTTP2ClientConnection(client, byteBufferPool, executor, endPoint, parser, session, client.getInputBufferSize(), promise, listener);
connection.addListener(connectionListener);
return customize(connection, context);
}
use of org.eclipse.jetty.util.thread.Scheduler in project jetty.project by eclipse.
the class HouseKeeper method findScheduler.
/**
* Get a scheduler. First try a common scheduler, failing that
* create our own.
*
* @throws Exception
*/
protected void findScheduler() throws Exception {
if (_scheduler == null) {
if (_sessionIdManager instanceof DefaultSessionIdManager) {
//try and use a common scheduler, fallback to own
_scheduler = ((DefaultSessionIdManager) _sessionIdManager).getServer().getBean(Scheduler.class);
}
if (_scheduler == null) {
_scheduler = new ScheduledExecutorScheduler();
_ownScheduler = true;
_scheduler.start();
if (LOG.isDebugEnabled())
LOG.debug("Using own scheduler for scavenging");
} else if (!_scheduler.isStarted())
throw new IllegalStateException("Shared scheduler not started");
}
}
use of org.eclipse.jetty.util.thread.Scheduler in project jetty.project by eclipse.
the class ThreadStarvationTest method params.
@Parameterized.Parameters(name = "{0}")
public static List<Object[]> params() {
List<Object[]> params = new ArrayList<>();
// HTTP
ConnectorProvider http = (server, acceptors, selectors) -> new ServerConnector(server, acceptors, selectors);
ClientSocketProvider httpClient = (host, port) -> new Socket(host, port);
params.add(new Object[] { "http", http, httpClient });
// HTTPS/SSL/TLS
ConnectorProvider https = (server, acceptors, selectors) -> {
Path keystorePath = MavenTestingUtils.getTestResourcePath("keystore");
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath(keystorePath.toString());
sslContextFactory.setKeyStorePassword("storepwd");
sslContextFactory.setKeyManagerPassword("keypwd");
sslContextFactory.setTrustStorePath(keystorePath.toString());
sslContextFactory.setTrustStorePassword("storepwd");
ByteBufferPool pool = new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged());
HttpConnectionFactory httpConnectionFactory = new HttpConnectionFactory();
ServerConnector connector = new ServerConnector(server, (Executor) null, (Scheduler) null, pool, acceptors, selectors, AbstractConnectionFactory.getFactories(sslContextFactory, httpConnectionFactory));
SecureRequestCustomizer secureRequestCustomer = new SecureRequestCustomizer();
secureRequestCustomer.setSslSessionAttribute("SSL_SESSION");
httpConnectionFactory.getHttpConfiguration().addCustomizer(secureRequestCustomer);
return connector;
};
ClientSocketProvider httpsClient = new ClientSocketProvider() {
private SSLContext sslContext;
{
try {
HttpsURLConnection.setDefaultHostnameVerifier((hostname, session) -> true);
sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, SslContextFactory.TRUST_ALL_CERTS, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
@Override
public Socket newSocket(String host, int port) throws IOException {
return sslContext.getSocketFactory().createSocket(host, port);
}
};
params.add(new Object[] { "https/ssl/tls", https, httpsClient });
return params;
}
use of org.eclipse.jetty.util.thread.Scheduler in project jetty.project by eclipse.
the class ResponseTest method init.
@Before
public void init() throws Exception {
_server = new Server();
Scheduler _scheduler = new TimerScheduler();
HttpConfiguration config = new HttpConfiguration();
LocalConnector connector = new LocalConnector(_server, null, _scheduler, null, 1, new HttpConnectionFactory(config));
_server.addConnector(connector);
_server.setHandler(new DumpHandler());
_server.start();
AbstractEndPoint endp = new ByteArrayEndPoint(_scheduler, 5000) {
@Override
public InetSocketAddress getLocalAddress() {
return LOCALADDRESS;
}
};
_channel = new HttpChannel(connector, new HttpConfiguration(), endp, new HttpTransport() {
private Throwable _channelError;
@Override
public void send(MetaData.Response info, boolean head, ByteBuffer content, boolean lastContent, Callback callback) {
if (_channelError == null)
callback.succeeded();
else
callback.failed(_channelError);
}
@Override
public boolean isPushSupported() {
return false;
}
@Override
public void push(org.eclipse.jetty.http.MetaData.Request request) {
}
@Override
public void onCompleted() {
}
@Override
public void abort(Throwable failure) {
_channelError = failure;
}
@Override
public boolean isOptimizedForDirectBuffers() {
return false;
}
});
}
Aggregations