java类javax.websocket.Endpoint的实例源码

WsWebSocketContainer.java 文件源码 项目:tomcat7 阅读 28 收藏 0 点赞 0 评论 0
protected void registerSession(Endpoint endpoint, WsSession wsSession) {

        if (!wsSession.isOpen()) {
            // The session was closed during onOpen. No need to register it.
            return;
        }
        synchronized (endPointSessionMapLock) {
            if (endpointSessionMap.size() == 0) {
                BackgroundProcessManager.getInstance().register(this);
            }
            Set<WsSession> wsSessions = endpointSessionMap.get(endpoint);
            if (wsSessions == null) {
                wsSessions = new HashSet<WsSession>();
                endpointSessionMap.put(endpoint, wsSessions);
            }
            wsSessions.add(wsSession);
        }
        sessions.put(wsSession, wsSession);
    }
WsWebSocketContainer.java 文件源码 项目:tomcat7 阅读 22 收藏 0 点赞 0 评论 0
protected void unregisterSession(Endpoint endpoint, WsSession wsSession) {

        synchronized (endPointSessionMapLock) {
            Set<WsSession> wsSessions = endpointSessionMap.get(endpoint);
            if (wsSessions != null) {
                wsSessions.remove(wsSession);
                if (wsSessions.size() == 0) {
                    endpointSessionMap.remove(endpoint);
                }
            }
            if (endpointSessionMap.size() == 0) {
                BackgroundProcessManager.getInstance().unregister(this);
            }
        }
        sessions.remove(wsSession);
    }
LogEventHandler.java 文件源码 项目:flow-platform 阅读 38 收藏 0 点赞 0 评论 0
private void initWebSocketSession(String url, int wsConnectionTimeout) throws Exception {
    CountDownLatch wsLatch = new CountDownLatch(1);
    ClientEndpointConfig cec = ClientEndpointConfig.Builder.create().build();
    ClientManager client = ClientManager.createClient();

    client.connectToServer(new Endpoint() {
        @Override
        public void onOpen(Session session, EndpointConfig endpointConfig) {
            wsSession = session;
            wsLatch.countDown();
        }
    }, cec, new URI(url));

    if (!wsLatch.await(wsConnectionTimeout, TimeUnit.SECONDS)) {
        throw new TimeoutException("Web socket connection timeout");
    }
}
ExamplesConfig.java 文件源码 项目:apache-tomcat-7.0.73-with-comment 阅读 22 收藏 0 点赞 0 评论 0
@Override
public Set<ServerEndpointConfig> getEndpointConfigs(
        Set<Class<? extends Endpoint>> scanned) {

    Set<ServerEndpointConfig> result = new HashSet<ServerEndpointConfig>();

    if (scanned.contains(EchoEndpoint.class)) {
        result.add(ServerEndpointConfig.Builder.create(
                EchoEndpoint.class,
                "/websocket/echoProgrammatic").build());
    }

    if (scanned.contains(DrawboardEndpoint.class)) {
        result.add(ServerEndpointConfig.Builder.create(
                DrawboardEndpoint.class,
                "/websocket/drawboard").build());
    }

    return result;
}
WsWebSocketContainer.java 文件源码 项目:apache-tomcat-7.0.73-with-comment 阅读 29 收藏 0 点赞 0 评论 0
protected void registerSession(Endpoint endpoint, WsSession wsSession) {

        if (!wsSession.isOpen()) {
            // The session was closed during onOpen. No need to register it.
            return;
        }
        synchronized (endPointSessionMapLock) {
            if (endpointSessionMap.size() == 0) {
                BackgroundProcessManager.getInstance().register(this);
            }
            Set<WsSession> wsSessions = endpointSessionMap.get(endpoint);
            if (wsSessions == null) {
                wsSessions = new HashSet<WsSession>();
                endpointSessionMap.put(endpoint, wsSessions);
            }
            wsSessions.add(wsSession);
        }
        sessions.put(wsSession, wsSession);
    }
