Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Pointcut around constructor

I think the issue of the OP is a little bit more subtle than this; in
the case of a constructor pointcut you have to consider that they are
defined without return type just implicitly they return an object of the
same type of the class, this could be puzzling for a new user especially
since you have to explicit such a return type by defining the around as
returning Object or Calc.

Moreover arounds on constructors behave differently if they are on calls
or executions. In the second case the object is created (but I suppose
not initialized) even if you don't call the proceed() and I suppose this
is not the behavior desired by the OP.

Last but not least to have your example working you have to change both
the call to the constructor but also the Calc class that should be a
server (that is, it has to extend UnicastRemoteObject or similar classes
and register on a rmiregistry).

HTH
Walter

On Wed, 30 Jun 2010, Matthew Adams wrote:

For your example, you actually want the around advice to return
something -- your Calc instance.  The reason around advice requires a
return type is that you can place around advice around any method
without the client necessarily knowing that around advice is being
executed.  If the client expects a return value, then give them one,
either via capturing the return value from proceed(), the advice's own
return value.  If it makes sense to return go ahead, and if the
advised method returns void, just return null from your around advice.

HTH,
Matthew

On Wed, Jun 30, 2010 at 2:23 AM, Pawel Branc <pbranc@xxxxxxxxx> wrote:
Hello,
I learn aspectJ, being at the beginning.

I have 2 classes. I want to send second class to another computer and
take its object remotely.

//class which will be used locally
public class CalcExecutor
{
       public static void main(String[] args)
       {
               long num1 = Integer.parseInt(args[0]);
               long num2 = Integer.parseInt(args[1]);
               Calc c = new Calc();
               System.out.println( "We add: "+num1 +" and: "+ num2 +"and obtain:
"+c.add(num1, num2) );
       }
}

//class which I want to send and use its object remotely
public class Calc
{
       public Calc() {}

       public long add(long a, long b)
       {
               return a + b;
       }
}

I would like to shadow with around() advice:
THIS
  Calc c = new Calc();
WITH THIS
  Calc c = (Calc)Naming.lookup("rmi://localhost:1099/CalculatorService");

I have problem with around() because it must return something. But why?
Could You help me. Thanks a lot.
Pawel
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users






--
Walter Cazzola, PhD - Assistant Professor, DICo, University of Milano
E-mail cazzola@xxxxxxxxxxxxx Ph.: +39 02 503 16300  Fax: +39 02 503 16253
· · · ---------------------------- · · · ---------------------------- · · ·
               ... recursive: adjective, see recursive ...
· · · ---------------------------- · · · ---------------------------- · · ·

Back to the top