package org.ourgrid.threadServicesAspects; import java.net.MalformedURLException; import java.rmi.Naming; import java.rmi.RemoteException; import org.ourgrid.common.config.Configuration; import org.ourgrid.test.functionalunits.FunctionalTestsURLProvider; import org.ourgrid.test.functionalunits.FunctionalUnitsControl; import org.ourgrid.test.functionalunits.RemoteTestServicesImpl; /** * This aspect binds an instance of RemoteTestServices after a service has started. */ privileged public aspect RemoteTestServicesBinder { /* * Softening Exceptions inside this aspect */ pointcut softnerPointcut(): within(RemoteTestServicesBinder) && adviceexecution(); declare soft : RemoteException : softnerPointcut(); declare soft : MalformedURLException : softnerPointcut(); /* * Pointcuts */ //Pointcut disables the not using aspects exception. pointcut notUsingAspectsException(): call(static void FunctionalUnitsControl.notUsingAspectsException()); //Pontcuts any of the start service methods. pointcut bindRemoteTestServices(): execution(public void org.ourgrid.corepeer.ui.CorePeerUIManager.startCorePeerService()) || execution(public void org.ourgrid.mygrid.ui.MyGridUIManager.startMyGridService()) || execution(public void org.ourgrid.peer.ui.PeerUIManager.startPeerService()); pointcut userAgentBindRemoteTestServices(): execution(private void org.ourgrid.gridmachine.useragent.ui.UserAgentUIManager.startFailureDetector(*)); /* * Advices */ //do not throw exception void around(): notUsingAspectsException() { } //Binds the RemoteTestServicesImpl to the service. after() returning : bindRemoteTestServices() { String port = Configuration.getInstance().getProperty(Configuration.PROP_PORT); String hostname = Configuration.getInstance().getProperty(Configuration.PROP_NAME); Naming.rebind(FunctionalTestsURLProvider.getRemoteTestServicesURL(hostname, Integer.parseInt(port)), new RemoteTestServicesImpl()); } after() returning : userAgentBindRemoteTestServices() { String port = Configuration.getInstance().getProperty(Configuration.PROP_PORT); String hostname = Configuration.getInstance().getProperty(Configuration.PROP_NAME); Naming.rebind(FunctionalTestsURLProvider.getRemoteTestServicesURL(hostname, Integer.parseInt(port)), new RemoteTestServicesImpl()); } }