001
014
015 package com.liferay.portal.liveusers.messaging;
016
017 import com.liferay.portal.kernel.json.JSONObject;
018 import com.liferay.portal.kernel.log.Log;
019 import com.liferay.portal.kernel.log.LogFactoryUtil;
020 import com.liferay.portal.kernel.messaging.Message;
021 import com.liferay.portal.kernel.messaging.MessageListener;
022 import com.liferay.portal.liveusers.LiveUsers;
023
024
027 public class LiveUsersMessageListener implements MessageListener {
028
029 public void receive(Message message) {
030 try {
031 doReceive(message);
032 }
033 catch (Exception e) {
034 _log.error("Unable to process message " + message, e);
035 }
036 }
037
038 protected void doCommandSignIn(JSONObject jsonObj) throws Exception {
039 long companyId = jsonObj.getLong("companyId");
040 long userId = jsonObj.getLong("userId");
041 String sessionId = jsonObj.getString("sessionId");
042 String remoteAddr = jsonObj.getString("remoteAddr");
043 String remoteHost = jsonObj.getString("remoteHost");
044 String userAgent = jsonObj.getString("userAgent");
045
046 LiveUsers.signIn(
047 companyId, userId, sessionId, remoteAddr, remoteHost, userAgent);
048 }
049
050 protected void doCommandSignOut(JSONObject jsonObj) throws Exception {
051 long companyId = jsonObj.getLong("companyId");
052 long userId = jsonObj.getLong("userId");
053 String sessionId = jsonObj.getString("sessionId");
054
055 LiveUsers.signOut(companyId, userId, sessionId);
056 }
057
058 protected void doReceive(Message message) throws Exception {
059 JSONObject jsonObj = (JSONObject)message.getPayload();
060
061 String command = jsonObj.getString("command");
062
063 if (command.equals("signIn")) {
064 doCommandSignIn(jsonObj);
065 }
066 else if (command.equals("signOut")) {
067 doCommandSignOut(jsonObj);
068 }
069 }
070
071 private static Log _log = LogFactoryUtil.getLog(
072 LiveUsersMessageListener.class);
073
074 }