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


Java EndpointConfig類代碼示例

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


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

示例1: onOpen

import javax.websocket.EndpointConfig; //導入依賴的package包/類
/**
 * 連接建立成功調用的方法-與前端JS代碼對應
 * 
 * @param session 可選的參數。session為與某個客戶端的連接會話,需要通過它來給客戶端發送數據
 */
@OnOpen
public void onOpen(Session session, EndpointConfig config) {
	// 單個會話對象保存
	this.session = session;
	webSocketSet.add(this); // 加入set中
	this.httpSession = (HttpSession) config.getUserProperties().get(HttpSession.class.getName());
	String uId = (String) httpSession.getAttribute("userid"); // 獲取當前用戶
	String sessionId = httpSession.getId();
	this.userid = uId + "|" + sessionId;
	if (!OnlineUserlist.contains(this.userid)) {
		OnlineUserlist.add(userid); // 將用戶名加入在線列表
	}
	routetabMap.put(userid, session); // 將用戶名和session綁定到路由表
	System.out.println(userid + " -> 已上線");
	String message = getMessage(userid + " -> 已上線", "notice", OnlineUserlist);
	broadcast(message); // 廣播
}
 
開發者ID:butter-fly,項目名稱:belling-admin,代碼行數:23,代碼來源:OnlineNoticeServer.java

示例2: onOpen

import javax.websocket.EndpointConfig; //導入依賴的package包/類
@Override
public void onOpen(Session session, EndpointConfig endpointConfig) {

	ServerEndpointConfig sec = (ServerEndpointConfig) endpointConfig;

	Object pojo;
	try {
		pojo = sec.getConfigurator().getEndpointInstance(sec.getEndpointClass());
	} catch (InstantiationException e) {
		throw new IllegalArgumentException(
				sm.getString("pojoEndpointServer.getPojoInstanceFail", sec.getEndpointClass().getName()), e);
	}
	setPojo(pojo);

	@SuppressWarnings("unchecked")
	Map<String, String> pathParameters = (Map<String, String>) sec.getUserProperties().get(POJO_PATH_PARAM_KEY);
	setPathParameters(pathParameters);

	PojoMethodMapping methodMapping = (PojoMethodMapping) sec.getUserProperties().get(POJO_METHOD_MAPPING_KEY);
	setMethodMapping(methodMapping);

	doOnOpen(session, endpointConfig);
}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:24,代碼來源:PojoEndpointServer.java

示例3: initWebSocketSession

import javax.websocket.EndpointConfig; //導入依賴的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: onOpen

import javax.websocket.EndpointConfig; //導入依賴的package包/類
/**連接建立成功調用的方法*/
@OnOpen
public void onOpen(Session session,EndpointConfig config){
	HttpSession httpSession = (HttpSession) config.getUserProperties().get(HttpSession.class.getName());
	if(StorageUtil.init(httpSession).getLoginMemberId()!=ReturnUtil.NOT_LOGIN_CODE){
		long userId = StorageUtil.init(httpSession).getLoginMemberId();
		mapUS.put(userId,session);
		mapSU.put(session,userId);
		//上線通知由客戶端自主發起
		onlineCount++;           //在線數加1
		System.out.println("用戶"+userId+"進入WebSocket!當前在線人數為" + onlineCount);
		getUserKey(userId);
	}else{
		try {
			session.close();
			System.out.println("未獲取到用戶信息,關閉WebSocket!");
		} catch (IOException e) {
			System.out.println("關閉WebSocket失敗!");
		}
	}
}
 
開發者ID:zhiqiang94,項目名稱:BasicsProject,代碼行數:22,代碼來源:WSMI.java

示例5: onOpen

import javax.websocket.EndpointConfig; //導入依賴的package包/類
@Override
public void onOpen(Session session, EndpointConfig arg1) {
	final RemoteEndpoint.Basic remote = session.getBasicRemote();
	session.addMessageHandler(new MessageHandler.Whole<String>() {
		public void onMessage(String text) {
			try {
				remote.sendText(text.toUpperCase());
			} catch (IOException ioe) {
				ioe.printStackTrace();
			}
		}
	});
}
 
開發者ID:Sunature,項目名稱:websocket,代碼行數:14,代碼來源:java7Ws.java

示例6: onOpen

