001
014
015 package com.liferay.portal.poller.messaging;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019 import com.liferay.portal.kernel.messaging.BaseMessageListener;
020 import com.liferay.portal.kernel.messaging.Message;
021 import com.liferay.portal.kernel.notifications.ChannelHubManagerUtil;
022 import com.liferay.portal.kernel.notifications.NotificationEvent;
023 import com.liferay.portal.kernel.notifications.NotificationEventFactoryUtil;
024 import com.liferay.portal.kernel.notifications.UnknownChannelException;
025 import com.liferay.portal.kernel.poller.PollerHeader;
026 import com.liferay.portal.kernel.poller.PollerResponse;
027
028
031 public class PollerNotificationsBridgeMessageListener
032 extends BaseMessageListener {
033
034 @Override
035 protected void doReceive(Message message) throws Exception {
036 Object messagePayload = message.getPayload();
037
038 if (!(messagePayload instanceof PollerResponse)) {
039 if (_log.isWarnEnabled()) {
040 _log.warn(
041 "Received message with payload not of type PollerResponse");
042 }
043
044 return;
045 }
046
047 PollerResponse pollerResponse = (PollerResponse)messagePayload;
048
049 if (pollerResponse.isEmpty()) {
050 return;
051 }
052
053 PollerHeader pollerHeader = pollerResponse.getPollerHeader();
054
055 NotificationEvent notificationEvent =
056 NotificationEventFactoryUtil.createNotificationEvent(
057 System.currentTimeMillis(),
058 PollerNotificationsBridgeMessageListener.class.getName(),
059 pollerResponse.toJSONObject());
060
061 try {
062 ChannelHubManagerUtil.sendNotificationEvent(
063 pollerHeader.getCompanyId(), pollerHeader.getUserId(),
064 notificationEvent);
065 }
066 catch (UnknownChannelException uce) {
067 if (_log.isDebugEnabled()) {
068 _log.debug(
069 "Unable to complete processing because user session ended",
070 uce);
071 }
072 }
073 }
074
075 private static Log _log = LogFactoryUtil.getLog(
076 PollerNotificationsBridgeMessageListener.class);
077
078 }