Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Andrea Pinazzi
How to use the poller service
November 19, 2009 9:17 AM
Answer

Andrea Pinazzi

Rank: New Member

Posts: 4

Join Date: October 8, 2009

Recent Posts

I'd like to implement a comet-like portlet (like chat portlet), but even after looking at souces I still have problems

liferay-porltet.xml
1
2  <portlet>
3    <portlet-name>TestPortlet</portlet-name>
4    <poller-processor-class>com.test.FooProcessor</poller-processor-class>
5    <instanceable>true</instanceable>
6  </portlet>


FooProcessor.java
 1
 2public class FooProcessor extends BasePollerProcessor {
 3    private static Log log = LogFactoryUtil.getLog( FooProcessor.class );
 4
 5    @Override
 6    protected void doReceive(PollerRequest request, PollerResponse response) throws Exception {
 7        log.debug("in doReceive");
 8    }
 9
10    @Override
11    protected void doSend(PollerRequest request) throws Exception {
12        log.debug("in doSend");
13    }
14}


javascript in view.jsp
 1
 2<script type="text/javascript">
 3    jQuery( function($){
 4        var dump = function( data ) {
 5            if( data.constructor == Array ||
 6                data.constructor == Object ) {
 7                for( var p in data ) {
 8                    if( p.constructor == Array ||
 9                        p.constructor == Object ) {
10                        console.log( "[" +p+"] => " + typeof p );
11                        dump( p );
12                    } else {
13                        console.log( "[" + p + "] => " + data[p] );
14                    }
15                }
16            }
17        };
18
19        HDS = {
20            init: function() {
21                var instance = this;
22                instance.id = "<%= portletDisplay.getId()%>";
23                // taken from  chat's javascript.js
24                Liferay.Poller.addListener( instance.id, instance.logIt, instance );
25            },
26            logIt: function( response, chunkId) {
27                dump( response );
28            }
29        };
30
31        HDS.init();
32    })


In the logs I get plenty of
1
2ERROR [PollerServlet:307] Poller processor not found for portlet TestPortlet_WAR_Integrating_INSTANCE_8Waf


Can anybody please point me in the right direction?

Thanks
Andrea Pinazzi
RE: How to use the poller service
December 4, 2009 4:46 AM
Answer

Andrea Pinazzi

Rank: New Member

Posts: 4

Join Date: October 8, 2009

Recent Posts

Is there anybody out there?
Philip P.
RE: How to use the poller service
July 22, 2010 1:42 AM
Answer

Philip P.

Rank: New Member

Posts: 1

Join Date: May 21, 2010

Recent Posts

Try to use
1portletDisplay.getRootPortletId()
instead of
1portletDisplay.getId()
(view.jsp, line 22)
Binh Thanh Le
RE: How to use the poller service
December 23, 2010 9:07 PM
Answer

Binh Thanh Le

Rank: New Member

Posts: 14

Join Date: August 1, 2010

Recent Posts

I believe you should do something like

package com.liferayinaction.poller;

import com.liferay.portal.kernel.poller.BasePollerProcessor;
import com.liferay.portal.kernel.poller.PollerRequest;
import com.liferay.portal.kernel.poller.PollerResponse;

public class TestPollerProcessor extends BasePollerProcessor {

@Override
protected void doReceive(PollerRequest arg0, PollerResponse arg1)
throws Exception {
// TODO Auto-generated method stub
System.out.println("doReceive is here");
}

@Override
protected void doSend(PollerRequest arg0) throws Exception {
// TODO Auto-generated method stub

}

}


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
and add this to the liferay-portlet.xml
<poller-processor-class>com.liferayinaction.poller.TestPollerProcessor</poller-processor-class>

in <portlet> tag
Barry Rowe
RE: How to use the poller service
July 19, 2012 1:23 PM
Answer

Barry Rowe

Rank: New Member

Posts: 14

Join Date: October 22, 2010

Recent Posts

Has anyone gotten this to work successfully with the chat portlet also deployed? I can create a working custom portlet with a custom PollerProcessor class, and wire up the Javascript poller that will work successfully on its own. The problem is if I deploy it alongside the chat-portlet, I find that either one or the other works, but not both. (seems to be tied to which one adds its listener via the Liferay.Poller.addListener() Javascript function).

I'm finding that if I register two Pollers (the chat registers one, then my custom portlet poller is registered), when the pollerResponse comes back to the client, only one of the poller's data is in the response even though I see both PollerProcessor classes execute in my server logs.

I'm tracking my progress on tracking this down in this forum post: http://www.liferay.com/community/forums/-/message_boards/message/14773771