本文整理汇总了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);
}
示例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();
}
}
}
示例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);
}
}
}
}
示例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();
}
}
示例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);
}
}
示例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);
}
示例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();
}
示例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();
}
示例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);
}
示例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);
}
}
示例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);
}
}
}
示例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);
}
}
示例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);
}
}
});
}
示例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();
}
示例15: onOpen
import org.apache.catalina.websocket.WsOutbound; //导入依赖的package包/类
@Override
public void onOpen(WsOutbound out)
{
this.out = out;
this.d.notifyOpen();
}