[Java] Spring AOP question

Chris Allen mrchrisallen at gmail.com
Tue Jan 31 15:46:35 EST 2006


Yeah that would work.  But that assumes that each instance of the Audit
class has to be in a separate thread.  That might not be the case, and it
certainly puts a limitation on how many of these Audit instances you can
have (one per thread).

On 1/31/06, Nicolas Désy <liguorien at hotmail.com> wrote:
>
> Hi Grant,
>
> Have you tried using a ThreadLocal to store the audit object ?
>
> /***** code *********/
>
> public class AuditRepository {
>
>     private static ThreadLocal _context = new ThreadLocal();
>
>     public static void setAudit(Audit audit){
>         _context.set(audit);
>     }
>
>     public static Audit getAudit(){
>         return (Audit) _context.get();
>     }
>
>     public static void clear(){
>         _context.set(null);
>     }
> }
>
>
>
> private void someMethod(){
>     AuditRepository.getAudit().write("foo");
> }
>
>
> Audit = new Audit(id, this.getClass().getName(), "login");
> audit.markReceipt();
>
> AuditRepository.setAudit(audit);
>
> someMethod();
>
> audit.markEnd();
>
> AuditRepository.clear();
>
> /***** code *********/
>
>
> Nicolas
>
> ----- Original Message -----
> From: <grant at bluetube.com>
> To: <Java at osflash.org>
> Sent: Tuesday, January 31, 2006 12:48 PM
> Subject: [Java] Spring AOP question
>
>
> >
> > Hey guys, just joined the list on advice from Mr Allen.
> >
> > I have something that seems like it would be a good AOP fit but breaks
> > part way through...
> >
> > I have some classes that need auditing and I CAN'T change the method
> > signature on these classes.
> >
> > Lets show a very simple example class that uses our auditing class
> without
> > spring :
> >
> > class SecurityManager
> > {
> >
> > public login(id, password)
> > {
> >
> >   Audit = new Audit(id, this.getClass().getName(), "login");
> >
> > audit.markReceipt();  // sets the timestamp of when we started our work
> >
> >
> >
> >   // log the user in and write to the audit log
> >
> >    if (someothersystem.login(id, password) == true)
> >     audit.write("user " + id "logged in at " + new Date().toString());
> >    else
> >        audit.write("user " + id " failed to login");
> >
> >   audit.markEnd();
> >
> > }
> >
> >
> > }
> >
> > Every method needs an audit object that knows the method that is being
> > audited and the user that has called this object
> >
> > Audit = new Audit(id, this.getClass().getName(), "login");
> >
> > so the method is id, the name of the class and the method that is called
> >
> > then we mark receipt of the call to say our business logic has started
> by
> > :
> >
> > audit.markReceipt();
> >
> > now, this class needs to write audits based on different things,
> sometimes
> > it wil be purely business so I don't want to tie the audit message to
> > sucesss/failure as there may be many audits, for example if a user has
> > failed to login but they have also tried 3 times before I may want to
> > audit that...
> >
> > so
> >
> > audit.write("some free form message");  is very method specific
> >
> >
> > at the end, all methods need
> >
> > audit.markServiceEnd();
> >
> >
> > So I jumped into AOP with both feet, I created a methodBeforeAdvice that
> > creates the audit object and calls the markReceipt
> >
> > I then got stuck...
> >
> > The login method needs access to the audit object which has "state", so
> it
> > can call the "write" method.  But i can't pass it as an argument as the
> > method signature can't be changed and giving it an audit object does
> seem
> > to polute a very business oriented method.  In discussions with chris I
> > thought of creating an audit manager but each audit object is unique to
> a
> > method call.  The 3 parts of an audit, markReceipt, write, and MarkEnd
> are
> > combined into 1 log entry in the audit log.  so I don't want an atomic
> > call like log4j as the data would be written 3 times and our audits are
> > big enough with just 1 line...
> >
> > Any ideas, I can re-architect the audit, but I can't change the method
> > signatures of the objects that need auditing, I can change the code
> inside
> > those methods, just not what they are passed or what they return...
> >
> >
> > Thanks guys.
> >
> > Grant.
> >
> >
> >
> >
> >
> >
> >
> >
> >
>
>
>
> --------------------------------------------------------------------------------
>
>
> > _______________________________________________
> > Java mailing list
> > Java at osflash.org
> > http://osflash.org/mailman/listinfo/java_osflash.org
> >
>
> _______________________________________________
> Java mailing list
> Java at osflash.org
> http://osflash.org/mailman/listinfo/java_osflash.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://osflash.org/pipermail/java_osflash.org/attachments/20060131/c4ca7455/attachment.htm


More information about the Java mailing list