Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Regarding queuing methods using AspectJ

Thanks everyone for your response!

I think Matthew's approach of wait() and notify() would solve my
purpose here since I am not very familiar with annotations and am
dealing with a simple environment

I couldn't find a lot of information in the usage but I am guessing
this is how I should be approaching it now:
around(): capturedMethod()
{
Object myObj = thisJoinPoint.getThis();
arrayList.add(myObj);
myObj.wait();
}

around(): execution(triggerMethod)
{
Iterate through ArrayList
    for each Object in ArrayList
       myObject.notify();
}

Is it as simple as this? I read that there is a need to have a
'synchronize()' method but I wasn't very clear on that either, if it
would be required in this case or not?

Thanks!

Sarthak

On 4/18/07, Kevin F <aj@xxxxxxxxxxxxxxxxxxxxxxx> wrote:
Admittedly, I didn't read all the details of this post thread; however,
accomplishing what I inferred from skimming is very simple indeed.  I have
written code that looks exactly like the following and works like a charm
(copy/pasted and trivially tweaked it for you).

void around() : execution( @RequireTransaction * *(..) )
{
        if( isTransactionThread() )        {            proceed();        }
      else        {            Runnable runnable = new Runnable()
{                public void run()                {
proceed();                }            };            transactionQueue.add(
runnable );        }
}

This allows you to avoid writing any complex pointcuts and place whatever
methods you like into the queue by using annotations.  Is this what you were
thinking?


________________________________
From: Matthew Webster <matthew_webster@xxxxxxxxxx>
Reply-To: <aspectj-users@xxxxxxxxxxx>
Date: Wed, 18 Apr 2007 15:07:49 +0100
To: <aspectj-users@xxxxxxxxxxx>
Subject: Re: [aspectj-users] Regarding queuing methods using AspectJ



Sarthak,

How about simply queueing "thisJoinPoint" then use wait() and notify(). The
thread running the method that has been queued will then wake up and execute
the original method with its context. If required you can use some
additional coordination to ensure that each method completes before the next
is notified.

Matthew Webster
Tools UI Strategy
CICS Technical Planning & Strategy, MP189
IBM United Kingdom Limited
Hursley Park, Winchester,  SO21 2JN, England
Telephone: +44 196 2816139 (external) 246139 (internal)


"Sarthak Grover" <sarthak.grover@xxxxxxxxx>
Sent by: aspectj-users-bounces@xxxxxxxxxxx 18/04/2007 03:02


Hello all,

What started with as a simple idea is turning out more confusing than
I initially thought (or I am making it that way for myself)

What I am trying to achieve is a transaction queue which is executed
only when a particular method is called.

Currently I have a bunch of pointcuts identifying methods which I want
to capture and prevent execution till the 'trigger' method is called.
So, my pseudo algorithm
was something like this:

In the following, myMethodA, myMethodB are the target methods that I
want to queue and myMethodC is the trigger method.

===================
pointcut A: execution (myMethodA)

void around(): A()
  {
   Add the methodCall(joinpointSignature) to an ArrayList();
// I don't want to proceed with the execution of the method right now
  }

pointcut B: execution (myMethodB)

void around() : B()
  {
  Add the methodCall to the above ArrayList();
  }

pointcut C: execution (myMethodC)

void around(): C()
 {

 Execute myMethodA();
 Execute myMethodB();
 }

===================
I am able to save the method information using reflection, but I am
not sure how to make a call in the advice of myMethodC to execute
myMethodA() and myMethodB() from within the aspect.

Is there some way of saving the state of these methods and then
executing them? Perhaps there is a simpler way and I am just not aware
of it?

I appreciate any ideas or advice in this regards.

Thanks,

Sarthak


Back to the top