You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Mark Lundquist <ml...@comcast.net> on 2005/10/25 07:20:18 UTC

callback for continuation timeout?

Hi,

I have some processing invoked from flow that's not OK to just abandon 
if the user abandons their session.  In particular, this processing 
logic "reserves" some resources in the database.  In the case of 
"success", the resources will remain permanently associated with a 
persistent object, but in the case of "failure" or "abandoned 
interaction", the resources must be released.

Is there any way to register a listener or something so that if a 
continuation is abandoned, I can release what needs to be released?

Thanks,
Mark


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: callback for continuation timeout?

Posted by Torsten Curdt <tc...@apache.org>.
>> ...any other way of approaching that logic? What is it?
>>
>
> The application is a ticketing system.  We have to reserve the  
> tickets in the database before we process the payment transaction  
> so that we don't oversell our tickets.  So, reserving the tickets  
> is transactional (using Spring+Hibernate+MySQL), while the payment  
> processing is long but non-transactional.  We have to know that we  
> will be able to issue the requested number of tickets, before we  
> can bill the customer's credit card.

I see

> There are other ways to handle this that I can think of, and they  
> are are all bad:
>
> 1) Process the payment first, with no guarantee of availability.   
> Once payment is secure, attempt to reserve the tickets.  If the  
> requested number of tickets are no longer available, then run  
> another transaction to reverse the payment.  I really don't like  
> this idea...

I think nobody that will try to buy some tickets would like that idea ;)

<snip/>

>>
>> Something like that *could* be implemented but endorses a bad design.
>>
>
> Well, once again I am most interested to hear just what it is that  
> is so bad about the design.  You say "BAD, BAD, BAD" with no  
> explanation, so that might as well just be FUD, FUD, FUD!

Well ...TBH in your scenario it's probably not thaaat BAD.
But I fear such a callback could be abused really badly.

I am not really sure how many users are actually aware of the
fact that they should *never* look a component and then release
it after a sendPageAndWait. A callback would legitimate such
a design. It should be obvious that this is a bad idea for
poolable components. But even threadsafe components need to
be released.

So being able to register a callback into the flow on a
timeout seems like a really bad idea to me.

An option that seems ok to me would be to have it not available
inside the flow but provide those hooks on the ContinuationManager.
That's a bit less reachable ...but would solve your problem.

So does that make sense or is it FUD? :-P

BTW: I think we should move that thread over to dev

cheers
--
Torsten

Re: callback for continuation timeout?

Posted by Ralph Goers <Ra...@dslextreme.com>.
Mark Lundquist wrote:

>
> The application is a ticketing system.  We have to reserve the tickets 
> in the database before we process the payment transaction so that we 
> don't oversell our tickets.  So, reserving the tickets is 
> transactional (using Spring+Hibernate+MySQL), while the payment 
> processing is long but non-transactional.  We have to know that we 
> will be able to issue the requested number of tickets, before we can 
> bill the customer's credit card.
>
> There are other ways to handle this that I can think of, and they are 
> are all bad:
>
> 1) Process the payment first, with no guarantee of availability.  Once 
> payment is secure, attempt to reserve the tickets.  If the requested 
> number of tickets are no longer available, then run another 
> transaction to reverse the payment.  I really don't like this idea...
>
> 2) Just do it all atomically within the transaction.  This is bad for 
> two reasons.  First of all, it has *really* poor concurrency 
> properties.  Suppose you and I are both trying to purchase tickets at 
> the same time, and I win the race and make it into my transaction 
> first.  Your transaction will then have to wait for as long as it 
> takes mine to complete — including the interaction with the payment 
> processor (Verisign) which takes a long time — before yours can even 
> get started, and then of course you will have to wait for your own 
> transaction to complete before you see any reply.  The second reason 
> it is bad is that the design calls for a self-refreshing "please wait, 
> transaction in process yada yada" screen to be displayed while the 
> transaction is in process.  This requires that the purchase processing 
> be done aysnchronously w.r.t. to the client request, and that is 
> impossible if it is all to be within a single database transaction, 
> due to lifetime issues with the Hibernate Session and Transaction 
> objects (specifically: the main thread would be closing the Hibernate 
> Session at the end of processing the HTTP request, while the secondary 
> thread is still in mid-transaction.  A solution to that would be to 
> use the Hibernate "long session" pattern, but that's too invasive of a 
> change to make at this point.  BTW you would not like that, you would 
> say it is "BAD BAD BAD"! :-) :-)
>
> 3) Use a delayed capture on the credit card, i.e. the first 
> transaction is an authorization that places a hold on the funds.  Then 
> if the attempt to reserve tickets is successful, we follow up with the 
> capture transaction.  If we weren't able to reserve the tickets after 
> all, then we don't.  This is bad because for multiple reasons that I 
> don't have time to go into right now.
>
> 4) Periodically run a task that sweeps through the database, 
> "harvesting" tickets that were reserved but never committed.
>
>
>> Something like that *could* be implemented but endorses a bad design.
>
>
> Well, once again I am most interested to hear just what it is that is 
> so bad about the design.  You say "BAD, BAD, BAD" with no explanation, 
> so that might as well just be FUD, FUD, FUD!
>
>
Mark,

