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

Ask Your Question
0

Reservation Design Pattern

I need some advice with a space-based design pattern regarding reservations.

Assume a problem domain like ticket sales or airline seat reservations. In each of these scenarios, the user is presented with an opportunity to reserve a particular seat. During the time the user is evaluating their seat options, it is helpful if they, temporarily, have exclusive rights to this seat. Here is a sample flow:

1. User requests a single ticket to the Mayday Parade concert.
2. System shows the details related to seat 4D.
3. System gives the user 2 minutes to decide.
4. Customer either:
   a) Accepts 4D
   b) Rejects 4D
c) Timeout

In this scenario, I want all my seats to be space entries. My only other restriction prevents a very easy approach to the problem; I don't want to use Take. I want to be able to query all my seats for some reporting, regardless as to their current state.

My idea is this:

1. READ one seat that has status of "ACTIVE" (Not worried about "best seat" yet)
2. UPDATE seat to "PENDING" status.
3. WRITE Reservation object to the space with a Lease period of 2 minutes.
4. If the user:
   a) Accepts the seat - Update seat to "RESERVED", TAKE the reservation.
   b) Rejects the seat - Update seat to "ACTIVE", TAKE the reservation.
c) Lease expires on Reservation - Update seat to "ACTIVE"

I hope this is a valid design pattern. I would welcome any insights on its suitability, especially in a replicated space under heavy load.

I would also be interested in other design patterns that could be applied, and any GigaSpaces-specific APIs that might make this easier. (I do hate having to introduce another entry into the space just for notification purposes.)

This thread was imported from the previous forum.
For your reference, the original is available here

asked 2008-08-11 21:17:25 -0500

oravecz gravatar image

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

jaissefsfex gravatar image
edit retag flag offensive close merge delete

4 Answers

Sort by » oldest newest most voted
0

answered 2008-08-12 10:35:08 -0500

shay hassidim gravatar image
edit flag offensive delete link more

Comments

Hi,

How do i register for an account to login to view this link ??

http://www.gigaspaces.com/wiki/displa...

Thanks.

wkhlim gravatar image wkhlim  ( 2008-10-06 23:02:13 -0500 )edit

Wilson ,

Try this: http://www.gigaspaces.com/wiki/displa...

Can you explain your scenario?

Any chance the polling container with its ReceiveOperationHandler can be more relevant for you? See: http://blog.gigaspaces.com/2008/10/03...

Shay

shay hassidim gravatar image shay hassidim  ( 2008-10-07 00:18:19 -0500 )edit

Hi,

I am trying to use GigaSpace read with exclusive lock instead of using IJSpace. For example , i can use the followings and it works.

IJSpace space = (IJSpace) SpaceFinder.find("jini:////mySpace"); space.setReadModifiers(ReadModifiers.EXCLUSIVE_READ_LOCK);

LocalTransactionManager trManager = (LocalTransactionManager)LocalTransactionManager.getInstance(space);

Transaction.Created tCreated1 = TransactionFactory.create(trManager, 1000 * 60); ServerTransaction txn1 = (ServerTransaction)tCreated1.transaction;

Lock lock1 = (Lock) space.read(lock_template1, txn1, 1000);

But i would like to use gigaspace : gigaSpace.read(template, Long.MAX_VALUE, ReadModifiers.EXCLUSIVE_READ_LOCK) Somehow it doesnt block any other reading.

Any idea why it doesnt work??

wkhlim gravatar image wkhlim  ( 2008-10-09 21:02:04 -0500 )edit

Here is how you can have (transactional) exclusive read with the polling container:

        PlatformTransactionManager ptm = null;
    UrlSpaceConfigurer urlConfig = new UrlSpaceConfigurer("/./space");
    IJSpace ijspace = urlConfig .space();
    GigaSpaceConfigurer gigaspacesConfig = new GigaSpaceConfigurer (urlConfig);
    ptm = new LocalJiniTxManagerConfigurer(ijspace ).defaultTimeout(100000).transactionManager();
    GigaSpace space = gigaspacesConfig.transactionManager(ptm).gigaSpace();
    ReceiveOperationHandler operationHandler = new ExclusiveReadReceiveOperationHandler();

    SimplePollingEventListenerContainer pollingContainer = new SimplePollingContainerConfigurer (space).transactionManager(ptm).
    eventListenerAnnotation(new Object() {
            @SpaceDataEvent
         public void eventHappened() throws IOException {
            System.out.println("event called");
             ............
        }
    }).
    autoStart(true).
    receiveOperationHandler(operationHandler).
    template(new MyData()).
    pollingContainer();

Shay

shay hassidim gravatar image shay hassidim  ( 2008-10-09 21:37:29 -0500 )edit

Hi,

Say i have a method called readWithLock with the following code:

IJSpace space = (IJSpace) SpaceFinder.find("jini:////mySpace"); space.setReadModifiers(ReadModifiers.EXCLUSIVE_READ_LOCK);

LocalTransactionManager trManager = (LocalTransactionManager)LocalTransactionManager.getInstance(space);

Transaction.Created tCreated1 = TransactionFactory.create(trManager, 1000 * 60); ServerTransaction txn1 = (ServerTransaction)tCreated1.transaction;

Lock lock_template1 = new Lock(); lock_template1.setId(1000);

Lock lock1 = (Lock) space.read(lock_template1, txn1, 1000); return lock1;

and i read this lock object with read lock, and say i changes some values and update the lock object back to gigaSpace.

How do i unlock the read lock after i finished ??

Can i lock on an object which is already locked?? What happen in this scenario??

Regards

wkhlim gravatar image wkhlim  ( 2008-10-15 02:23:00 -0500 )edit
0

Hi Shay,

The Exclusive Read Lock seems to cause what I am hoping to avoid -- a long running transaction. It seems like it would be detrimental if you are suggesting I place the object in an ERL for the two minutes the user has to decide.

However, I do use Exclusive Read Lock when I perform an update to an object in the space.

answered 2008-08-12 20:19:34 -0500

oravecz gravatar image
edit flag offensive delete link more
0

Thanks for the confirmation Randy. I'm glad to see that the Isolation Levels mirror what I would expect from a typical RDBMS.

answered 2008-08-12 20:23:08 -0500

oravecz gravatar image
edit flag offensive delete link more

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: 2008-08-11 21:17:25 -0500

Seen: 189 times

Last updated: Aug 12 '08