WsWebSocketContainer.java 文件源码 项目:apache-tomcat-7.0.73-with-comment 阅读 24 收藏 0 点赞 0 评论 0
protected void unregisterSession(Endpoint endpoint, WsSession wsSession) {

        synchronized (endPointSessionMapLock) {
            Set<WsSession> wsSessions = endpointSessionMap.get(endpoint);
            if (wsSessions != null) {
                wsSessions.remove(wsSession);
                if (wsSessions.size() == 0) {
                    endpointSessionMap.remove(endpoint);
                }
            }
            if (endpointSessionMap.size() == 0) {
                BackgroundProcessManager.getInstance().unregister(this);
            }
        }
        sessions.remove(wsSession);
    }
ExamplesConfig.java 文件源码 项目:apache-tomcat-7.0.73-with-comment 阅读 25 收藏 0 点赞 0 评论 0
@Override
public Set<ServerEndpointConfig> getEndpointConfigs(
        Set<Class<? extends Endpoint>> scanned) {

    Set<ServerEndpointConfig> result = new HashSet<ServerEndpointConfig>();

    if (scanned.contains(EchoEndpoint.class)) {
        result.add(ServerEndpointConfig.Builder.create(
                EchoEndpoint.class,
                "/websocket/echoProgrammatic").build());
    }

    if (scanned.contains(DrawboardEndpoint.class)) {
        result.add(ServerEndpointConfig.Builder.create(
                DrawboardEndpoint.class,
                "/websocket/drawboard").build());
    }

    return result;
}
WsWebSocketContainer.java 文件源码 项目:lazycat 阅读 24 收藏 0 点赞 0 评论 0
protected void registerSession(Endpoint endpoint, WsSession wsSession) {

        if (!wsSession.isOpen()) {
            // The session was closed during onOpen. No need to register it.
            return;
        }
        synchronized (endPointSessionMapLock) {
            if (endpointSessionMap.size() == 0) {
                BackgroundProcessManager.getInstance().register(this);
            }
            Set<WsSession> wsSessions = endpointSessionMap.get(endpoint);
            if (wsSessions == null) {
                wsSessions = new HashSet<WsSession>();
                endpointSessionMap.put(endpoint, wsSessions);
            }
            wsSessions.add(wsSession);
        }
        sessions.put(wsSession, wsSession);
    }
WsWebSocketContainer.java 文件源码 项目:lazycat 阅读 37 收藏 0 点赞 0 评论 0
protected void unregisterSession(Endpoint endpoint, WsSession wsSession) {

        synchronized (endPointSessionMapLock) {
            Set<WsSession> wsSessions = endpointSessionMap.get(endpoint);
            if (wsSessions != null) {
                wsSessions.remove(wsSession);
                if (wsSessions.size() == 0) {
                    endpointSessionMap.remove(endpoint);
                }
            }
            if (endpointSessionMap.size() == 0) {
                BackgroundProcessManager.getInstance().unregister(this);
            }
        }
        sessions.remove(wsSession);
    }
