Foren

How to use the poller service

thumbnail
Andrea Pinazzi, geändert vor 14 Jahren.

How to use the poller service

New Member Beiträge: 4 Beitrittsdatum: 08.10.09 Neueste Beiträge
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

  <portlet>
    <portlet-name>TestPortlet</portlet-name>
    <poller-processor-class>com.test.FooProcessor</poller-processor-class>
    <instanceable>true</instanceable>
  </portlet>


FooProcessor.java

public class FooProcessor extends BasePollerProcessor {
    private static Log log = LogFactoryUtil.getLog( FooProcessor.class );

    @Override
    protected void doReceive(PollerRequest request, PollerResponse response) throws Exception {
        log.debug("in doReceive");
    }

    @Override
    protected void doSend(PollerRequest request) throws Exception {
        log.debug("in doSend");
    }
}


javascript in view.jsp

<script type="text/javascript">
    jQuery( function($){
        var dump = function( data ) {
            if( data.constructor == Array ||
                data.constructor == Object ) {
                for( var p in data ) {
                    if( p.constructor == Array ||
                        p.constructor == Object ) {
                        console.log( "[" +p+"] => " + typeof p );
                        dump( p );
                    } else {
                        console.log( "[" + p + "] => " + data[p] );
                    }
                }
            }
        };

        HDS = {
            init: function() {
                var instance = this;
                instance.id = "<%= portletDisplay.getId()%>";
                // taken from  chat's javascript.js
                Liferay.Poller.addListener( instance.id, instance.logIt, instance );
            },
            logIt: function( response, chunkId) {
                dump( response );
            }
        };

        HDS.init();
    })
</code></pre><br /><br />In the logs I get plenty of<br /><pre><code>
ERROR [PollerServlet:307] Poller processor not found for portlet TestPortlet_WAR_Integrating_INSTANCE_8Waf
</code></pre><br /><br />Can anybody please point me in the right direction?<br /><br />Thanks</script>
thumbnail
Andrea Pinazzi, geändert vor 14 Jahren.

RE: How to use the poller service

New Member Beiträge: 4 Beitrittsdatum: 08.10.09 Neueste Beiträge
Is there anybody out there?
thumbnail
Binh Thanh Le, geändert vor 13 Jahren.

RE: How to use the poller service

New Member Beiträge: 14 Beitrittsdatum: 01.08.10 Neueste Beiträge
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
thumbnail
Barry Rowe, geändert vor 11 Jahren.

RE: How to use the poller service

New Member Beiträge: 14 Beitrittsdatum: 22.10.10 Neueste Beiträge
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
Philip Peterhansl, geändert vor 13 Jahren.

RE: How to use the poller service

New Member Beitrag: 1 Beitrittsdatum: 21.05.10 Neueste Beiträge
Try to use
portletDisplay.getRootPortletId()
instead of
portletDisplay.getId()
(view.jsp, line 22)