Event Queue beyond request scope

5 views
Skip to first unread message

Sumit Verma

unread,
Nov 17, 2009, 3:11:38 PM11/17/09
to Mach-II for CFML
Hi Guys,

How do you all generally handle accessing Event data between multiple
requests. Here is the use case:

1. User submits a form.
2. Security plugin performs session check and announces a login event
because session has timeout out.
3. User logs in and using the continuationEvent we announce the
previous (form save) event.

But, at this point we have lost all the event args that came from step
1.

I was thinking of writing a session based event queue, but thought I
will check here first to see what other are doing. BTW: I think
session based event queue will be a great feature for the framework
itself.

Thanks,
Sumit

Brian FitzGerald

unread,
Nov 17, 2009, 3:53:15 PM11/17/09
to Mach-II for CFML
How about in the login plugin, before you announce the "showLoginForm"
event, you store the "attempted" event name event args in the
session ...

if(sessionExpired)
{
getSessionFacade().setAttemptedEventName(arguments.event.getName());
getSessionFacade().setAttemptedEventArgs(arguments.event.getArgs());
redirectEvent("showLoginForm");
}

And then after the successful login, you grab them back out of the
session? That's how I do it, if I'm understanding your situation
correctly.

Best,
Brian

Peter J. Farrell

unread,
Nov 17, 2009, 4:15:59 PM11/17/09
to mach-ii-for...@googlegroups.com
To piggy back on Brian's suggestion, the simplest way to do this is to cache the entire incoming Event object into the session scope.  The Event object contains the requested event name under the event-arg that matches the value of getProperty("eventParameter").

It's as simple as :

1) If a login is triggered, cache the current Event object in the session scope.
2. After a valid login, check for an Event in the session scope.
3. If a cached Event exists, clear the event-queue, grab the Event name to be announced from the cached Event and announceEvent(cachedEvent.getArg(getProperty("eventParameter")),  cachedEvent.getArgs()) if the event-args from the cached Event.

Essentially, you are caching and later replaying the incoming Event that triggered the login condition in your application flow.  FYI - if you are using modules, you'll have to break the event parameter value and check for a module name as well.

.Peter

Brian FitzGerald said the following on 11/17/2009 02:53 PM:

Brian FitzGerald

unread,
Nov 17, 2009, 4:16:58 PM11/17/09
to Mach-II for CFML
Ah, great suggestion Peter, store the entire event object in the
session rather than it's pieces ... so simple, now why didn't I think
of that?! Gonna have to make this mod in my own app =)

Does that fully address your question Sumit?

Thanks,
Brian

Peter J. Farrell

unread,
Nov 17, 2009, 4:47:35 PM11/17/09
to mach-ii-for...@googlegroups.com
Just wanted to know if a community member could volunteer to add this to the wiki?

I'm thinking a separate FAQ entry because could link to it from plugins and filters entries.  Like so:

http://greatbiztoolsllc.trac.cvsdude.com/mach-ii/wiki/IntroToPlugins#LoginPlugin

One step to be aware of is to remember to *delete* the saved event object after you use get it.  Typically, I'm using a session facade object so my explicitly named getter - getSavedEventPostLogin() method either returns an object or nothing so I can use IsObject() on the returned data *and* if an object exists -- it clears it.  There is no sense for it to hang around in memory once used and also it ups the chance of somebody triggering it hours down the line (due to a coding problem or something).

Another thing to be aware of is saving the event to a session when search engine spiders come for a visit.  Typically, a spider will trigger a new session on each request because it doesn't keep cookies.  So you might look into session management when it comes to bots.  On one system, we engineered the onSessionStart logic to differ when the user agent was a know spider -- a) there session was set to 1 minute b) a whole ton of session objects weren't created.  In regards to b), you may have to change your session facade to return dummy data if an object doesn't exist.  For example, we normal instantiate a cart object into the session scope.  For bots we did not.  So calling, getTotalCartItemCount() would return a 0 if a cart object hadn't been instantiate.

Brian FitzGerald said the following on 11/17/2009 03:16 PM:

Sumit Verma

unread,
Nov 18, 2009, 12:02:21 AM11/18/09
to mach-ii-for...@googlegroups.com
Thanks guys. That's exactly what I was thinking off. I implemented it a little bit different by creating an eventQueue (Array) in session, so that I can replay multiple events in a sequence if need be.  

--
You received this message because you are subscribed to Mach-II for CFML list.
To post to this group, send email to mach-ii-for...@googlegroups.com
To unsubscribe from this group, send email to mach-ii-for-coldf...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/mach-ii-for-coldfusion?hl=en
SVN: http://greatbiztoolsllc.svn.cvsdude.com/mach-ii/
Wiki / Documentation / Tickets: http://greatbiztoolsllc.trac.cvsdude.com/mach-ii/

Peter J. Farrell

unread,
Nov 18, 2009, 12:26:15 AM11/18/09
to mach-ii-for...@googlegroups.com
Good to know it solved your problem.  Maybe you could write a wiki entry about it? ;-)

Sumit Verma said the following on 11/17/2009 11:02 PM:

Sumit Verma

unread,
Nov 18, 2009, 12:21:29 AM11/18/09
to mach-ii-for...@googlegroups.com
Sure Peter. Will do that once I wrap up implementation in couple of days :)
Reply all
Reply to author
Forward
0 new messages