Clarification of concrete aspect implementation whether it is SINGLETON

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Clarification of concrete aspect implementation whether it is SINGLETON

sridhar thiyagarajan
Hello,

I am using concrete aspects in my project. Could anyone please help me to understand whether the
implementation objects of concrete aspects defined in the below aop.xml are singleton.

Please confirm my understanding that there will be only one instance of concrete-aspect implementation created for each concrete aspect definition in the aop.xml generated by the aspectJ. JFYI that load time weaving is employed in my project.


<?xml version="1.0" encoding="UTF-8"?>
<aspectj>
<aspects>

  <concrete-aspect name="main.java.aop.field.
MyFieldAspect">
    <around pointcut="get(@main.java.aop.
field.Field * *)" invokeClass="main.java.aop.field.FieldAspect" invokeMethod="getField()"/>
  </concrete-aspect>

  <concrete-aspect name="main.java.aop.extend.
ConcreteTracingImpl">
    <around pointcut="execution(@main.
java.aop.method.Method * *(..))" invokeClass="main.java.aop.extend.AbstractTracing" invokeMethod="traceMethod()"/>
  </concrete-aspect>

</aspects>

<weaver options="-verbose -showWeaveInfo" />
</aspectj>


Thanks.

Sridhar Thiyagarajan

_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev
Reply | Threaded
Open this post in threaded view
|

Re: Clarification of concrete aspect implementation whether it is SINGLETON

Andy Clement
Yep, if you don’t specify then it is singleton.

cheers,
Andy

On Jun 2, 2015, at 12:21 AM, sridhar thiyagarajan <[hidden email]> wrote:

Hello,

I am using concrete aspects in my project. Could anyone please help me to understand whether the implementation objects of concrete aspects defined in the below aop.xml are singleton.

Please confirm my understanding that there will be only one instance of concrete-aspect implementation created for each concrete aspect definition in the aop.xml generated by the aspectJ. JFYI that load time weaving is employed in my project.


<?xml version="1.0" encoding="UTF-8"?>
<aspectj>
<aspects>

  <concrete-aspect name="main.java.aop.field.
MyFieldAspect">
    <around pointcut="get(@main.java.aop.
field.Field * *)" invokeClass="main.java.aop.field.FieldAspect" invokeMethod="getField()"/>
  </concrete-aspect>

  <concrete-aspect name="main.java.aop.extend.
ConcreteTracingImpl">
    <around pointcut="execution(@main.
java.aop.method.Method * *(..))" invokeClass="main.java.aop.extend.AbstractTracing" invokeMethod="traceMethod()"/>
  </concrete-aspect>

</aspects>

<weaver options="-verbose -showWeaveInfo" />
</aspectj>


Thanks.

Sridhar Thiyagarajan
_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev
Reply | Threaded
Open this post in threaded view
|

Re: Clarification of concrete aspect implementation whether it is SINGLETON

sridhar thiyagarajan
Many thanks for the response .. Andy. Could you please help me about the attribute to be added in the below concrete aspect definition that controls the object creation and the possible values for it.


  <concrete-aspect name="main.java.aop.field.
MyFieldAspect">
    <around pointcut="get(@main.java.aop.
field.Field * *)" invokeClass="main.java.aop.field.FieldAspect" invokeMethod="getField()"/>
  </concrete-aspect>


Thanks.
Sridhar Thiyagarajan


On Tue, Jun 2, 2015 at 11:21 PM, Andy Clement <[hidden email]> wrote:
Yep, if you don’t specify then it is singleton.

cheers,
Andy

On Jun 2, 2015, at 12:21 AM, sridhar thiyagarajan <[hidden email]> wrote:

Hello,

I am using concrete aspects in my project. Could anyone please help me to understand whether the implementation objects of concrete aspects defined in the below aop.xml are singleton.

Please confirm my understanding that there will be only one instance of concrete-aspect implementation created for each concrete aspect definition in the aop.xml generated by the aspectJ. JFYI that load time weaving is employed in my project.


<?xml version="1.0" encoding="UTF-8"?>
<aspectj>
<aspects>

  <concrete-aspect name="main.java.aop.field.
MyFieldAspect">
    <around pointcut="get(@main.java.aop.
field.Field * *)" invokeClass="main.java.aop.field.FieldAspect" invokeMethod="getField()"/>
  </concrete-aspect>

  <concrete-aspect name="main.java.aop.extend.
ConcreteTracingImpl">
    <around pointcut="execution(@main.
java.aop.method.Method * *(..))" invokeClass="main.java.aop.extend.AbstractTracing" invokeMethod="traceMethod()"/>
  </concrete-aspect>

</aspects>

<weaver options="-verbose -showWeaveInfo" />
</aspectj>


Thanks.

Sridhar Thiyagarajan
_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev
Reply | Threaded
Open this post in threaded view
|

Re: Clarification of concrete aspect implementation whether it is SINGLETON

Andy Clement
I’m not sure you can control the creation of the aspect object instance. If it isn’t covered in the docs ( https://eclipse.org/aspectj/doc/released/devguide/ltw-configuration.html#concrete-aspect )  or the readme describing this extension ( https://eclipse.org/aspectj/doc/released/README-1612.html ) then I don’t think it is supported. You could raise an enhancement request or if you post your use case here there may be alternative ways to achieve it.

cheers,
Andy

On Jun 3, 2015, at 8:42 AM, sridhar thiyagarajan <[hidden email]> wrote:

Many thanks for the response .. Andy. Could you please help me about the attribute to be added in the below concrete aspect definition that controls the object creation and the possible values for it.


  <concrete-aspect name="main.java.aop.field.
MyFieldAspect">
    <around pointcut="get(@main.java.aop.
field.Field * *)" invokeClass="main.java.aop.field.FieldAspect" invokeMethod="getField()"/>
  </concrete-aspect>


Thanks.
Sridhar Thiyagarajan


On Tue, Jun 2, 2015 at 11:21 PM, Andy Clement <[hidden email]> wrote:
Yep, if you don’t specify then it is singleton.

cheers,
Andy

On Jun 2, 2015, at 12:21 AM, sridhar thiyagarajan <[hidden email]> wrote:

Hello,

I am using concrete aspects in my project. Could anyone please help me to understand whether the implementation objects of concrete aspects defined in the below aop.xml are singleton.

Please confirm my understanding that there will be only one instance of concrete-aspect implementation created for each concrete aspect definition in the aop.xml generated by the aspectJ. JFYI that load time weaving is employed in my project.


<?xml version="1.0" encoding="UTF-8"?>
<aspectj>
<aspects>

  <concrete-aspect name="main.java.aop.field.