EndpointConnectionManager.java 文件源码 项目:spring4-understanding 阅读 26 收藏 0 点赞 0 评论 0
@Override
protected void openConnection() {
    this.taskExecutor.execute(new Runnable() {
        @Override
        public void run() {
            try {
                logger.info("Connecting to WebSocket at " + getUri());
                Endpoint endpointToUse = (endpoint != null) ? endpoint : endpointProvider.getHandler();
                ClientEndpointConfig endpointConfig = configBuilder.build();
                session = getWebSocketContainer().connectToServer(endpointToUse, endpointConfig, getUri());
                logger.info("Successfully connected");
            }
            catch (Throwable ex) {
                logger.error("Failed to connect", ex);
            }
        }
    });
}
WebSphereRequestUpgradeStrategy.java 文件源码 项目:spring4-understanding 阅读 24 收藏 0 点赞 0 评论 0
@Override
public void upgradeInternal(ServerHttpRequest httpRequest, ServerHttpResponse httpResponse,
        String selectedProtocol, List<Extension> selectedExtensions, Endpoint endpoint)
        throws HandshakeFailureException {

    HttpServletRequest request = getHttpServletRequest(httpRequest);
    HttpServletResponse response = getHttpServletResponse(httpResponse);

    StringBuffer requestUrl = request.getRequestURL();
    String path = request.getRequestURI();  // shouldn't matter
    Map<String, String> pathParams = Collections.<String, String> emptyMap();

    ServerEndpointRegistration endpointConfig = new ServerEndpointRegistration(path, endpoint);
    endpointConfig.setSubprotocols(Collections.singletonList(selectedProtocol));
    endpointConfig.setExtensions(selectedExtensions);

    try {
        ServerContainer container = getContainer(request);
        upgradeMethod.invoke(container, request, response, endpointConfig, pathParams);
    }
    catch (Exception ex) {
        throw new HandshakeFailureException(
                "Servlet request failed to upgrade to WebSocket for " + requestUrl, ex);
    }
}
UndertowRequestUpgradeStrategy.java 文件源码 项目:spring4-understanding 阅读 24 收藏 0 点赞 0 评论 0
private ConfiguredServerEndpoint createConfiguredServerEndpoint(String selectedProtocol,
        List<Extension> selectedExtensions, Endpoint endpoint, HttpServletRequest servletRequest) {

    String path = servletRequest.getRequestURI();  // shouldn't matter
    ServerEndpointRegistration endpointRegistration = new ServerEndpointRegistration(path, endpoint);
    endpointRegistration.setSubprotocols(Arrays.asList(selectedProtocol));
    endpointRegistration.setExtensions(selectedExtensions);

    EncodingFactory encodingFactory = new EncodingFactory(
            Collections.<Class<?>, List<InstanceFactory<? extends Encoder>>>emptyMap(),
            Collections.<Class<?>, List<InstanceFactory<? extends Decoder>>>emptyMap(),
            Collections.<Class<?>, List<InstanceFactory<? extends Encoder>>>emptyMap(),
            Collections.<Class<?>, List<InstanceFactory<? extends Decoder>>>emptyMap());
    try {
        return (endpointConstructorWithEndpointFactory ?
                endpointConstructor.newInstance(endpointRegistration,
                        new EndpointInstanceFactory(endpoint), null, encodingFactory, null) :
                endpointConstructor.newInstance(endpointRegistration,
                        new EndpointInstanceFactory(endpoint), null, encodingFactory));
    }
    catch (Exception ex) {
        throw new HandshakeFailureException("Failed to instantiate ConfiguredServerEndpoint", ex);
    }
}
SlackWebsocketConnectionTest.java 文件源码 项目:slack-rtm-api 阅读 24 收藏 0 点赞 0 评论 0
@Test
public void testCreateWebSocketAndConnectToServer() throws Exception {
    SlackWebsocketConnection slack = new SlackWebsocketConnection("token", null, 8080);

    SlackAuthen slackAuthen = PowerMockito.mock(SlackAuthen.class);
    PowerMockito.whenNew(SlackAuthen.class).withNoArguments().thenReturn(slackAuthen);
    PowerMockito.when(slackAuthen.tokenAuthen(Mockito.anyString(), Mockito.anyString(), Mockito.anyInt())).thenReturn(slackInfo);

    ClientManager clientManager = PowerMockito.mock(ClientManager.class);
    PowerMockito.mockStatic(ClientManager.class);
    PowerMockito.when(ClientManager.createClient()).thenReturn(clientManager);

    boolean connect = slack.connect();
    assertThat(connect, is(true));

    Mockito.verify(clientManager).connectToServer(Mockito.any(Endpoint.class), Mockito.any(URI.class));
    PowerMockito.verifyStatic();
    ClientManager.createClient();
}
WebSocketConnectionClasser.java 文件源码 项目:PearlHarbor 阅读 28 收藏 0 点赞 0 评论 0
@Override
public Set<ServerEndpointConfig> getEndpointConfigs(
        Set<Class<? extends Endpoint>> scanned) {

    Set<ServerEndpointConfig> result = new HashSet<>();

    // Endpoint subclass config

    if (scanned.contains(MyEndpoint.class)) {
        result.add(ServerEndpointConfig.Builder.create(
                MyEndpoint.class,
                "/MyEndpoint").build());
    }

    if (scanned.contains(GameEndpoint.class)) {
        result.add(ServerEndpointConfig.Builder.create(
                GameEndpoint.class,
                "/Game").build());
    }

    return result;
}
AbstractOcelotTest.java 文件源码 项目:ocelot 阅读 29 收藏 0 点赞 0 评论 0
/**
 * Create session
 *
 * @param jsessionid
 * @param userpwd
 * @return
 */
