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


Java Session.isOpen方法代码示例

本文整理汇总了Java中javax.websocket.Session.isOpen方法的典型用法代码示例。如果您正苦于以下问题:Java Session.isOpen方法的具体用法?Java Session.isOpen怎么用?Java Session.isOpen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.websocket.Session的用法示例。


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

示例1: broadcast

import javax.websocket.Session; //导入方法依赖的package包/类
public void broadcast(@Observes @LeaderDataQualifier String leaderboard) {
    for (final Session s : CLIENTS) {
        if (s != null && s.isOpen()) {
            /**
             * Asynchronous push
             */
            s.getAsyncRemote().sendText(leaderboard, new SendHandler() {
                @Override
                public void onResult(SendResult result) {
                    if (result.isOK()) {
                        //Logger.getLogger(MeetupGroupsLiveLeaderboardEndpoint.class.getName()).log(Level.INFO, " sent to client {0}", s.getId());
                    } else {
                        Logger.getLogger(MeetupGroupsLiveLeaderboardEndpoint.class.getName()).log(Level.SEVERE, "Could not send to client " + s.getId(),
                                result.getException());
                    }
                }
            });
        }

    }

}
 
开发者ID:abhirockzz,项目名称:redis-websocket-javaee,代码行数:23,代码来源:MeetupGroupsLiveLeaderboardEndpoint.java

示例2: sendAddTimeRequest