MyFieldAspect">
    <around pointcut="get(@main.java.aop.
field.Field * *)" invokeClass="main.java.aop.field.FieldAspect" invokeMethod="getField()"/>
  </concrete-aspect>

  <concrete-aspect name="main.java.aop.extend.
ConcreteTracingImpl">
    <around pointcut="execution(@main.
java.aop.method.Method * *(..))" invokeClass="main.java.aop.extend.AbstractTracing" invokeMethod="traceMethod()"/>
  </concrete-aspect>

</aspects>

<weaver options="-verbose -showWeaveInfo" />
</aspectj>


Thanks.

Sridhar Thiyagarajan
_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev

_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev
Reply | Threaded
Open this post in threaded view
|

Re: Clarification of concrete aspect implementation whether it is SINGLETON

sridhar thiyagarajan
Many thanks for the response .. Andy. I learnt that following are the different types of associations possible in aspectj.

  • Singleton (default)
  • Per object
  • Per control-flow
  • Per type

Below shows the syntax about how to use the association when defined in aspect.

aspect <AspectName> [<perthis|pertarget|percflow|percflowbelow>(<Pointcut>)] {
    ... aspect body
}

I have defined all aspects in the configuration aop.xml like below as load time weaving and configurable pointcuts are needed.

<concrete-aspect name="main.java.aop.field.MyFieldAspect">
    <around pointcut="get(@main.java.aop.
field.Field * *)" invokeClass="main.java.aop.field.FieldAspect" invokeMethod="getField()"/>
  </concrete-aspect>

Can you please help me about how should I define a "Per object" aspect association to the above concrete aspect definition in an XML.

Many thanks.

Sridhar Thiyagarajan

On Wed, Jun 3, 2015 at 11:38 PM, Andy Clement <[hidden email]> wrote:
I’m not sure you can control the creation of the aspect object instance. If it isn’t covered in the docs ( https://eclipse.org/aspectj/doc/released/devguide/ltw-configuration.html#concrete-aspect )  or the readme describing this extension ( https://eclipse.org/aspectj/doc/released/README-1612.html ) then I don’t think it is supported. You could raise an enhancement request or if you post your use case here there may be alternative ways to achieve it.

cheers,
Andy

On Jun 3, 2015, at 8:42 AM, sridhar thiyagarajan <[hidden email]> wrote:

Many thanks for the response .. Andy. Could you please help me about the attribute to be added in the below concrete aspect definition that controls the object creation and the possible values for it.


  <concrete-aspect name="main.java.aop.field.
MyFieldAspect">
    <around pointcut="get(@main.java.aop.
field.Field * *)" invokeClass="main.java.aop.field.FieldAspect" invokeMethod="getField()"/>
  </concrete-aspect>


Thanks.
Sridhar Thiyagarajan


On Tue, Jun 2, 2015 at 11:21 PM, Andy Clement <[hidden email]> wrote:
Yep, if you don’t specify then it is singleton.

cheers,
Andy

On Jun 2, 2015, at 12:21 AM, sridhar thiyagarajan <[hidden email]> wrote:

Hello,

I am using concrete aspects in my project. Could anyone please help me to understand whether the implementation objects of concrete aspects defined in the below aop.xml are singleton.

Please confirm my understanding that there will be only one instance of concrete-aspect implementation created for each concrete aspect definition in the aop.xml generated by the aspectJ. JFYI that load time weaving is employed in my project.


<?xml version="1.0" encoding="UTF-8"?>
<aspectj>
<aspects>

  <concrete-aspect name="main.java.aop.field.
MyFieldAspect">
    <around pointcut="get(@main.java.aop.
field.Field * *)" invokeClass="main.java.aop.field.FieldAspect" invokeMethod="getField()"/>
  </concrete-aspect>

  <concrete-aspect name="main.java.aop.extend.
ConcreteTracingImpl">
    <around pointcut="execution(@main.
java.aop.method.Method * *(..))" invokeClass="main.java.aop.extend.AbstractTracing" invokeMethod="traceMethod()"/>
  </concrete-aspect>

</aspects>

<weaver options="-verbose -showWeaveInfo" />
</aspectj>


Thanks.

Sridhar Thiyagarajan
_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev

_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev
Reply | Threaded
Open this post in threaded view
|

Re: Clarification of concrete aspect implementation whether it is SINGLETON

Andy Clement
Should just be perclause=“”

<concrete-aspect name=“main.java.aop.field.MyFieldAspect” perclause=“pertypewithin(Foo)">
  <around pointcut="get(@main.java.aop.field.Field * *)" invokeClass="main.java.aop.field.FieldAspect" invokeMethod="getField()”/>
</concrete-aspect>

But I’ll admit I have no AspectJ test cases that use the non extending form of the concrete-aspect with a perclause. All my test cases use the extending form:

    <concrete-aspect name="SubAspect" extends="Base2" perclause="pertypewithin(*)">
      <pointcut name="scope" expression="within(D*)"/>
    </concrete-aspect>

That doesn’t mean it won’t work, it just means it isn’t reliably tested.

Andy

On Jun 5, 2015, at 2:42 AM, sridhar thiyagarajan <[hidden email]> wrote:

Many thanks for the response .. Andy. I learnt that following are the different types of associations possible in aspectj.

  • Singleton (default)
  • Per object
  • Per control-flow
  • Per type

Below shows the syntax about how to use the association when defined in aspect.

aspect <AspectName> [<perthis|pertarget|percflow|percflowbelow>(<Pointcut>)] {
    ... aspect body
}

I have defined all aspects in the configuration aop.xml like below as load time weaving and configurable pointcuts are needed.

<concrete-aspect name="main.java.aop.field.MyFieldAspect">
    <around pointcut="get(@main.java.aop.
field.Field * *)" invokeClass="main.java.aop.field.FieldAspect" invokeMethod="getField()"/>
  </concrete-aspect>

Can you please help me about how should I define a "Per object" aspect association to the above concrete aspect definition in an XML.

Many thanks.

Sridhar Thiyagarajan

On Wed, Jun 3, 2015 at 11:38 PM, Andy Clement <[hidden email]> wrote:
I’m not sure you can control the creation of the aspect object instance. If it isn’t covered in the docs ( https://eclipse.org/aspectj/doc/released/devguide/ltw-configuration.html#concrete-aspect )  or the readme describing this extension ( https://eclipse.org/aspectj/doc/released/README-1612.html ) then I don’t think it is supported. You could raise an enhancement request or if you post your use case here there may be alternative ways to achieve it.

cheers,
Andy

On Jun 3, 2015, at 8:42 AM, sridhar thiyagarajan <[hidden email]> wrote:

Many thanks for the response .. Andy. Could you please help me about the attribute to be added in the below concrete aspect definition that controls the object creation and the possible values for it.


  <concrete-aspect name="main.java.aop.field.
MyFieldAspect">
    <around pointcut="get(@main.java.aop.
field.Field * *)" invokeClass="main.java.aop.field.FieldAspect" invokeMethod="getField()"/>
  </concrete-aspect>


