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

Ask Your Question
0

Polling with time as the filter

Hi there,

I'm polling for objects in my space and want to filter them on time .i.e. to check if the expiry time of the object is greater than the current time. I'm currently doing the following:

@EventDriven @Polling @TransactionalEvent public class InstrumentExpirationProcessor { private final Log log = LogFactory.getLog(InstrumentExpirationProcessor.class);

@Autowired
private GigaSpace gigaSpace;

@EventTemplate
public SQLQuery<InstrumentTemplate> unprocessedData() {
    SQLQuery<InstrumentTemplate> template = new SQLQuery<InstrumentTemplate>(
            InstrumentTemplate.class, 
            "instrumentTemplateStatus = ?", 
            InstrumentTemplateStatus.OPEN);
    return template;
}

@SpaceDataEvent
public InstrumentTemplate processExpiringInstruments(InstrumentTemplate instrumentTemplate) {
    if(System.currentTimeMillis() < instrumentTemplate.getNextExpiryTime()){
        return instrumentTemplate;
    }

The issue I have is that this is sending my CPU up to 100% because it's pulling in the objects all of the time and then comparing the times, as shown above.

I was initially using the @NotifyType(leaseExpire = true) but it only calls this approximately every 10s, but I need it to be instantaneous.

Any ideas or suggestions?

Thanks in advance

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

asked 2011-05-10 08:02:56 -0600

robertral gravatar image

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

jaissefsfex gravatar image
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

Paul, Can you explain why you do that? What's the use case?
Shay

answered 2011-05-10 08:11:34 -0600

shay hassidim gravatar image
edit flag offensive delete link more

Comments

Once the instrument has come to the end of its life, instrumentTemplate.getNextExpiryTime(), I want to settle this instrument (i.e. it's closing/end price) and then instantly create a new instrument. This worked ok with the Notify(lease expiry) but the time delay wasn't acceptable.

Does this make sense?

robertral gravatar imagerobertral ( 2011-05-10 08:16:26 -0600 )edit

Or is there a way to do this filter in the actual @EventTemplate method?

robertral gravatar imagerobertral ( 2011-05-10 08:17:12 -0600 )edit

Paul,
You can change the behavior to have finer resolution using space-config.leasemanager.expirationtime_interval. See:
http://www.gigaspaces.com/wiki/display/XAP8/Leases#Leases-LeaseManager
You can make it to scan the expired entries and trigger the notification every second for example.

Another option is to use the Trigger Receive Operation and adapt the Query to use different range each time it polls the space. This will consume relevant objects. In this case you don't need to use the Lease mechanism.
http://www.gigaspaces.com/wiki/display/XAP8/PollingContainer#PollingContainer-TriggerReceiveOperation

You can find an example for such here:
http://www.gigaspaces.com/wiki/display/SBP/CustomEviction#CustomEviction-EvictionStrategies
See the Using a Polling Container section.
Shay

shay hassidim gravatar imageshay hassidim ( 2011-05-10 08:25:49 -0600 )edit

Have a look at the following form post, I have offered there a solution with a changing event template:

/[/question/3117/sql-query-to-identify-object-that-has-expired/]&tstart=258

eitany gravatar imageeitany ( 2011-05-10 08:26:16 -0600 )edit

Hi,

Thanks for the very prompt reply, really appreciate it
I will check these examples out this afternoon and get back to you.

Paul

robertral gravatar imagerobertral ( 2011-05-10 08:30:18 -0600 )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: 2011-05-10 08:02:56 -0600

Seen: 31 times

Last updated: May 10 '11