当前位置: 首页>>代码示例>>Java>>正文


Java WebSocketHandler类代码示例

本文整理汇总了Java中org.eclipse.jetty.websocket.server.WebSocketHandler的典型用法代码示例。如果您正苦于以下问题:Java WebSocketHandler类的具体用法?Java WebSocketHandler怎么用?Java WebSocketHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


WebSocketHandler类属于org.eclipse.jetty.websocket.server包,在下文中一共展示了WebSocketHandler类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: start

import org.eclipse.jetty.websocket.server.WebSocketHandler; //导入依赖的package包/类
public static void start(@Nonnull Config config, @Nonnull List<Handler> extraHandlers,
		@Nonnull WebSocketCreator creator) throws Exception {
	checkNotNull(config);
	checkNotNull(creator);

	long idleTimeout = config.getTime("webserver.idleTimeout", "10m");
	int maxTextMessageSize = config.getInt("webserver.maxTextMessageSize", 1024 * 1024);

	HandlerList handlers = new HandlerList();
	handlers.addHandler(new WebSocketHandler() {
		@Override
		public void configure(WebSocketServletFactory factory) {
			factory.getPolicy().setIdleTimeout(idleTimeout);
			factory.getPolicy().setMaxTextMessageSize(maxTextMessageSize);
			factory.setCreator(creator);
		}
	});
	for (Handler handler : extraHandlers) {
		handlers.addHandler(handler);
	}

	Server server = new Server(config.getInt("webserver.port", 8034));
	server.setHandler(handlers);
	server.start();
}
 
开发者ID:lithiumtech,项目名称:flow,代码行数:26,代码来源:JettyServer.java

示例2: addWebSocket

import org.eclipse.jetty.websocket.server.WebSocketHandler; //导入依赖的package包/类
@Signature
public void addWebSocket(Environment env, String path, ArrayMemory _handlers) {
    WebSocketParam param = _handlers.toBean(env, WebSocketParam.class);

    ContextHandler contextHandler = new ContextHandler(path);
    contextHandler.setHandler(new WebSocketHandler() {
        @Override
        public void configure(WebSocketServletFactory factory) {
            factory.setCreator(new WebSocketCreator() {
                @Override
                public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp) {
                    return new WebSocket(env, param);
                }
            });
        }
    });

    handlers.addHandler(contextHandler);
}
 
开发者ID:jphp-compiler,项目名称:jphp,代码行数:20,代码来源:PHttpServer.java

示例3: getWebSocketHandler

import org.eclipse.jetty.websocket.server.WebSocketHandler; //导入依赖的package包/类
@Override
public WebSocketHandler getWebSocketHandler() {
    return new WebSocketHandler() {
        @Override
        public void configure(WebSocketServletFactory factory) {
            factory.register(EchoSocket.class);
        }
    };
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:10,代码来源:ProxyTunnellingTest.java

示例4: setupServer

import org.eclipse.jetty.websocket.server.WebSocketHandler; //导入依赖的package包/类
private static Server setupServer() throws Exception {
    // String webDir = "target/classes/webui";
    // String webDir = "src/main/resources/webui";
    String webDir = WebServer.class.getClassLoader().getResource("webui").toExternalForm();
    log.info("Base webdir is {}", webDir);

    int httpPort = ConfigFactory.load().getInt("resource-reporting.visualization.webui-port");
    log.info("Resource reporting web ui port is ", httpPort);

    // Create Jetty server
    Server server = new Server(httpPort);

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    resource_handler.setWelcomeFiles(new String[] { "filter.html" });
    resource_handler.setResourceBase(webDir);

    WebSocketHandler wsHandler = new WebSocketHandler.Simple(PubSubProxyWebSocket.class);

    ContextHandler context = new ContextHandler();
    context.setContextPath("/ws");
    context.setHandler(wsHandler);

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { context, resource_handler, new DefaultHandler() });

    server.setHandler(handlers);

    ClusterResources.subscribeToAll(callback);

    return server;
}
 
开发者ID:brownsys,项目名称:tracing-framework,代码行数:33,代码来源:WebServer.java

示例5: init

