Java Code Examples for org.eclipse.jetty.server.nio.NetworkTrafficSelectChannelConnector

Following code examples demonstrate how to use org.eclipse.jetty.server.nio.NetworkTrafficSelectChannelConnector from jetty. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.eclipse.jetty.server.nio.NetworkTrafficSelectChannelConnector and various code implementation of this class.

	public static void main(String[] args) throws Exception{
		Server server = new Server();
		
		NetworkTrafficSelectChannelConnector connector = new NetworkTrafficSelectChannelConnector(server);
		connector.setPort(9000);
		server.addConnector(connector);

		WebAppContext webapp = new WebAppContext();
		webapp.setContextPath("/test");
		webapp.setWar("/Users/chengda/jetty-learn/jetty/src/main/resources/test.war");
		
		server.setHandler(webapp);
		server.start();
		server.join();
	} 


	public static void main(String[] args) throws Exception{
		Server server = new Server();
		
		NetworkTrafficSelectChannelConnector connector = new NetworkTrafficSelectChannelConnector(server);
		connector.setPort(9000);
		
		server.addConnector(connector);
		
		ServletContextHandler context = new ServletContextHandler();
		context.setContextPath("/");
		
		server.setHandler(context);
		context.addServlet(HelloServlet.class, "/hello");
		
		context.addServlet(new ServletHolder(HiSevlet.class), "/hi");
		
		server.start();
		server.join();
	} 

	public static void main(String[] args) throws Exception{
		Server server = new Server();
		
		NetworkTrafficSelectChannelConnector connector = new NetworkTrafficSelectChannelConnector(server);
		connector.setPort(9000);
		
		server.addConnector(connector);
		
		ResourceHandler handler = new ResourceHandler();
		handler.setDirectoriesListed(true);
		handler.setWelcomeFiles(new String[]{"index.html"});

		handler.setResourceBase("/Users/chengda/Sites");
		handler.setEtags(true);
		server.setHandler(handler);
		
		server.start();
		server.join();
		
	} 

    public static void main(String[] args) {
        try {
            int port = 7001;

            Server server = new Server();
            NetworkTrafficSelectChannelConnector connector = new NetworkTrafficSelectChannelConnector(server);
            connector.setPort(port);
            server.addConnector(connector);

            server.setHandler(webApp);
            server.start();
        } catch (Exception ex) {
            Logger.getLogger(CalcServer.class.getName()).log(Level.SEVERE, null, ex);
        }
    } 

    private static void initServer() {
        try {
            server = new Server();
            NetworkTrafficSelectChannelConnector connector = new NetworkTrafficSelectChannelConnector(server);
            connector.setPort(port);
            server.addConnector(connector);

            ServletContextHandler webApp = new ServletContextHandler(server, "");
            server.setHandler(webApp);
            initServices(webApp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } 

    public static void main(String[] args) throws Exception {
        Server server = new Server();
        SslContextFactory sslContextFactory = new SslContextFactory(
                KEYSTORE_LOCATION);
        sslContextFactory.setKeyStorePassword(KEYSTORE_PASS);
        sslContextFactory.setTrustStorePath(TRUSTSTORE_LOCATION);
        sslContextFactory.setTrustStorePassword(TRUSTSTORE_PASS);
        sslContextFactory.setNeedClientAuth(true);
        NetworkTrafficSelectChannelConnector connector = new NetworkTrafficSelectChannelConnector(
                server, sslContextFactory);
        connector.setPort(8443);
        server.setConnectors(new Connector[] { connector });
        ServletContextHandler scHandler = new ServletContextHandler(server, "/");
        scHandler.addServlet(CatalogServlet.class, "/");
        server.start();
        server.join();
    } 

    public RegistryBandwidthUtilizationListener(Server server, Boolean isFederated, BandwidthMap map, IBandwidthBucketDao bucketDao) {
        
        this.setFederated(isFederated);
        this.lastRun = TimeUtil.currentTimeMillis();
        BandwidthRoute route = map.getRoute(network);
        this.bucketSize = route.getBucketSizeMinutes();
        this.bucketDao = bucketDao;
        String cron = getCronString(route.getBucketSizeMinutes());
        createQuartzCron(cron, network.name());
        
        for (Connector connector: server.getConnectors()) {
            if (connector instanceof NetworkTrafficSelectChannelConnector) {
                NetworkTrafficSelectChannelConnector nconnector = ((NetworkTrafficSelectChannelConnector)connector);
                nconnector.addNetworkTrafficListener(this);
                statusHandler.debug(nconnector.toString()+ " on Network: "+network);
            }
        }
    } 

    @Override
    public void projectOpened()
    {
        if (!ProjectUtils.hasRandoriModuleType(project))
            return;

        server = new Server();
        NetworkTrafficSelectChannelConnector connector = new NetworkTrafficSelectChannelConnector();
        connector.setServer(server);

        int portNr = component.getState().getPort();
        if (portNr < 0)
        {
            portNr = findFreePort();
            if (portNr < 0)
            {
                return;
            }
            component.getState().setPort(portNr);
        }

        connector.setPort(portNr);

        server.addConnector(connector);

        startServer(component.getState());
    } 

  protected void connectContainer() throws Exception {
    logger.info( "Connecting container." );
    this.moduleConfigurationHandle.checkEnvironmentVariables();
    Thread currentThread = Thread.currentThread();
    ClassLoader previousCcl = currentThread.getContextClassLoader();
    this.server = new Server();
    this.server.setStopTimeout(TimeUnit.SECONDS.toMillis(30));
    this.server.setStopAtShutdown(true);

    try {
      final ForwardedRequestCustomizer forwardedRequestCustomizer = new ForwardedRequestCustomizer();
      forwardedRequestCustomizer.setForwardedOnly(true);
      forwardedRequestCustomizer.setForwardedHeader(null);
      forwardedRequestCustomizer.setForwardedForHeader(HttpHeader.X_FORWARDED_FOR.toString());
      forwardedRequestCustomizer.setForwardedProtoHeader(HttpHeader.X_FORWARDED_PROTO.toString());
      final HttpConfiguration httpConfiguration = new HttpConfiguration();
      httpConfiguration.addCustomizer(forwardedRequestCustomizer);
      final HttpConnectionFactory connectionFactory = new HttpConnectionFactory(httpConfiguration);
      NetworkTrafficSelectChannelConnector connector = new NetworkTrafficSelectChannelConnector(this.server, null, null, null, 0, Runtime.getRuntime().availableProcessors(), connectionFactory );
      connector.setHost(this.address);
      connector.setPort(this.port);
      connector.open();
      this.server.addConnector(connector);
      this.port = connector.getLocalPort();
    } finally {
      currentThread.setContextClassLoader(previousCcl);
    }
  } 

Advertisement
Javadoc
@deprecated use org.eclipse.jetty.server.NetworkTrafficServerConnector instead.
Advertisement