protected Session createAndGetSession(String jsessionid, String userpwd) {
    WebSocketContainer container = ContainerProvider.getWebSocketContainer();
    try {
        StringBuilder sb = new StringBuilder("ws://localhost:");
        sb.append(PORT).append(Constants.SLASH).append(CTXPATH).append(Constants.SLASH).append("ocelot-endpoint");
        URI uri = new URI(sb.toString());
        return container.connectToServer(new Endpoint() {
            @Override
            public void onOpen(Session session, EndpointConfig config) {
            }
        }, createClientEndpointConfigWithJsession(jsessionid, userpwd), uri);
    } catch (URISyntaxException | DeploymentException | IOException ex) {
        ex.getCause().printStackTrace();
        fail("CONNEXION FAILED " + ex.getMessage());
    }
    return null;
}
SparkWSTest.java 文件源码 项目:spark-ws 阅读 30 收藏 0 点赞 0 评论 0
private void assertMessageReceived( String endpoint, String expectedMessage, String messageToSend ) throws Exception {
    final SettableFuture<String> futureMessage = SettableFuture.create();

    client.connectToServer( new Endpoint() {

        @Override
        public void onOpen( Session session, EndpointConfig config ) {
            clientSession = session;
            try {
                session.addMessageHandler( new MessageHandler.Whole<String>() {

                    @Override
                    public void onMessage( String message ) {
                        System.out.println( "Received message: " + message );
                        futureMessage.set( message );
                    }
                } );
                session.getBasicRemote().sendText( messageToSend );
            } catch ( IOException e ) {
                e.printStackTrace();
            }
        }
    }, cec, new URI( "ws://localhost:8025/" + endpoint ) );

    assertEquals( expectedMessage, futureMessage.get( 2, TimeUnit.SECONDS ) );
}
WsWebSocketContainer.java 文件源码 项目:class-guard 阅读 27 收藏 0 点赞 0 评论 0
protected void registerSession(Endpoint endpoint, WsSession wsSession) {

        Class<?> endpointClazz = endpoint.getClass();

        if (!wsSession.isOpen()) {
            // The session was closed during onOpen. No need to register it.
            return;
        }
        synchronized (endPointSessionMapLock) {
            if (endpointSessionMap.size() == 0) {
                BackgroundProcessManager.getInstance().register(this);
            }
            Set<WsSession> wsSessions = endpointSessionMap.get(endpointClazz);
            if (wsSessions == null) {
                wsSessions = new HashSet<WsSession>();
                endpointSessionMap.put(endpointClazz, wsSessions);
            }
            wsSessions.add(wsSession);
        }
        sessions.put(wsSession, wsSession);
    }
WsWebSocketContainer.java 文件源码 项目:class-guard 阅读 26 收藏 0 点赞 0 评论 0
protected void unregisterSession(Endpoint endpoint, WsSession wsSession) {

        Class<?> endpointClazz = endpoint.getClass();

        synchronized (endPointSessionMapLock) {
            Set<WsSession> wsSessions = endpointSessionMap.get(endpointClazz);
            if (wsSessions != null) {
                wsSessions.remove(wsSession);
                if (wsSessions.size() == 0) {
                    endpointSessionMap.remove(endpointClazz);
                }
            }
            if (endpointSessionMap.size() == 0) {
                BackgroundProcessManager.getInstance().unregister(this);
            }
        }
        sessions.remove(wsSession);
    }
