Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] Use aspectj to inject control flow

Thanks, Gregor, I reformatted my question using the real code I'm working
with. Sorry for being lazy of using a domain specific example. 

Basically, I have this problem during re-factoring a crosscutting logic
out of CORBA. This code snippet is part of the message sending
functionality. There are two "if" statements at the end of the code
snippet which need to essentially re-created in the re-factored code using
AspectJ. To be more specific, the boolean flag "responseExpected" is going
to be added as inter type attribute member instead. And then additional
control flows involving this flag, as illustrated by the two "if"
statements at the end of the code snippet, need to be inserted. It is
obvious that these control flow blocks are not needed if it is not
necessary to consider the value of the flag. The re-factored code would
just consist of calls 1-5. This is what i call injecting control flows. I
did not find any aspectj example that directly addresses this type of
problem. I hope I explained the problem well, and I really appriciate the
advice and help. 

Charles 
 
   public boolean  send(Downcall down, boolean b)
    {
      down.initStateMonitor();
      Upcall up;
      synchronized(this)
        {
            while(hold_ && !destroy_)
            {
					 //some code
            }

            //
            // Collect the Upcall data
            //
            com.ooc.OCI.ProfileInfo profileInfo = down.profileInfo();
            int reqId = down.requestId();
            String op = down.operation();
            com.ooc.CORBA.OutputStream out = down.output();
            com.ooc.OCI.Buffer buf = new com.ooc.OCI.Buffer();
            buf.consume(out._OB_buffer());
            org.omg.IOP.ServiceContext[] requestSCL =
            down.getRequestSCL();

            if(down.responseExpected())
            {
     //call 1   callMap_.put(...);
     //call 2   down.setPending();
     //call 3   up = oaInterface_.createUpcall(...);
            }
            else
            {
                down.setNoException(null);
                up = oaInterface_.createUpcall(...)
            }
	   }
     //call4   up.invoke();
        if(down.responseExpected())
    //call5  return false;
        else
            return true;
    }


Charles Zhang 		(http://www.eecg.utoronto.ca/~czhang)
Computer Group, Dept. of Elec. & Comp. Engineering 
U. of Toronto, Ontario, Canada
*********************************************************
" Yawn!!" (Charles Zhang) 

On Tue, 1 Jul 2003, Gregor Kiczales wrote:

> It would help us to better answer your question if you sent what I like
> to call a "realistic example".
> 
> By that I mean an example in which all the class, method, variable,
> and aspect names are realistic, and connote as part of their name
> what you are trying to do.
> 
> Examples with names like method1, method2, A, B, C can help explain
> the actual semantics of the language, but they are a lot less useful
> for giving advice about how to best use the language.  I generally
> don't consider them to be realistic examples.
> 
> The problem with examples like the one below is that all we can do
> is tell you how to do exactly what you are asking for. We can't see
> around the exact thing you are asking for to suggest a better approach
> to the real underlying problem.
> 
> The AspectJ FAQ entry 15.5 talks some more about this as well.
> 
> 
> 
> > -----Original Message-----
> > From: aspectj-users-admin@xxxxxxxxxxx 
> > [mailto:aspectj-users-admin@xxxxxxxxxxx] On Behalf Of Charles Zhang
> > Sent: Tuesday, July 01, 2003 7:14 PM
> > To: aspectj-users@xxxxxxxxxxx
> > Subject: Re: [aspectj-users] Use aspectj to inject control flow
> > 
> > 
> > Thanks for the help. However, the around construct requires all of the
> > methods have the same return type. Although "Object" can be 
> > used as the
> > generic return type, I don't know if it will take care of the 
> > primitive
> > types. And, indeed, my question is general. Suppose I want to have 10
> > methods included in the conditional block, then it becomes 
> > cumbersome to 
> > list every method signature. Is this something can be done in
> > AspectJ? 
> > 
> > Thanks again
> > 
> > Charles
> > 
> > On Tue, 1 Jul 2003, Ramnivas Laddad wrote:
> > 
> > > You can do the following (although, I suspect, your real question
> > > is of more general nature, so this may not help you):
> > > 
> > > aspect ConitionalExecution {
> > >     pointcut inMethodABody() : withincode(String methodA());
> > > 
> > >     Object around() : call(* method3()) || call(* method4())) 
> > >          && inMethodABody() {
> > >          if(conditionA) {
> > >               return proceed();
> > >          }
> > >     }
> > > 
> > >     Object around() : call(* method5()) 
> > >          && inMethodABody() {
> > >          if(!conditionA) {
> > >               return proceed();
> > >          }
> > >     }
> > > }
> > > 
> > > -Ramnivas
> > > 
> > > --- Charles Zhang <czhang@xxxxxxxxxxxxxxxx> wrote:
> > > > Hi, I want to write a piece of AspectJ code that adds new control
> > > > flow to
> > > > a sequence of execution such that code like the following:
> > > > public String methodA()
> > > > {
> > > >   method1();
> > > >   method2();
> > > >   method3();
> > > >   method4();
> > > >   method5();
> > > >   method6();
> > > > } 
> > > > will behave like the following:
> > > > public String methodA()
> > > > {
> > > >   method1();
> > > >   method2();
> > > >   if(conditionA)
> > > >   { 
> > > >     method3();
> > > >     method4();
> > > >    }else
> > > >    {
> > > >      method5();
> > > >    }
> > > >    method6();
> > > > }
> > > > 
> > > > I remember someone asked a similar question sometime ago. But I
> > > > couldn't
> > > > dig it out. 
> > > > 
> > > > Anyone has any suggestions? Thanks a lot.  
> > > > 
> > > > Charles Zhang 		(http://www.eecg.utoronto.ca/~czhang)
> > > > Dept. of Elec. & Comp. Engineering 
> > > > U. of Toronto, Ontario, Canada
> > > > *********************************************************
> > > > " Yawn!!" (Charles Zhang) 
> > > > 
> > > > 
> > > > _______________________________________________
> > > > aspectj-users mailing list
> > > > aspectj-users@xxxxxxxxxxx
> > > > http://dev.eclipse.org/mailman/listinfo/aspectj-users
> > > 
> > > 
> > > __________________________________
> > > Do you Yahoo!?
> > > SBC Yahoo! DSL - Now only $29.95 per month!
> > > http://sbc.yahoo.com
> > > _______________________________________________
> > > aspectj-users mailing list
> > > aspectj-users@xxxxxxxxxxx
> > > http://dev.eclipse.org/mailman/listinfo/aspectj-users
> > > 
> > 
> > _______________________________________________
> > aspectj-users mailing list
> > aspectj-users@xxxxxxxxxxx
> > http://dev.eclipse.org/mailman/listinfo/aspectj-users
> > 
> 
> 
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users
> 



Back to the top