Welcome to the new Gigaspaces XAP forum. To recover your account, please follow these instructions.

Ask Your Question
0

leaseExpire events not picked up by event listener

Hi,

The goal I'm trying to accomplish in my application is to change an object after a certain amount of time (24h and 72h specifically). The solution we thought up involves leases. First insert the object into the space with a lease of 24h, after which a notify container get notified of the lease expiry, which does some changes, and writes it back with a new lease of 48h (72-24)... etc

Now the listener does not get called. I just wrote a little integration test testing this specifically:

My TestEntity POJO:

@SpaceClass public class TestEntity { private String _value; private Boolean _isProcessedByLeaseExpiryListener; public TestEntity() { } public String getValue() { return _value; } public TestEntity setValue(String value) { _value = value; return this; } public Boolean getIsProcessedByLeaseExpiryListener() { return _isProcessedByLeaseExpiryListener; } public TestEntity setIsProcessedByLeaseExpiryListener(Boolean processedByLeaseExpiryListener) { _isProcessedByLeaseExpiryListener = processedByLeaseExpiryListener; return this; } }

And a simple event listener that should get notified when leases expire:

@EventDriven @Notify @NotifyType(leaseExpire = true) public class LeaseExpiryTestListener { @EventTemplate public TestEntity template() { return new TestEntity().setIsProcessedByLeaseExpiryListener(false); } @SpaceDataEvent public TestEntity eventHappened(TestEntity event, GigaSpace gigaSpace) { // write it back with a different lease gigaSpace.write(event.setIsProcessedByLeaseExpiryListener(true), Lease.FOREVER); return null; } }

Note that I am writing entities to the space as follows:

// expiry of 1 second gigaspace.write(new TestEntity().setValue("1 second lease").setIsProcessedByLeaseExpiryListener(false), 1 * 1000L);

After a few seconds I do see that the object disappears from the space (e.g. it expired), however the listener is never called. I can confirm this by not having a new object present in the space and by having put a debugging breakpoint on the eventHappened() method.

Is there anything I'm missing here? I have a very similar integration test case which tests a listener for write events, which _does_ work.

Also if anyone has a simpler solution for the problem I'm trying to solve, suggestions are welcome.

FYI: I'm using gigaspaces-xap-premium-7.0.0-m6-b3494

Thanks for your help & time,

Bart Kloker

{quote}This thread was imported from the previous forum. For your reference, the original is [available here|http://forum.openspaces.org/thread.jspa?threadID=3082]{quote}

asked 2009-05-12 10:21:12 -0500

bklok gravatar image

updated 2013-08-08 09:52:00 -0500

jaissefsfex gravatar image
edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

Are you getting lease expiration event when using a template that all its fields are null?

Are you getting lease expiration event when using the Session messaging API?

Please note lease expiration events will be delivered by both primary and backup space.

Why not having a single thread/timer that will check the space in periodic manner for relevant objects (make sure you index the boolean field) instead of using the leasing mechanism? It should be simpler solution than writing back into the space an object that has been expired.

Shay
Sent on the Sprint® Now Network from my BlackBerry®

answered 2009-05-12 20:35:42 -0500

shay hassidim gravatar image
edit flag offensive delete link more

Comments

Are you getting lease expiration event when using a template that all its fields are null?

I replaced the template with one with all null fields (verified in the debugger), still the listener is not being called.

Are you getting lease expiration event when using the Session messaging API?

I just toyed around with the Session messaging API, but couldn't get it to work at all. Any suggestions on how to test this? Currently I tried following the example that's on the wiki:

    EventSessionFactory factory = EventSessionFactory.getFactory(javaSpace);
    EventSessionConfig config = new EventSessionConfig();
    DataEventSession session = factory.newDataEventSession(config, null);
    TestListener testListener = new TestListener();
    EventRegistration registration = session.addListener(new TestEntity(),testListener,Lease.FOREVER,null,null,NotifyActionType.NOTIFY_ALL);
    // wait for notifications
    session.removeListener(registration);
    session.close();

My TestListener is simply:

public class TestListener implements RemoteEventListener { public int notified; @Override public void notify(RemoteEvent arg0) throws UnknownEventException, RemoteException { notified++; } }

Why not having a single thread/timer that will check the space in periodic manner for relevant objects (make sure you index the boolean field) instead of using the leasing mechanism? It should be simpler solution than writing back into the space an object that has been expired.

That's a good idea, I'm not sure how I could best deploy this single thread in gigaspaces though. Just as a bean that bootstraps itself from pu.xml is what comes to mind first. Any suggestions for other methods are welcome.

Thanks for your help,

Bart

bklok gravatar imagebklok ( 2009-05-13 04:01:22 -0500 )edit

You can have a periodic activity done via this: Here is what the pu.xml would have: {code} <bean id="scheduledTask" class="org.springframework.scheduling.timer.ScheduledTimerTask" >="" <!--="" wait="" x="" seconds="" before="" starting="" repeated="" execution="" --=""> <property name="delay" value="3000"/> <property name="period" value="5000"/> <property name="timerTask" ref="feeder"/> </bean>

<bean id="timerFactory" class="org.springframework.scheduling.timer.TimerFactoryBean"> <property name="scheduledTimerTasks"> <list> <ref bean="scheduledTask"/> </list> </property> </bean>

<bean id="PeriodicActivity" class="MyPeriodicActivity"/> {code}

The MyPeriodicActivity would look like this:

{code} import org.openspaces.core.GigaSpace; import java.util.TimerTask;

public class MyPeriodicActivity extends TimerTask {

@GigaSpaceContext private GigaSpace space;

public MyPeriodicActivity (){ SpaceClass myTemplate = new SpaceClass(); myTemplate.processed = false; // indexed field }

public void run() { SpaceClass objects [] = space.readMultiple ( myTemplate , Integer.MAX_VALUE) // iterate thru the objects and do that ever space.updateMultiple (objects…) } } {code}

You can have the MyPeriodicActivity as a single separate PU accessing remote spaces or collocated with each partition (the preferred mode - will avoid remote calls). If you have it as collocated Bean , make sure it is active only with the primary. The readMultiple is very fast - so I don't think this will impact the performance too much.

Shay

shay hassidim gravatar imageshay hassidim ( 2009-05-13 07:40:48 -0500 )edit

Thanks a lot Shay, that looks really interesting, I am going to play with it now.

One question though: is there a way to create these beans without the XML, but with for instance annotations so I can create unit tests for this behavior?

Thanks, Bart

bklok gravatar imagebklok ( 2009-05-13 08:38:57 -0500 )edit

You can use spring @Component annotation over the class instead of defining it in the xml and it will have the same affect.

Eitan

eitany gravatar imageeitany ( 2009-05-13 10:31:34 -0500 )edit
0

Hi,

I am in similar situation where i am using lease expiry to trigger events; however my listener is not able to receive any Lease Expiry events. I have tried to use NOTIFY_ALL as well, still no event.

Is there something wrong with Lease Expiry notification mechanism or some special way to get lease expiry event?

regards, Tarun Naithani

answered 2009-07-13 02:35:14 -0500

tarun_naithani gravatar image
edit flag offensive delete link more

Comments

Can you post a test case?
Notifications for expired objects works.
Shay

shay hassidim gravatar imageshay hassidim ( 2009-07-13 08:07:00 -0500 )edit

Hi Shay,

I have got it running now. I am able to get events however there is one issue, with NotificationActionType received as part of RemoteEvent if i use isLeaseExpiration method, it returns false.

However if use getModifier it return s me 8 as value which is constant throughout. So my problem is solved.

One more clarification i needed. As you mentioned above that i will get 2 events one from primary and one from backup, can i weed out the back up one by any means and will this event notification work in case fail over when primary becomes backup and vice versa.

Thanks and regards, Tarun Naithani

tarun_naithani gravatar imagetarun_naithani ( 2009-07-16 01:12:29 -0500 )edit

Are you sure the isLeaseExpiration return wrong value? Can you please submit a support case reporting this problem ?

AFAIK - you can get from the RemoteEvent the source space that delivered the notification. This should help you to filter our double notifications send from the backup.

Shay

shay hassidim gravatar imageshay hassidim ( 2009-07-20 05:05:59 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2009-05-12 10:21:12 -0500

Seen: 378 times

Last updated: Jul 13 '09