001
014
015 package com.liferay.portal.poller.comet;
016
017 import com.liferay.portal.kernel.json.JSONObject;
018 import com.liferay.portal.kernel.log.Log;
019 import com.liferay.portal.kernel.log.LogFactoryUtil;
020 import com.liferay.portal.kernel.notifications.ChannelException;
021 import com.liferay.portal.kernel.notifications.ChannelHubManagerUtil;
022 import com.liferay.portal.kernel.notifications.ChannelListener;
023 import com.liferay.portal.kernel.notifications.UnknownChannelException;
024 import com.liferay.portal.kernel.poller.comet.CometRequest;
025 import com.liferay.portal.kernel.poller.comet.CometSession;
026
027
030 public class PollerCometChannelListener implements ChannelListener {
031
032 public PollerCometChannelListener(
033 CometSession cometSession, JSONObject pollerResponseHeaderJSONObject) {
034
035 _cometSession = cometSession;
036 _pollerResponseHeaderJSONObject = pollerResponseHeaderJSONObject;
037 }
038
039 @Override
040 public void channelListenerRemoved(long channelId) {
041 }
042
043 @Override
044 public void notificationEventsAvailable(long channelId) {
045 sendProcessMessage();
046 }
047
048 protected void sendProcessMessage() {
049 CometRequest cometRequest = _cometSession.getCometRequest();
050
051 try {
052 ChannelHubManagerUtil.unregisterChannelListener(
053 cometRequest.getCompanyId(), cometRequest.getUserId(), this);
054 }
055 catch (UnknownChannelException uce) {
056 }
057 catch (ChannelException ce) {
058 if (_log.isWarnEnabled()) {
059 _log.warn("Unable to unregister channel listener", ce);
060 }
061 }
062
063 PollerCometDelayedTask pollerCometDelayedTask =
064 new PollerCometDelayedTask(
065 _cometSession, _pollerResponseHeaderJSONObject);
066
067 PollerCometDelayedJobUtil.addPollerCometDelayedTask(
068 pollerCometDelayedTask);
069 }
070
071 private static Log _log = LogFactoryUtil.getLog(
072 PollerCometChannelListener.class);
073
074 private CometSession _cometSession;
075 private JSONObject _pollerResponseHeaderJSONObject;
076
077 }