Thanks.
Sridhar Thiyagarajan


On Tue, Jun 2, 2015 at 11:21 PM, Andy Clement <[hidden email]> wrote:
Yep, if you don’t specify then it is singleton.

cheers,
Andy

On Jun 2, 2015, at 12:21 AM, sridhar thiyagarajan <[hidden email]> wrote:

Hello,

I am using concrete aspects in my project. Could anyone please help me to understand whether the implementation objects of concrete aspects defined in the below aop.xml are singleton.

Please confirm my understanding that there will be only one instance of concrete-aspect implementation created for each concrete aspect definition in the aop.xml generated by the aspectJ. JFYI that load time weaving is employed in my project.


<?xml version="1.0" encoding="UTF-8"?>
<aspectj>
<aspects>

  <concrete-aspect name="main.java.aop.field.
MyFieldAspect">
    <around pointcut="get(@main.java.aop.
field.Field * *)" invokeClass="main.java.aop.field.FieldAspect" invokeMethod="getField()"/>
  </concrete-aspect>

  <concrete-aspect name="main.java.aop.extend.
ConcreteTracingImpl">
    <around pointcut="execution(@main.
java.aop.method.Method * *(..))" invokeClass="main.java.aop.extend.AbstractTracing" invokeMethod="traceMethod()"/>
  </concrete-aspect>

</aspects>

<weaver options="-verbose -showWeaveInfo" />
</aspectj>


Thanks.

Sridhar Thiyagarajan
_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev

_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev

_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev
Reply | Threaded
Open this post in threaded view
|

Re: Clarification of concrete aspect implementation whether it is SINGLETON

sridhar thiyagarajan
Many thanks for the response .. Andy. I used perthis aspect association in perclause attribute of concrete aspect definition and worked fine in the sample application.

Please find below the definition of concrete aspect.with perthis aspect association.

<concrete-aspect name="aop.field2.MyField2Aspect"
            extends="aop.field2.Field2Aspect" perclause="perthis(getField2() || setField2())">
            <pointcut name="getField2" expression="get(@aop.field2.Field2 * *)" />
            <pointcut name="setField2" expression="set(@aop.field2.Field2 * *)" />
</concrete-aspect>


JFYI that load time weaving is employed and the version of aspectJ used is 1.8.5 and the version of java is 1.7 in testing with sample application.

Please consider the below aspect. In this aspect, a string variable name is annotated with @Field. As per aspect defined for the annotation @Field, it should return the value "Andy" but it is null. When I created a helper object of FieldHelper.java, I can see the value "Andy".


Field2Aspect.java

package aop.field2;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

import aop.field.Field;
import aop.helper.FieldHelper;

@Aspect
public abstract class Field2Aspect {

   
    private FieldHelper fieldHelper = new FieldHelper();
   
    @Field
    public String name;

    @Pointcut
    public abstract void getField2();
   
    @Pointcut
    public abstract void setField2();

    @Around("getField2()")
    public String getFieldValue() {

        String output = null;

        if (name != null) {
            output = name + "Clement";
        } else {
            output = "Clement";
        }
       
        System.out.println("fieldHelper name --> " + fieldHelper.getName());
       
        System.out.println("In getFieldValue() of Field2Aspect - name  : "
                + name);
        System.out
                .println("In getFieldValue() of Field2Aspect - getting field value : "
                        + output);
        System.out.println("fieldHelper object --> " + fieldHelper.hashCode());
        System.out.println("fieldHelper object --> " + fieldHelper.toString());
        return output;
    }

    @Around("setField2()")
    public void setFieldValue(final ProceedingJoinPoint invocation) {       

        System.out.println("In setFieldValue() of Field2Aspect");
        throw new RuntimeException();
    }
}


FieldHelper .java

package aop.helper;

import aop.field.Field;

public class FieldHelper {

    @Field
    private String name;

    public String getName() {
        System.out.println("In getName() of FieldHelper : " + name);
        return name;
    }
}


My first question is that will a annotated variable within an aspect that requires another aspect to load its value not work ? Should this scenario be done using only helper or holder classes ?


When I employed the solution arrived using the sample application in my real application, deployment gets failed with the below error when perclause="perthis(pointcut)" attribute is used in aop.xml for concrete aspect definitions. My real application uses MBeans and this error comes for all MBeans and am running on Wildfly 8.2.0 application server. When I remove this attribute, deployment happens fine.

Caused by: java.lang.ClassFormatError: Duplicate method name&signature in class file

JFYI that When I looked into the link https://bugs.eclipse.org/bugs/show_bug.cgi?id=223226, I saw the same error and this was resolved in the version 1.6.1.  Also, load time weaving is employed and the version of aspectJ used is 1.8.5 and the version of java is 1.7 in testing with real application.

As the default aspect association is SINGLETON, could you please help me about how to resolve this error as I need to use perclause="perthis(pointcut)" and the aspectJ version employed is 1.8.5. Should I need to go for any other aspectJ version to resolve this error. Please guide me.

Many thanks for the help.

Sridhar Thiyagarajan


On Fri, Jun 5, 2015 at 10:11 PM, Andy Clement <[hidden email]> wrote:
Should just be perclause=“”

<concrete-aspect name=“main.java.aop.field.MyFieldAspect” perclause=“pertypewithin(Foo)">
  <around pointcut="get(@main.java.aop.field.Field * *)" invokeClass="main.java.aop.field.FieldAspect" invokeMethod="getField()”/>
</concrete-aspect>

But I’ll admit I have no AspectJ test cases that use the non extending form of the concrete-aspect with a perclause. All my test cases use the extending form:

    <concrete-aspect name="SubAspect" extends="Base2" perclause="pertypewithin(*)">
      <pointcut name="scope" expression="within(D*)"/>
    </concrete-aspect>

That doesn’t mean it won’t work, it just means it isn’t reliably tested.

Andy

On Jun 5, 2015, at 2:42 AM, sridhar thiyagarajan <[hidden email]> wrote:

Many thanks for the response .. Andy. I learnt that following are the different types of associations possible in aspectj.

  • Singleton (default)
  • Per object
  • Per control-flow
  • Per type

Below shows the syntax about how to use the association when defined in aspect.

aspect <AspectName> [<perthis|pertarget|percflow|percflowbelow>(<Pointcut>)] {
    ... aspect body
}