import org.eclipse.jetty.websocket.server.WebSocketHandler; //导入依赖的package包/类
private static void init() {
    middlewares = new LinkedHashSet<>();
    server = new Server(PORT);
    try {
        server.dump(System.err);
    } catch (IOException e) {
        e.printStackTrace();
    }

    HandlerCollection handlerCollection = new HandlerCollection();

    WebSocketHandler wsHandler = new WebSocketHandler() {
        @Override
        public void configure(WebSocketServletFactory factory) {
            factory.register(BRGeoWebSocketHandler.class);
        }
    };

    ServerHandler serverHandler = new ServerHandler();
    handlerCollection.addHandler(serverHandler);
    handlerCollection.addHandler(wsHandler);

    server.setHandler(handlerCollection);

    setupIntegrations();

}
 
开发者ID:breadwallet,项目名称:breadwallet-android,代码行数:28,代码来源:HTTPServer.java

示例6: start

import org.eclipse.jetty.websocket.server.WebSocketHandler; //导入依赖的package包/类
public void start() {

        // create and configure embedded jetty server
        Server server = new Server(8080);

        // create resource handler for static content
        ResourceHandler resourceHandler = new ResourceHandler();
        resourceHandler.setDirectoriesListed(false);
        resourceHandler.setWelcomeFiles(new String[]{"index.html"});
        String webDir = this.getClass().getClassLoader().getResource("/html").toExternalForm();
        resourceHandler.setResourceBase(webDir);
        ContextHandler resourceContext = new ContextHandler();
        resourceContext.setContextPath("/");
        resourceContext.setHandler(resourceHandler);

        // create resource handler for track
        TrackHandler trackHandler = new TrackHandler(track);
        ContextHandler trackContext = new ContextHandler();
        trackContext.setContextPath("/track/");
        trackContext.setHandler(trackHandler);

        // create websocket handler
        WebSocketHandler wsHandler = new WebSocketHandler() {
            @Override
            public void configure(WebSocketServletFactory factory) {
                factory.getPolicy().setIdleTimeout(60 * 60 * 1000);
                factory.setCreator(
                        (servletUpgradeRequest, servletUpgradeResponse)
                                -> new WebSocketAdapter(webServer));
            }
        };
        ContextHandler websocketContext = new ContextHandler();
        websocketContext.setContextPath("/ws");
        websocketContext.setHandler(wsHandler);

        // add resource handlers to the server.
        HandlerList handlers = new HandlerList();
        handlers.setHandlers(new Handler[]{trackContext, resourceContext, websocketContext, new DefaultHandler()});
        server.setHandler(handlers);

        // start jetty
        try {
            server.start();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
 
开发者ID:slintes,项目名称:Webracer,代码行数:49,代码来源:WebServerStarter.java

示例7: start

import org.eclipse.jetty.websocket.server.WebSocketHandler; //导入依赖的package包/类
public void start(boolean block) throws Exception {
	
	this.server = new Server();
	ServerConnector connector = new ServerConnector(server);
	connector.setPort(getPort());
	connector.setReuseAddress(true);
	server.addConnector(connector);   
	
	// We enable sessions on the server so that 
	// we can cache LoaderFactories to a given session.
	// The loader factory therefore needs a non-global 
	// data soft reference cache.
	ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
	context.setContextPath("/");
	server.setHandler(context);
     
       // Make individual servlets
       // Slicing (large data in binary http)
	ServletHolder holderSlice = new ServletHolder("slice", SliceServlet.class);
	context.addServlet(holderSlice, "/slice/*");
	
	// Doing events, like data changing shape.
	// FIXME Should not be needed
	WebSocketHandler wsHandler = new WebSocketHandler() {
		@Override
		public void configure(WebSocketServletFactory factory) {
			factory.register(FileMonitorSocket.class);
		}
	};
	context.setHandler(wsHandler);
	// FIXME End should not be needed.		
	
	ServletHolder holderInfo = new ServletHolder("info", InfoServlet.class);
	context.addServlet(holderInfo, "/info/*");
	
	ServletHolder holderTree = new ServletHolder("tree", TreeServlet.class);
	context.addServlet(holderTree, "/tree/*");

    
	// Events json objects to notify of problems.
	ServletHolder holderEvent = new ServletHolder("event", EventServlet.class);
	context.addServlet(holderEvent, "/event/*");
	
    server.start();
    if (block) server.join();

}
 
开发者ID:eclipse,项目名称:dawnsci,代码行数:48,代码来源:DataServer.java

示例8: getWebSocketHandler

import org.eclipse.jetty.websocket.server.WebSocketHandler; //导入依赖的package包/类
public abstract WebSocketHandler getWebSocketHandler(); 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:2,代码来源:AbstractBasicTest.java


注:本文中的org.eclipse.jetty.websocket.server.WebSocketHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。