Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package net.javapla.jawn.server;
 
 
public class UndertowServer implements JawnServer {
    
    public void setupAndStartServer(ServerConfig configthrows Exception {
        String filtername = "jawnFilter";
        // Setup the server application
        DeploymentInfo deployment = Servlets.deployment()
            .setClassLoader(UndertowServer.class.getClassLoader())
            .setContextPath(config.getContextPath())
            .setDeploymentName("test.war");
            
        // security
        //configureServerAuthentication(deployment, config);
            
            
        // Add the framework
        deployment
            .addFilter(Servlets.filter(filternameRequestDispatcher.class))
            .addFilterUrlMapping(filtername"/*".)
            
            
            // The resource folder to read from
            .setResourceManager(new FileResourceManager(new File(config.getWebappPath()), 100));
        
        // Make the server use the framework
        DeploymentManager manager = Servlets.defaultContainer().addDeployment(deployment);
        manager.deploy();
        
        // Start the server
        HttpHandler start = manager.start();
        Builder serverBuilder = Undertow.builder()
            .addHttpListener(config.getPort(), config.getHost())
            
            // from undertow-edge benchmark
            .setHandler(Handlers.header(start."Undertow"));
        
        configureServerPerformance(serverBuilderconfig);
            
        serverBuilder.build().start();
    }
    
    /*private void configureServerAuthentication(DeploymentInfo deployment, ServerConfig config) {
        if (config.useAuthentication()) {
            deployment
                .addListener(Servlets.listener(EnvironmentLoaderListener.class))
                .addFilter(Servlets.filter("shiro", ShiroFilter.class))
                .addFilterUrlMapping("shiro",config.getAuthenticationFilterUrlMapping(),DispatcherType.REQUEST);
        }
    }*/
    
    private void configureServerPerformance(Builder serverBuilderServerConfig config) {
        // TODO investigate serverBuilder.setWorkerThreads
        // Per default it gets set to ioThreads * 8, but it does not get updated, when setting ioThreads,
        // so we need to set it explicitly
        switch (config.getServerPerformance()) {
            case :
                serverBuilder.setIoThreads(Runtime.getRuntime().availableProcessors() * 2);
                break;
            case :
                serverBuilder.setIoThreads(Runtime.getRuntime().availableProcessors());
                break;
            case :
                serverBuilder.setIoThreads(Math.max(Runtime.getRuntime().availableProcessors() / 2, 2));
                break;
            case :
                serverBuilder.setIoThreads(2);//may not be less than 2 because of the inner workings of Undertow 
                break;
            case :
                serverBuilder.setIoThreads(Math.max(config.getIoThreads(), 2));
                break;
        }
    }
New to GrepCode? Check out our FAQ X