I have defined all aspects in the configuration aop.xml like below as load time weaving and configurable pointcuts are needed.

<concrete-aspect name="main.java.aop.field.MyFieldAspect">
    <around pointcut="get(@main.java.aop.
field.Field * *)" invokeClass="main.java.aop.field.FieldAspect" invokeMethod="getField()"/>
  </concrete-aspect>

Can you please help me about how should I define a "Per object" aspect association to the above concrete aspect definition in an XML.

Many thanks.

Sridhar Thiyagarajan

On Wed, Jun 3, 2015 at 11:38 PM, Andy Clement <[hidden email]> wrote:
I’m not sure you can control the creation of the aspect object instance. If it isn’t covered in the docs ( https://eclipse.org/aspectj/doc/released/devguide/ltw-configuration.html#concrete-aspect )  or the readme describing this extension ( https://eclipse.org/aspectj/doc/released/README-1612.html ) then I don’t think it is supported. You could raise an enhancement request or if you post your use case here there may be alternative ways to achieve it.

cheers,
Andy

On Jun 3, 2015, at 8:42 AM, sridhar thiyagarajan <[hidden email]> wrote:

Many thanks for the response .. Andy. Could you please help me about the attribute to be added in the below concrete aspect definition that controls the object creation and the possible values for it.


  <concrete-aspect name="main.java.aop.field.
MyFieldAspect">
    <around pointcut="get(@main.java.aop.
field.Field * *)" invokeClass="main.java.aop.field.FieldAspect" invokeMethod="getField()"/>
  </concrete-aspect>


Thanks.
Sridhar Thiyagarajan


On Tue, Jun 2, 2015 at 11:21 PM, Andy Clement <[hidden email]> wrote:
Yep, if you don’t specify then it is singleton.

cheers,
Andy

On Jun 2, 2015, at 12:21 AM, sridhar thiyagarajan <[hidden email]> wrote:

Hello,

I am using concrete aspects in my project. Could anyone please help me to understand whether the implementation objects of concrete aspects defined in the below aop.xml are singleton.

Please confirm my understanding that there will be only one instance of concrete-aspect implementation created for each concrete aspect definition in the aop.xml generated by the aspectJ. JFYI that load time weaving is employed in my project.


<?xml version="1.0" encoding="UTF-8"?>
<aspectj>
<aspects>

  <concrete-aspect name="main.java.aop.field.
MyFieldAspect">
    <around pointcut="get(@main.java.aop.
field.Field * *)" invokeClass="main.java.aop.field.FieldAspect" invokeMethod="getField()"/>
  </concrete-aspect>

  <concrete-aspect name="main.java.aop.extend.
ConcreteTracingImpl">
    <around pointcut="execution(@main.
java.aop.method.Method * *(..))" invokeClass="main.java.aop.extend.AbstractTracing" invokeMethod="traceMethod()"/>
  </concrete-aspect>

</aspects>

<weaver options="-verbose -showWeaveInfo" />
</aspectj>


Thanks.

Sridhar Thiyagarajan
_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev

_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev

_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev
Reply | Threaded
Open this post in threaded view
|

Re: Clarification of concrete aspect implementation whether it is SINGLETON

Andy Clement
My first question is that will a annotated variable within an aspect that requires another aspect to load its value not work ? Should this scenario be done using only helper or holder classes ?

It should work if you have set appropriate precedence amongst your aspects such that the one that loads the value does its work before the one that reads it.

Caused by: java.lang.ClassFormatError: Duplicate method name&signature in class file

There are many many possible causes of this, the bug you reference is very unlikely to be your case as that is generics related, not related to perthis instantiation models.

Given that this is an AspectJ bug you should raise a bug in bugzilla and ideally attach a minimal test program that I can run that shows it failing.

If you want to do further debugging you could use the aop.xml option ‘dump’ to dump the code before/after weaving and take a look at what the duplicate name/signature is. But to fix it I’d still need a reliable testcase that showed the problem.

To workaround this bug you could just manage the aspect state yourself. i.e. implement the effect of perthis in your advice. I know it isn’t ideal but I’m not sure when I can get to fixing the bug mentioned here.

cheers,
Andy


On Jun 8, 2015, at 4:31 AM, sridhar thiyagarajan <[hidden email]> wrote:

Many thanks for the response .. Andy. I used perthis aspect association in perclause attribute of concrete aspect definition and worked fine in the sample application.

Please find below the definition of concrete aspect.with perthis aspect association.

<concrete-aspect name="aop.field2.MyField2Aspect"
            extends="aop.field2.Field2Aspect" perclause="perthis(getField2() || setField2())">
            <pointcut name="getField2" expression="get(@aop.field2.Field2 * *)" />
            <pointcut name="setField2" expression="set(@aop.field2.Field2 * *)" />
</concrete-aspect>


JFYI that load time weaving is employed and the version of aspectJ used is 1.8.5 and the version of java is 1.7 in testing with sample application.

Please consider the below aspect. In this aspect, a string variable name is annotated with @Field. As per aspect defined for the annotation @Field, it should return the value "Andy" but it is null. When I created a helper object of FieldHelper.java, I can see the value "Andy".


Field2Aspect.java

package aop.field2;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

import aop.field.Field;
import aop.helper.FieldHelper;

@Aspect
public abstract class Field2Aspect {

   
    private FieldHelper fieldHelper = new FieldHelper();
   
    @Field
    public String name;

    @Pointcut
    public abstract void getField2();
   
    @Pointcut
    public abstract void setField2();

    @Around("getField2()")
    public String getFieldValue() {

        String output = null;

        if (name != null) {
            output = name + "Clement";
        } else {
            output = "Clement";
        }
       
        System.out.println("fieldHelper name --> " + fieldHelper.getName());
       
        System.out.println("In getFieldValue() of Field2Aspect - name  : "
                + name);
        System.out
                .println("In getFieldValue() of Field2Aspect - getting field value : "
                        + output);
        System.out.println("fieldHelper object --> " + fieldHelper.hashCode());
        System.out.println("fieldHelper object --> " + fieldHelper.toString());
        return output;
    }

    @Around("setField2()")
    public void setFieldValue(final ProceedingJoinPoint invocation) {       

        System.out.println("In setFieldValue() of Field2Aspect");
        throw new RuntimeException();
    }
}


FieldHelper .java

package aop.helper;

import aop.field.Field;

public class FieldHelper {

    @Field
    private String name;

    public String getName() {
        System.out.println("In getName() of FieldHelper : " + name);
        return name;
    }
}


My first question is that will a annotated variable within an aspect that requires another aspect to load its value not work ? Should this scenario be done using only helper or holder classes ?


