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.messaging.BaseMessageListener;
020 import com.liferay.portal.kernel.messaging.Message;
021 import com.liferay.portal.liveusers.LiveUsers;
022
023
026 public class LiveUsersMessageListener extends BaseMessageListener {
027
028 protected void doCommandSignIn(JSONObject jsonObject) throws Exception {
029 long companyId = jsonObject.getLong("companyId");
030 long userId = jsonObject.getLong("userId");
031 String sessionId = jsonObject.getString("sessionId");
032 String remoteAddr = jsonObject.getString("remoteAddr");
033 String remoteHost = jsonObject.getString("remoteHost");
034 String userAgent = jsonObject.getString("userAgent");
035
036 LiveUsers.signIn(
037 companyId, userId, sessionId, remoteAddr, remoteHost, userAgent);
038 }
039
040 protected void doCommandSignOut(JSONObject jsonObject) throws Exception {
041 long companyId = jsonObject.getLong("companyId");
042 long userId = jsonObject.getLong("userId");
043 String sessionId = jsonObject.getString("sessionId");
044
045 LiveUsers.signOut(companyId, userId, sessionId);
046 }
047
048 @Override
049 protected void doReceive(Message message) throws Exception {
050 String payload = (String)message.getPayload();
051
052 JSONObject jsonObject = JSONFactoryUtil.createJSONObject(payload);
053
054 String command = jsonObject.getString("command");
055
056 if (command.equals("signIn")) {
057 doCommandSignIn(jsonObject);
058 }
059 else if (command.equals("signOut")) {
060 doCommandSignOut(jsonObject);
061 }
062 }
063
064 }