Showing posts with label Aspect J. Show all posts
Showing posts with label Aspect J. Show all posts

Saturday, June 27, 2009

Terracotta like implementation :: code

So this is what we thought:

The user object we remove all the field variable initializations and replace them with our custom code. So, the user says

this.list = new ArrayList(),

and during the byte code construction we will mke this equivalent to

this.list= new MyList().

Now the successive updates now happen over MYList which records the deltas.

So, say our object is UserAttributes::

public class UserAttributes implements Interceptable {

@LIST(3)
private ArrayList alias;

public List getAlias() {
return alias;
}

public void setAlias(ArrayList alias) {
this.alias = alias;
}

public static void main(String[] argv) {
UserAttributes u = new UserAttributes();
u.alias = new ArrayList();
System.out.println("alias::" + u.alias + " class:" + u.alias.getClass());
}
}


Now to replace the newArrayList() where ever possible we write a point cut as follows in InAspect.aj file

public aspect INAspect {

pointcut listCut(List value, LIST in) : set(@LIST * * ) && args(value) && @annotation(in);

@SuppressWarnings("unchecked")
void around(List value, LIST in) :listCut(value,in) {
System.out.println("**annotation " + thisJoinPoint + " ann:"
+ in.value());
value = new MyList(in.value());
value.add("val 1");
proceed(value, in);
}
}

Now the sop of the UserAttributes gives the out put as MyList class with one entry in it. Let me put few words abt the listCut.

  1. set(@LIST * * )&& @annotation(in) => cut all the modifying fields of the fields annotated with LIST annotation. Pickeup the annotation into in variable
  2. pointcut listCut(List value...args(value)=> picks up the modifying data as value variable. If u modify the value then it makes modification in the userAttributes class and thats what happens in the advice: around...
  3. proceed continues with the remaining point cuts (if any)


Terracotta like implementation

Terracotta, in one line, is the fast transport layer btw multiple JVMs. How is hte speed achieved? Simple he transfers the delta that happened in an object i.e.. if the object has changed one field variable then he transfers only that variable reather the entire object.

So we had an idea:
We need to transmit data from our Java servers to the Client where the end user plays his game and we thought why not take this terracotta apprach?

Aspect J:
here comes the here (as of now, to the knowledge we have till now). Now we want to manipulate the byte code that is generated by javac so that the new byte code now has new code which is intelligent enough to pickup the deltas between two consecuting updates of the object.

Aspect J

This is open source project and as any other open source it suffers in low documentation, So i thought i will put my work here so that it may help out somebody there trying to figure out the solutions.

Starting point:
  1. Aspect J site; get the eclipse plugin installed (2.0) Actually the plugin keeps u started off blackboxing the intricacies of compiling etc.
  2. Get the basic understanding of the technology jargon is here: https://www.ibm.com/developerworks/java/library/j-aspectj/
  3. in this link search for pointcut/ joinpoint/ advice and u are at their definitions
  4. Open eclipse and start experimenting.