import javax.websocket.Session; //导入方法依赖的package包/类
/**
    * Monitor has added one more minute to the time limit. All learners will need
    * to add +1 minute to their countdown counters.
    */
   private static void sendAddTimeRequest(Long toolContentId, int timeLimit) throws JSONException, IOException {
Set<Session> toolContentWebsockets = websockets.get(toolContentId);
if (toolContentWebsockets == null) {
    return;
}

JSONObject responseJSON = new JSONObject();
responseJSON.put("addTime", timeLimit);
String response = responseJSON.toString();

for (Session websocket : toolContentWebsockets) {
    if (websocket.isOpen()) {
	websocket.getBasicRemote().sendText(response);
    }
}
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:LearningWebsocketServer.java

示例3: sendPageRefreshRequest

import javax.websocket.Session; //导入方法依赖的package包/类
/**
    * Monitor has launched time limit. All learners will need to refresh the page in order to stop showing them
    * waitForTimeLimitLaunch page.
    */
   private static void sendPageRefreshRequest(Long toolContentId) throws JSONException, IOException {
Set<Session> toolContentWebsockets = websockets.get(toolContentId);
if (toolContentWebsockets == null) {
    return;
}

JSONObject responseJSON = new JSONObject();
responseJSON.put("pageRefresh", true);
String response = responseJSON.toString();

for (Session websocket : toolContentWebsockets) {
    if (websocket.isOpen()) {
	websocket.getBasicRemote().sendText(response);
    }
}
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:LearningWebsocketServer.java

示例4: send

import javax.websocket.Session; //导入方法依赖的package包/类
/**
 * Feeds opened websockets with commands.
 */
private void send(Long lessonId) throws IOException {
    Long lastSendTime = lastSendTimes.get(lessonId);
    if (lastSendTime == null) {
	lastSendTime = System.currentTimeMillis() - CHECK_INTERVAL;
    }
    lastSendTimes.put(lessonId, System.currentTimeMillis());

    List<Command> commands = CommandWebsocketServer.getLearnerService().getCommandsForLesson(lessonId,
	    new Date(lastSendTime));
    Map<String, Session> lessonWebsockets = CommandWebsocketServer.websockets.get(lessonId);
    for (Command command : commands) {
	Session websocket = lessonWebsockets.get(command.getUserName());
	if (websocket != null && websocket.isOpen()) {
	    websocket.getBasicRemote().sendText(command.getCommandText());
	}
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:CommandWebsocketServer.java

示例5: sendCloseRequest

import javax.websocket.Session; //导入方法依赖的package包/类
/**
    * The leader finished scratching and also . Non-leaders will have
    * Finish button displayed.
    */
   public static void sendCloseRequest(Long toolSessionId) throws JSONException, IOException {
Set<Session> sessionWebsockets = LearningWebsocketServer.websockets.get(toolSessionId);
if (sessionWebsockets == null) {
    return;
}

JSONObject responseJSON = new JSONObject();
responseJSON.put("close", true);
String response = responseJSON.toString();

for (Session websocket : sessionWebsockets) {
    if (websocket.isOpen()) {
	websocket.getBasicRemote().sendText(response);
    }
}
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:LearningWebsocketServer.java

示例6: sendCloseRequest

import javax.websocket.Session; //导入方法依赖的package包/类
/**
    * The scribe or a Monitor has force completed the activity. Browsers will refresh and display report summary.
    */
   static void sendCloseRequest(Long toolSessionId) throws JSONException, IOException {
Set<Session> sessionWebsockets = LearningWebsocketServer.websockets.get(toolSessionId);
if (sessionWebsockets == null) {
    return;
}

JSONObject responseJSON = new JSONObject();
responseJSON.put("close", true);
String response = responseJSON.toString();

for (Session websocket : sessionWebsockets) {
    if (websocket.isOpen()) {
	websocket.getBasicRemote().sendText(response);
    }
}
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:LearningWebsocketServer.java

示例7: updateStatus

import javax.websocket.Session; //导入方法依赖的package包/类
public static synchronized void updateStatus(@Observes StatusEvent event) {
    log.info("updateStatus");
    for (Session s : sessions) {
        if (s.isOpen()) {
            try {
                String studentUpdate = jsonStudentUpdate(event.getStudent());
                s.getBasicRemote().sendText(studentUpdate);
                log.log(Level.INFO, "[StatusEndpoint] {0} is now {1}", 
                        new Object[]{event.getStudent().getName(), 
                            event.getStudent().getStatus()});
                /* Send update */
            } catch (IOException e) {
                log.log(Level.INFO, "[StatusEndpoint] {0}", e.getMessage());
            }
        }
    }
}
 
开发者ID:wwu-pi,项目名称:tap17-muggl-javaee,代码行数:18,代码来源:StatusEndpoint.java

示例8: updateStatus2

import javax.websocket.Session; //导入方法依赖的package包/类
public static synchronized void updateStatus2(Student student) {
    log.info("updateStatus2");
    for (Session s : sessions) {
        if (s.isOpen()) {
            try {
                String studentUpdate = jsonStudentUpdate(student);
                s.getBasicRemote().sendText(studentUpdate);
                log.log(Level.INFO, "[StatusEndpoint] {0} is now {1}", 
                        new Object[]{student.getName(), 
                            student.getStatus()});
                /* Send update */
            } catch (IOException e) {
                log.log(Level.INFO, "[StatusEndpoint] {0}", e.getMessage());
            }
        }
    }
}
 
开发者ID:wwu-pi,项目名称:tap17-muggl-javaee,代码行数:18,代码来源:StatusEndpoint.java

示例9: closeWebSocketConnection

import javax.websocket.Session; //导入方法依赖的package包/类
/**
 * Close Websocket connection Connection
 * @param session
 */
private void closeWebSocketConnection(final Session session ){
	try {
		Thread.sleep(3000);
	} catch (InterruptedException e1) {
	}

	if (session != null && session.isOpen()) {
		try {
			CloseReason closeReason = new CloseReason(
					CloseCodes.NORMAL_CLOSURE, "Session Closed");
			session.close(closeReason);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:21,代码来源:JobScpAndProcessUtility.java

示例10: closeWebSocketConnection

import javax.websocket.Session; //导入方法依赖的package包/类
/**
 * 
 * Close websocket client connection.
 * @param session
 */
public void closeWebSocketConnection(Session session){
	try {
		Thread.sleep(DELAY);
	} catch (InterruptedException e1) {
	}
	if (session != null  && session.isOpen()) {
		try {
			CloseReason closeReason = new CloseReason(CloseCodes.NORMAL_CLOSURE,"Closed");
			session.close(closeReason);
			logger.info("Session closed");
		} catch (IOException e) {
			logger.error("Fail to close connection ",e);
		}
		
	}

}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:23,代码来源:TrackingDisplayUtils.java

示例11: onMessage

import javax.websocket.Session; //导入方法依赖的package包/类
@OnMessage
public void onMessage(Session session, String message) {
    String messageToSend = message.toUpperCase();

    try {
        if (session.isOpen()) session.getBasicRemote().sendText(messageToSend);
    } catch (Exception e) {
        LOGGER.error("Failed to send message to client, message: {}, session: {}", messageToSend, session);
    }
}
 
开发者ID:asafalima,项目名称:guice-websocket,代码行数:11,代码来源:EchoEndpoint.java

示例12: getOpenCount

import javax.websocket.Session; //导入方法依赖的package包/类
private int getOpenCount(Set<Session> sessions) {
    int result = 0;
    for (Session session : sessions) {
        if (session.isOpen()) {
            result++;
        }
    }
    return result;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:10,代码来源:TestWsWebSocketContainer.java

示例13: echoBinaryMessage

import javax.websocket.Session; //导入方法依赖的package包/类
@OnMessage
public void echoBinaryMessage(Session session, ByteBuffer bb,
        boolean last) {
    try {
        if (session.isOpen()) {
            session.getBasicRemote().sendBinary(bb, last);
        }
    } catch (IOException e) {
        try {
            session.close();
        } catch (IOException e1) {
            // Ignore
        }
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:16,代码来源:TesterWsClientAutobahn.java

示例14: broadcastMessage

import javax.websocket.Session; //导入方法依赖的package包/类
public static void broadcastMessage(String message) {
	for (Session s : sessions) {
		if (s.isOpen()) {
			try {
				s.getBasicRemote().sendText(message);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
 
开发者ID:costea7,项目名称:ChronoBike,代码行数:12,代码来源:SimpleWSHandler.java

示例15: doMaxMessageSize

import javax.websocket.Session; //导入方法依赖的package包/类
private void doMaxMessageSize(String path, long size, boolean expectOpen)
        throws Exception {

    Tomcat tomcat = getTomcatInstance();
    // No file system docBase required
    Context ctx = tomcat.addContext("", null);
    ctx.addApplicationListener(TesterEchoServer.Config.class.getName());
    Tomcat.addServlet(ctx, "default", new DefaultServlet());
    ctx.addServletMapping("/", "default");

    tomcat.start();

    WebSocketContainer wsContainer =
            ContainerProvider.getWebSocketContainer();

    Session s = connectToEchoServer(wsContainer, new EndpointA(), path);

    // One for the client, one for the server
    validateBackgroundProcessCount(2);

    StringBuilder msg = new StringBuilder();
    for (long i = 0; i < size; i++) {
        msg.append('x');
    }

    s.getBasicRemote().sendText(msg.toString());

    // Wait for up to 5 seconds for the client session to open
    boolean open = s.isOpen();
    int count = 0;
    while (open != expectOpen && count < 50) {
        Thread.sleep(100);
        count++;
        open = s.isOpen();
    }

    Assert.assertEquals(Boolean.valueOf(expectOpen),
            Boolean.valueOf(s.isOpen()));

    // Close the session if it is expected to be open
    if (expectOpen) {
        s.close();
    }

    // Ensure both server and client have shutdown
    validateBackgroundProcessCount(0);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:48,代码来源:TestWsWebSocketContainer.java


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