incubator-s4-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matthieu Morel <matth...@yahoo-inc.com>
Subject Re: how to maintain state in ProcessElement
Date Wed, 10 Jul 2013 19:20:11 GMT

On Jul 10, 2013, at 20:01 , Jiaan Zeng <l.allen09@gmail.com>
 wrote:

> By reset I mean that variable is 0 every time when onEvent() is
> called. Sorry for the confusion. From the wordcount point of view, it
> is correct because the "int wordCounter;" is incremented to 1 in
> onEvent(). I don't understand when and where the variable is reset to
> 0.

that variable initially has a 0 value when S4 creates a new PE instance in order to process
a previously unseen key.

Matthieu

> 
> 
> On Wed, Jul 10, 2013 at 12:04 PM, Matthieu Morel <mmorel@apache.org> wrote:
>> 
>> On Jul 10, 2013, at 17:30 , Jiaan Zeng <l.allen09@gmail.com> wrote:
>> 
>>> Hi,
>>> 
>>> I wonder how to maintain state in ProcessElement. For example,
>>> 
>>> s4-core/src/test/java/org/apache/s4/wordcount/WordCountPE.java
>>> The variable "int wordCounter;" is used in onEvent() function and is
>>> reset to zero after the onEvent() function finishes. This is
>>> stateless.
>> 
>> I don't see where that variable is reset to 0, can you point out the code?
>> 
>>> 
>>> s4-core/src/test/java/org/apache/s4/wordcount/WordClassifierPE.java
>>> The variables "private int counter;" and "TreeMap<String, Integer>
>>> counts" are used in onEvent() function to keep total word count and
>>> word count for each word. This is stateful.
>>> 
>>> I am confused about such behavior of ProcessElement. How do I turn
>>> on/off stateless if there is such option?
>> 
>> You can keep state in instance variables.
>> 
>> Regards,
>> 
>> Matthieu
>> 
>>> 
>>> Thanks in advance.
>>> 
>>> --
>>> Regards,
>>> Jiaan
>> 
> 
> 
> 
> -- 
> Regards,
> Jiaan


Mime
View raw message