本文整理匯總了Java中javax.websocket.OnMessage類的典型用法代碼示例。如果您正苦於以下問題:Java OnMessage類的具體用法?Java OnMessage怎麽用?Java OnMessage使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
OnMessage類屬於javax.websocket包,在下文中一共展示了OnMessage類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: msgReceived
import javax.websocket.OnMessage; //導入依賴的package包/類
@OnMessage
public void msgReceived(ChatMessage msg, Session s) {
if (msg.getMsg().equals(LOGOUT_MSG)) {
try {
s.close();
return;
} catch (IOException ex) {
Logger.getLogger(ChatServer.class.getName()).log(Level.SEVERE, null, ex);
}
}
Predicate<Session> filterCriteria = null;
if (!msg.isPrivate()) {
//for ALL (except self)
filterCriteria = (session) -> !session.getUserProperties().get("user").equals(user);
} else {
String privateRecepient = msg.getRecepient();
//private IM
filterCriteria = (session) -> privateRecepient.equals(session.getUserProperties().get("user"));
}
s.getOpenSessions().stream()
.filter(filterCriteria)
//.forEach((session) -> session.getAsyncRemote().sendText(msgContent));
.forEach((session) -> session.getAsyncRemote().sendObject(new Reply(msg.getMsg(), user, msg.isPrivate())));
}
示例2: echoBinaryMessage
import javax.websocket.OnMessage; //導入依賴的package包/類
@OnMessage
public void echoBinaryMessage(Session session, ByteBuffer msg,
boolean last) {
try {
session.getBasicRemote().sendBinary(msg, last);
} catch (IOException e) {
try {
session.close();
} catch (IOException e1) {
// Ignore
}
}
}
示例3: onMessage
import javax.websocket.OnMessage; //導入依賴的package包/類
@OnMessage
public String onMessage(String message) {
List<String> splittedMessage = Arrays.asList(message.split(Pattern.quote("|")));
switch (splittedMessage.get(0)) {
case "configuration-name":
this.configName = splittedMessage.get(1);
break;
case "callback":
this.callback = splittedMessage.get(1);
break;
}
if (log.isDebugEnabled())
log.debug("Message from the client: " + message);
return this.createConfigurationText();
}
示例4: receiveRequest
import javax.websocket.OnMessage; //導入依賴的package包/類
/**
* Receives a message sent by Learner via a websocket.
*
* @throws IOException
*/
@OnMessage
public void receiveRequest(String input, Session session) throws JSONException, IOException {
if (StringUtils.isBlank(input)) {
return;
}
if (input.equalsIgnoreCase("ping")) {
// just a ping every few minutes
return;
}
JSONObject requestJSON = new JSONObject(input);
switch (requestJSON.getString("type")) {
case "message":
PresenceWebsocketServer.storeMessage(requestJSON, session);
break;
case "fetchConversation":
PresenceWebsocketServer.sendConversation(requestJSON, session);
break;
}
}
示例5: receiveRequest
import javax.websocket.OnMessage; //導入依賴的package包/類
/**
* Receives a message sent by Learner via a websocket.
*/
@OnMessage
public void receiveRequest(String input, Session websocket) throws JSONException {
if (StringUtils.isBlank(input)) {
return;
}
if (input.equalsIgnoreCase("ping")) {
// just a ping every few minutes
return;
}
JSONObject requestJSON = new JSONObject(input);
switch (requestJSON.getString("type")) {
case "vote":
LearningWebsocketServer.vote(websocket);
break;
case "submitReport":
LearningWebsocketServer.submitReport(requestJSON, websocket);
break;
}
}
示例6: updateJobTrackingStatus
import javax.websocket.OnMessage; //導入依賴的package包/類
/**
*
* Called by web socket server, message contain execution tracking status that updated on job canvas.
*
* @param message the message
* @param session the session
*/
@OnMessage
public void updateJobTrackingStatus(String message, Session session) {
final String status = message;
Display.getDefault().asyncExec(new Runnable() {
public void run() {
Gson gson = new Gson();
ExecutionStatus executionStatus=gson.fromJson(status, ExecutionStatus.class);
IWorkbenchPage page = PlatformUI.getWorkbench().getWorkbenchWindows()[0].getActivePage();
IEditorReference[] refs = page.getEditorReferences();
for (IEditorReference ref : refs){
IEditorPart editor = ref.getEditor(false);
if(editor instanceof ELTGraphicalEditor){
ELTGraphicalEditor editPart=(ELTGraphicalEditor)editor;
if(editPart.getJobId().equals(executionStatus.getJobId()) || (((editPart.getContainer()!=null) &&
(editPart.getContainer().getUniqueJobId().equals(executionStatus.getJobId()))) && editPart.getContainer().isOpenedForTracking() )){
TrackingStatusUpdateUtils.INSTANCE.updateEditorWithCompStatus(executionStatus, (ELTGraphicalEditor)editor,false);
}
}
}
}
});
}
示例7: onMessage
import javax.websocket.OnMessage; //導入依賴的package包/類
/**
* Client onMessage get called to kill the job
* @param message
* @param session
*/
@OnMessage
public void onMessage(String message, Session session) {
logger.info("Trying to kill the job");
final Timer timer = new Timer();
TimerTask task = new TimerTask() {
@Override
public void run() {
if (execution != null) {
logger.info("Job killed successfully");
execution.kill();
timer.cancel();
}
}
};
timer.schedule(task, 0l, 600);
}
示例8: handleMessage
import javax.websocket.OnMessage; //導入依賴的package包/類
@OnMessage
public void handleMessage(Session session, String message) throws IOException {
logger.info("Received msg: " + message);
String sendMsg = "Reversed: " + new StringBuilder(message).reverse();
session.getBasicRemote().sendText(sendMsg);
logger.info("Send msg: " + sendMsg);
}
示例9: msgReceived
import javax.websocket.OnMessage; //導入依賴的package包/類
@OnMessage
public void msgReceived(ChatMessage msg, Session s) {
msg.from(user);
if (msg.getMsg().equals(LOGOUT_MSG)) {
try {
s.close();
return;
} catch (IOException ex) {
Logger.getLogger(ChatServer.class.getName()).log(Level.SEVERE, null, ex);
}
}
ChatEventBus.getInstance().publishChat(msg);
System.out.println("Chat Message placed on HZ Topic " + CHAT_TOPIC_NAME);
}
示例10: onMessage
import javax.websocket.OnMessage; //導入依賴的package包/類
@OnMessage
public void onMessage(String message, Session session) throws IOException {
logger.info("Welcome BroadSocket onMessage " + new Date());
logger.info("Welcome BroadSocket onMessage " + message);
synchronized(clients) {
for(Session client : clients) {
if(!client.equals(session)) {
String msg=cf.rmScript(message);
logger.info("Welcome BroadSocket onMessage " + msg);
client.getBasicRemote().sendText(msg);
}
}
}
}
示例11: onMessage
import javax.websocket.OnMessage; //導入依賴的package包/類
/**
* 收到客戶端消息後調用的方法
*
* @param message 客戶端發送過來的消息
* @param session 可選的參數
*/
@OnMessage
public void onMessage(String message, Session session) {
log.debug("來自客戶端的消息:" + message);
/*群發消息*/
for (WebSocketController item : webSocketSet) {
try {
Principal principal = session.getUserPrincipal();
if (null == principal) {
log.debug("群發消息,未獲取到當前用戶認證信息。");
continue;
}
item.serializeMessage(message,principal);
} catch (IOException e) {
e.printStackTrace();
continue;
}
}
}
示例12: onWebSocketText
import javax.websocket.OnMessage; //導入依賴的package包/類
@OnMessage
public void onWebSocketText(final Session sess, final JSONRPC2Message msg, @PathParam(CCOWContextListener.PATH_NAME) final String applicationName) {
if (msg instanceof JSONRPC2Request) {
//All operations that are invokable on ContextManager that does not return void
logger.debug("The message is a Request");
}
else if (msg instanceof JSONRPC2Notification) {
//All operations that are invokable on ContextManager that does return void
logger.debug("The message is a Notification");
}
else if (msg instanceof JSONRPC2Response) {
//All operations that are invokable from ContextManager that does not return void and are initially called from ContextManager
participant.onMessage((JSONRPC2Response) msg);
logger.debug("The message is a Response");
}
}
示例13: onWebSocketText
import javax.websocket.OnMessage; //導入依賴的package包/類
@OnMessage
public void onWebSocketText(final Session sess, final JSONRPC2Message msg) throws IOException, EncodeException {
this.latestMessage = msg;
if (msg instanceof JSONRPC2Request) {
//All operations that are invokable on ContextManager that does not return void
System.out.println("The message is a Request " + msg.toJSONString());
final JSONRPC2Response data = new JSONRPC2Response(((JSONRPC2Request) msg).getID());
final Map<String,String> result = Maps.newHashMap();
result.put("decision", "valid");
result.put("reason", "");
data.setResult(result);
sess.getBasicRemote().sendObject(data);
}
else if (msg instanceof JSONRPC2Notification) {
//All operations that are invokable on ContextManager that does return void
System.out.println("The message is a Notification " + msg.toJSONString());
}
else if (msg instanceof JSONRPC2Response) {
//Can only be ContextChangesPending
System.out.println("The message is a Response " + msg.toJSONString());
}
}
示例14: message
import javax.websocket.OnMessage; //導入依賴的package包/類
@OnMessage
public void message(Session session, JsonObject request) {
sessionized(session, () -> {
LOGGER.info("Message ThreadID: {}", Thread.currentThread().getName());
LOGGER.info("MyCore Session ID (message): {}", MCRSessionMgr.getCurrentSessionID());
if (!MCRAccessManager.checkPermission("use-webcli")) {
try {
session.getBasicRemote().sendText("noPermission");
} catch (IOException ex) {
LOGGER.error("Cannot send message to client.", ex);
}
return;
}
handleMessage(session, request);
});
}
示例15: onJsonMessage
import javax.websocket.OnMessage; //導入依賴的package包/類
@OnMessage
public void onJsonMessage(String jsonMessage, Session session) {
MessageAction messageAction = jsonUtil.getProperty(jsonMessage, JsonConst.MESSAGE_ACTION, MessageAction.class);
switch (messageAction) {
case ROUTING_ACTION:
RequestMessage request = jsonUtil.deserializeRequest(jsonMessage);
dispatcher.executeRoutingActionRequest(request);
break;
case ERROR:
ResponseMessage response = jsonUtil.deserializeResponse(jsonMessage);
LOGGER.error("Server error", response.getException());
break;
default:
LOGGER.error("Invalid message action.");
break;
}
}