當前位置: 首頁>>代碼示例>>Java>>正文


Java OnMessage類代碼示例

本文整理匯總了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())));

}
 
開發者ID:abhirockzz,項目名稱:websocket-chat,代碼行數:27,代碼來源:ChatServer.java

示例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
        }
    }
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:14,代碼來源:TesterEchoServer.java

示例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();

}
 
開發者ID:webrtc,項目名稱:KITE,代碼行數:17,代碼來源:ConfiguratorWsServlet.java

示例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;
}
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:26,代碼來源:PresenceWebsocketServer.java

示例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;
}
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:24,代碼來源:LearningWebsocketServer.java

示例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);
					}
				}
			}
		}
	});
}
 
開發者ID:capitalone,項目名稱:Hydrograph,代碼行數:31,代碼來源:HydrographUiClientSocket.java

示例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);
}
 
開發者ID:capitalone,項目名稱:Hydrograph,代碼行數:23,代碼來源:HydrographEngineCommunicatorSocket.java

示例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);
}
 
開發者ID:DanielJyc,項目名稱:simpleblockchain,代碼行數:8,代碼來源:ReverseWebSocketEndpoint.java

示例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);

}
 
開發者ID:abhirockzz,項目名稱:scalable-websocket-chat-with-hazelcast,代碼行數:17,代碼來源:ChatServer.java

示例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);
			}
		}
	}
}
 
開發者ID:okfarm09,項目名稱:JYLAND,代碼行數:15,代碼來源:BroadSocket.java

示例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;
    }
  }
}
 
開發者ID:MiniPa,項目名稱:cjs_ssms,代碼行數:25,代碼來源:WebSocketController.java

示例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");
	}
}
 
開發者ID:jkiddo,項目名稱:ccow,代碼行數:17,代碼來源:SubscriptionEndpoint.java

示例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());
	}
}
 
開發者ID:jkiddo,項目名稱:ccow,代碼行數:25,代碼來源:WSClientConnection.java

示例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);
    });
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:17,代碼來源:MCRWebCLIResourceSockets.java

示例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;
    }
}
 
開發者ID:MusalaSoft,項目名稱:atmosphere-agent,代碼行數:19,代碼來源:AgentEndpoint.java


注:本文中的javax.websocket.OnMessage類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。