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

Ask Your Question

Lease Expiry

Hi All,

I'm looking for a way to make sure an entry that I put into the space is picked up when the lease on it expires, this is so that I can future date an event to happen.

While I know a worker can pick up a lease expiry event, theres always a chance that this worker is unavailable hence causing the event to be missed as the entry would then disapear from the space.

Is there a way, without the use of a worker to create a new entry in the space on the expiry of the first entry.

This would then allow me to have other workers pick up the newly created event and hence stop the possiblility of not actioning the initial entry.

Any help apppreciated.


Mark Thomas

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

asked 2006-07-18 12:25:02 -0500

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 the space is persistent (using JDBC SA or indexed file) it will re-register the notify registration once it will be restarted and recover from the database/file.
Spaces using CacheLoader/Store do have the ability to re-register the notify registration since CacheLoader/Store do not support space meta data recovery.

If the space is transient it will not have the registrations re-registered and the client will need to register these again.

If the space is clustered you can notify registration can be replicated and notifications can be delivered to clients based on notify registration that has been replicated. See - The Replicate Notify Template and the Trigger Notify Template Options:

With 5.1 we will support notify registration recovery for partitioned spaces - i.e. once you register for notifications to partitioned space and a partition failed and re-started or simple started it will get notify registrations from his partners (spaces part of his load-balancing group).

In future versions the client will re-register for notification once the space re-started.


answered 2006-08-16 05:44:00 -0500

shay hassidim gravatar image
edit flag offensive delete link more

Mark, Your questions is really not worker-specific - i.e. subscribing to lease-expiry events has nothing to do with workers..

You would need to be notified for lease-expiry by using:

NotifyModifiers.NOTIFY_LEASE_EXPIRATION with your NotofyDelegator

For example: {code} NotifyDelegator nDelegator = new NotifyDelegator((IJSpace)spaceProxy, new MyEntry(), txn, listner, Lease.FOREVER, null, fifo, NotifyModifiers.NOTIFY_LEASE_EXPIRATION); {code}

In your {code}RemoteEventListener{code} you would need to then get the notification type and implement your business logic at that point:

