I took a look at your example:
1) Initially when I ran it the class cast failed. However, I found this to be due to
running within Eclipse, with your jboss-aop-stack on the source path. And my personal
build.xml is set up to use the Eclipse output classes. For some reason, this was
causing Stack to not implement IStackHeight on my setup. I'm not sure why...
2) Next I ran into another ClassCastException occuring inside the interceptors when
trying to intercept introduced methods. I've fixed that bug, get the latest from cvs.
Hard to say if 1) or 2) caused your problems, but give it a go.
3) Regarding your separation of the the static/dynamic stuff I deleted the StackHeight
class.
StackHeightAspect now contains "everything" - no cheap tricks ;-)
| public class StackHeightAspect implements IStackHeight
| {
| private int height;
|
| public Object pushInvocation ( MethodInvocation invocation ) throws Throwable
| {
| ++ this.height;
| return invocation.invokeNext();
| }
|
| public Object popInvocation ( MethodInvocation invocation ) throws Throwable
| {
| if ( this.height > 0 )
| {
| -- this.height;
| }
|
| return invocation.invokeNext();
| }
|
| //As per documentation advices must return Object
| public Object sizeInvocation ( MethodInvocation invocation ) throws Throwable
| {
| return new Integer(this.height);
| }
| }
|
jboss-aop.xml:
| <aop>
| <aspect class="StackHeightAspect" scope="PER_INSTANCE"/>
| <aspect class="StackSynchronizationAspect" scope="PER_INSTANCE"/>
|
| <introduction class="Stack">
| <mixin>
| <interfaces>
| IStackHeight
| </interfaces>
| <class>StackHeightAspect</class>
| </mixin>
| </introduction>
|
| <!-- Note that the fully qualified name of the class must be used -->
| <pointcut name="pushExecution" expr="execution(void
Stack->push(java.lang.Object))" />
| <pointcut name="popExecution" expr="execution(java.lang.Object Stack->pop())" />
| <pointcut name="sizeExecution" expr="execution(int Stack->size())" />
|
| <bind pointcut="popExecution">
| <advice name="popInvocation" aspect="StackHeightAspect"/>
| </bind>
|
| <!-- This was bound to StackHeightAspect, but the advice is in
StackHeightAspect -->
| <bind pointcut="pushExecution OR popExecution OR sizeExecution">
| <advice name="synchronize" aspect="StackSynchronizationAspect"/>
| </bind>
|
| <bind pointcut="pushExecution">
| <advice name="pushInvocation" aspect="StackHeightAspect"/>
| </bind>
|
| <bind pointcut="sizeExecution">
| <advice name="sizeInvocation" aspect="StackHeightAspect"/>
| </bind>
|
| </aop>
|
|
4) Synchronization aspect. You use invocation.getTargetObject():
| public class StackSynchronizationAspect
| {
| private boolean semaphore = false;
|
| public Object synchronize ( MethodInvocation invocation ) throws Throwable
| {
| System.out.println("synch aspect");
| // synchronized ( invocation.getInstance () )
| Object obj = invocation.getTargetObject();
| synchronized ( obj )
| {
| if ( this.semaphore == true )
| {
| try {
| obj.wait ();
| } catch(InterruptedException e) {}
|
| this.semaphore = true;
| }
| }
|
| Object result = invocation.invokeNext();
|
| // synchronized ( invocation.getInstance () )
| synchronized ( obj )
| {
| this.semaphore = false;
|
| obj.notify ();
| }
|
| return result;
| }
| }
Cheers,
Kab
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3840996#3840996
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3840996
-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
digital self defense, top technical experts, no vendor pitches,
unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
JBoss-Development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development