Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] How best to code instance-based aspects?

Hi Joel,

It's good to see you and that you're using AspectJ.

You could solve this problem by creating a decorator in advice. Write around advice on getting streams for a socket. In the advice test if you want to watch this socket (or this stream). If you do, want to watch this, then return the decorator that wraps the original returned result.

You can then either write advice on the decorator class, or you can just use inheritance to watch the data flow. 

Other ideas that might work would be to restrict your advice to affect calls to streams within certain classes, withincode certain methods, or in the cflow of some method. 

Ron

Ron Bodkin
Chief Technology Officer
New Aspects of Security
m: (415) 509-2895

> ------------Original Message-------------
> From: RothnJ@xxxxxxxxxxxxxxxx
> To: aspectj-users@xxxxxxxxxxx
> Date: Wed, Aug-13-2003 11:06 AM
> Subject: [aspectj-users] How best to code instance-based aspects?
> 
> (First off, "hi" to Ron from an old friend ...)
> 
> My question relates to the runtime-control of aspects. Specifically, I am
> trying to watch the data going over a number of java.net.Socket objects.
> Since the I/O methods won't be called on the socket objects directly, but
> on their associated I/O streams, a pointcut on the socket will only be able
> to match when the I/O stream reference is retrieved. However, matching the
> I/O stream class is too broad, as it applies to non-socket streams as well.
> I need a way to retain the historic fact that a stream has been acquired
> from a socket.
> 
> One way would be to watch the getters for the streams on the socket. When
> they're called, I would 'tag' the returned stream object with an inter-type
> field and then watch it in a second pointcut. That seems awfully clumsy and
> would only work if I wanted to watch every socket.
> 
> Much rather, I'd like to be able to control at runtime who gets watched,
> along the lines of:
> 
> Socket s;
> SocketLoggerAspect sla = new SocketLoggerAspect ();
> sla.watch (s);
> ...
> sla.close ();
> 
> What patterns would support that kind of instance-dependent flexibility?
> 
> Thanks for bearing with me
> 
> -- Joel
> 
> 
> 
> Joel Roth-Nater <rothnj@xxxxxxxxxxxxxxxx>
> Sr. Software Engineer, R & D
> Lakeview Technology, Burlington MA
> ph 781-744-6921 / fx 781-744-6805
> 
> [ save the whales :: feed the hungry :: free the mallocs ]
> 
> 
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users
> 


Back to the top