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

Ask Your Question

sql-query to identify object that has expired


I am using a PU to expire "processed" object by checking the timestamp e.g. if (timestamp + 5 min) is more than current time then status is "expired" However, the pu is polled based on the status "processed" only.

Is there any way to use pu.xml to identify "processed" and time expired object?? Currently my pu.xml look like this:

<os-core:template> <bean class="mypackage.Request"> <property name="status" value="Processed"/> </bean> </os-core:template>

I want the pu to only handle processed object that has expired. h4. Attachments


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

asked 2009-05-14 22:16:03 -0500

wkhlim 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

If you are running in ALLINCACHE + EDS - you can't query expired objects.
If you are running in LRU + EDS - If there are no enough matching objects - your query will be delegated to the database , where you will need to have relevant field that will have the time stamp value.

In any case - you can't query space objects based on their lease.


answered 2009-05-14 23:54:37 -0500

shay hassidim gravatar image
edit flag offensive delete link more



Yes , i have a timestamp field of type DATE in my object. But how do i squery the object based on status ="processed" and timestamp <= current time.

how can i do the following in pu.xml??

<os-core:template> <bean class="mypackage.Request"> <property name="status" value="Processed"/> <property name="timestamp" value="<=currentTime"/> </bean> </os-core:template>

if i cant do the above then how can i do this in java code,

SQLQuery<request> query = new SQLQuery<request>(Request.class,"status = ' "+Request.STATUS_PROCESSED+" ' And timestamp < = ' "+currentTime+" ' ");

Please advise. Thanks in advance.

wkhlim gravatar imagewkhlim ( 2009-05-15 01:19:51 -0500 )edit

This is currently not supported

nirpaz gravatar imagenirpaz ( 2009-05-15 01:27:03 -0500 )edit

Since you have the object creation time within the object (I presume this is what the timestamp field stores) you should be able to search based on this field.

You should turn on the extended matching. This will use the btree index for mypackage.Request class and will speed up bigger/less than queries execution: {code} <os-core:space id="space" url="/./space"> <os-core:properties> <props> <prop key=" space-config.engine.extended-match.enabled-classes ">mypackage.Request</prop>
</props> </os-core:properties> </os-core:space> {code}

I don?t see a problem executing a query that will find all matching objects that has been processed and been created before a specific point in time: ?status = '? + Request.STATUS_PROCESSED +?' AND timestamp < = ?? + (now ? 5 min) + ???

Where now ? 5 min will be calculated each time.

Make sure you have the timestamp indexed.

You might want to use long date type instead of Date for your timestamp field. It will be simpler to handle. The polling container should also support such SQL template.


Edited by: Shay Hassidim on May 15, 2009 3:23 AM

shay hassidim gravatar imageshay hassidim ( 2009-05-15 01:57:06 -0500 )edit

I've done exactly the same thing in one of my projects. You'll need to do some tricks in order to make it work.

First you need to disable the snapshot of the template because your template will be updated every round with the current time, to do so put @Polling(performSnapshot=false).

Second in order to update your template every round with the current time, you'll need to use a TriggerOperationHandler to do so.

For instance: lets assume you query is like this new SQLQuery<data>("processed = 'true' AND timestamp < ?");

In your listener implementation

@Polling(performSnapshot=false) class MyListener { ... @TriggerHandler public TriggerOperationHandler timeStampUpdatingTrigger() { return new TriggerOperationHandler() {

        public boolean isUseTriggerAsTemplate() {
            return true;

        public Object triggerReceive(Object originalTemplate, GigaSpace space, long timeout)
                throws DataAccessException {
            template.setParameter(1, System.currentTimeMillis() + timeout);
            return template;



Another important thing is you should move to nonBlocking receive handler because SQLQuery which isn't snapshot, doesn't support blocking mode and it will cause the processer to work in busy loop mode.

You do so by adding this to your listener class

@ReceiveHandler public ReceiveOperationHandler receiveOperationHandler(){ MultiTakeReceiveOperationHandler operationHandler = new MultiTakeReceiveOperationHandler(); operationHandler.setNonBlocking(true); operationHandler.setNonBlockingFactor(5);

    return operationHandler;

Note that I am using MultiTakeReceiveHandler, you can use which ever one you use.

The above works because I use it in one of my projects, if you don't get it to work, feel free to ask. I hope this helps


Edited by: Eitan Yanovsky on May 15, 2009 4:11 AM

eitany gravatar imageeitany ( 2009-05-15 02:17:08 -0500 )edit

Can you go into more details.....?

Any example files?? I think it would definitely helps.


wkhlim gravatar imagewkhlim ( 2009-05-17 20:54:55 -0500 )edit

Need more understanding h4. Attachments


answered 2009-05-17 21:17:34 -0500

wkhlim gravatar image
edit flag offensive delete link more


I've attached the code of the processor in my project, without all the rest so it won't compile.

You can see how I replaced the TriggerHandler and the ReceiveHandler in it as described. The action objects are written with the timestamp when created like you described in your case.

I recommend reading the polling container wiki page because it described all the elements I've used in my processor.

If it still not clear, please explain what is unclear and I'll try to elaborate.

Eitan h4. Attachments


eitany gravatar imageeitany ( 2009-05-18 10:05:19 -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


Asked: 2009-05-14 22:16:03 -0500

Seen: 86 times

Last updated: May 17 '09