IIUC your system reserves the tickets and then charges the credit card. 
If the payment isn't processed than you want to release the tickets.  
What happens if your JVM happens to crash?  Do you have a way of 
completing (or rolling back) the transaction from another JVM?

The problem here is that you really do have a transaction that spans 
both reserving the tickets and paying for them.  It is understandable 
that you don't want the "real" transaction to span all of that, but the 
logical one does anyway. 

Frankly, this is one case where I would look into using a workflow 
engine to manage the full transaction.  Most do a nice job of handling 
all the issues involved and allowing you to specify rules and when to do 
what and how.  Unfortunately, most are oriented towards B2B stuff and 
are heavily biased towards SOAP, which is probably unnecessary in your case.

Ralph


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: callback for continuation timeout?

Posted by Mark Lundquist <ml...@wrinkledog.com>.
On Oct 25, 2005, at 12:18 AM, Torsten Curdt wrote:

>> I have some processing invoked from flow that's not OK to just 
>> abandon if the user abandons their session.  In particular, this 
>> processing logic "reserves" some resources in the database.
>
> BAD BAD BAD!! Don't!!

Why?  What's so BAD about it? :-)

> ...any other way of approaching that logic? What is it?

The application is a ticketing system.  We have to reserve the tickets 
in the database before we process the payment transaction so that we 
don't oversell our tickets.  So, reserving the tickets is transactional 
(using Spring+Hibernate+MySQL), while the payment processing is long 
but non-transactional.  We have to know that we will be able to issue 
the requested number of tickets, before we can bill the customer's 
credit card.

There are other ways to handle this that I can think of, and they are 
are all bad:

1) Process the payment first, with no guarantee of availability.  Once 
payment is secure, attempt to reserve the tickets.  If the requested 
number of tickets are no longer available, then run another transaction 
to reverse the payment.  I really don't like this idea...

2) Just do it all atomically within the transaction.  This is bad for 
two reasons.  First of all, it has *really* poor concurrency 
properties.  Suppose you and I are both trying to purchase tickets at 
the same time, and I win the race and make it into my transaction 
first.  Your transaction will then have to wait for as long as it takes 
mine to complete — including the interaction with the payment processor 
(Verisign) which takes a long time — before yours can even get started, 
and then of course you will have to wait for your own transaction to 
complete before you see any reply.  The second reason it is bad is that 
the design calls for a self-refreshing "please wait, transaction in 
process yada yada" screen to be displayed while the transaction is in 
process.  This requires that the purchase processing be done 
aysnchronously w.r.t. to the client request, and that is impossible if 
it is all to be within a single database transaction, due to lifetime 
issues with the Hibernate Session and Transaction objects 
(specifically: the main thread would be closing the Hibernate Session 
at the end of processing the HTTP request, while the secondary thread 
is still in mid-transaction.  A solution to that would be to use the 
Hibernate "long session" pattern, but that's too invasive of a change 
to make at this point.  BTW you would not like that, you would say it 
is "BAD BAD BAD"! :-) :-)

3) Use a delayed capture on the credit card, i.e. the first transaction 
is an authorization that places a hold on the funds.  Then if the 
attempt to reserve tickets is successful, we follow up with the capture 
transaction.  If we weren't able to reserve the tickets after all, then 
we don't.  This is bad because for multiple reasons that I don't have 
time to go into right now.

