1
19
20 package com.liferay.portal.liveusers.messaging;
21
22 import com.liferay.portal.kernel.json.JSONObject;
23 import com.liferay.portal.kernel.log.Log;
24 import com.liferay.portal.kernel.log.LogFactoryUtil;
25 import com.liferay.portal.kernel.messaging.Message;
26 import com.liferay.portal.kernel.messaging.MessageListener;
27 import com.liferay.portal.liveusers.LiveUsers;
28
29
35 public class LiveUsersMessageListener implements MessageListener {
36
37 public void receive(Message message) {
38 try {
39 doReceive(message);
40 }
41 catch (Exception e) {
42 _log.error("Unable to process message " + message, e);
43 }
44 }
45
46 public void doReceive(Message message) throws Exception {
47 JSONObject jsonObj = (JSONObject)message.getPayload();
48
49 String command = jsonObj.getString("command");
50
51 if (command.equals("signIn")) {
52 doCommandSignIn(jsonObj);
53 }
54 else if (command.equals("signOut")) {
55 doCommandSignOut(jsonObj);
56 }
57 }
58
59 protected void doCommandSignIn(JSONObject jsonObj) throws Exception {
60 long companyId = jsonObj.getLong("companyId");
61 long userId = jsonObj.getLong("userId");
62 String sessionId = jsonObj.getString("sessionId");
63 String remoteAddr = jsonObj.getString("remoteAddr");
64 String remoteHost = jsonObj.getString("remoteHost");
65 String userAgent = jsonObj.getString("userAgent");
66
67 LiveUsers.signIn(
68 companyId, userId, sessionId, remoteAddr, remoteHost, userAgent);
69 }
70
71 protected void doCommandSignOut(JSONObject jsonObj) throws Exception {
72 long companyId = jsonObj.getLong("companyId");
73 long userId = jsonObj.getLong("userId");
74 String sessionId = jsonObj.getString("sessionId");
75
76 LiveUsers.signOut(companyId, userId, sessionId);
77 }
78
79 private static Log _log =
80 LogFactoryUtil.getLog(LiveUsersMessageListener.class);
81
82 }