掲示板

How to use the poller service

thumbnail
14年前 に Andrea Pinazzi によって更新されました。

How to use the poller service

New Member 投稿: 4 参加年月日: 09/10/08 最新の投稿
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
14年前 に Andrea Pinazzi によって更新されました。

RE: How to use the poller service

New Member 投稿: 4 参加年月日: 09/10/08 最新の投稿
Is there anybody out there?
thumbnail
13年前 に Binh Thanh Le によって更新されました。

RE: How to use the poller service

New Member 投稿: 14 参加年月日: 10/08/01 最新の投稿
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
11年前 に Barry Rowe によって更新されました。

RE: How to use the poller service

New Member 投稿: 14 参加年月日: 10/10/22 最新の投稿
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
13年前 に Philip Peterhansl によって更新されました。

RE: How to use the poller service

New Member 投稿: 1 参加年月日: 10/05/21 最新の投稿
Try to use
portletDisplay.getRootPortletId()
instead of
portletDisplay.getId()
(view.jsp, line 22)