Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #12325

Re: Aspect questions?

From Novice <novice@example..com>
Newsgroups comp.lang.java.programmer
Subject Re: Aspect questions?
Date 2012-02-25 17:17 +0000
Organization Your Company
Message-ID <XnsA0047E34BAB40jpnasty@94.75.214.39> (permalink)
References <XnsA0039B9FFFA32jpnasty@94.75.214.39> <ji8u23$f6m$1@news.albasani.net> <XnsA00493ECED98jpnasty@94.75.214.39> <m662r.13950$yb.8316@newsfe20.iad>

Show all headers | View raw


Arved Sandstrom <asandstrom3minus1@eastlink.ca> wrote in
news:m662r.13950$yb.8316@newsfe20.iad: 
[snip]

>>But the
>> bigger issue remains: are aspects a good approach for what I want to
>> do? If not, what would be a better strategy?
>> 
> A bit of reasoning can go a long ways to telling you whether aspects
> make sense for a particular job. This reasoning starts with an
> examination of the join points that AspectJ makes available in its
> join point model (JPM). You'll find this information tabulated in the
> AspectJ programming guide.
> 
> You'll see that the join points available to us in AspectJ include
> method calls/executions. The method call/execution join points have
> state, one piece of which is the object array of method arguments. As
> you might expect the other pieces of state are the objects involved
> (only one for the method execution join point).
> 
> You also know, or should be starting to understand, that pointcuts are
> the mechanism by which you choose *which* join points are in use. This
> can be very powerful: for the method execution join point you could
> easily select only the public methods for a given class, and that
> becomes a certain pointcut that you use.
> 
> Dynamic pointcuts would even allow you to say that, for example, if
> you have defined a pointcut, say Pointcut 1, that selects all the
> public methods for class A (more precisely, selects the join points
> that represent the executions for all the public methods in class A),
> that you are also interested in the executions of methods that happen
> within the context of those join points. In other words, if "public
> A.someMethod(args)" runs, that's been identified by Pointcut 1.
> Pointcut 2 could include any methods that are *called by*
> A.someMethod(args). 
> 
> Finally, with the _advice_, you have even more control on what code
> you run at each selected join point, *when* you run it in temporal
> relation to the join point (e.g. maybe you run some code if the method
> threw an exception), and even whether you run the code at all. And as
> you might expect, the advice knows about certain state - advice
> associated with a pointcut has access to the state of the join points.
> So an advice associated with our Pointcut 1 sees the method arguments.
> 
> Of all the other join points available in AspectJ, let's keep field
> assignment and constructor calls/executions in mind as well, as we
> think logging.
> 
> So let's consider logging, armed with all of this knowledge. If
> nothing else, you know that you can log method calls & executions with
> great flexibility. If you wanted to, you could be logging, using log4j
> say, messages out at an error or warn level for exceptions thrown by
> any methods which are called by public methods in package
> org.whatsit.*. At the same time you might log the public calls in that
> package at debug level. 
> 
> As an aside, you can see why this type of application of AOP is called
> tracing. Very powerful tracing, but still execution tracing.
> 
> But, and this is one main "but", you don't have access to the guts of
> interesting methods unless the internals are also identifiable by join
> points. If there is an important conditional, the correct behaviour of
> which is bedevilling you, and which relies on local variables computed
> in a local chunk of code in that method, AspectJ has no eyes on it.
> You're not going to be logging this kind of thing with aspects.
> 
I think you just saved me a fair bit of time ;-) I was curious to see 
whether I could use aspects to do what I'll call diagnostic logging. I 
have some methods that do "calculations" of one kind or another, like the 
best width for a column in a JTable given the width of the values in each 
column, and it would be neat if I could remove all of that logging code 
from the method itself and put it in aspects. Then, when the method is 
working 100% to my satisfaction, I can discard that aspect and leave the 
method uncluttered. 

From what you're saying, I may not be able to capture the values of all 
the variables that are being juggled in the suspect method. I had 
wondered about that and was going to try it myself to see. I probably 
still will but I'll be less surprised/disappointed if I can't access the 
information I want.