When I employed the solution arrived using the sample application in my real application, deployment gets failed with the below error when perclause="perthis(pointcut)" attribute is used in aop.xml for concrete aspect definitions. My real application uses MBeans and this error comes for all MBeans and am running on Wildfly 8.2.0 application server. When I remove this attribute, deployment happens fine.

Caused by: java.lang.ClassFormatError: Duplicate method name&signature in class file

JFYI that When I looked into the link https://bugs.eclipse.org/bugs/show_bug.cgi?id=223226, I saw the same error and this was resolved in the version 1.6.1.  Also, load time weaving is employed and the version of aspectJ used is 1.8.5 and the version of java is 1.7 in testing with real application.

As the default aspect association is SINGLETON, could you please help me about how to resolve this error as I need to use perclause="perthis(pointcut)" and the aspectJ version employed is 1.8.5. Should I need to go for any other aspectJ version to resolve this error. Please guide me.

Many thanks for the help.

Sridhar Thiyagarajan


On Fri, Jun 5, 2015 at 10:11 PM, Andy Clement <[hidden email]> wrote:
Should just be perclause=“”

<concrete-aspect name=“main.java.aop.field.MyFieldAspect” perclause=“pertypewithin(Foo)">
  <around pointcut="get(@main.java.aop.field.Field * *)" invokeClass="main.java.aop.field.FieldAspect" invokeMethod="getField()”/>
</concrete-aspect>

But I’ll admit I have no AspectJ test cases that use the non extending form of the concrete-aspect with a perclause. All my test cases use the extending form:

    <concrete-aspect name="SubAspect" extends="Base2" perclause="pertypewithin(*)">
      <pointcut name="scope" expression="within(D*)"/>
    </concrete-aspect>

That doesn’t mean it won’t work, it just means it isn’t reliably tested.

Andy

On Jun 5, 2015, at 2:42 AM, sridhar thiyagarajan <[hidden email]> wrote:

Many thanks for the response .. Andy. I learnt that following are the different types of associations possible in aspectj.

  • Singleton (default)
  • Per object
  • Per control-flow
  • Per type

Below shows the syntax about how to use the association when defined in aspect.

aspect <AspectName> [<perthis|pertarget|percflow|percflowbelow>(<Pointcut>)] {
    ... aspect body
}

I have defined all aspects in the configuration aop.xml like below as load time weaving and configurable pointcuts are needed.

<concrete-aspect name="main.java.aop.field.MyFieldAspect">
    <around pointcut="get(@main.java.aop.
field.Field * *)" invokeClass="main.java.aop.field.FieldAspect" invokeMethod="getField()"/>
  </concrete-aspect>

Can you please help me about how should I define a "Per object" aspect association to the above concrete aspect definition in an XML.

Many thanks.

Sridhar Thiyagarajan

On Wed, Jun 3, 2015 at 11:38 PM, Andy Clement <[hidden email]> wrote:
I’m not sure you can control the creation of the aspect object instance. If it isn’t covered in the docs ( https://eclipse.org/aspectj/doc/released/devguide/ltw-configuration.html#concrete-aspect )  or the readme describing this extension ( https://eclipse.org/aspectj/doc/released/README-1612.html ) then I don’t think it is supported. You could raise an enhancement request or if you post your use case here there may be alternative ways to achieve it.

cheers,
Andy

On Jun 3, 2015, at 8:42 AM, sridhar thiyagarajan <[hidden email]> wrote:

Many thanks for the response .. Andy. Could you please help me about the attribute to be added in the below concrete aspect definition that controls the object creation and the possible values for it.


  <concrete-aspect name="main.java.aop.field.
MyFieldAspect">
    <around pointcut="get(@main.java.aop.
field.Field * *)" invokeClass="main.java.aop.field.FieldAspect" invokeMethod="getField()"/>
  </concrete-aspect>


Thanks.
Sridhar Thiyagarajan


On Tue, Jun 2, 2015 at 11:21 PM, Andy Clement <[hidden email]> wrote:
Yep, if you don’t specify then it is singleton.

cheers,
Andy

On Jun 2, 2015, at 12:21 AM, sridhar thiyagarajan <[hidden email]> wrote:

Hello,

I am using concrete aspects in my project. Could anyone please help me to understand whether the implementation objects of concrete aspects defined in the below aop.xml are singleton.

Please confirm my understanding that there will be only one instance of concrete-aspect implementation created for each concrete aspect definition in the aop.xml generated by the aspectJ. JFYI that load time weaving is employed in my project.


<?xml version="1.0" encoding="UTF-8"?>
<aspectj>
<aspects>

  <concrete-aspect name="main.java.aop.field.
MyFieldAspect">
    <around pointcut="get(@main.java.aop.
field.Field * *)" invokeClass="main.java.aop.field.FieldAspect" invokeMethod="getField()"/>
  </concrete-aspect>

  <concrete-aspect name="main.java.aop.extend.
ConcreteTracingImpl">
    <around pointcut="execution(@main.
java.aop.method.Method * *(..))" invokeClass="main.java.aop.extend.AbstractTracing" invokeMethod="traceMethod()"/>
  </concrete-aspect>

</aspects>

<weaver options="-verbose -showWeaveInfo" />
</aspectj>


Thanks.

Sridhar Thiyagarajan
_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev

_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev

_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev

_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev
Reply | Threaded
Open this post in threaded view
|

Re: Clarification of concrete aspect implementation whether it is SINGLETON

sridhar thiyagarajan
Many thanks .. Andy. I understood. Regarding the second question, I tried implementing perthis along with @aspect annotation in the aspect java class like below but I am still getting the same error highlighted in blue in my real application.

@Aspect("perthis(getField2() || setField2())")
public abstract class Field2Aspect {
...
...
}


Caused by: java.lang.ClassFormatError: Duplicate method name&signature in class file

I tried implementing perthis around advice methods in aspect java class (eg: @around("perthis(pointcutname())")) but got invalid pointcut error and parse exception. Concrete aspects are defined in XML as mentioned below and would like to have pointcuts configurable and hence, could not employ pointcut expression and perthis in aspect java class.

<concrete-aspect name="aop.field2.MyField2Aspect"
            extends="aop.field2.Field2Aspect">
            <pointcut name="getField2" expression="get(@aop.field2.Field2 * *)" />
            <pointcut name="setField2" expression="set(@aop.field2.Field2 * *)" />
        </concrete-aspect>

I am still investigating the root cause of java.lang.ClassFormatError occurring in my real application and I suspect the issue could be around singleton EJBs implemented as MBeans and related aspects. Meanwhile, I have just posted the issue in the below link.

