java - Accessing class members in after advice for execution pointcut -


i trying value of read string after execution of readobject() in sample code below after advice advises readobject() join point.

public class eg {      private objectoutputstream output;     private objectinputstream input;     public string request="";      public eg(file source){             output; // output stream client             input= new objectinputstream( file );          }      public void method() {             try{                             while(true) {                     request =(string) input.readobject();                     //do request                 }//while             }             catch (ioexception ex)              {                 ex.printstacktrace();             }      }  } 

and aspect:

public aspect readstringgetter {     public pointcut readoperation() :       execution(* java.io.objectinputstream.readobject());      after() : readoperation() {         eg eg = (eg) thisjoinpoint.getthis();         system.out.println(eg.request);     } } 

you use this pointcut obtain context of join point (instance of eg):

class eg {     public string request = "";     public void method() {         request = "xy";         system.out.println(request);     } } 

caller:

eg c = new eg(); c.method(); 

aspect:

public aspect myaspect {      pointcut egmethodsexecution(eg eg) :          execution(* eg.method(..)) && this(eg);      after(eg eg) : egmethodsexecution(eg) {         system.out.println("~ in aspect ~ " + eg.request);     }  } 

output:

xy
~ in aspect ~ xy


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -