Search in sources :

Example 1 with HttpSvrConfig

use of org.webpieces.frontend2.api.HttpSvrConfig in project webpieces by deanhiller.

the class AbstractFrontendHttp2Test method setUp.

@Before
public void setUp() throws InterruptedException, ExecutionException, TimeoutException {
    MockTcpServerChannel svrChannel = new MockTcpServerChannel();
    mockChanMgr.addTCPSvrChannelToReturn(svrChannel);
    mockTcpChannel.setIncomingFrameDefaultReturnValue(XFuture.completedFuture(null));
    mockListener.setDefaultRetVal(mockStreamWriter);
    mockStreamWriter.setDefaultRetValToThis();
    Http2Config config = new Http2Config();
    config.setLocalSettings(localSettings);
    SimpleMeterRegistry metrics = new SimpleMeterRegistry();
    InjectionConfig injConfig = new InjectionConfig(mockTime, config, metrics);
    HttpSvrConfig frontendConfig = new HttpSvrConfig("http", new InetSocketAddress("me", 8080));
    HttpFrontendManager manager = HttpFrontendFactory.createFrontEnd(mockChanMgr, mockTimer, injConfig, Metrics.globalRegistry);
    HttpServer httpServer = manager.createHttpServer(frontendConfig, mockListener);
    httpServer.start();
    simulateClientConnecting();
    simulateClientSendingPrefaceAndSettings();
}
Also used : HttpFrontendManager(org.webpieces.frontend2.api.HttpFrontendManager) InetSocketAddress(java.net.InetSocketAddress) Http2Config(com.webpieces.http2engine.api.client.Http2Config) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) HttpServer(org.webpieces.frontend2.api.HttpServer) HttpSvrConfig(org.webpieces.frontend2.api.HttpSvrConfig) InjectionConfig(com.webpieces.http2engine.api.client.InjectionConfig) MockTcpServerChannel(org.webpieces.httpfrontend2.api.mock2.MockTcpServerChannel) Before(org.junit.Before)

Example 2 with HttpSvrConfig

use of org.webpieces.frontend2.api.HttpSvrConfig in project webpieces by deanhiller.

the class ServerFactory method createTestServer.

static int createTestServer(boolean alwaysHttp2, Long maxConcurrentStreams) {
    TwoPools pool = new TwoPools("pl", new SimpleMeterRegistry());
    ScheduledExecutorService timer = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory("webpieces-timer"));
    FrontendMgrConfig config = new FrontendMgrConfig();
    HttpFrontendManager frontEndMgr = HttpFrontendFactory.createFrontEnd("frontEnd", timer, pool, config, Metrics.globalRegistry);
    HttpSvrConfig svrConfig = new HttpSvrConfig("id2");
    HttpServer server = frontEndMgr.createHttpServer(svrConfig, new OurListener());
    XFuture<Void> fut = server.start();
    try {
        fut.get(2, TimeUnit.SECONDS);
    } catch (ExecutionException | InterruptedException | TimeoutException e) {
        throw SneakyThrow.sneak(e);
    }
    return server.getUnderlyingChannel().getLocalAddress().getPort();
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) HttpFrontendManager(org.webpieces.frontend2.api.HttpFrontendManager) TwoPools(org.webpieces.data.api.TwoPools) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) NamedThreadFactory(org.webpieces.util.threading.NamedThreadFactory) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) HttpSvrConfig(org.webpieces.frontend2.api.HttpSvrConfig) FrontendMgrConfig(org.webpieces.frontend2.api.FrontendMgrConfig) HttpServer(org.webpieces.frontend2.api.HttpServer) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 3 with HttpSvrConfig

use of org.webpieces.frontend2.api.HttpSvrConfig in project webpieces by deanhiller.

the class ServerAsync method createFrontend.

private HttpServer createFrontend() {
    if (config.getServerThreadCount() != null) {
        return createFrontendMultiThreaded();
    }
    log.info("Creating single threaded server");
    TwoPools pool = new TwoPools("pl", new SimpleMeterRegistry());
    ChannelManagerFactory factory = ChannelManagerFactory.createFactory(metrics);
    ChannelManager chanMgr = factory.createSingleThreadedChanMgr("svrCmLoop", pool, config.getBackpressureConfig());
    AsyncServerManager svrMgr = AsyncServerMgrFactory.createAsyncServer(chanMgr, metrics);
    HttpFrontendManager mgr = HttpFrontendFactory.createFrontEnd(svrMgr, pool, http2Config, new SimpleMeterRegistry());
    return mgr.createHttpServer(new HttpSvrConfig("asyncsvr"), new EchoListener());
}
Also used : ChannelManager(org.webpieces.nio.api.ChannelManager) HttpFrontendManager(org.webpieces.frontend2.api.HttpFrontendManager) TwoPools(org.webpieces.data.api.TwoPools) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) HttpSvrConfig(org.webpieces.frontend2.api.HttpSvrConfig) AsyncServerManager(org.webpieces.asyncserver.api.AsyncServerManager) ChannelManagerFactory(org.webpieces.nio.api.ChannelManagerFactory)