{code} public void notify(RemoteEvent evt){
EntryArrivedRemoteEvent rEvt=(EntryArrivedRemoteEvent)evt;
int notifyType = rEvt.getNotifyType();

            if (notifyType == NotifyModifiers.NOTIFY_LEASE_EXPIRATION){           
                try {                                                    
                    Entry entry =                               

                     // your code here............                                                                            
                } catch (Throwable e) {                                 




answered 2006-07-19 13:23:03 -0500

gbarnea gravatar image
edit flag offensive delete link more


1.The init method of a worker gets an embedded space instance.

SH this is how it should be.

No matter how u configure your "Replicate Notify Template and the Trigger Notify Template Options" ( I tried with false , false for both of them) u willl still receive the notification,

Am I correct in my analysis.

SH I see you got NotifyModifiers.NOTIFYLEASEEXPIRATION.
Does this happen also for other Modifiers (write/update/take)?
The backup should trigger notifications only when the primary failed.


shay hassidim gravatar imageshay hassidim ( 2006-08-22 16:10:00 -0500 )edit

The behavior you see is the expected one and will be modified in future versions. This is submitted as case CORE-417.

A workaround will be to check the source ( http://www.gigaspaces.com/docs/JiniAp... ) of the notification and react only if it came from the right space or register for notifications only when the space is active.

See below example for such:

{code} package com.gigaspaces.example.worker;

import com.j_spaces.worker.IWorker; import com.j_spaces.core.IJSpace; import com.j_spaces.core.SpaceStandbyException; import com.j_spaces.core.client.SpaceURL;

import java.util.logging.Level; import java.util.logging.Logger; import java.rmi.RemoteException;

import net.jini.core.entry.UnusableEntryException; import net.jini.core.transaction.TransactionException;

public class BaseWorker implements IWorker { // ------------------------------ FIELDS ------------------------------

private static final Logger LOGGER = Logger.getLogger(BaseWorker.class.getName());
private static final String SPACE_POLLING_THREAD = "SpacePollingThread";
protected IJSpace space;
protected String name;
protected Thread pollThread;
private boolean isPrimary = false;

// ------------------------ INTERFACE METHODS ------------------------

// --------------------- Interface IWorker ---------------------

public void init(IJSpace ijSpace, String string, String string1) throws Exception {
    space = ijSpace;

    SpaceURL url = space.getURL();
    name = url.getContainerName();
    LOGGER.log(Level.INFO, name + ":init()");

 * subclass must call this to cleanup
public void close() {
    LOGGER.log(Level.INFO, name + ":close()");

// --------------------- Interface Runnable ---------------------

 * starts a thread to poll for primary
public void run() {
    LOGGER.log(Level.INFO, name + ":run()");
    pollThread = new Thread(
            new Runnable() {
                public void run() {
                    while (pollThread != null && !isPrimary) {
                        try {
                        } catch (InterruptedException e) {
                            LOGGER.log(Level.FINEST, e.toString(), e);
                    LOGGER.log(Level.INFO, SPACE_POLLING_THREAD + " Stopping.");

// -------------------------- OTHER METHODS --------------------------

 * @return true if primary
public boolean isPrimary(){
    return isPrimary;

 * poll the space to check if primary
private void poll() {
    try {
        space.read(null, null, 0);
        isPrimary = true;
    } catch (SpaceStandbyException e){
        LOGGER.log(Level.INFO, name + ":In Backup Mode...Keep polling.");
    } catch (UnusableEntryException e) {
        LOGGER.log(Level.WARNING, e.toString(), e);
    } catch (TransactionException e) {
        LOGGER.log(Level.WARNING, e.toString(), e);
    } catch (InterruptedException e) {
        LOGGER.log(Level.WARNING, e.toString(), e);
    } catch (RemoteException e) {
        LOGGER.log(Level.WARNING, e.toString(), e);

 * called when primary, this is only called once
protected void becomesPrimary() {
    LOGGER.log(Level.INFO, name +":Becomes Primary.");

 * stops polling the space
protected void stopPolling() {
    if (pollThread == null) {
    Thread temp = pollThread;
    pollThread = null;


package com.gigaspaces.example.worker;

import com.gigaspaces.poc.worker.BaseWorker; import com.j_spaces.core.client.NotifyDelegator; import com.j_spaces.core.client.NotifyModifiers; import com.j_spaces.core.client.EntryArrivedRemoteEvent; import net.jini.core.transaction.TransactionException; import net.jini.core.lease.Lease; import net.jini.core.entry.Entry; import net.jini.core.entry.UnusableEntryException; import net.jini.core.event.RemoteEventListener; import net.jini.core.event.RemoteEvent; import net.jini.core.event.UnknownEventException;

import java.rmi.RemoteException; import java.util.logging.Level; import java.util.logging.Logger;

public class MyWorker extends BaseWorker implements RemoteEventListener { // ------------------------------ FIELDS ------------------------------

private static final Logger LOGGER = Logger.getLogger(MyWorker.class.getName());
private NotifyDelegator notifyDelegator;
private int count;

// ------------------------ INTERFACE METHODS ------------------------

// --------------------- Interface IWorker ---------------------

public void close() {

// --------------------- Interface RemoteEventListener ---------------------

public void notify(RemoteEvent ...
shay hassidim gravatar imageshay hassidim ( 2006-08-23 03:40:00 -0500 )edit

We are looking into issue 1. Seems we managed to reproduce this. Will get back to you on this.


shay hassidim gravatar imageshay hassidim ( 2006-08-25 21:12:00 -0500 )edit

The multiple active spaces for the same partition in partitioned backup schema will be fixed for 5.1.

This will make sure the IWorker will be active only for the active space.


shay hassidim gravatar imageshay hassidim ( 2006-08-28 08:41:00 -0500 )edit

List of issues and enhancement that will make it in 5.1: http://www.gigaspaces.com/wiki/displa...http://www.gigaspaces.com/wiki/displa...

The problem we had with incorrect active partition has been fixed with 5.1. When the active space failed the IWroker running as part of the new primary (the backup that switched to active mode) will be able to access its space. Once anther backup of the same partition will be restarted its IWroker will get SpaceStandbyException when trying to access its space. This will happen when the fail-back option is disabled - i.e. do not switch back to primary in case it is restarted, but continue to use the existing active node as primary.


shay hassidim gravatar imageshay hassidim ( 2006-09-24 13:49:04 -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: 2006-07-18 12:25:02 -0500

Seen: 195 times

Last updated: Jul 19 '06