ExamplesConfig.java 文件源码 项目:class-guard 阅读 23 收藏 0 点赞 0 评论 0
@Override
public Set<ServerEndpointConfig> getEndpointConfigs(
        Set<Class<? extends Endpoint>> scanned) {

    Set<ServerEndpointConfig> result = new HashSet<ServerEndpointConfig>();

    if (scanned.contains(EchoEndpoint.class)) {
        result.add(ServerEndpointConfig.Builder.create(
                EchoEndpoint.class,
                "/websocket/echoProgrammatic").build());
    }

    if (scanned.contains(DrawboardEndpoint.class)) {
        result.add(ServerEndpointConfig.Builder.create(
                DrawboardEndpoint.class,
                "/websocket/drawboard").build());
    }

    return result;
}
MyApplicationConfig.java 文件源码 项目:JavaIncrementalParser 阅读 24 收藏 0 点赞 0 评论 0
@Override
public Set<ServerEndpointConfig> getEndpointConfigs(Set<Class<? extends Endpoint>> set) {
    return new HashSet<ServerEndpointConfig>() {{
        add(ServerEndpointConfig.Builder
                .create(MyEndpoint.class, "/websocket")
                .configurator(new ServerEndpointConfig.Configurator() {

                    @Override
                    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
                        HttpSession session = (HttpSession)request.getHttpSession();
                        System.out.println("HttpSession id: " + session.getId());
                        System.out.println("HttpSession creation time: " + session.getCreationTime());
                        super.modifyHandshake(sec, request, response);
                    }

                })
                .build());
    }};
}
ExamplesConfig.java 文件源码 项目:apache-tomcat-7.0.57 阅读 24 收藏 0 点赞 0 评论 0
@Override
public Set<ServerEndpointConfig> getEndpointConfigs(
        Set<Class<? extends Endpoint>> scanned) {

    Set<ServerEndpointConfig> result = new HashSet<ServerEndpointConfig>();

    if (scanned.contains(EchoEndpoint.class)) {
        result.add(ServerEndpointConfig.Builder.create(
                EchoEndpoint.class,
                "/websocket/echoProgrammatic").build());
    }

    if (scanned.contains(DrawboardEndpoint.class)) {
        result.add(ServerEndpointConfig.Builder.create(
                DrawboardEndpoint.class,
                "/websocket/drawboard").build());
    }

    return result;
}
WsWebSocketContainer.java 文件源码 项目:apache-tomcat-7.0.57 阅读 29 收藏 0 点赞 0 评论 0
protected void registerSession(Endpoint endpoint, WsSession wsSession) {

        Class<?> endpointClazz = endpoint.getClass();

        if (!wsSession.isOpen()) {
            // The session was closed during onOpen. No need to register it.
            return;
        }
        synchronized (endPointSessionMapLock) {
            if (endpointSessionMap.size() == 0) {
                BackgroundProcessManager.getInstance().register(this);
            }
            Set<WsSession> wsSessions = endpointSessionMap.get(endpointClazz);
            if (wsSessions == null) {
                wsSessions = new HashSet<WsSession>();
                endpointSessionMap.put(endpointClazz, wsSessions);
            }
            wsSessions.add(wsSession);
        }
        sessions.put(wsSession, wsSession);
    }
WsWebSocketContainer.java 文件源码 项目:apache-tomcat-7.0.57 阅读 37 收藏 0 点赞 0 评论 0
protected void unregisterSession(Endpoint endpoint, WsSession wsSession) {

        Class<?> endpointClazz = endpoint.getClass();

        synchronized (endPointSessionMapLock) {
            Set<WsSession> wsSessions = endpointSessionMap.get(endpointClazz);
            if (wsSessions != null) {
                wsSessions.remove(wsSession);
                if (wsSessions.size() == 0) {
                    endpointSessionMap.remove(endpointClazz);
                }
            }
            if (endpointSessionMap.size() == 0) {
                BackgroundProcessManager.getInstance().unregister(this);
            }
        }
        sessions.remove(wsSession);
    }
ExamplesConfig.java 文件源码 项目:apache-tomcat-7.0.57 阅读 28 收藏 0 点赞 0 评论 0
@Override
public Set<ServerEndpointConfig> getEndpointConfigs(
        Set<Class<? extends Endpoint>> scanned) {

    Set<ServerEndpointConfig> result = new HashSet<ServerEndpointConfig>();

    if (scanned.contains(EchoEndpoint.class)) {
        result.add(ServerEndpointConfig.Builder.create(
                EchoEndpoint.class,
                "/websocket/echoProgrammatic").build());
    }

    if (scanned.contains(DrawboardEndpoint.class)) {
        result.add(ServerEndpointConfig.Builder.create(
                DrawboardEndpoint.class,
                "/websocket/drawboard").build());
    }

    return result;
}
WsWebSocketContainer.java 文件源码 项目:apache-tomcat-7.0.57 阅读 29 收藏 0 点赞 0 评论 0
protected void registerSession(Endpoint endpoint, WsSession wsSession) {

        Class<?> endpointClazz = endpoint.getClass();

        if (!wsSession.isOpen()) {
            // The session was closed during onOpen. No need to register it.
            return;
        }
        synchronized (endPointSessionMapLock) {
            if (endpointSessionMap.size() == 0) {
                BackgroundProcessManager.getInstance().register(this);
            }
            Set<WsSession> wsSessions = endpointSessionMap.get(endpointClazz);
            if (wsSessions == null) {
                wsSessions = new HashSet<WsSession>();
                endpointSessionMap.put(endpointClazz, wsSessions);
            }
            wsSessions.add(wsSession);
        }
        sessions.put(wsSession, wsSession);
    }
