We sport architecture_implementation

968 views

Published on

We-Sport.com architecture implementation with Google Web Toolkit and Google App Engine.

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
968
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

We sport architecture_implementation

  1. 1. Architecture and Implementation
  2. 2. Short video...
  3. 3. User selects the sports he practices or wouldlike to practice
  4. 4. User selects places on map where practicesthe selected sports
  5. 5. User selects his favourite days and time
  6. 6. HomePage showing participants and eventsnear the selected location
  7. 7. January 2011, We-Sport is sponsor of"2011 IPC ALPINE SKIING WORLD CHAMPIONSHIPS"
  8. 8. Quick diagram
  9. 9. Spring configurationweb.xml...<servlet> <servlet-name>sports</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>sports</servlet-name> <url-pattern>/api/*</url-pattern> </servlet-mapping>...
  10. 10. SportController@Controller@RequestMapping("/sport")public class SportController extends AbstractController {@Autowiredprivate SportsService sportsService;@Override@RequestMapping(method = RequestMethod.GET)protected ModelAndView handleRequestInternal(HttpServletRequest request,HttpServletResponse response) throws Exception {setParams(request);Sport sport = null;ModelAndView result = new ModelAndView();sport = sportsService.findSportById(getSportId());result.addObject("sport", sport);return result;} private void setParams(request){...}}
  11. 11. Handle multiple output types<?xml..><beans ..."><bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> <property name="mediaTypes"><map><entry key="json" value="application/json" /> <entry key="xml" value="application/xml" /> <entry key="pdf"value="application/pdf" /></map> </property> <property name="defaultViews"> <list> <bean class="com.sports.service.PDFPage" Spring 3p:contentType="application/pdf" /> <bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" /><bean class="org.springframework.web.servlet.view.xml.MarshallingView"> <constructor-arg> <bean id="castorMarshaller" ContentNegotiatingViewResolverclass="org.springframework.oxm.castor.CastorMarshaller" /> </constructor-arg> </bean></list></property> </bean></beans> (sports-servlet.xml)
  12. 12. Examples of API requests:
  13. 13. RpcSportsServiceImplpublic class RpcSportsServiceImpl extends AutoinjectingRemoteServiceServletimplementsRpcSportsService { @Autowired private SportsService sportsService; public Sport findSportById(Long sportId) { return sportsService.findSportById(sportId); } // getters and setters of sportsService}
  14. 14. AutoinjectingRemoteServiceServletpublic abstract class AutoinjectingRemoteServiceServlet extendsRemoteServiceServlet { @Override public void init(ServletConfig config) throws ServletException { super.init(config);WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(config.getServletContext()); AutowireCapableBeanFactory beanFactory = ctx.getAutowireCapableBeanFactory(); beanFactory.autowireBean(this); }}
  15. 15. SportsServiceImplpublic class SportsServiceImpl implements SportsService { @Autowired private SportDao sportDao; public Sport findSportById(Long sportId) { final String cacheKey = "findSportById_"+sportId; if (!getCache().contains(cacheKey) || getCache().get(cacheKey) == null) {getCache().put(cacheKey, sportDao.findById(sportId)); } return (Sport) getCache().get(cacheKey); }}
  16. 16. DataStore Access - JDO<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"....... default-lazy-init="true"> Spring 3 - JDOTemplate<context:component-scan base-package="com.sports.dao.jdo" /> <context:component-scan base- Configurationpackage="com.sports.server.servlet.filter" /> <bean id="sportsService" class="com.sports.service.SportsServiceImpl" /> (applicationContext.xml)<tx:annotation-driven /> <bean id="persistenceManagerFactory" class="com.sports.server.utils.GaePMF" factory-method="getPersistenceManagerFactory"> </bean> <bean id="transactionManager"class="org.springframework.orm.jdo.JdoTransactionManager"> <property name="persistenceManagerFactory"ref="persistenceManagerFactory" /> </bean> <bean id="jdoTemplate" class="org.springframework.orm.jdo.JdoTemplate"><constructor-arg ref="persistenceManagerFactory" /> <constructor-arg value="false" type="boolean" /> </bean> </beans>
  17. 17. BaseDaoJdopackage com.sports.dao.jdo;import ...public abstract class BaseDaoJdo {@Autowiredprotected PersistenceManagerFactory pmf;@Autowiredprotected JdoTemplate jdoTemplate;@Autowiredprotected JdoTransactionManager transactionManager;}
  18. 18. SportDaoJdopackage com.sports.dao.jdo;import ...@Componentpublic class SportDaoJdo extends BaseDaoJdo implements SportDao { public Sport save(Sport sport) {return jdoTemplate.makePersistent(sport);} @SuppressWarnings("unchecked")public Collection<Sport> findAll() {Object[] a = {};return jdoTemplate.detachCopyAll(jdoTemplate.find("select from " +Sport.class.getName() + " order by name", a));}}
  19. 19. Cron + TaskQueuecron:- description: Update Sports Counter url: /api/cron/updateSportCounter cron.yaml schedule: every 24 hours
  20. 20. UpdateSportCounter@Controller@RequestMapping("/cron/updateSportCounter")public class UpdateSportCounter { @Autowiredprivate SportsService sportsService; @RequestMapping(method = RequestMethod.GET) public void execute(HttpServletResponse response) throws IOException { for (SportOutput sportOut : sportsService.findAllSports()){ final Long id = sportOut.getId(); final int counter = sportsService.getCountPlayersBySport(id); UpdateCounterSportTaskQueue.updateCounterSportTask(id, counter);}response.getWriter().write("Scheduled all taskqueues.");}}
  21. 21. UpdateCounterSportTaskQueuepublic class UpdateCounterSportTaskQueue { public static void updateCounterSportTask(final Long id, final int counter) { TaskOptions taskOptions = TaskOptions.Builder.withUrl("/api/task/updateCounterSport"); taskOptions.param("id", String.valueOf(id)); taskOptions.param("counter", String.valueOf(counter)); QueueFactory.getDefaultQueue().add(taskOptions); }}
  22. 22. UpdateCounterSportWorker@Controller@RequestMapping("/task/updateCounterSport")public class UpdateCounterSportWorker { @Autowiredprivate SportDao sportDao; @RequestMapping(method = RequestMethod.POST)@ResponseStatus(HttpStatus.ACCEPTED)@Transactional(propagation = Propagation.REQUIRES_NEW)public void execute(@RequestParam long id, @RequestParam int counter) {Sport sport = sportDao.findById(id);sport.setCounter(counter);sport.setUpdatedDate(new Date());sportDao.save(sport);}}
  23. 23. Version Control - GITDecentralizationDistributed Version Control Systems take advantage of the peer-to-peerapproach. Clients can communicate between each other and maintain theirown local branches without having to go through a CentralServer/Repository. Then synchronization takes place between the peers whodecide which changesets to exchange.
  24. 24. GIT + Dropbox I think that git on dropbox is great. I use it all of the time. I have multiple computers (two at home and one elsewhere) that I use dropbox as a central bare repo. Since I dont want to host it on a public service and I dont have access to a server that I can always ssh to, Dropbox takes care of this by syncing (very quickly) in the background. Setup is something like this:http://stackoverflow.com/questions/1960799/using-gitdropbox-together-effectively
  25. 25. Thank you for your kind attentionbusy busy ...

×