public synchronized String getNotificationEvents(long timeout) throws ChannelException {

    try {
      if (!_complete) {
        this.wait(timeout);
      }
    } catch (InterruptedException ie) {
    }

    try {
      Thread.sleep(PropsValues.POLLER_NOTIFICATIONS_TIMEOUT);
    } catch (InterruptedException ie) {
    }

    List<NotificationEvent> notificationEvents =
        ChannelHubManagerUtil.getNotificationEvents(_companyId, _userId, true);

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    jsonArray.put(_pollerResponseHeaderJSONObject);

    for (NotificationEvent notificationEvent : notificationEvents) {
      jsonArray.put(notificationEvent.toJSONObject());
    }

    return jsonArray.toString();
  }
  protected void sendProcessMessage() {
    CometRequest cometRequest = _cometSession.getCometRequest();

    try {
      ChannelHubManagerUtil.unregisterChannelListener(
          cometRequest.getCompanyId(), cometRequest.getUserId(), this);
    } catch (UnknownChannelException uce) {
    } catch (ChannelException ce) {
      if (_log.isWarnEnabled()) {
        _log.warn("Unable to unregister channel listener", ce);
      }
    }

    PollerCometDelayedTask pollerCometDelayedTask =
        new PollerCometDelayedTask(_cometSession, _pollerResponseHeaderJSONObject);

    PollerCometDelayedJobUtil.addPollerCometDelayedTask(pollerCometDelayedTask);
  }
  protected void sendNotificationEvent(MemberRequest memberRequest)
      throws PortalException, SystemException {

    JSONObject notificationEventJSONObject = JSONFactoryUtil.createJSONObject();

    notificationEventJSONObject.put("groupId", memberRequest.getGroupId());
    notificationEventJSONObject.put("memberRequestId", memberRequest.getMemberRequestId());
    notificationEventJSONObject.put("portletId", PortletKeys.SO_INVITE_MEMBERS);
    notificationEventJSONObject.put("title", "x-invited-you-to-join-x");
    notificationEventJSONObject.put("userId", memberRequest.getUserId());

    NotificationEvent notificationEvent =
        NotificationEventFactoryUtil.createNotificationEvent(
            System.currentTimeMillis(), PortletKeys.SO_NOTIFICATION, notificationEventJSONObject);

    notificationEvent.setDeliveryRequired(0);

    ChannelHubManagerUtil.sendNotificationEvent(
        memberRequest.getCompanyId(), memberRequest.getReceiverUserId(), notificationEvent);
  }
  protected void sendNotificationEvent(MicroblogsEntry microblogsEntry)
      throws PortalException, SystemException {

    JSONObject notificationEventJSONObject = JSONFactoryUtil.createJSONObject();

    notificationEventJSONObject.put("body", microblogsEntry.getContent());
    notificationEventJSONObject.put("entryId", microblogsEntry.getMicroblogsEntryId());
    notificationEventJSONObject.put("entryKeyName", "receiverMicroblogsEntryId");
    notificationEventJSONObject.put("mvcPath", "/microblogs/view.jsp");
    notificationEventJSONObject.put("portletId", "1_WAR_microblogsportlet");
    notificationEventJSONObject.put("title", "x-commented-on-your-post");
    notificationEventJSONObject.put("userId", microblogsEntry.getUserId());

    NotificationEvent notificationEvent =
        NotificationEventFactoryUtil.createNotificationEvent(
            System.currentTimeMillis(), "6_WAR_soportlet", notificationEventJSONObject);

    notificationEvent.setDeliveryRequired(0);

    ChannelHubManagerUtil.sendNotificationEvent(
        microblogsEntry.getCompanyId(), microblogsEntry.getReceiverUserId(), notificationEvent);
  }