http://stackoverflow.com/questions/30727389/getting-java-lang-classformaterror-duplicate-method-namesignature-in-class-fil

Once I find root cause and when it is related to aspectJ, then I will surely reply you with the use case.

Many thanks for your help and please share if you have any comments on the above.

Sridhar Thiyagarajan



On Mon, Jun 8, 2015 at 10:00 PM, Andy Clement <[hidden email]> wrote:
My first question is that will a annotated variable within an aspect that requires another aspect to load its value not work ? Should this scenario be done using only helper or holder classes ?

It should work if you have set appropriate precedence amongst your aspects such that the one that loads the value does its work before the one that reads it.

Caused by: java.lang.ClassFormatError: Duplicate method name&signature in class file

There are many many possible causes of this, the bug you reference is very unlikely to be your case as that is generics related, not related to perthis instantiation models.

Given that this is an AspectJ bug you should raise a bug in bugzilla and ideally attach a minimal test program that I can run that shows it failing.

If you want to do further debugging you could use the aop.xml option ‘dump’ to dump the code before/after weaving and take a look at what the duplicate name/signature is. But to fix it I’d still need a reliable testcase that showed the problem.

To workaround this bug you could just manage the aspect state yourself. i.e. implement the effect of perthis in your advice. I know it isn’t ideal but I’m not sure when I can get to fixing the bug mentioned here.

cheers,
Andy


On Jun 8, 2015, at 4:31 AM, sridhar thiyagarajan <[hidden email]> wrote:

Many thanks for the response .. Andy. I used perthis aspect association in perclause attribute of concrete aspect definition and worked fine in the sample application.

Please find below the definition of concrete aspect.with perthis aspect association.

<concrete-aspect name="aop.field2.MyField2Aspect"
            extends="aop.field2.Field2Aspect" perclause="perthis(getField2() || setField2())">
            <pointcut name="getField2" expression="get(@aop.field2.Field2 * *)" />
            <pointcut name="setField2" expression="set(@aop.field2.Field2 * *)" />
</concrete-aspect>


JFYI that load time weaving is employed and the version of aspectJ used is 1.8.5 and the version of java is 1.7 in testing with sample application.

Please consider the below aspect. In this aspect, a string variable name is annotated with @Field. As per aspect defined for the annotation @Field, it should return the value "Andy" but it is null. When I created a helper object of FieldHelper.java, I can see the value "Andy".


Field2Aspect.java

package aop.field2;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

import aop.field.Field;
import aop.helper.FieldHelper;

@Aspect
public abstract class Field2Aspect {

   
    private FieldHelper fieldHelper = new FieldHelper();
   
    @Field
    public String name;

    @Pointcut
    public abstract void getField2();
   
    @Pointcut
    public abstract void setField2();

    @Around("getField2()")
    public String getFieldValue() {

        String output = null;

        if (name != null) {
            output = name + "Clement";
        } else {
            output = "Clement";
        }
       
        System.out.println("fieldHelper name --> " + fieldHelper.getName());
       
        System.out.println("In getFieldValue() of Field2Aspect - name  : "
                + name);
        System.out
                .println("In getFieldValue() of Field2Aspect - getting field value : "
                        + output);
        System.out.println("fieldHelper object --> " + fieldHelper.hashCode());
        System.out.println("fieldHelper object --> " + fieldHelper.toString());
        return output;
    }

    @Around("setField2()")
    public void setFieldValue(final ProceedingJoinPoint invocation) {       

        System.out.println("In setFieldValue() of Field2Aspect");
        throw new RuntimeException();
    }
}


FieldHelper .java

package aop.helper;

import aop.field.Field;

public class FieldHelper {

    @Field
    private String name;

    public String getName() {
        System.out.println("In getName() of FieldHelper : " + name);
        return name;
    }
}


My first question is that will a annotated variable within an aspect that requires another aspect to load its value not work ? Should this scenario be done using only helper or holder classes ?


When I employed the solution arrived using the sample application in my real application, deployment gets failed with the below error when perclause="perthis(pointcut)" attribute is used in aop.xml for concrete aspect definitions. My real application uses MBeans and this error comes for all MBeans and am running on Wildfly 8.2.0 application server. When I remove this attribute, deployment happens fine.

Caused by: java.lang.ClassFormatError: Duplicate method name&signature in class file

JFYI that When I looked into the link https://bugs.eclipse.org/bugs/show_bug.cgi?id=223226, I saw the same error and this was resolved in the version 1.6.1.  Also, load time weaving is employed and the version of aspectJ used is 1.8.5 and the version of java is 1.7 in testing with real application.

As the default aspect association is SINGLETON, could you please help me about how to resolve this error as I need to use perclause="perthis(pointcut)" and the aspectJ version employed is 1.8.5. Should I need to go for any other aspectJ version to resolve this error. Please guide me.

Many thanks for the help.

Sridhar Thiyagarajan


On Fri, Jun 5, 2015 at 10:11 PM, Andy Clement <[hidden email]> wrote:
Should just be perclause=“”

<concrete-aspect name=“main.java.aop.field.MyFieldAspect” perclause=“pertypewithin(Foo)">
  <around pointcut="get(@main.java.aop.field.Field * *)" invokeClass="main.java.aop.field.FieldAspect" invokeMethod="getField()”/>
</concrete-aspect>

But I’ll admit I have no AspectJ test cases that use the non extending form of the concrete-aspect with a perclause. All my test cases use the extending form:

    <concrete-aspect name="SubAspect" extends="Base2" perclause="pertypewithin(*)">
      <pointcut name="scope" expression="within(D*)"/>
    </concrete-aspect>

That doesn’t mean it won’t work, it just means it isn’t reliably tested.

Andy

On Jun 5, 2015, at 2:42 AM, sridhar thiyagarajan <[hidden email]> wrote:

Many thanks for the response .. Andy. I learnt that following are the different types of associations possible in aspectj.

  • Singleton (default)
  • Per object
  • Per control-flow
  • Per type

Below shows the syntax about how to use the association when defined in aspect.

aspect <AspectName> [<perthis|pertarget|percflow|percflowbelow>(<Pointcut>)] {
    ... aspect body
}

I have defined all aspects in the configuration aop.xml like below as load time weaving and configurable pointcuts are needed.

<concrete-aspect name="main.java.aop.field.MyFieldAspect">
    <around pointcut="get(@main.java.aop.
field.Field * *)" invokeClass="main.java.aop.field.FieldAspect" invokeMethod="getField()"/>
  </concrete-aspect>

Can you please help me about how should I define a "Per object" aspect association to the above concrete aspect definition in an XML.

Many thanks.

Sridhar Thiyagarajan