4) Periodically run a task that sweeps through the database, 
"harvesting" tickets that were reserved but never committed.


> Something like that *could* be implemented but endorses a bad design.

Well, once again I am most interested to hear just what it is that is 
so bad about the design.  You say "BAD, BAD, BAD" with no explanation, 
so that might as well just be FUD, FUD, FUD!

—ml—


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: callback for continuation timeout?

Posted by Torsten Curdt <tc...@apache.org>.
> I have some processing invoked from flow that's not OK to just  
> abandon if the user abandons their session.  In particular, this  
> processing logic "reserves" some resources in the database.

BAD BAD BAD!! Don't!!

A continuation should not even keep a component reference across a  
suspend!

...any other way of approaching that logic? What is it?

>   In the case of "success", the resources will remain permanently  
> associated with a persistent object, but in the case of "failure"  
> or "abandoned interaction", the resources must be released.
>
> Is there any way to register a listener or something so that if a  
> continuation is abandoned, I can release what needs to be released?

Something like that *could* be implemented but endorses a bad design.
So -1 on that.

cheers
--
Torsten


Re: Popups in Cocoon

Posted by Upayavira <uv...@odoko.co.uk>.
Oleg Konovalov wrote:
> Upayavira,
> 
> Let me get that straight:
> you are saying that all popups are a HTML/Javascript thing
> (so I should start and close them using Javascript),
> but for having multiple SQL queries, you suggest using
> aggregation (sitemap aggregation?) to use multiple
> SQL queries in one popup ?

Pretty much, yes. I've never really used SQL queries. I don't see why
you couldn't include more than one of them in one page though, without
using aggregation. But then one way or the other should work.

Regards, Upayavira
> 
> --- Upayavira <uv...@odoko.co.uk> wrote:
> 
> 
>>Oleg Konovalov wrote:
>>
>>>Hi,
>>>
>>>I am implementing enhancements to the existing Cocoon 2.0.4
>>>project (sitemap actions, lots of xsl/xml, some Java).
>>>When customer clicks on some link, it's supposed to display
>>>a popup with data from several queries [no inserts/updates].
>>>
>>>A few Cocoon newbie questions in that regard:
>>>1) Is there any support for popups in Cocoon ?
>>
>>Cocoon is no different from anything else. Popups are an
>>HTML/Javascript
>>thing.
>>
>>
>>>2) How do you make sure that it can only displays 1 instance
>>>of that popup ?
>>
>>You open a new window with a name, and point new content at
>>that name.
>>
>>
>>>3) Is there a way to automatically close that popup
>>>when user moved out from that page ?
>>
>>Hmm. Not that sure. If there is, I'd doubt it'd work on all
>>browsers.
>>You'd need to use an onblur property and set it to
>>javascript:window.close()
>>
>>
>>>4) How do you get data from (multiple) SQL queries in popup
>>
>>?
>>
>>>(normally in that app the queries are in XML, usually 1 per
>>>screen)
>>
>>Use aggregation to join two or more XML SQL queries into one
>>file?
>>
>>Regards, Upayavira
>>
>>
> 
> ---------------------------------------------------------------------
> 
>>To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>>For additional commands, e-mail: users-help@cocoon.apache.org
>>
>>
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Popups in Cocoon

Posted by Oleg Konovalov <ol...@yahoo.com>.
Upayavira,

Let me get that straight:
you are saying that all popups are a HTML/Javascript thing
(so I should start and close them using Javascript),
but for having multiple SQL queries, you suggest using
aggregation (sitemap aggregation?) to use multiple
SQL queries in one popup ?

Thank you,
Oleg.

--- Upayavira <uv...@odoko.co.uk> wrote:

