Search in sources :

Example 1 with FutureHelper

use of org.webpieces.util.futures.FutureHelper in project webpieces by deanhiller.

the class TestFilters method testFilters.

/**
 * Filter demonstration.  Could make more advanced but this works great and I prefer KISS so
 * others that read it can understand it easier as it is already more complicated than I wish.
 * @throws ExecutionException
 * @throws InterruptedException
 */
@Test
public void testFilters() throws InterruptedException, ExecutionException {
    Filter.setFutureUtil(new FutureHelper());
    MyFilter filterMiddle = new MyFilter("middle");
    MyFilter filterTop = new MyFilter("top");
    Service<Integer, String> service2 = filterTop.chain(filterMiddle).chain(new SomeService());
    Service<Integer, String> x3 = filterMiddle.chain(filterTop).chain(new SomeService());
    XFuture<String> future = service2.invoke(5);
    String result = future.get();
    Assert.assertEquals("top", result);
    XFuture<String> future2 = x3.invoke(2);
    String result2 = future2.get();
    Assert.assertEquals("middle", result2);
}
Also used : FutureHelper(org.webpieces.util.futures.FutureHelper) Test(org.junit.Test)

Example 2 with FutureHelper

use of org.webpieces.util.futures.FutureHelper in project webpieces by deanhiller.

the class FrontEndServerManagerImpl method buildDatalListener.

private Layer1ServerListener buildDatalListener(StreamListener httpListener, boolean isBackend) {
    ProxyStreamListener proxyStreamListener = new ProxyStreamListener(httpListener);
    Layer2Http11Handler http11 = new Layer2Http11Handler(httpParser, proxyStreamListener);
    Layer2Http2Handler http2 = new Layer2Http2Handler(http2EngineFactory, proxyStreamListener);
    FutureHelper futureUtil = new FutureHelper();
    Layer1ServerListener listener = new Layer1ServerListener(futureUtil, http11, http2, isBackend);
    return listener;
}
Also used : FutureHelper(org.webpieces.util.futures.FutureHelper)

Example 3 with FutureHelper

use of org.webpieces.util.futures.FutureHelper in project webpieces by deanhiller.

the class WebServerFactory method create.

public static WebServer create(WebServerConfig config, RouterConfig routerConfig, TemplateConfig templateConfig, Arguments args) {
    if (!routerConfig.getMetaFile().exists())
        throw new RuntimeException("file not found=" + routerConfig.getMetaFile());
    try {
        // logback called getLocalhost(resulting in 5 seconds)
        // H2 called getLocalHost like 3 times(resulting in 15 more seconds)
        // overall, it really screwed the startup time!!
        // https://stackoverflow.com/questions/33289695/inetaddress-getlocalhost-slow-to-run-30-seconds/33289897#33289897
        log.info("Checking timing on getLocalHost (seems very bad on many MAC computers) which makes webpieces startup look slow(and we like a fast startup");
        long start = System.currentTimeMillis();
        InetAddress.getLocalHost();
        long totalTimeSeconds = (System.currentTimeMillis() - start) / 1000;
        if (totalTimeSeconds > 3)
            throw new IllegalStateException("Your computer configuration is messed up.  getLocalHost " + "is taking longer\nthan 3 seconds.  FIX THIS NOW!!!  You can typically edit your hosts file\n" + "to do so.  See https://stackoverflow.com/questions/33289695/inetaddress-getlocalhost-slow-to-run-30-seconds/33289897#33289897 for more info");
    } catch (UnknownHostException e) {
        throw SneakyThrow.sneak(e);
    }
    Module allModules = getModules(config, routerConfig, templateConfig, args);
    Module platformOverrides = config.getPlatformOverrides();
    if (platformOverrides != null)
        allModules = Modules.override(allModules).with(platformOverrides);
    Injector injector = Guice.createInjector(allModules);
    WebServerImpl serverImpl = injector.getInstance(WebServerImpl.class);
    // special case and I HATE statics but if customer swapped in their own FutureUtil, then we replace it with theirs here.  If they didn't
    // this literally just sets the same FutureUtil into the filters
    FutureHelper util = injector.getInstance(FutureHelper.class);
    Filter.setFutureUtil(util);
    // configure must be called as after configured, Arguments.checkConsumedCorrectly must
    serverImpl.configureSync(args);
    // be called before start is called on the webserver
    return serverImpl;
}
Also used : FutureHelper(org.webpieces.util.futures.FutureHelper) UnknownHostException(java.net.UnknownHostException) Injector(com.google.inject.Injector) WebServerImpl(org.webpieces.webserver.impl.WebServerImpl) Module(com.google.inject.Module) WebServerModule(org.webpieces.webserver.impl.WebServerModule) ProdTemplateModule(org.webpieces.templating.api.ProdTemplateModule) ProdRouterModule(org.webpieces.router.api.ProdRouterModule)

Aggregations

FutureHelper (org.webpieces.util.futures.FutureHelper)3 Injector (com.google.inject.Injector)1 Module (com.google.inject.Module)1 UnknownHostException (java.net.UnknownHostException)1 Test (org.junit.Test)1 ProdRouterModule (org.webpieces.router.api.ProdRouterModule)1 ProdTemplateModule (org.webpieces.templating.api.ProdTemplateModule)1 WebServerImpl (org.webpieces.webserver.impl.WebServerImpl)1 WebServerModule (org.webpieces.webserver.impl.WebServerModule)1