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