Message Boards

CounterLocalService does not work properly.

ali forghani, modified 2 Years ago.

CounterLocalService does not work properly.

New Member Posts: 3 Join Date: 9/8/21 Recent Posts

Hi

I'm ali and try to understand how counter is working.

As i undertood, counter increment a varialble and retrive value. by default its increment one by one. but we can change step. problem is here. i increase counter number to 80 and at next a call increment method with size =70. basically i should get 150 but in practice i get 180.

i shared my codes on github

https://github.com/a-forghani-y79/7.3ga8

liferay version : 7.3ga8

 

thumbnail
Mohammed Yasin, modified 2 Years ago.

RE: CounterLocalService does not work properly.

Liferay Master Posts: 591 Join Date: 8/8/14 Recent Posts

Hi,

The next step is calculated from the last incremented value saved in memory  and not the size which is in DB, so  you  may need reset the counter completely  and then set the size as below .

counterLocalService.reset(name);
counterLocalService.reset(name, 80);
counterLocalService.increment(name, 70);

You are getting 180 instead of 150 is because the counter value saved in memory may be 110

thumbnail
Olaf Kock, modified 2 Years ago.

RE: CounterLocalService does not work properly.

Liferay Legend Posts: 6403 Join Date: 9/23/08 Recent Posts

You're linking to a full repository with multiple modules, and probably refer to some random class in there.

Please condense your code so much that you can include it in the question, describe the expected vs actual outcome. It's a lot of work to figure out what you do/see/expect otherwise, and you probably want to make answering as easy as possible...

ali forghani, modified 2 Years ago.

RE: RE: CounterLocalService does not work properly.

New Member Posts: 3 Join Date: 9/8/21 Recent Posts

hi

if i explain it in simple way:

1- try to deploy module that incloude this component:


​​​​​​​so we except this output:

- hi its a test

- new value: 1

- new value: 10

- new value: 80

- new value: 130

-end

but actually we got this:

- hi its a test

- new value: 1

- new value: 10

- new value: 80

- new value: 150

-end

may be liferay has some special mathemathic rules. but as i know 50+80 equals 130. its NOT 150.

    

thumbnail
Mohammed Yasin, modified 2 Years ago.

RE: CounterLocalService does not work properly.

Liferay Master Posts: 591 Join Date: 8/8/14 Recent Posts

As the counter, by default uses 100 as increment count for DB update , once your incremented value crosses 100 it will create new set of counter values. This is the reason why your getting 150 instead of 130.

If you need contineous counter you can set below value in your portal-ext.properties file.

counter.increment.[$COUNTER_NAME$]=1

In your case,you can use

counter.increment.test=1