import javax.websocket.EndpointConfig; //導入依賴的package包/類
@Override
public void onOpen(Session session, EndpointConfig endpointConfig) {

    ServerEndpointConfig sec = (ServerEndpointConfig) endpointConfig;

    Object pojo;
    try {
        pojo = sec.getConfigurator().getEndpointInstance(
                sec.getEndpointClass());
    } catch (InstantiationException e) {
        throw new IllegalArgumentException(sm.getString(
                "pojoEndpointServer.getPojoInstanceFail",
                sec.getEndpointClass().getName()), e);
    }
    setPojo(pojo);

    @SuppressWarnings("unchecked")
    Map<String,String> pathParameters =
            (Map<String, String>) sec.getUserProperties().get(
                    POJO_PATH_PARAM_KEY);
    setPathParameters(pathParameters);

    PojoMethodMapping methodMapping =
            (PojoMethodMapping) sec.getUserProperties().get(
                    POJO_METHOD_MAPPING_KEY);
    setMethodMapping(methodMapping);

    doOnOpen(session, endpointConfig);
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:30,代碼來源:PojoEndpointServer.java

示例7: getMessageHandlers

import javax.websocket.EndpointConfig; //導入依賴的package包/類
public Set<MessageHandler> getMessageHandlers(Object pojo,
        Map<String,String> pathParameters, Session session,
        EndpointConfig config) {
    Set<MessageHandler> result = new HashSet<MessageHandler>();
    for (MessageHandlerInfo messageMethod : onMessage) {
        result.addAll(messageMethod.getMessageHandlers(pojo, pathParameters,
                session, config));
    }
    return result;
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:11,代碼來源:PojoMethodMapping.java

示例8: buildArgs

import javax.websocket.EndpointConfig; //導入依賴的package包/類
private static Object[] buildArgs(PojoPathParam[] pathParams,
        Map<String,String> pathParameters, Session session,
        EndpointConfig config, Throwable throwable, CloseReason closeReason)
        throws DecodeException {
    Object[] result = new Object[pathParams.length];
    for (int i = 0; i < pathParams.length; i++) {
        Class<?> type = pathParams[i].getType();
        if (type.equals(Session.class)) {
            result[i] = session;
        } else if (type.equals(EndpointConfig.class)) {
            result[i] = config;
        } else if (type.equals(Throwable.class)) {
            result[i] = throwable;
        } else if (type.equals(CloseReason.class)) {
            result[i] = closeReason;
        } else {
            String name = pathParams[i].getName();
            String value = pathParameters.get(name);
            try {
                result[i] = Util.coerceToType(type, value);
            } catch (Exception e) {
                throw new DecodeException(value, sm.getString(
                        "pojoMethodMapping.decodePathParamFail",
                        value, type), e);
            }
        }
    }
    return result;
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:30,代碼來源:PojoMethodMapping.java

示例9: matchDecoders

import javax.websocket.EndpointConfig; //導入依賴的package包/類
private static List<Class<? extends Decoder>> matchDecoders(Class<?> target,
        EndpointConfig endpointConfig, boolean binary) {
    DecoderMatch decoderMatch = matchDecoders(target, endpointConfig);
    if (binary) {
        if (decoderMatch.getBinaryDecoders().size() > 0) {
            return decoderMatch.getBinaryDecoders();
        }
    } else if (decoderMatch.getTextDecoders().size() > 0) {
        return decoderMatch.getTextDecoders();
    }
    return null;
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:13,代碼來源:Util.java

示例10: buildArgs

import javax.websocket.EndpointConfig; //導入依賴的package包/類
private static Object[] buildArgs(PojoPathParam[] pathParams, Map<String, String> pathParameters, Session session,
		EndpointConfig config, Throwable throwable, CloseReason closeReason) throws DecodeException {
	Object[] result = new Object[pathParams.length];
	for (int i = 0; i < pathParams.length; i++) {
		Class<?> type = pathParams[i].getType();
		if (type.equals(Session.class)) {
			result[i] = session;
		} else if (type.equals(EndpointConfig.class)) {
			result[i] = config;
		} else if (type.equals(Throwable.class)) {
			result[i] = throwable;
		} else if (type.equals(CloseReason.class)) {
			result[i] = closeReason;
		} else {
			String name = pathParams[i].getName();
			String value = pathParameters.get(name);
			try {
				result[i] = Util.coerceToType(type, value);
			} catch (Exception e) {
				throw new DecodeException(value, sm.getString("pojoMethodMapping.decodePathParamFail", value, type),
						e);
			}
		}
	}
	return result;
}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:27,代碼來源:PojoMethodMapping.java

示例11: onOpen

import javax.websocket.EndpointConfig; //導入依賴的package包/類
@OnOpen
public void onOpen(@SuppressWarnings("unused") Session session,
        EndpointConfig config) {
    if (config == null) {
        throw new RuntimeException();
    }
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:8,代碼來源:TestPojoEndpointBase.java

示例12: onOpen

import javax.websocket.EndpointConfig; //導入依賴的package包/類
@Override
public void onOpen(Session sn, EndpointConfig ec) {
    try {
        sn.addMessageHandler(String.class, new MessageHandler.Whole<String>() {
            @Override
            public void onMessage(String m) {
                System.out.println("got message from server - " + m);
            }
        });
    } catch (Exception ex) {
        Logger.getLogger(WebSocketEndpointConcurrencyTest.class.getName()).log(Level.SEVERE, null, ex);
    }

}
 
開發者ID:abhirockzz,項目名稱:websocket-http-session,代碼行數:15,代碼來源:WebSocketEndpointConcurrencyTest.java

示例13: onOpen

import javax.websocket.EndpointConfig; //導入依賴的package包/類
@OnOpen
public void onOpen(final Session session, EndpointConfig ec) {
	currentSession = session;
	agent = getRandomSupportAgent(); 
	
	String greeting = getGreeting(agent); 
	currentSession.getAsyncRemote().sendText(greeting);
}
 
開發者ID:ibmruntimes,項目名稱:acmeair-modular,代碼行數:9,代碼來源:SupportWebSocket.java

示例14: onOpen

import javax.websocket.EndpointConfig; //導入依賴的package包/類
@Override
   public void onOpen(Session session, EndpointConfig endpointConfig) {
this.session = session;
if (messageHandler != null) {
    session.addMessageHandler(messageHandler);
}
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:8,代碼來源:WebsocketClient.java

示例15: opened

import javax.websocket.EndpointConfig; //導入依賴的package包/類
@OnOpen
public void opened(@PathParam("user") String user, Session session, EndpointConfig config) throws IOException{
    System.out.println("opened() Current thread "+ Thread.currentThread().getName());
    this.httpSession = (HttpSession) config.getUserProperties().get(user);
    System.out.println("User joined "+ user + " with http session id "+ httpSession.getId());
    String response = "User " + user + " | WebSocket session ID "+ session.getId() +" | HTTP session ID " + httpSession.getId();
    System.out.println(response);
    session.getBasicRemote().sendText(response);
}
 
開發者ID:abhirockzz,項目名稱:websocket-http-session,代碼行數:10,代碼來源:Service.java


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