當前位置: 首頁>>代碼示例>>Java>>正文


Java Endpoint類代碼示例

本文整理匯總了Java中javax.websocket.Endpoint的典型用法代碼示例。如果您正苦於以下問題:Java Endpoint類的具體用法?Java Endpoint怎麽用?Java Endpoint使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Endpoint類屬於javax.websocket包,在下文中一共展示了Endpoint類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: registerSession

import javax.websocket.Endpoint; //導入依賴的package包/類
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);
    }
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:20,代碼來源:WsWebSocketContainer.java

示例2: unregisterSession

import javax.websocket.Endpoint; //導入依賴的package包/類
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);
    }
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:17,代碼來源:WsWebSocketContainer.java

示例3: initWebSocketSession

import javax.websocket.Endpoint; //導入依賴的package包/類
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");
    }
}
 
開發者ID:FlowCI,項目名稱:flow-platform,代碼行數:18,代碼來源:LogEventHandler.java

示例4: getEndpointConfigs

import javax.websocket.Endpoint; //導入依賴的package包/類
@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;
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:21,代碼來源:ExamplesConfig.java

示例5: registerSession

import javax.websocket.Endpoint; //導入依賴的package包/類
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);
	}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:20,代碼來源:WsWebSocketContainer.java

示例6: unregisterSession

import javax.websocket.Endpoint; //導入依賴的package包/類
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);
	}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:17,代碼來源:WsWebSocketContainer.java

示例7: openConnection

import javax.websocket.Endpoint; //導入依賴的package包/類
@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);
			}
		}
	});
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:19,代碼來源:EndpointConnectionManager.java

示例8: upgradeInternal

import javax.websocket.Endpoint; //導入依賴的package包/類
@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);
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:26,代碼來源:WebSphereRequestUpgradeStrategy.java

示例9: createConfiguredServerEndpoint

import javax.websocket.Endpoint; //導入依賴的package包/類
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);
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:25,代碼來源:UndertowRequestUpgradeStrategy.java

示例10: testCreateWebSocketAndConnectToServer

import javax.websocket.Endpoint; //導入依賴的package包/類
@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();
}
 
開發者ID:mockupcode,項目名稱:slack-rtm-api,代碼行數:20,代碼來源:SlackWebsocketConnectionTest.java

示例11: getEndpointConfigs

import javax.websocket.Endpoint; //導入依賴的package包/類
@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;
}
 
開發者ID:AlkaidFang,項目名稱:PearlHarbor,代碼行數:23,代碼來源:WebSocketConnectionClasser.java

示例12: createAndGetSession

import javax.websocket.Endpoint; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:ocelotds,項目名稱:ocelot,代碼行數:25,代碼來源:AbstractOcelotTest.java

示例13: assertMessageReceived

import javax.websocket.Endpoint; //導入依賴的package包/類
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 ) );
}
 
開發者ID:renatoathaydes,項目名稱:spark-ws,代碼行數:27,代碼來源:SparkWSTest.java

示例14: registerSession

import javax.websocket.Endpoint; //導入依賴的package包/類
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);
    }
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:22,代碼來源:WsWebSocketContainer.java

示例15: unregisterSession

import javax.websocket.Endpoint; //導入依賴的package包/類
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);
    }
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:19,代碼來源:WsWebSocketContainer.java


注:本文中的javax.websocket.Endpoint類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。