Example 4 with HttpSvrConfig

use of org.webpieces.frontend2.api.HttpSvrConfig in project webpieces by deanhiller.

the class ServerAsync method createFrontendMultiThreaded.

private HttpServer createFrontendMultiThreaded() {
    ScheduledExecutorService timer = Executors.newSingleThreadScheduledExecutor();
    FrontendMgrConfig frontendConfig = new FrontendMgrConfig();
    frontendConfig.setHttp2Config(http2Config);
    frontendConfig.setBackpressureConfig(config.getBackpressureConfig());
    frontendConfig.setThreadPoolSize(config.getServerThreadCount());
    log.info("Creating multithreaded server. threads=" + frontendConfig.getThreadPoolSize());
    HttpFrontendManager mgr = HttpFrontendFactory.createFrontEnd("deansvr", timer, new TwoPools("pl", new SimpleMeterRegistry()), frontendConfig, metrics);
    return mgr.createHttpServer(new HttpSvrConfig("asyncsvr"), new EchoListener());
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) FrontendMgrConfig(org.webpieces.frontend2.api.FrontendMgrConfig) HttpFrontendManager(org.webpieces.frontend2.api.HttpFrontendManager) TwoPools(org.webpieces.data.api.TwoPools) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) HttpSvrConfig(org.webpieces.frontend2.api.HttpSvrConfig)

Example 5 with HttpSvrConfig

use of org.webpieces.frontend2.api.HttpSvrConfig in project webpieces by deanhiller.

the class WebServerImpl method startServerOnHttpPort.

private XFuture<Void> startServerOnHttpPort(Injector injector, InetSocketAddress httpAddress, boolean httpsOverHttpEnabled) {
    XFuture<Void> fut1;
    String type;
    if (httpsOverHttpEnabled) {
        type = "both";
        // This is inside the if statement BECAUSE we do not need to bind an SSLConfiguration if they do not
        // enable the backend or https ports
        SSLEngineFactory factory = fetchSSLEngineFactory(injector);
        HttpSvrConfig httpSvrConfig = new HttpSvrConfig(type, httpAddress, 10000);
        httpSvrConfig.asyncServerConfig.functionToConfigureBeforeBind = s -> configure(s);
        httpServer = serverMgr.createUpgradableServer(httpSvrConfig, serverListener, factory);
    } else {
        type = "http";
        HttpSvrConfig httpSvrConfig = new HttpSvrConfig(type, httpAddress, 10000);
        httpSvrConfig.asyncServerConfig.functionToConfigureBeforeBind = s -> configure(s);
        httpServer = serverMgr.createHttpServer(httpSvrConfig, serverListener);
    }
    log.info("Created and now starting the '" + type + "' over port=" + httpAddress + "  'both' means this port supports both http and https");
    fut1 = httpServer.start();
    return fut1;
}
Also used : HttpSvrConfig(org.webpieces.frontend2.api.HttpSvrConfig) SSLEngineFactory(org.webpieces.nio.api.SSLEngineFactory)

Aggregations

HttpSvrConfig (org.webpieces.frontend2.api.HttpSvrConfig)9 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)6 HttpFrontendManager (org.webpieces.frontend2.api.HttpFrontendManager)6 HttpServer (org.webpieces.frontend2.api.HttpServer)4 Http2Config (com.webpieces.http2engine.api.client.Http2Config)3 InjectionConfig (com.webpieces.http2engine.api.client.InjectionConfig)3 InetSocketAddress (java.net.InetSocketAddress)3 Before (org.junit.Before)3 TwoPools (org.webpieces.data.api.TwoPools)3 MockTcpServerChannel (org.webpieces.httpfrontend2.api.mock2.MockTcpServerChannel)3 SSLEngineFactory (org.webpieces.nio.api.SSLEngineFactory)3 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 FrontendMgrConfig (org.webpieces.frontend2.api.FrontendMgrConfig)2 ExecutionException (java.util.concurrent.ExecutionException)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 TimeoutException (java.util.concurrent.TimeoutException)1 AsyncServerManager (org.webpieces.asyncserver.api.AsyncServerManager)1 ChannelManager (org.webpieces.nio.api.ChannelManager)1 ChannelManagerFactory (org.webpieces.nio.api.ChannelManagerFactory)1 SSLConfiguration (org.webpieces.nio.api.SSLConfiguration)1