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