Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Passing a parameter created in an advice to the pointcut implementation

The usage will be something like following. ConnectionCreatorAspect  becomes context holder for crosscutting concern objects. SomeOtherAspect  is your other aspect that needs to look up for connection object.

public aspect ConnectionCreatorAspect percflow(callPointCut()) {
    private Connection connection;
   
    pointcut callPointCut() : call(* *.foo(..) );
   
    before( ) : callPointCut( ) && !within(ConnectionCreatorAspect +) {
        // create your connection here and set it to instance variable of ConnectionCreatorAspect
        // Since this is percflow association you dun have to clean up thread local explicitly as it's handled by aspectj behind the scene
    }
    public Connection getConnection() { return this.connection; }
}


public aspect SomeOtherAspect {
    before( ) : // some pointcuts {
        ConnectionCreatorAspect.aspectOf().getConnection()
    }
}


For more information about that, check out aspectj in action book that explains well about this.

Regards,
Anggiat

On Sun, Feb 22, 2015 at 12:01 PM, Dave Brosius <dbrosius@xxxxxxxxxxxxxxx> wrote:
However you access them, the ThreadLocal variable should be static, otherwise odd things occur when you have multiple instances of the class holding the ThreadLocal.

You almost always want to to override the intialValue() method of the ThreadLocal class.


On 02/21/2015 10:42 PM, Archie Cobbs wrote:
On Sat, Feb 21, 2015 at 6:33 PM, Holger King <HolgerKing@xxxxxxx> wrote:
So, when using a ThreadLocal you would declare it as "public static" to allow accessing the added connection object in the target code, here the "FSIdmAdaptor"?

That would work. More commonly you make it private and provide access via a static method e.g.

  public static Connection getCurrentConnection()
  throws IllegalStateException {     // if no connection is set in the current thread


For lots of examples look at Spring, e.g., TransactionAspectSupport.

-Archie

--
Archie L. Cobbs


_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-users


_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top