1

I'm tring to get something from HBase.Using AspectJ's load time weaving.I have wrote the AbstractAspect.aj and aop.xml.I also have tried use "ajc -outxml AbstractAspect.aj" to generate aop.xml,it is too simple and can not get the method's parameters.I doubt if the way(LTW) could get context.

AbstractAspect.aj:

package com.test.apectj.aj;

import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.GetRequest;
import com.google.protobuf.RpcController;

public abstract aspect AbstractAspect {

    pointcut scan();

    pointcut multi();

    pointcut getdata(final RpcController controller, final GetRequest request): target(org.apache.hadoop.hbase.protobuf.generated.ClientProtos) && call (public * org.apache.hadoop.hbase.regionserver.HRegionServer.get(RpcController, GetRequest)) && args(controller, request);

    pointcut scope();

    before() : scan() {
      System.out.println("[aop]before methon scan()");
      System.out.println(thisEnclosingJoinPointStaticPart);
      System.out.println(thisJoinPoint.getSourceLocation());
    }

    before() : multi() {
      System.out.println("[aop]before methon multi()");
      System.out.println("[aop]Execute multiple actions on a table: get,                        
                          mutate,and/orexecCoprocessor");
    }

    after() : multi(){
      System.out.println("[aop]after methon multi()");
    }

    before(RpcController controller, GetRequest request) : getdata(controller, request)                   
    {

      System.out.println("[aop]before methon get()");
      System.out.println("[aop]Get data from a table");
      System.out.println(request.toString());
    }

}

aop.xml:

<?xml version="1.0" encoding="UTF-8"?>
    <aspectj>
        <aspects>
            <concrete-aspect name="com.test.apectj.aj.ConcreteAspect"
                extends="com.test.apectj.aj.AbstractAspect">
                <pointcut name="scan"
                    expression="execution(public * org.apache.hadoop.hbase.regionserver.HRegionServer.scan(com.google.protobuf.RpcController, org.apache.hadoop.hbase.protobuf.generated.ClientProtos.ScanRequest)) AND target(org.apache.hadoop.hbase.regionserver.HRegionServer)" />
                <pointcut name="multi"
                    expression="execution(public * org.apache.hadoop.hbase.regionserver.HRegionServer.multi(..)) AND target(org.apache.hadoop.hbase.regionserver.HRegionServer)" />
                <pointcut name="getdata()"
                    expression="call(public * org.apache.hadoop.hbase.regionserver.HRegionServer.get(..))" />
            </concrete-aspect>
        </aspects>


        <weaver options="-verbose -Xset:weaveJavaxPackages=true">
        </weaver>

    </aspectj>

when running:

  • no arguments[ pointcut: scan() multi() ]: success. Can print information
  • have arguments[ pointcut: getdata() ]: failure. Warning like this:...
[AppClassLoader@4d97507c] warning at com/test/apectj/aj/E:\EclipseWorkspace\hbase-regionserver-aop\src\com\test\apectj\aj\AbstractAspect.aj:25::0 does not match because declaring type is org.apache.hadoop.hbase.protobuf.generated.ClientProtos$ClientService$BlockingInterface, if match desired use target(org.apache.hadoop.hbase.regionserver.HRegionServer) 
[Xlint:unmatchedSuperTypeInCall]
see also: org/apache/hadoop/hbase/protobuf/generated/ClientProtos.java:28857::0

Only a simple abstract pointcut can be implemented when using this mechanism,if the mothod is not abstract.

My question is whether this way could get parameters?If possible,how to config.

kriegaex
  • 63,017
  • 15
  • 111
  • 202
zld1005
  • 11
  • 3
  • I have added some syntax highlighting to your code to make it a bit more readable. But please be a little bit more careful with your spelling and grammar. You use package names like "apect" instead of "aspect" and log messages saying "methon" instead of "method". You do not write full sentences in many places, making it extremely difficult to undersand anything of what you are trying to say. My suggestion is to either take some more time to write more understandably or, if your English is just not good enough (no problem) to find someone in your company's department to help you with it. – kriegaex Sep 13 '14 at 09:49

1 Answers1

1

Your aop.xml defines a concrete aspect providing pointcuts for two abstract base aspect pointcuts, scan() and multi(). So far, so good. But what are you trying to do with pointcut getdata(final RpcController controller, final GetRequest request)? It is already concretely defined in the base aspect, having two parameters as well as parameter binding. It seems you are trying to redefine it (same name) without any parameters and with another target. That does not make sense, and how can you expect parameter bindings if you do not define them by yourself and overwrite the existing ones (if that is possible at all, I never tried)?

Update: I forgot to mention what the warning message means:

pointcut getdata(final RpcController controller, final GetRequest request):
    target(org.apache.hadoop.hbase.protobuf.generated.ClientProtos) &&
    call (public * org.apache.hadoop.hbase.regionserver.HRegionServer.get(RpcController, GetRequest)) &&
    args(controller, request);

If you compare the target type ClientProtos with the intercepted target method HRegionServer.get(..), you see that there is a contradiction: The target object cannot have the type ClientProtos, it must be an HRegionServer because you are intercepting a method of that class. AspectJ is friendly enough to tell you that.

Logically, this(Foo) && call(* Bar.blah(..)) is possible, because the caller type can be different from the callee type, but target(Foo) && call(* Bar.blah(..)) does not make sense because the resulting set of joinpoints will always be empty due to the fact that call(* Bar.blah(..)) always means that the target type must be Bar.

kriegaex
  • 63,017
  • 15
  • 111
  • 202