当前位置: 首页>>代码示例>>Java>>正文


Java WsOutbound类代码示例

本文整理汇总了Java中org.apache.catalina.websocket.WsOutbound的典型用法代码示例。如果您正苦于以下问题:Java WsOutbound类的具体用法?Java WsOutbound怎么用?Java WsOutbound使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


WsOutbound类属于org.apache.catalina.websocket包,在下文中一共展示了WsOutbound类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onOpen

import org.apache.catalina.websocket.WsOutbound; //导入依赖的package包/类
@Override
protected void onOpen(WsOutbound outbound) {
	if(uid == -1){		//过期用户直接下线
		Map<String, Object> outMap = new HashMap<String, Object>();
		outMap.put("response", "notlogin");
          	String jsonString = JSONObject.fromObject(outMap).toString();
  			CharBuffer buffer = CharBuffer.wrap(jsonString);
  			try {
  				outbound.writeTextMessage(buffer);
  				outbound.flush();
  			} catch (IOException e) {
  				e.printStackTrace();
  			}
	}else{
		userMap.put(uid, outbound);
		System.out.println("[上线]==>uid:"+uid+"在线用户==>"+userMap.size());
		sendUnread(outbound);		//登录即检查有没有未读消息
	}
	super.onOpen(outbound);
}
 
开发者ID:HsingPeng,项目名称:ALLGO,代码行数:21,代码来源:PushServlet.java

示例2: sendUnread

