Skip to Content.
Sympa Menu

grouper-dev - RE: [grouper-dev] Use of sessions in hooks

Subject: Grouper Developers Forum

List archive

RE: [grouper-dev] Use of sessions in hooks


Chronological Thread 
  • From: Chris Hyzer <>
  • To: "" <>, "" <>
  • Subject: RE: [grouper-dev] Use of sessions in hooks
  • Date: Fri, 7 Aug 2009 11:01:50 -0400
  • Accept-language: en-US
  • Acceptlanguage: en-US

There are two cases:

1. If you are in a hook, and you know there is an active grouper session
being used, and you want to use it (or get a root session from it), then call:

GrouperSession grouperSession = GrouperSession.staticGrouperSession();

Don't stop it when done. :)

2. If there might not be an existing session (e.g. asynchrounous hook, or
hook on operation which doesn't require a session, though most do, might be
hard to know :) ), then you can start a new one, and do it like the email
example (note, below I stop session in finally block which is probably better
:) ). Also note that any variables you want to use in the callback need to
be declared as final...

static void checkEmailAddress(final String emailAddress) {

try {
//start session, dont clobber existing session
GrouperSession grouperSession =
GrouperSession.start(SubjectFinder.findRootSubject(), false);
GrouperSession.callbackGrouperSession(grouperSession, new
GrouperSessionHandler() {

public Object callback(GrouperSession grouperSession)
throws GrouperSessionException {

//do your logic

return null;
}

});
} catch (Exception e) {
throw new RuntimeException("Problem checking email address: '" +
emailAddress + "'", e);
} finally {
GrouperSession.stopQuietly(grouperSession);
}
}


> -----Original Message-----
> From: Arnaud Deman
> [mailto:]
> Sent: Friday, August 07, 2009 9:10 AM
> To:
>
> Subject: [grouper-dev] Use of sessions in hooks
>
> Hello,
>
> Could someone tell me how to use/create a GrouperSession when you don't
> know if another one is already started.
> I looked at the example in checkEmailAddress of
> GroupHooksImplExampleEmail - Is it the good way ?
>
> I have a no deterministic error when I stress test my system and I
> think
> that maybe it's because I don't use the sessions correctly.
>
> Many thanks,
> Arnaud.
>
>
>
>
>
> --
>
> Arnaud Deman
> GIP RECIA
> Parc d'activit├ęs les Aulnaies
> 151 rue de la Juine - 45160 OLIVET
> Tel : 02 38 42 14 69
>




Archive powered by MHonArc 2.6.16.

Top of Page