当前位置: 首页>>代码示例>>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;未经允许,请勿转载。