Distribution Concern Implementation
This transformation generates aspects to implement the
distribution concern. We used RMI to achieve it, but it would
be possible to use other distribution technology, such as EJB.
This transformation follows the guideline proposed by Soares
(2002) .
To apply this refactoring, the source
project should implement the Façade design pattern. The
generated code creates a remote instance of the façade and
redirects method calls from local one. AJaTS also creates
other auxiliary classes (AbstractClientSideAspect, AbstractServerSideAspect),
as well as an interface that extends RMI's Remote interface.
Source example |
Transformed code - Client
Side Aspect |
public class
BankFacade {
AccountRecord
accounts;
public
BankFacade(){
this.accounts = new
AccountRecord();
}
public void
insertAccount(Account account){
this.accounts.insert(account);
}
}
|
import cin.aspects.framework.distribution.AbstractClientSideAspect;
import cin.aspects.framework.updateState.UpdateStateControl;
import javax.servlet.http.HttpServlet ;
import org.aspectj.lang.SoftException;
public aspect FacadeClientSideAspect extends AbstractClientSideAspect {
private IRemoteFacade facade;
void setRemoteFacade( IRemoteFacade remote) {
facade = remote;
}
public Object getRemoteFacade() {
prepareFacade();
return facade;
}
private synchronized void prepareFacade() {
if(facade == null) {
try {
System.out.println("About to lookup...");
facade = (IRemoteFacade)java.rmi.Naming.lookup("//" +
FacadeServerSideAspect.RMI_SERVER_NAME + "/" +
FacadeServerSideAspect.SYSTEM_NAME);
System.out.println("Remote #FACADE found");
}
catch(Throwable ex){
throw new SoftException(ex);
}
}
pointcut facadeCallers () : this (HttpServlet) || within (UpdateStateControl) ;
pointcut facadeCalls () : call (* IRemoteFacade+.* (..)) && !call (static * IRemoteFacade+.* (..)) ;
pointcut facadeLocalCalls () : facadeCallers() &&
facadeCalls();
Object around () : facadeCallers() && call (*
FacadeServerSideAspect.getInstance ()) {
return null;
}
} |
|