11 Replies Latest reply on Dec 12, 2006 5:20 PM by ykrishnaprasad

    Tracing/Logging - Actual RMI calls vs calls between EJBs

    ykrishnaprasad

      I am trying to use AOP to trace/log the calls made to the methods in EJBs.But i want to log only the actual RMI calls coming from outside the EJB container(a user of our system through a web browser) to methods in my EJBs but not the calls made between EJBs.
      Can i make this distinguishion in the interceptors(aspects) that i write?

      Thanks.

        • 1. Re: Tracing/Logging - Actual RMI calls vs calls between EJBs
          kabirkhan

          EJB 2 or 3?

          • 2. Re: Tracing/Logging - Actual RMI calls vs calls between EJBs
            ykrishnaprasad

            EJB 3

            • 3. Re: Tracing/Logging - Actual RMI calls vs calls between EJBs
              kabirkhan

              There is no easy way to do this at the AOP layer, but it seems that if the call is local the EJBContainerInvocation will contain something under

              invocation.getMetaData("IS_LOCAL", "IS_LOCAL");
              


              You could customize the stack of interceptors used for your ejb 3 container(s) in ejb3-interceptors-aop.xml, or create your own domains by deploying your own whatever-aop.xml file and override the domain used in your bean using the @Domain annotation.
              I am not sure if this is shown in the ejb3 documentation, but there is a test in the ejb3 testsuite under org.jboss.ejb3.test.aspectdomain that you could look at.


              • 4. Re: Tracing/Logging - Actual RMI calls vs calls between EJBs
                ykrishnaprasad

                Kabir,
                In my interceptor class i can get a reference to the target object.
                How can i get a reference to the caller object in the interceptor class?

                Thanks

                • 5. Re: Tracing/Logging - Actual RMI calls vs calls between EJBs
                  kabirkhan

                  You can't if you use "execution" or "field" pointcuts, if you want access to the caller you need a "call" pointcut, but those have certain limitations.

                  • 6. Re: Tracing/Logging - Actual RMI calls vs calls between EJBs
                    nacho26

                    Hello Krishna,
                    I am trying to get something similar working as you had put in your question on the message forums. I am trying to get the "caller" and "callee" of a call between two EJBs. Do you have suggestions ?
                    Thanks for your time !
                    Gunjan

                    "ykrishnaprasad" wrote:
                    Kabir,
                    In my interceptor class i can get a reference to the target object.
                    How can i get a reference to the caller object in the interceptor class?

                    Thanks


                    • 7. Re: Tracing/Logging - Actual RMI calls vs calls between EJBs
                      ykrishnaprasad

                      I haven't yet exactly figured out the solution to my specific problem.But here is somthing that might be of help - caller pointcuts(http://wiki.jboss.org/wiki/Wiki.jsp?page=CallerPointcuts) and MethodCalledByMethod class in org.jboss.aop.joinpoint package.
                      If i am successful i will post a reply.
                      I am open to any ideas you might be able to throw in.

                      • 8. Re: Tracing/Logging - Actual RMI calls vs calls between EJBs
                        ykrishnaprasad

                        Kabir,

                        a) Can get the type of an invocation(whether its a METHOD)?
                        To be specific i was looking at -http://www.onjava.com/pub/a/onjava/2003/05/28/aop_jboss.html?page=1

                        Things might have changed since the article was written.Wondering how to do the same with the new APIs.


                        b) Can i use org.jboss.aop.joinpoint.MethodCalledByMethodInvocation to see if a method is invoked by another method?

                        Appreciate if you could point me to any examples.

                        Thanks.

                        • 9. Re: Tracing/Logging - Actual RMI calls vs calls between EJBs
                          stalep

                           

                          "ykrishnaprasad" wrote:

                          a) Can get the type of an invocation(whether its a METHOD)?

                          i guess you mean in the interceptor, so yes. just either try to cast it to a MethodInvocation or check if its an instanceof MethodInvocation.
                          "ykrishnaprasad" wrote:

                          b) Can i use org.jboss.aop.joinpoint.MethodCalledByMethodInvocation to see if a method is invoked by another method?

                          i believe you are thinking of cflow here. with cflow you can define a stack of eg. method calls that has to occur before a pointcut matches.
                          take a look at the cflow examples in the dist and let me know if it solves your problem.

                          • 10. Re: Tracing/Logging - Actual RMI calls vs calls between EJBs
                            flavia.rainone.old

                            You can write an advice that receives a MethodCalledByMethodInvocation. This way, you can access the caller.

                            However, this invocation must be used only on advices bound to "call" pointcut expressions.

                            If you use an "execution" pointcut, what you get is MethodInvocation, and you will only have access to the called method.

                            If you use call + withincode on your pointcut expression, you can specify the method called (inside of call), and the caller method (inside of withincode).

                            Look at this example:

                            call(int java.util.ArrayList->size()) AND withincode(void Driver->caller())
                            


                            This pointcut expression matches all calls to ArrayList.size() made by the method Driver.caller(). Look at the complete example here:
                            http://labs.jboss.com/portal/jbossaop/docs/1.5.0.GA/docs/aspect-framework/examples/caller/caller.html

                            We will allow more flexibility in this area on JBoss AOP 2.0. You will be able to receive the caller and the target of the call as arguments to your advice.

                            • 11. Re: Tracing/Logging - Actual RMI calls vs calls between EJBs
                              ykrishnaprasad

                              Thanks a bunch guys!
                              I think i got the basic caller pointcut working for MethodCalledByMethodInvocation.

                              Here is a simple set of classes that i used for this purpose:

                              package DCR2;
                              
                              public class HelloAOP {
                               public static void main(String args[]){
                               new callTest().printText();
                               }
                               public void callMe(){
                               System.out.println("AOP!");
                               }
                              }
                              
                              
                              package DCR2;
                              
                              public class callTest {
                               public void printText(){
                               callMe();
                               }
                               public void callMe(){
                               System.out.println("AOP!");
                               }
                              }
                              
                              package DCR2;
                              
                              import org.jboss.aop.advice.Interceptor;
                              import org.jboss.aop.joinpoint.Invocation;
                              import org.jboss.aop.joinpoint.MethodCalledByMethodInvocation;
                              
                              public class HelloAOPInterceptor implements Interceptor{
                               public String getName(){
                               return "HelloAOPInterceptor";
                               }
                               public Object invoke(Invocation invocation) throws Throwable{
                               if (invocation instanceof MethodCalledByMethodInvocation){
                               System.out.print("MethodCalledByMethodInvocation, ");
                               }
                               else System.out.print("Hello, ");
                               return invocation.invokeNext();
                               }
                              }
                              
                              
                              


                              And my jboss-aop.xml looks like:

                              
                              
                              <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
                              <aop>
                               <bind pointcut="call(public void DCR2.callTest->callMe()) and withincode(public void DCR2.callTest->printText())">
                               <interceptor class="DCR2.HelloAOPInterceptor"/>
                               </bind>
                              </aop>
                              


                              The output after running the project should be:

                              MethodCalledByMethodInvocation, AOP!

                              The reason i used the callTest class in between is that i could not get the interceptor to work if i had a statement
                              new HelloAOP().callMe();
                              
                              (a method call in the constructor)
                              
                              instead of:
                              new callTest().printText();
                              


                              What i could do on the whole is to see if a call for a method is coming from another method or not. My next step is to see if i can differentiate between a method call coming from a JSP page(JSP->EJB) and the method calling method(EJB->EJB).

                              I may have to comeback for your help again.