On Wed, Jun 3, 2015 at 11:38 PM, Andy Clement <[hidden email]> wrote:
I’m not sure you can control the creation of the aspect object instance. If it isn’t covered in the docs ( https://eclipse.org/aspectj/doc/released/devguide/ltw-configuration.html#concrete-aspect )  or the readme describing this extension ( https://eclipse.org/aspectj/doc/released/README-1612.html ) then I don’t think it is supported. You could raise an enhancement request or if you post your use case here there may be alternative ways to achieve it.

cheers,
Andy

On Jun 3, 2015, at 8:42 AM, sridhar thiyagarajan <[hidden email]> wrote:

Many thanks for the response .. Andy. Could you please help me about the attribute to be added in the below concrete aspect definition that controls the object creation and the possible values for it.


  <concrete-aspect name="main.java.aop.field.
MyFieldAspect">
    <around pointcut="get(@main.java.aop.
field.Field * *)" invokeClass="main.java.aop.field.FieldAspect" invokeMethod="getField()"/>
  </concrete-aspect>


Thanks.
Sridhar Thiyagarajan


On Tue, Jun 2, 2015 at 11:21 PM, Andy Clement <[hidden email]> wrote:
Yep, if you don’t specify then it is singleton.

cheers,
Andy

On Jun 2, 2015, at 12:21 AM, sridhar thiyagarajan <[hidden email]> wrote:

Hello,

I am using concrete aspects in my project. Could anyone please help me to understand whether the implementation objects of concrete aspects defined in the below aop.xml are singleton.

Please confirm my understanding that there will be only one instance of concrete-aspect implementation created for each concrete aspect definition in the aop.xml generated by the aspectJ. JFYI that load time weaving is employed in my project.


<?xml version="1.0" encoding="UTF-8"?>
<aspectj>
<aspects>

  <concrete-aspect name="main.java.aop.field.
MyFieldAspect">
    <around pointcut="get(@main.java.aop.
field.Field * *)" invokeClass="main.java.aop.field.FieldAspect" invokeMethod="getField()"/>
  </concrete-aspect>

  <concrete-aspect name="main.java.aop.extend.
ConcreteTracingImpl">
    <around pointcut="execution(@main.
java.aop.method.Method * *(..))" invokeClass="main.java.aop.extend.AbstractTracing" invokeMethod="traceMethod()"/>
  </concrete-aspect>

</aspects>

<weaver options="-verbose -showWeaveInfo" />
</aspectj>


Thanks.

Sridhar Thiyagarajan
_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev

_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev

_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev

_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev
Reply | Threaded
Open this post in threaded view
|

Re: Clarification of concrete aspect implementation whether it is SINGLETON

sridhar thiyagarajan
Just an update that percflow aspect association usage solved the issue I had mentioned. Many thanks for your help .. Andy.

Sridhar Thiyagarajan

On Tue, Jun 9, 2015 at 5:04 PM, sridhar thiyagarajan <[hidden email]> wrote:
Many thanks .. Andy. I understood. Regarding the second question, I tried implementing perthis along with @aspect annotation in the aspect java class like below but I am still getting the same error highlighted in blue in my real application.

@Aspect("perthis(getField2() || setField2())")
public abstract class Field2Aspect {
...
...
}


Caused by: java.lang.ClassFormatError: Duplicate method name&signature in class file

I tried implementing perthis around advice methods in aspect java class (eg: @around("perthis(pointcutname())")) but got invalid pointcut error and parse exception. Concrete aspects are defined in XML as mentioned below and would like to have pointcuts configurable and hence, could not employ pointcut expression and perthis in aspect java class.

<concrete-aspect name="aop.field2.MyField2Aspect"
            extends="aop.field2.Field2Aspect">
            <pointcut name="getField2" expression="get(@aop.field2.Field2 * *)" />
            <pointcut name="setField2" expression="set(@aop.field2.Field2 * *)" />
        </concrete-aspect>

I am still investigating the root cause of java.lang.ClassFormatError occurring in my real application and I suspect the issue could be around singleton EJBs implemented as MBeans and related aspects. Meanwhile, I have just posted the issue in the below link.

http://stackoverflow.com/questions/30727389/getting-java-lang-classformaterror-duplicate-method-namesignature-in-class-fil

Once I find root cause and when it is related to aspectJ, then I will surely reply you with the use case.

Many thanks for your help and please share if you have any comments on the above.

Sridhar Thiyagarajan



On Mon, Jun 8, 2015 at 10:00 PM, Andy Clement <[hidden email]> wrote:
My first question is that will a annotated variable within an aspect that requires another aspect to load its value not work ? Should this scenario be done using only helper or holder classes ?

It should work if you have set appropriate precedence amongst your aspects such that the one that loads the value does its work before the one that reads it.

Caused by: java.lang.ClassFormatError: Duplicate method name&signature in class file

There are many many possible causes of this, the bug you reference is very unlikely to be your case as that is generics related, not related to perthis instantiation models.

Given that this is an AspectJ bug you should raise a bug in bugzilla and ideally attach a minimal test program that I can run that shows it failing.

If you want to do further debugging you could use the aop.xml option ‘dump’ to dump the code before/after weaving and take a look at what the duplicate name/signature is. But to fix it I’d still need a reliable testcase that showed the problem.

To workaround this bug you could just manage the aspect state yourself. i.e. implement the effect of perthis in your advice. I know it isn’t ideal but I’m not sure when I can get to fixing the bug mentioned here.

cheers,
Andy


On Jun 8, 2015, at 4:31 AM, sridhar thiyagarajan <[hidden email]> wrote:

Many thanks for the response .. Andy. I used perthis aspect association in perclause attribute of concrete aspect definition and worked fine in the sample application.

Please find below the definition of concrete aspect.with perthis aspect association.

<concrete-aspect name="aop.field2.MyField2Aspect"
            extends="aop.field2.Field2Aspect" perclause="perthis(getField2() || setField2())">
            <pointcut name="getField2" expression="get(@aop.field2.Field2 * *)" />
            <pointcut name="setField2" expression="set(@aop.field2.Field2 * *)" />
</concrete-aspect>


JFYI that load time weaving is employed and the version of aspectJ used is 1.8.5 and the version of java is 1.7 in testing with sample application.

Please consider the below aspect. In this aspect, a string variable name is annotated with @Field. As per aspect defined for the annotation @Field, it should return the value "Andy" but it is null. When I created a helper object of FieldHelper.java, I can see the value "Andy".


Field2Aspect.java

package aop.field2;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

import aop.field.Field;
import aop.helper.FieldHelper;

@Aspect
public abstract class Field2Aspect {

   
    private FieldHelper fieldHelper = new FieldHelper();
   
