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

Hello Anggiat,

not quite sure whether you understood my problem completely as you talk about two aspects. One called "ConnectionCreatorAspect" the other "SomeOtherAspect". Me, I just have one. The other class implements the code that has to be enhanced with the aspect where the connection creation and closing has to be  done. And the created connection object has to be used by the non-aspect implementation. Here, the central question is: how to use this connection object.  Please take a look at my sample code before.

When really a solution is available that prevents the implementation of a ThreadLocal-based solution I would vote for that one.

Or am I wrong and I misunderstood you? It would be kind to help me understanding you :-)

As I'm an owner of the "AspectJ in Action" book you can even tell me the chapter you meant.

I'm looking forward to reading from you again.

Kind regards
Holger

Am 22.02.2015 um 10:02 schrieb Anggiat Barita:
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



_______________________________________________
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