import org.apache.catalina.websocket.WsOutbound; //导入依赖的package包/类
private void sendUnread(WsOutbound outbound){
	Map<String, Object> outMap = new HashMap<String, Object>();
	outMap.put("response", "remind_unread");
	UnreadDAO dao = new UnreadDAOimpl();
	List<UnreadVo> list = dao.getUnread(uid);
	if(list != null){
		outMap.put("remind_unread", list);
		String jsonString = JSONObject.fromObject(outMap).toString();
		CharBuffer buffer = CharBuffer.wrap(jsonString);
		try {
			outbound.writeTextMessage(buffer);
			outbound.flush();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
 
开发者ID:HsingPeng,项目名称:ALLGO,代码行数:18,代码来源:PushServlet.java

示例3: attributeAdded

import org.apache.catalina.websocket.WsOutbound; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void attributeAdded(ServletContextAttributeEvent arg0) {
	if(userMap == null){
		userMap = (Map<Integer, WsOutbound>) arg0.getServletContext().getAttribute("OnLineList");
	}
	//System.out.println("listener==>attributeAdded");
	Enumeration<String> att = arg0.getServletContext().getAttributeNames();
	while(att.hasMoreElements()){
		String next = att.nextElement();
		if(next.startsWith("action")){
				ServerMsg message = (ServerMsg) arg0.getServletContext().getAttribute(next);
			if(message != null){
			arg0.getServletContext().removeAttribute(next);
			doAction(message);
			}
		}
	}
}
 
开发者ID:HsingPeng,项目名称:ALLGO,代码行数:20,代码来源:ActionListener.java

示例4: sendUnread

import org.apache.catalina.websocket.WsOutbound; //导入依赖的package包/类
private void sendUnread(UnreadVo unread, WsOutbound outbound) {
	Map<String, Object> outMap = new HashMap<String, Object>();
	outMap.put("response", "remind_unread");
	List<UnreadVo> list = new ArrayList<UnreadVo>();
	list.add(unread);
	outMap.put("remind_unread", list);
	String jsonString = JSONObject.fromObject(outMap).toString();
	CharBuffer buffer = CharBuffer.wrap(jsonString);
	try {
		outbound.writeTextMessage(buffer);
		outbound.flush();
	} catch (IOException e) {
		e.printStackTrace();
	}
	
}
 
开发者ID:HsingPeng,项目名称:ALLGO,代码行数:17,代码来源:ActionListener.java

示例5: action10

import org.apache.catalina.websocket.WsOutbound; //导入依赖的package包/类
private void action10(ServerMsg message){
	EventFollowerVo action = (EventFollowerVo) message.getAction();
	int eid = action.getEid();
	String uname = action.getUname();
	dao.countFollower(eid);		//活动参与人数计数+1
	//发送给活动创建者
	int euid = dao.getEventUID(eid);
	WsOutbound outbound = userMap.get(euid);
	if(outbound != null){
		UnreadVo unread = dao.putUnread(euid,3,action.getEid(),0,uname+"加入了你的活动",DateTimeUtil.currentTime(),true);
		unread.setIsread(false);
		sendUnread(unread,outbound);
	}else{
		dao.putUnread(euid,3,action.getEid(),0,uname+"加入了你的活动",DateTimeUtil.currentTime(),false);
	}
}
 
开发者ID:HsingPeng,项目名称:ALLGO,代码行数:17,代码来源:ActionListener.java

示例6: action15

import org.apache.catalina.websocket.WsOutbound; //导入依赖的package包/类
public void action15(ServerMsg message){
	EventVo action = (EventVo) message.getAction();
	int eid = action.getEid();
	List<Integer> uids = dao.getAllFollowerUser(eid);	//通知所有参与的用户
	for(int uid:uids){
		WsOutbound outbound = userMap.get(uid);
		if(outbound != null){
			UnreadVo unread = dao.putUnread(uid,4,eid,1,action.getOutline(),DateTimeUtil.currentTime(),true);
			unread.setIsread(false);
			sendUnread(unread,outbound);
		}else{
			dao.putUnread(uid,4,eid,1,action.getOutline(),DateTimeUtil.currentTime(),false);
		}
	}
	
	dao.deleteFollower(eid);		//删除所有参与者,补充和评论
	dao.deleteAdd(eid);
	dao.deleteComment(eid);
	
}
 
开发者ID:HsingPeng,项目名称:ALLGO,代码行数:21,代码来源:ActionListener.java

示例7: onBinaryData

import org.apache.catalina.websocket.WsOutbound; //导入依赖的package包/类
@Override
protected void onBinaryData(InputStream is) throws IOException {
    // Simply echo the data to back to the client.
    WsOutbound outbound = getWsOutbound();

    int i = is.read();
    while (i != -1) {
        outbound.writeBinaryData(i);
        i = is.read();
    }

    outbound.flush();
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:14,代码来源:EchoStream.java

示例8: onTextData

import org.apache.catalina.websocket.WsOutbound; //导入依赖的package包/类
@Override
protected void onTextData(Reader r) throws IOException {
    // Simply echo the data to back to the client.
    WsOutbound outbound = getWsOutbound();

    int c = r.read();
    while (c != -1) {
        outbound.writeTextData((char) c);
        c = r.read();
    }

    outbound.flush();
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:14,代码来源:EchoStream.java

示例9: onOpen

import org.apache.catalina.websocket.WsOutbound; //导入依赖的package包/类
@Override
protected void onOpen(WsOutbound outbound) {
    connections.add(this);
    String message = String.format("* %s %s",
            nickname, "has joined.");
    broadcast(message);
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:8,代码来源:ChatWebSocketServlet.java

示例10: closeConnection

import org.apache.catalina.websocket.WsOutbound; //导入依赖的package包/类
/**
 * Sends the given status on the given WebSocket connection and closes the
 * connection.
 *
 * @param outbound The outbound WebSocket connection to close.
 * @param guac_status The status to send.
 */
public void closeConnection(WsOutbound outbound, GuacamoleStatus guac_status) {

    try {
        byte[] message = Integer.toString(guac_status.getGuacamoleStatusCode()).getBytes("UTF-8");
        outbound.close(guac_status.getWebSocketCode(), ByteBuffer.wrap(message));
    }
    catch (IOException e) {
        logger.debug("Unable to close WebSocket tunnel.", e);
    }

}
 
开发者ID:apache,项目名称:guacamole-client,代码行数:19,代码来源:GuacamoleWebSocketTunnelServlet.java

示例11: action14

import org.apache.catalina.websocket.WsOutbound; //导入依赖的package包/类
public void action14(ServerMsg message){
	EventAddVo action = (EventAddVo) message.getAction();
	int eid = action.getEid();
	List<Integer> uids = dao.getAllFollowerUser(eid);
	for(int uid:uids){
		WsOutbound outbound = userMap.get(uid);
		if(outbound != null){
			UnreadVo unread = dao.putUnread(uid,0,eid,0,action.getContent(),DateTimeUtil.currentTime(),true);
			unread.setIsread(false);
			sendUnread(unread,outbound);
		}else{
			dao.putUnread(uid,0,eid,0,action.getContent(),DateTimeUtil.currentTime(),false);
		}
	}
}
 
开发者ID:HsingPeng,项目名称:ALLGO,代码行数:16,代码来源:ActionListener.java

示例12: createWebSocketInbound

import org.apache.catalina.websocket.WsOutbound; //导入依赖的package包/类
@Override
protected StreamInbound createWebSocketInbound(String subProtocol, HttpServletRequest request) {
	try{
		final URI uri = new URI(request.getRequestURI());
		return new MessageInbound() {
			@Override
			protected void onBinaryMessage(ByteBuffer arg0) throws IOException {
			}

			@Override
			protected void onTextMessage(CharBuffer message) throws IOException {
				l.onTextMessage(message);
			}

			@Override
			protected void onOpen(final WsOutbound outbound) {
				l.onOpen(new Connection() {
					@Override
					public URI getRequestUri() {
						return uri;
					}
					@Override
					public void send(CharSequence text) throws IOException {
						outbound.writeTextMessage(CharBuffer.wrap(text));
					}
				});
			}

			@Override
			protected void onClose(int status) {
				l.onClose(status);
			}

			private ConnectionListener l = handler.createConnectionListener();
		};
	} catch(URISyntaxException e){
		throw new RuntimeException(e);
	}
}
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:40,代码来源:TomcatWebSocketServlet.java

示例13: send

import org.apache.catalina.websocket.WsOutbound; //导入依赖的package包/类
/**
 * Sends send the result of {@link Serializer#serialize(List)} to a destination.
 * 
 * @param buffer the bytes to send.
 * @param destination The peer to send to.
 */
private void send(final byte[] buffer, final Object destination) {
    if (LOG.isTraceEnabled()) {
        LOG.trace("Sending from thread: id: " + Thread.currentThread().getName() + ", name: "
                + Thread.currentThread().getName());
    }

    final WsOutbound outbound = ((MessageInbound) destination).getWsOutbound();

    final ExecutorService executorService = connectionThreads.get(destination);
    // execute asynchronously to avoid slower clients from interfering with faster clients
    executorService.execute(new Runnable() {
        @Override
        public void run() {
            try {
                outbound.writeBinaryMessage(ByteBuffer.wrap(buffer));
            } catch (final IOException e) {
                LOG.warn("Sending data to a client failed. Closing connection to this client.");
                try {
                    outbound.close(1002, null);
                    // CHECKSTYLE:OFF
                } catch (final IOException e1) {
                    // Maybe the connection is already closed. This is no exceptional state but rather the
                    // default in
                    // this case. So it's safe to ignore this exception.
                }
                // CHECKSTYLE:ON
                connectionCloses((SynchronizeFXTomcatConnection) destination);
            }
        }
    });
}
 
开发者ID:saxsys,项目名称:SynchronizeFX,代码行数:38,代码来源:SynchronizeFXTomcatChannel.java

示例14: Snake

import org.apache.catalina.websocket.WsOutbound; //导入依赖的package包/类
public Snake(int id, WsOutbound outbound) {
    this.id = id;
    this.outbound = outbound;
    this.hexColor = SnakeWebSocketServlet.getRandomHexColor();
    resetState();
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:7,代码来源:Snake.java

示例15: onOpen

import org.apache.catalina.websocket.WsOutbound; //导入依赖的package包/类
@Override
public void onOpen(WsOutbound out)
{
	this.out = out;
	this.d.notifyOpen();
}
 
开发者ID:EricssonResearch,项目名称:trap,代码行数:7,代码来源:WSSocket.java


注:本文中的org.apache.catalina.websocket.WsOutbound类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。