Java 类javax.websocket.server.ServerEndpointConfig.Configurator 实例源码

项目:OpenChatAlytics    文件:ServerMain.java   
/**
 *
 * @param context the context to add the web socket endpoints to
 * @param rtEventResource The instance of the websocket endpoint to return
 * @throws DeploymentException
 */
private static void setWebSocketEndpoints(ServletContextHandler context,
                                          EventsResource rtEventResource)
        throws DeploymentException, ServletException {

    ServerContainer wsContainer = WebSocketServerContainerInitializer.configureContext(context);

    ServerEndpointConfig serverConfig =
            ServerEndpointConfig.Builder
                                .create(EventsResource.class, EventsResource.RT_EVENT_ENDPOINT)
                                .configurator(new Configurator() {
                                    @Override
                                    public <T> T getEndpointInstance(Class<T> endpointClass)
                                            throws InstantiationException {
                                        return endpointClass.cast(rtEventResource);
                                    }
                                }).build();

    wsContainer.addEndpoint(serverConfig);
}
项目:asity    文件:JwaServerWebSocketTest.java   
@Override
protected void startServer(int port, final Action<ServerWebSocket> websocketAction) throws
  Exception {
  server = new Server();
  ServerConnector connector = new ServerConnector(server);
  connector.setPort(port);
  server.addConnector(connector);
  ServletContextHandler handler = new ServletContextHandler();
  server.setHandler(handler);
  ServerContainer container = WebSocketServerContainerInitializer.configureContext(handler);
  ServerEndpointConfig config = ServerEndpointConfig.Builder.create(AsityServerEndpoint.class,
    TEST_URI)
  .configurator(new Configurator() {
    @Override
    public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException {
      return endpointClass.cast(new AsityServerEndpoint().onwebsocket(websocketAction));
    }
  })
  .build();
  container.addEndpoint(config);
  server.start();
}
项目:vibe-java-platform    文件:JwaServerWebSocketTest.java   
@Override
protected void startServer() throws Exception {
    server = new Server();
    ServerConnector connector = new ServerConnector(server);
    connector.setPort(port);
    server.addConnector(connector);
    ServletContextHandler handler = new ServletContextHandler();
    server.setHandler(handler);
    ServerContainer container = WebSocketServerContainerInitializer.configureContext(handler);
    ServerEndpointConfig config = ServerEndpointConfig.Builder.create(VibeServerEndpoint.class, "/test")
    .configurator(new Configurator() {
        @Override
        public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException {
            return endpointClass.cast(new VibeServerEndpoint().onwebsocket(performer.serverAction()));
        }
    })
    .build();
    container.addEndpoint(config);
    server.start();
}
项目:minijax    文件:MinijaxWebSocketUtils.java   
public static void init(final ServletContextHandler context, final MinijaxApplication application)
        throws ServletException, DeploymentException {

    final ServerContainer container = WebSocketServerContainerInitializer.configureContext(context);
    final Configurator configurator = new MinijaxWebSocketConfigurator(application);

    for (final Class<?> c : application.getWebSockets()) {
        final ServerEndpointConfig config = ServerEndpointConfig.Builder
                .create(c, c.getAnnotation(ServerEndpoint.class).value())
                .configurator(configurator)
                .build();
        container.addEndpoint(config);
    }
}