    @Field
    public String name;

    @Pointcut
    public abstract void getField2();
   
    @Pointcut
    public abstract void setField2();

    @Around("getField2()")
    public String getFieldValue() {

        String output = null;

        if (name != null) {
            output = name + "Clement";
        } else {
            output = "Clement";
        }
       
        System.out.println("fieldHelper name --> " + fieldHelper.getName());
       
        System.out.println("In getFieldValue() of Field2Aspect - name  : "
                + name);
        System.out
                .println("In getFieldValue() of Field2Aspect - getting field value : "
                        + output);
        System.out.println("fieldHelper object --> " + fieldHelper.hashCode());
        System.out.println("fieldHelper object --> " + fieldHelper.toString());
        return output;
    }

    @Around("setField2()")
    public void setFieldValue(final ProceedingJoinPoint invocation) {       

        System.out.println("In setFieldValue() of Field2Aspect");
        throw new RuntimeException();
    }
}


FieldHelper .java

package aop.helper;

import aop.field.Field;

public class FieldHelper {

    @Field
    private String name;

    public String getName() {
        System.out.println("In getName() of FieldHelper : " + name);
        return name;
    }
}


My first question is that will a annotated variable within an aspect that requires another aspect to load its value not work ? Should this scenario be done using only helper or holder classes ?


When I employed the solution arrived using the sample application in my real application, deployment gets failed with the below error when perclause="perthis(pointcut)" attribute is used in aop.xml for concrete aspect definitions. My real application uses MBeans and this error comes for all MBeans and am running on Wildfly 8.2.0 application server. When I remove this attribute, deployment happens fine.

Caused by: java.lang.ClassFormatError: Duplicate method name&signature in class file

JFYI that When I looked into the link https://bugs.eclipse.org/bugs/show_bug.cgi?id=223226, I saw the same error and this was resolved in the version 1.6.1.  Also, load time weaving is employed and the version of aspectJ used is 1.8.5 and the version of java is 1.7 in testing with real application.

As the default aspect association is SINGLETON, could you please help me about how to resolve this error as I need to use perclause="perthis(pointcut)" and the aspectJ version employed is 1.8.5. Should I need to go for any other aspectJ version to resolve this error. Please guide me.

Many thanks for the help.

Sridhar Thiyagarajan


On Fri, Jun 5, 2015 at 10:11 PM, Andy Clement <[hidden email]> wrote:
Should just be perclause=“”

<concrete-aspect name=“main.java.aop.field.MyFieldAspect” perclause=“pertypewithin(Foo)">
  <around pointcut="get(@main.java.aop.field.Field * *)" invokeClass="main.java.aop.field.FieldAspect" invokeMethod="getField()”/>
</concrete-aspect>

But I’ll admit I have no AspectJ test cases that use the non extending form of the concrete-aspect with a perclause. All my test cases use the extending form:

    <concrete-aspect name="SubAspect" extends="Base2" perclause="pertypewithin(*)">
      <pointcut name="scope" expression="within(D*)"/>
    </concrete-aspect>

That doesn’t mean it won’t work, it just means it isn’t reliably tested.

Andy

On Jun 5, 2015, at 2:42 AM, sridhar thiyagarajan <[hidden email]> wrote:

Many thanks for the response .. Andy. I learnt that following are the different types of associations possible in aspectj.

  • Singleton (default)
  • Per object
  • Per control-flow
  • Per type

Below shows the syntax about how to use the association when defined in aspect.

aspect <AspectName> [<perthis|pertarget|percflow|percflowbelow>(<Pointcut>)] {
    ... aspect body
}

I have defined all aspects in the configuration aop.xml like below as load time weaving and configurable pointcuts are needed.

<concrete-aspect name="main.java.aop.field.MyFieldAspect">
    <around pointcut="get(@main.java.aop.
field.Field * *)" invokeClass="main.java.aop.field.FieldAspect" invokeMethod="getField()"/>
  </concrete-aspect>

Can you please help me about how should I define a "Per object" aspect association to the above concrete aspect definition in an XML.

Many thanks.

Sridhar Thiyagarajan

On Wed, Jun 3, 2015 at 11:38 PM, Andy Clement <[hidden email]> wrote:
I’m not sure you can control the creation of the aspect object instance. If it isn’t covered in the docs ( https://eclipse.org/aspectj/doc/released/devguide/ltw-configuration.html#concrete-aspect )  or the readme describing this extension ( https://eclipse.org/aspectj/doc/released/README-1612.html ) then I don’t think it is supported. You could raise an enhancement request or if you post your use case here there may be alternative ways to achieve it.

cheers,
Andy

On Jun 3, 2015, at 8:42 AM, sridhar thiyagarajan <[hidden email]> wrote:

Many thanks for the response .. Andy. Could you please help me about the attribute to be added in the below concrete aspect definition that controls the object creation and the possible values for it.


  <concrete-aspect name="main.java.aop.field.
MyFieldAspect">
    <around pointcut="get(@main.java.aop.
field.Field * *)" invokeClass="main.java.aop.field.FieldAspect" invokeMethod="getField()"/>
  </concrete-aspect>


Thanks.
Sridhar Thiyagarajan


On Tue, Jun 2, 2015 at 11:21 PM, Andy Clement <[hidden email]> wrote:
Yep, if you don’t specify then it is singleton.

cheers,
Andy

On Jun 2, 2015, at 12:21 AM, sridhar thiyagarajan <[hidden email]> wrote:

Hello,

I am using concrete aspects in my project. Could anyone please help me to understand whether the implementation objects of concrete aspects defined in the below aop.xml are singleton.

Please confirm my understanding that there will be only one instance of concrete-aspect implementation created for each concrete aspect definition in the aop.xml generated by the aspectJ. JFYI that load time weaving is employed in my project.


<?xml version="1.0" encoding="UTF-8"?>
<aspectj>
<aspects>

  <concrete-aspect name="main.java.aop.field.
MyFieldAspect">
    <around pointcut="get(@main.java.aop.
field.Field * *)" invokeClass="main.java.aop.field.FieldAspect" invokeMethod="getField()"/>
  </concrete-aspect>

  <concrete-aspect name="main.java.aop.extend.
ConcreteTracingImpl">
    <around pointcut="execution(@main.
java.aop.method.Method * *(..))" invokeClass="main.java.aop.extend.AbstractTracing" invokeMethod="traceMethod()"/>
  </concrete-aspect>

</aspects>

<weaver options="-verbose -showWeaveInfo" />
</aspectj>


Thanks.

Sridhar Thiyagarajan
_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev

_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev

_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev

_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev



_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev