Architecture and Implementation
Short video...
User selects the sports he practices or would
like to practice
User selects places on map where practices
the selected sports
User selects his favourite days and time
HomePage showing participants and events
near the selected location
January 2011, We-Sport is sponsor of
"2011 IPC ALPINE SKIING WORLD CHAMPIONSHIPS"
Quick diagram
Spring configuration

web.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>
...
SportController
@Controller
@RequestMapping("/sport")
public class SportController extends AbstractController {

@Autowired
private 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){...}
}
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 3
p: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"
                                                                            ContentNegotiatingViewResolver
class="org.springframework.oxm.castor.CastorMarshaller" /> </constructor-arg> </bean></list></property> </bean></beans>
                                                                                 (sports-servlet.xml)
Examples of API requests:
RpcSportsServiceImpl
public class RpcSportsServiceImpl extends AutoinjectingRemoteServiceServlet
implements
RpcSportsService {

    @Autowired
    private SportsService sportsService;

    public Sport findSportById(Long sportId) {
      return sportsService.findSportById(sportId);
    }

    // getters and setters of sportsService
}
AutoinjectingRemoteServiceServlet
public abstract class AutoinjectingRemoteServiceServlet extends
RemoteServiceServlet {

 @Override
 public void init(ServletConfig config) throws ServletException {
  super.init(config);
WebApplicationContext ctx = WebApplicationContextUtils
  .getRequiredWebApplicationContext(config.getServletContext());

  AutowireCapableBeanFactory beanFactory = ctx
.getAutowireCapableBeanFactory();
    beanFactory.autowireBean(this);
  }
}
SportsServiceImpl
public 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);
  }
}
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-
                                                                                            Configuration
package="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>
BaseDaoJdo
package com.sports.dao.jdo;
import ...

public abstract class BaseDaoJdo {

@Autowired
protected PersistenceManagerFactory pmf;

@Autowired
protected JdoTemplate jdoTemplate;
@Autowired
protected JdoTransactionManager transactionManager;

}
SportDaoJdo
package com.sports.dao.jdo;
import ...

@Component
public 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));
}
}
Cron + TaskQueue

cron:
- description: Update Sports Counter
  url: /api/cron/updateSportCounter    cron.yaml
  schedule: every 24 hours
UpdateSportCounter
@Controller
@RequestMapping("/cron/updateSportCounter")
public class UpdateSportCounter {
 @Autowired
private 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.");
}
}
UpdateCounterSportTaskQueue
public 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);

    }
}
UpdateCounterSportWorker
@Controller
@RequestMapping("/task/updateCounterSport")
public class UpdateCounterSportWorker {
     @Autowired
private 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);
}
}
Version Control - GIT
Decentralization
Distributed Version Control Systems take advantage of the peer-to-peer
approach. Clients can communicate between each other and maintain their
own local branches without having to go through a Central
Server/Repository. Then synchronization takes place between the peers who
decide which changesets to exchange.
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 don't want to host it on a public service and I don't 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
Thank you for your kind attention


busy busy ...

More Related Content

PDF
What’s new in Android JetPack
PDF
Greach 2019 - Creating Micronaut Configurations
PPTX
IndexedDB - Querying and Performance
PDF
Improving app performance with Kotlin Coroutines
PDF
Introduction to Struts
PDF
Optimize CollectionView Scrolling
PDF
Fifty Features of Java EE 7 in 50 Minutes
PDF
Heroku pop-behind-the-sense
What’s new in Android JetPack
Greach 2019 - Creating Micronaut Configurations
IndexedDB - Querying and Performance
Improving app performance with Kotlin Coroutines
Introduction to Struts
Optimize CollectionView Scrolling
Fifty Features of Java EE 7 in 50 Minutes
Heroku pop-behind-the-sense

What's hot (20)

PPTX
Reactive state management with Jetpack Components
PPTX
Paging Like A Pro
PPTX
AngularJs-training
PPTX
Asp.Net Mvc Internals &amp; Extensibility
PDF
Building an app with Google's new suites
PDF
Jetpack, with new features in 2021 GDG Georgetown IO Extended
PDF
What's new in Java EE 7
PDF
망고100 보드로 놀아보자 18
PDF
Introducing Rendr: Run your Backbone.js apps on the client and server
PDF
[22]Efficient and Testable MVVM pattern
PDF
Ui perfomance
PPT
Jsp/Servlet
PPT
Android - Api & Debugging in Android
PDF
PDF
Alfredo-PUMEX
PDF
RicoLiveGrid
PDF
50 new features of Java EE 7 in 50 minutes
PDF
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
PDF
td_mxc_rubyrails_shin
PDF
Android programming -_pushing_the_limits
Reactive state management with Jetpack Components
Paging Like A Pro
AngularJs-training
Asp.Net Mvc Internals &amp; Extensibility
Building an app with Google's new suites
Jetpack, with new features in 2021 GDG Georgetown IO Extended
What's new in Java EE 7
망고100 보드로 놀아보자 18
Introducing Rendr: Run your Backbone.js apps on the client and server
[22]Efficient and Testable MVVM pattern
Ui perfomance
Jsp/Servlet
Android - Api & Debugging in Android
Alfredo-PUMEX
RicoLiveGrid
50 new features of Java EE 7 in 50 minutes
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
td_mxc_rubyrails_shin
Android programming -_pushing_the_limits
Ad

Viewers also liked (7)

PDF
Social Media Sport A Community Building Partnership
DOCX
Moho Pu’ Uwai Basket Ball Sport Complex
PPTX
Architecture By Baseball
PDF
Sport Complex
PPTX
Ppt on stadium construction
PPTX
Beijing National Stadium
PPT
Stadium Project
Social Media Sport A Community Building Partnership
Moho Pu’ Uwai Basket Ball Sport Complex
Architecture By Baseball
Sport Complex
Ppt on stadium construction
Beijing National Stadium
Stadium Project
Ad

Similar to We sport architecture_implementation (20)

PDF
jDays2015 - JavaEE vs. Spring Smackdown
PDF
Spring 3 - An Introduction
PDF
Spring 3.0 dependancy injection
PDF
An Introduction to Spring Data
PPT
Spring talk111204
PDF
Spring 3 - Der dritte Frühling
PDF
Advance Java Training in Bangalore | Best Java Training Institute
PPTX
0205_HandsOn_orm_java_springboot_tp_4.pptx
PPT
Story ofcorespring infodeck
PDF
Building Flexible APIs for Web 2.x/Cloud Applications (JavaOne 2011 Session ...
KEY
A Walking Tour of (almost) all of Springdom
PPTX
ORM Allhggvvvvvhhhgghhhhhhhhhhhghhh.pptx
PDF
Spring - CDI Interop
PDF
BlazeDS
PDF
Vaadin 8 with Spring Frameworks AutoConfiguration
PPT
Spring, web service, web server, eclipse by a introduction sandesh sharma
PPTX
Java TechTalk "Spring boot made life easier with Kubernetes and Microservices"
PPT
Spring 3.1: a Walking Tour
PPTX
Spring Basics
PDF
NIG 系統開發指引
jDays2015 - JavaEE vs. Spring Smackdown
Spring 3 - An Introduction
Spring 3.0 dependancy injection
An Introduction to Spring Data
Spring talk111204
Spring 3 - Der dritte Frühling
Advance Java Training in Bangalore | Best Java Training Institute
0205_HandsOn_orm_java_springboot_tp_4.pptx
Story ofcorespring infodeck
Building Flexible APIs for Web 2.x/Cloud Applications (JavaOne 2011 Session ...
A Walking Tour of (almost) all of Springdom
ORM Allhggvvvvvhhhgghhhhhhhhhhhghhh.pptx
Spring - CDI Interop
BlazeDS
Vaadin 8 with Spring Frameworks AutoConfiguration
Spring, web service, web server, eclipse by a introduction sandesh sharma
Java TechTalk "Spring boot made life easier with Kubernetes and Microservices"
Spring 3.1: a Walking Tour
Spring Basics
NIG 系統開發指引

We sport architecture_implementation

  • 3. User selects the sports he practices or would like to practice
  • 4. User selects places on map where practices the selected sports
  • 5. User selects his favourite days and time
  • 6. HomePage showing participants and events near the selected location
  • 7. January 2011, We-Sport is sponsor of "2011 IPC ALPINE SKIING WORLD CHAMPIONSHIPS"
  • 9. Spring configuration web.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. SportController @Controller @RequestMapping("/sport") public class SportController extends AbstractController { @Autowired private 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. 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 3 p: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" ContentNegotiatingViewResolver class="org.springframework.oxm.castor.CastorMarshaller" /> </constructor-arg> </bean></list></property> </bean></beans> (sports-servlet.xml)
  • 12. Examples of API requests:
  • 13. RpcSportsServiceImpl public class RpcSportsServiceImpl extends AutoinjectingRemoteServiceServlet implements RpcSportsService { @Autowired private SportsService sportsService; public Sport findSportById(Long sportId) { return sportsService.findSportById(sportId); } // getters and setters of sportsService }
  • 14. AutoinjectingRemoteServiceServlet public abstract class AutoinjectingRemoteServiceServlet extends RemoteServiceServlet { @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. SportsServiceImpl public 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. 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- Configuration package="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. BaseDaoJdo package com.sports.dao.jdo; import ... public abstract class BaseDaoJdo { @Autowired protected PersistenceManagerFactory pmf; @Autowired protected JdoTemplate jdoTemplate; @Autowired protected JdoTransactionManager transactionManager; }
  • 18. SportDaoJdo package com.sports.dao.jdo; import ... @Component public 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. Cron + TaskQueue cron: - description: Update Sports Counter url: /api/cron/updateSportCounter cron.yaml schedule: every 24 hours
  • 20. UpdateSportCounter @Controller @RequestMapping("/cron/updateSportCounter") public class UpdateSportCounter { @Autowired private 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. UpdateCounterSportTaskQueue public 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. UpdateCounterSportWorker @Controller @RequestMapping("/task/updateCounterSport") public class UpdateCounterSportWorker { @Autowired private 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. Version Control - GIT Decentralization Distributed Version Control Systems take advantage of the peer-to-peer approach. Clients can communicate between each other and maintain their own local branches without having to go through a Central Server/Repository. Then synchronization takes place between the peers who decide which changesets to exchange.
  • 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 don't want to host it on a public service and I don't 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. Thank you for your kind attention busy busy ...