WsWebSocketContainer.java 文件源码 项目:apache-tomcat-7.0.57 阅读 26 收藏 0 点赞 0 评论 0
protected void unregisterSession(Endpoint endpoint, WsSession wsSession) {

        Class<?> endpointClazz = endpoint.getClass();

        synchronized (endPointSessionMapLock) {
            Set<WsSession> wsSessions = endpointSessionMap.get(endpointClazz);
            if (wsSessions != null) {
                wsSessions.remove(wsSession);
                if (wsSessions.size() == 0) {
                    endpointSessionMap.remove(endpointClazz);
                }
            }
            if (endpointSessionMap.size() == 0) {
                BackgroundProcessManager.getInstance().unregister(this);
            }
        }
        sessions.remove(wsSession);
    }
ExamplesConfig.java 文件源码 项目:tomcat7-eap6-examples 阅读 29 收藏 0 点赞 0 评论 0
@Override
public Set<ServerEndpointConfig> getEndpointConfigs(
        Set<Class<? extends Endpoint>> scanned) {

    Set<ServerEndpointConfig> result = new HashSet<ServerEndpointConfig>();

    if (scanned.contains(EchoEndpoint.class)) {
        result.add(ServerEndpointConfig.Builder.create(
                EchoEndpoint.class,
                "/websocket/echoProgrammatic").build());
    }

    if (scanned.contains(DrawboardEndpoint.class)) {
        result.add(ServerEndpointConfig.Builder.create(
                DrawboardEndpoint.class,
                "/websocket/drawboard").build());
    }

    return result;
}
XSServletWSConfig.java 文件源码 项目:OftenPorter 阅读 26 收藏 0 点赞 0 评论 0
@Override
public Set<ServerEndpointConfig> getEndpointConfigs(Set<Class<? extends Endpoint>> set)
{
    Set<ServerEndpointConfig> sets = new HashSet<>();
    ServerEndpointConfig config = ServerEndpointConfig.Builder.create(ProgrammaticServer.class, WS_PATH)
            .configurator(new HttpSessionConfigurator())
            .build();
    sets.add(config);
    return sets;
}
WsWebSocketContainer.java 文件源码 项目:tomcat7 阅读 26 收藏 0 点赞 0 评论 0
Set<Session> getOpenSessions(Endpoint endpoint) {
    HashSet<Session> result = new HashSet<Session>();
    synchronized (endPointSessionMapLock) {
        Set<WsSession> sessions = endpointSessionMap.get(endpoint);
        if (sessions != null) {
            result.addAll(sessions);
        }
    }
    return result;
}
WsHttpUpgradeHandler.java 文件源码 项目:tomcat7 阅读 26 收藏 0 点赞 0 评论 0
public void preInit(Endpoint ep, EndpointConfig endpointConfig,
        WsServerContainer wsc, WsHandshakeRequest handshakeRequest,
        List<Extension> negotiatedExtensionsPhase2, String subProtocol,
        Transformation transformation, Map<String,String> pathParameters,
        boolean secure) {
    this.ep = ep;
    this.endpointConfig = endpointConfig;
    this.webSocketContainer = wsc;
    this.handshakeRequest = handshakeRequest;
    this.negotiatedExtensions = negotiatedExtensionsPhase2;
    this.subProtocol = subProtocol;
    this.transformation = transformation;
    this.pathParameters = pathParameters;
    this.secure = secure;
}


问题


面经


文章

微信
公众号

扫码关注公众号