> Oleg Konovalov wrote:
> > Hi,
> > 
> > I am implementing enhancements to the existing Cocoon 2.0.4
> > project (sitemap actions, lots of xsl/xml, some Java).
> > When customer clicks on some link, it's supposed to display
> > a popup with data from several queries [no inserts/updates].
> > 
> > A few Cocoon newbie questions in that regard:
> > 1) Is there any support for popups in Cocoon ?
> 
> Cocoon is no different from anything else. Popups are an
> HTML/Javascript
> thing.
> 
> > 2) How do you make sure that it can only displays 1 instance
> > of that popup ?
> 
> You open a new window with a name, and point new content at
> that name.
> 
> > 3) Is there a way to automatically close that popup
> > when user moved out from that page ?
> 
> Hmm. Not that sure. If there is, I'd doubt it'd work on all
> browsers.
> You'd need to use an onblur property and set it to
> javascript:window.close()
> 
> > 4) How do you get data from (multiple) SQL queries in popup
> ?
> > (normally in that app the queries are in XML, usually 1 per
> > screen)
> 
> Use aggregation to join two or more XML SQL queries into one
> file?
> 
> Regards, Upayavira
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Popups in Cocoon

Posted by Upayavira <uv...@odoko.co.uk>.
Oleg Konovalov wrote:
> Hi,
> 
> I am implementing enhancements to the existing Cocoon 2.0.4
> project (sitemap actions, lots of xsl/xml, some Java).
> When customer clicks on some link, it's supposed to display
> a popup with data from several queries [no inserts/updates].
> 
> A few Cocoon newbie questions in that regard:
> 1) Is there any support for popups in Cocoon ?

Cocoon is no different from anything else. Popups are an HTML/Javascript
thing.

> 2) How do you make sure that it can only displays 1 instance
> of that popup ?

You open a new window with a name, and point new content at that name.

> 3) Is there a way to automatically close that popup
> when user moved out from that page ?

Hmm. Not that sure. If there is, I'd doubt it'd work on all browsers.
You'd need to use an onblur property and set it to javascript:window.close()

> 4) How do you get data from (multiple) SQL queries in popup ?
> (normally in that app the queries are in XML, usually 1 per
> screen)

Use aggregation to join two or more XML SQL queries into one file?

Regards, Upayavira

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Popups in Cocoon

Posted by Oleg Konovalov <ol...@yahoo.com>.
Hi,

I am implementing enhancements to the existing Cocoon 2.0.4
project (sitemap actions, lots of xsl/xml, some Java).
When customer clicks on some link, it's supposed to display
a popup with data from several queries [no inserts/updates].

A few Cocoon newbie questions in that regard:
1) Is there any support for popups in Cocoon ?

2) How do you make sure that it can only displays 1 instance
of that popup ?

3) Is there a way to automatically close that popup
when user moved out from that page ?

4) How do you get data from (multiple) SQL queries in popup ?
(normally in that app the queries are in XML, usually 1 per
screen)

Any help is very appreciated.


TIA,
Oleg. 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: callback for continuation timeout?

Posted by Ellis Pritchard <el...@nukinetics.com>.
Mark Lundquist wrote:

> I have some processing invoked from flow that's not OK to just abandon 
> if the user abandons their session.  In particular, this processing 
> logic "reserves" some resources in the database.  In the case of 
> "success", the resources will remain permanently associated with a 
> persistent object, but in the case of "failure" or "abandoned 
> interaction", the resources must be released.

I model I've seen used in other ticketing sites is that you reserve the 
tickets for that user session for a given period of time, e.g. 10 
minutes, and they become available to re-allocation after that period.

i.e.

1. [DB Trans] your application will run a transaction which finds the 
tickets, and then marks them as reserved for a particular session id, 
with an expiration time. Any tickets which have been reserved by another 
session, but the reservation time has expired are available for reservation.
2. you send the form requesting the credit card details from the user.
3. [DB Trans] If the details are sent by the user to your app whilst you 
are still in the timeout period, extend the reservation period on the 
reserved tickets.
4. Attempt to authorize the CC.
5. [DB Trans] Given that 4. succeeds and takes a reasonable amount of 
time, you can now mark the tickets as permanently allocated. This 
transaction should fail if the tickets have been reallocated to another 
session or the ticket reservation has timed out.
6. You can now complete the CC transaction, if this fails for some 
reason, deallocate all the allocated tickets.

If a client fails to complete any stage, or takes too long to send in 
their details, the tickets will be reallocatable to another client; if 
CC authorization fails, you can either remove the reservation, or let 
the time-out do its work. If final CC transaction fails for some reason, 
you can deallocate the tickets.

Ellis.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org