> Another big "but", maybe not so much a "but" rather a general
> consideration, is that if you start getting very fine-grained about
> pointcuts, you're sort of defeating the purpose of AOP. We're, I
> expect, considering a codebase that has no extensive logging, maybe
> none. If you are going to spend inordinate amounts of time tailoring
> pointcuts and advice for umpteen different types of logging, *you may
> as well bite the bullet and go into the code and directly use the
> logging framework*, rather than apply it through the agency of
> aspects. 
> 
Actually, I already have logging in place for most of classes and am 
retrofitting it to the rest. I use the Java Logging classes, as opposed 
to Log4j, but I'm not fanatical about it. I'm hearing more and more to 
the effect that Log4j is better so maybe I'll make the switch. The better 
I design my logging, the less painful that is going to be ;-)

> In a nutshell, for logging, I myself have used AspectJ for emergency
> maintenance: the codebase in question has no logging, or what it has
> is useless, and there is limited time to add logging to source. So
> this is execution tracing logging.
> 
> I hope this helps.
> 
It does, Arved. Thanks!

So what do you use aspects for, besides the occasional need to add 
logging into poorly-logged classes?

-- 
Novice

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Aspect questions? Novice <novice@example..com> - 2012-02-24 20:10 +0000
  Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-02-24 13:05 -0800
    Re: Aspect questions? Novice <novice@example..com> - 2012-02-25 05:47 +0000
      Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-02-24 23:40 -0800
        Re: Aspect questions? Novice <novice@example..com> - 2012-02-25 17:02 +0000
          Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-02-25 12:08 -0800
            Re: Aspect questions? Novice <novice@example..com> - 2012-02-25 22:12 +0000
              Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-02-25 14:27 -0800
                Re: Aspect questions? Novice <novice@example..com> - 2012-02-25 23:29 +0000
                Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-02-25 18:33 -0500
                Re: Aspect questions? Novice <novice@example..com> - 2012-02-26 14:38 +0000
                Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-02-26 10:49 -0500
                Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-02-26 10:53 -0500
                Re: Aspect questions? Novice <novice@example..com> - 2012-02-26 18:17 +0000
                Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-02-25 16:01 -0800
                Re: Aspect questions? Novice <novice@example..com> - 2012-02-26 17:22 +0000
                Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-02-26 12:25 -0500
                Re: Aspect questions? Novice <novice@example..com> - 2012-02-26 21:08 +0000
                Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-02-26 18:33 -0500
                Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-02-26 17:05 -0800
                Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-02-26 20:18 -0500
                Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-02-26 21:29 -0800
                Re: Aspect questions? Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-02-27 05:44 -0400
                Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-02-27 21:37 -0500
                Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-02-28 00:04 -0800
                Re: Aspect questions? Patricia Shanahan <pats@acm.org> - 2012-02-28 01:39 -0800
                Re: Aspect questions? Novice <novice@example..com> - 2012-02-29 14:54 +0000
                Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-02-28 17:24 -0500
                Re: Aspect questions? Novice <novice@example..com> - 2012-02-27 04:53 +0000
                Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-03-02 17:08 -0500
                Re: Aspect questions? Novice <novice@example..com> - 2012-02-27 05:12 +0000
                Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-02-26 21:38 -0800
                Re: Aspect questions? Novice <novice@example..com> - 2012-02-27 17:27 +0000
                Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-02-27 12:22 -0800
                Re: Aspect questions? Novice <novice@example..com> - 2012-02-27 22:50 +0000
                Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-02-27 17:24 -0800
                Re: Aspect questions? Novice <novice@example..com> - 2012-02-29 15:00 +0000
                Re: Aspect questions? Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-02-29 09:14 -0800
                Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-02-29 09:55 -0800
                Re: Aspect questions? Novice <novice@example..com> - 2012-02-29 21:31 +0000
                Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-02-29 23:06 -0800
                Re: Aspect questions? Novice <novice@example..com> - 2012-03-02 04:33 +0000
                Re: Aspect questions? Novice <novice@example..com> - 2012-03-04 23:00 +0000
                Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-03-04 17:07 -0800
                Re: Aspect questions? Novice <novice@example..com> - 2012-03-05 15:33 +0000
                JavaDoc linking (Was: Aspect questions?) Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-03-05 08:38 -0800
                Re: JavaDoc linking (Was: Aspect questions?) Novice <novice@example..com> - 2012-03-05 17:40 +0000
                Re: JavaDoc linking (Was: Aspect questions?) Patricia Shanahan <pats@acm.org> - 2012-03-05 21:25 -0800
                Re: JavaDoc linking (Was: Aspect questions?) Arne Vajhøj <arne@vajhoej.dk> - 2012-03-06 17:23 -0500
                Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-03-05 23:45 -0800
                Re: Aspect questions? Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-03-06 06:03 -0400
                Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-03-06 21:05 -0800
                Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-03-02 17:11 -0500
                Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-03-02 17:09 -0500
                Re: Aspect questions? Martin Gregorie <martin@address-in-sig.invalid> - 2012-02-26 23:43 +0000
                Re: Aspect questions? Novice <novice@example..com> - 2012-02-27 05:20 +0000
                Re: Aspect questions? Patricia Shanahan <pats@acm.org> - 2012-02-26 21:32 -0800
                Re: Aspect questions? Novice <novice@example..com> - 2012-02-27 17:36 +0000
                Re: Aspect questions? Jeff Higgins <jeff@invalid.invalid> - 2012-02-27 13:18 -0500
                Re: Aspect questions? Jeff Higgins <jeff@invalid.invalid> - 2012-02-27 14:05 -0500
                Re: Aspect questions? Jeff Higgins <jeff@invalid.invalid> - 2012-02-27 14:33 -0500
                Re: Aspect questions? Jeff Higgins <jeff@invalid.invalid> - 2012-02-27 14:53 -0500
                Re: Aspect questions? Jeff Higgins <jeff@invalid.invalid> - 2012-02-27 15:16 -0500
                Re: Aspect questions? Jeff Higgins <jeff@invalid.invalid> - 2012-02-27 17:57 -0500
                Re: Aspect questions? Novice <novice@example..com> - 2012-02-27 22:59 +0000
                Re: Aspect questions? Jeff Higgins <jeff@invalid.invalid> - 2012-02-28 05:50 -0500
                Re: Aspect questions? Novice <novice@example..com> - 2012-02-29 15:03 +0000
                Re: Aspect questions? Patricia Shanahan <pats@acm.org> - 2012-02-27 13:17 -0800
                Re: Aspect questions? Novice <novice@example..com> - 2012-02-27 22:55 +0000
                Re: Aspect questions? Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-02-27 05:58 -0400
                Re: Aspect questions? Novice <novice@example..com> - 2012-02-27 18:14 +0000
                Re: Aspect questions? Martin Gregorie <martin@address-in-sig.invalid> - 2012-02-28 00:12 +0000
                Re: Aspect questions? Novice <novice@example..com> - 2012-02-28 02:04 +0000
                Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-02-27 21:22 -0500
                Re: Aspect questions? Novice <novice@example..com> - 2012-02-29 15:11 +0000
                Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-03-02 17:14 -0500
                Re: Aspect questions? Martin Gregorie <martin@address-in-sig.invalid> - 2012-02-28 23:09 +0000
                Re: Aspect questions? Novice <novice@example..com> - 2012-02-29 15:25 +0000
                Re: Aspect questions? Martin Gregorie <martin@address-in-sig.invalid> - 2012-03-01 00:22 +0000
                Re: Aspect questions? Novice <novice@example..com> - 2012-03-01 01:44 +0000
                Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-02-29 23:24 -0800
                Re: Aspect questions? Martin Gregorie <martin@address-in-sig.invalid> - 2012-03-01 21:19 +0000
                Re: Aspect questions? Novice <novice@example..com> - 2012-03-02 01:52 +0000
                Re: Aspect questions? Martin Gregorie <martin@address-in-sig.invalid> - 2012-03-03 01:39 +0000
                Re: Aspect questions? Novice <novice@example..com> - 2012-03-05 15:38 +0000
                Re: Aspect questions? Martin Gregorie <martin@address-in-sig.invalid> - 2012-03-05 22:50 +0000
                Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-03-05 23:46 -0800
                Re: Aspect questions? Patricia Shanahan <pats@acm.org> - 2012-03-06 08:14 -0800
                Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-03-06 21:23 -0800
                Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-03-08 20:10 -0500
                Re: Aspect questions? Novice <novice@example..com> - 2012-03-02 01:49 +0000
                Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-03-01 22:38 -0800
                Re: Aspect questions? Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-03-02 06:05 -0400
                Re: Aspect questions? Novice <novice@example..com> - 2012-03-02 14:25 +0000
                Re: Aspect questions? Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-03-02 18:10 -0400
                Re: Aspect questions? Novice <novice@example..com> - 2012-03-02 14:12 +0000
                Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-03-02 08:57 -0800
                Re: Aspect questions? Novice <novice@example..com> - 2012-03-05 15:57 +0000
                Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-03-05 23:48 -0800
                Re: Aspect questions? Novice <novice@example..com> - 2012-03-07 20:33 +0000
                Re: Aspect questions? Lew <lewbloch@gmail.com> - 2012-03-07 13:09 -0800
                Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-03-02 17:20 -0500
                Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-03-02 14:28 -0800
                Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-03-02 17:16 -0500
                Re: Aspect questions? markspace <-@.> - 2012-02-26 10:10 -0800
                Re: Aspect questions? Novice <novice@example..com> - 2012-02-26 20:52 +0000
                Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-02-26 13:48 -0800
                Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-02-26 13:47 -0800
                Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-02-26 18:40 -0500
                Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-02-26 18:36 -0500
                Re: Aspect questions? markspace <-@.> - 2012-02-26 16:04 -0800
                Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-02-26 19:38 -0500
                Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-02-26 17:09 -0800
                Re: Aspect questions? Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-02-26 20:08 -0400
                Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-02-26 19:43 -0500
                Re: Aspect questions? Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-02-27 22:03 -0400
                Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-02-27 21:18 -0500
                Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-02-26 13:43 -0800
                Re: Aspect questions? Novice <novice@example..com> - 2012-02-27 01:11 +0000
                Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-02-26 21:49 -0800
                Re: Aspect questions? Novice <novice@example..com> - 2012-02-27 18:37 +0000
                Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-02-27 12:28 -0800
                Re: Aspect questions? Novice <novice@example..com> - 2012-02-28 00:55 +0000
                Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-02-27 17:37 -0800
                Re: Aspect questions? Novice <novice@example..com> - 2012-02-29 15:57 +0000
                Re: Aspect questions? Leif Roar Moldskred <leifm@dimnakorr.com> - 2012-02-28 03:21 -0600
                Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-02-28 09:19 -0800
                Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-02-27 21:12 -0500
                Re: Aspect questions? Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-02-28 05:59 -0400
                Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-02-28 17:27 -0500
                Re: Aspect questions? Novice <novice@example..com> - 2012-02-29 16:07 +0000
                Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-03-02 17:26 -0500
              Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-02-25 18:22 -0500
                Re: Aspect questions? markspace <-@.> - 2012-02-25 20:22 -0800
                Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-02-25 22:20 -0800
                Re: Aspect questions? markspace <-@.> - 2012-02-26 00:04 -0800
                Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-02-26 00:21 -0800
                Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-02-26 00:33 -0800
                Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-02-26 10:43 -0500
                Re: Aspect questions? Martin Gregorie <martin@address-in-sig.invalid> - 2012-02-26 11:18 +0000
                Re: Aspect questions? Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-02-26 11:04 -0400
                Re: Aspect questions? Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-02-26 10:22 -0400
                Re: Aspect questions? Novice <novice@example..com> - 2012-02-26 21:04 +0000
                Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-02-26 14:01 -0800
                Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-02-26 18:46 -0500
                Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-02-26 09:50 -0500
                Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-02-26 10:38 -0500
                Re: Aspect questions? Novice <novice@example..com> - 2012-02-26 20:49 +0000
      Re: Aspect questions? jlp <jlp@jlp.com> - 2012-02-25 09:47 +0100
        Re: Aspect questions? Novice <novice@example..com> - 2012-02-25 17:03 +0000
          Re: Aspect questions? jlp <jlp@jlp.com> - 2012-02-25 20:02 +0100
      Re: Aspect questions? Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-02-25 10:20 -0400
        Re: Aspect questions? markspace <-@.> - 2012-02-25 08:18 -0800
          Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-02-25 12:04 -0500
        Re: Aspect questions? Novice <novice@example..com> - 2012-02-25 17:17 +0000
          Re: Aspect questions? Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-02-25 18:40 -0400
          Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-02-25 18:18 -0500
      Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-02-25 09:21 -0500
      Re: Aspect questions? Roedy Green <see_website@mindprod.com.invalid> - 2012-02-25 14:35 -0800
  Re: Aspect questions? markspace <-@.> - 2012-02-24 14:30 -0800
    Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-02-24 19:47 -0500
      Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-02-24 20:52 -0800
        Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-02-25 09:31 -0500
        Re: Aspect questions? Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-02-25 11:05 -0400
          Re: Aspect questions? Lew <noone@lewscanon.com> - 2012-02-25 12:20 -0800
  Re: Aspect questions? Arne Vajhøj <arne@vajhoej.dk> - 2012-02-24 19:00 -0500
  Re: Aspect questions? Tom Anderson <twic@urchin.earth.li> - 2012-02-25 00:22 +0000

csiph-web