Polling and Using EL to change Interval

UI Components for JSF
Post Reply
bassoman
Posts: 1
Joined: 23 Nov 2010, 03:38

24 Nov 2010, 03:31

Hello.

Is it possible to dynamically change the interval of the polling component when using 'update'? I have been trying to use 'update' as part of a 'poll' element to re-render another element on a page. I have placed the 'poll' element as a child of the element being re-rendered. The element re-renders perfectly as desired. All works at first, then the timing of the poll starts to go wild... A generic example:

<p:panel id="toUpdate">
<new info that renders...>
<p:poll interval="#{sessBean.nextInterval()}" update="toUpdate"/>
</p:panel>

Is there a concept I'm missing here? Do I need to reset the polling somehow for each update?? Should I try to use 'remoteCommand'?

The method call to my session bean as part of the interval attribute updates the data to be re-rendered. It works fine. I have that call return an integer to use as a new interval...however...things go wild after a bit. The timing seems to work properly at first, but after several iterations, the timing goes random...

Thanks for a reply, and thanks for a great framework!

publicdinamicpi
Posts: 7
Joined: 09 Sep 2011, 15:55

14 Aug 2018, 13:38

I was facing to similar behavior which is solved just setting the values in the bean and embedding the poll in a panel which can be updated eg after every poll. Otherwises, poll is just js code, and not added in the DOM. Otherwise you may play around executing js on callback parameters and refreshing the values on the Client Side.

I was having other issues about queued the requests on the Client side and worked when the Server is able to do it, causing overloading server domino's effect.

For solving those, I just consuming the requests while the listener is busy.

Here a piece of my test:

Code: Select all

<p:outputPanel id="infoPanel" >
	<h:panelGrid columns="1">
		<h1>TESTING POLLING</h1>
		<h:outputText id="ts" value="TS Update:#{testPollBean.timeStamp}"/>
		<h:outputText id="callNum" value="Call Number:#{testPollBean.callNumber}°"/>
		<h:outputText id="interval" value="Interval:#{testPollBean.interval} second"/>
		<h:outputText id="Stop" value="Stop:"#{testPollBean.stopPolling}"/>
	</h:panelGrid>	
</p:outputPanel>
		
<h:panelGrid id="panelPolling">
	<p:poll id="durrPolling" async="true" stop="#{testPollBean.stopPolling}"
		interval="#{testPollBean.interval}" 
		process="@this" partialSubmit="true" listener="#{testPollBean.listener}"
		update="panelPolling infoPanel" widgetVar="polling"
		autoStart="true" rendered="true"/>
</h:panelGrid>

Code: Select all

@ViewScoped
@Named(value = "testPollBean")
public class TestPollBean implements Serializable {

	private static final long serialVersionUID = 1L;
	private static final Logger LOG = Logger.getLogger(TestPollBean.class);
	private Calendar calendar;
	private Date timeStamp;
	private Date nextCall;
	private int callNumber;
	private int interval;
	private boolean stopPolling;
	private boolean listenerBusy;
	
	@PostConstruct
	public void init() {
		this.calendar = Calendar.getInstance();
		this.timeStamp = calendar.getTime();
		this.nextCall = null;
		this.callNumber = 0;
		this.interval = 1;
		stopPolling = false;
		listenerBusy = false;
	}
	
	public void listener() {
		callNumber ++;
		LOG.info("-> Poll "+ callNumber + "° on thread " + Thread.currentThread().getId());
		if (!listenerBusy) {
			listenerBusy = true; // skip any other concurrence call 
			
			if (callNumber >= 30) {
				//stopPolling = true;
				this.interval = 30;
			}
	
			if (callNumber < 20) {
				this.timeStamp = calendar.getTime();
				calendar.add(Calendar.SECOND, interval);
				nextCall = calendar.getTime();
				
				LOG.info("\t > Attennding "+ callNumber + "° call on  thread " + Thread.currentThread().getId() + ". Sleeping ..." );
				try {
					Thread.sleep(5000);
				} catch (InterruptedException e) {
					LOG.info("\t\t E R R O R ! ! ! \t > Attennding "+ callNumber + "° call on  thread " + Thread.currentThread().getId() );
				}
				//Later on we will try to adapt dynamically the interval.
			} else  {
				LOG.info("\t > Attennding inmediately "+ callNumber + "° call on  thread " + Thread.currentThread().getId() + "." );
			}
			LOG.info("<-  Poll "+ callNumber + "° on thread " + Thread.currentThread().getId());
		
			listenerBusy = false;
		} else {
			LOG.info("<- Listener on thread " + Thread.currentThread().getId() + " dismiss call " + callNumber + "° cause is already busy.");
		}
	}
	+ Getters / Setters
	

huseyinT
Posts: 123
Joined: 27 Mar 2016, 13:05

15 Aug 2018, 12:27

Glad to hear!

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 37 guests