Monthly Archives: September 2014

Log your miles and community runs: Java EE 7 Real World Experience

miles2run-logo

miles2run.org is an easy way to track your running activities and share with friends and families. Day-based or distance-based goals can be created and then tracked. It also allows to create community run goals and have multiple runners participate and track their activities towards that goal. You can also find out local runners and connect with them.

The project was started to help track running activities for #JavaOneStreak. The goal was to run at least a mile every day all the way until JavaOne and use this website to track the runs. There are tons of sophisticated applications and websites that allow you to track running activity. Most of them provide integration with your GPS watch, phone GPS, and other fancy features. Some of them even allow creating a group but none of them is based on Java :-)

The application is hosted as a website and built using HTML5 and Java EE 7. The landing page provides a summary of total runners, their city/country, miles, and hours logged so far.

miles2run-landingpage

The website can be viewed on a desktop, tablet, or a cell phone. The runners can login to the website using common social brokers such as Facebook, Google, and Twitter.

Any body can click on “Community Runs” on the top-right corner to see what all group runs have been created so far. These can only be created by an administrator. The group run page for JavaOne shows how many runners have joined this run and other statistics.

miles2run-javaone-mainpage

Each runner is presented with a dashboard showing how much distance they’ve run so far and total/completed/remaining/missed days.

miles2run-javaone-dashboard1

A visual representation of the progress and a heat map of the activity calendar is shown:

miles2run-javaone-dashboard2

A line chart of mileage over the days is shown:

miles2run-javaone-dashboard3

And then a summary of activities over the past months is shown as well:

miles2run-javaone-dashboard4

Runners also have the opportunity to follow other runners and track their activities.

Here is a conceptual view of the application:

miles2run-architecture

And here is a technology view of the application:

miles2run-tech

Here is a brief description of the technology stack:

  • Presentation
    • Thymeleaf template engine views rendered by JAX-RS
    • Social brokering using native APIs for Facebook, Google, Twitter
  • Middle Tier
    • @Stateless EJB for all transactional JPA interactions, @Asynchronous for posting status to social networks
    • JAX-RS for exposing REST endpoints. ContainerRequestFilter and ContainerResponseFilter for security for cross-cutting concerns like authentication, injecting profile, and CORS.
    • Bean Validation constraints in JAX-RS resources.
    • Bean discovery mode=”all”
  • Backend
    • CDI producers for creating EntityManagers and other configuration objects like Redis connection pool objects or MongoDB configuration object. All NoSQL services are created @ApplicationScoped.
    • Using native drivers for Redis and MongoDB. Jedis is being used for Redis and MongoDB Java driver is used for MongoDB. CDI services wrap these driver API and expose business functionalities that other layers could use.
    • JPA + Bean Validation. Database scripts are generated from JPA model, added to source control, manually applied to the database. Using @Index and Entity Graph.
    • Servlets are used for callback URLs for social brokers.
    • Error pages are configured using <error-page>.
    • MySQL is used for all business entities like Activity, Goal, User Profile etc. Redis is used for storing counters and timeline data. MongoDB is used for location-based user recommendations and follower/following recommendations.

Technologies from outside the platform:

  • JavaScript
    • D3.js and C3.js for visually appealing graphs
    • AngularJS for views
    • Cal Heatmap for calendar heatmap
    • jQuery
  • Google Geocoding API to convert Location Text to latitude and longitude
  • Jadira usertype for storing dates in UTC
  • Joda-Time for working with dates
  • Thymeleaf was used instead of JavaServer Faces because:
    • Allows JAX-RS to be used as an MVC framework to render server side HTML pages and exposing REST services.
    • This application is a Single Page application built using AngularJS. So, we needed a lightweight approach to render server side pages. JAX-RS along with Thyemleaf render the main HTML 5 page and then we use AngularJS to render different partials/views on that page. For example, the main home page is rendered by JAX-RS and Thymeleaf. When you work with different sections of this page all of them are part of a SPA managed by AngualarJS.
    • Thymeleaf documents are valid HTML 5 documents so you can work with them offline for static prototyping.
  • Redis is used for storing all the counters like number of runners, cities, counters specific to goal like total distance covered in a goal etc. To avoid lots of read/write from the database, an an in-memory database is used so all the write and read operations are very performant. Redis counters are atomic, which means there are no concurrency issues associated with it. INCR andINCRBY Redis operations are used to update counters.
  • MongoDB is used for location data.

Toolset

  • JDK 8
  • IntelliJ 13.1 with Maven
  • Wildfly 8.1.0.Final – Development was done using a local WildFly instance and then pushed to scalable WildFly instances on OpenShift for deployment. HA Proxy is used as the load balancer.The advantage of working with OpenShift is that there is no OpenShift specific code in your application. So, it’s the same application that work locally that is deployed to test and production environment. You just have to use environment variables to abstract out environment specific configuration.
  • Github

Planned updates

  • Use Jenkins for Continuous Integration and manage deployments
  • JPA 2.1 converter instead of Jadira
  • Keycloak instead of native social broker
  • Opensource the application

Wish list for Java EE 8

  • Integration with OAuth providers
  • A real MVC framework with support for pluggable template engines
  • Seamless working with NoSQL databases

Download WildFly 8.1 today, learn the technology by reading/trying Java EE 7 samples, browse through Java EE 7 resources.

Or if you want to be on the bleeding edge, check out WildFly 9.0.

Many thanks to Shekhar Gulati (@shekhargulati) for authoring the application and providing all the answers!

Are you using Java EE 7 and WildFly to deploy your projects ? Would love to feature you here! Send me an email or leave a comment on the blog.

Java EE 7, JBoss, WildFly, Devoxx4Kids, and Parties at JavaOne 2014

JavaOne 2014 is about a week away, although some of festivities will start next Friday! This is going to be my 16th JavaOne in as many years and I’ve really enjoyed participating in each one of them. As always, there is great content lined up with rockstar speakers. This conference is a confluence of movers and shakers in the Java world and provides plenty of opportunities to engage with them. This is going to be my first year as Red Hatter and looking forward to catching up with friends and colleagues.

And in case you are wondering, and care about it, here are my engagements for that week:

Saturday, Sep 27

Devoxx4Kids Day
7pm – 11:30pm: NetBeans Party

Sunday, Sep 28

8am – 9:30am, Java Champions Brunch
7pm – 8:30pm: Duke Choice Awards
8pm – 11pm: Java EE Appreciation Event

Monday, Sep 29

8:30am – 10:30am Java EE 7 Soup to Nuts Tutorial [TUT1952]
11:30pm – 12:30pm Meet the Experts on Java EE and HTML5 Enterprise Application Development
1:30pm – 2:00pm Java EE 7 Essentials book signing at O’Reilly Booth

Tuesday, Sep 30

8:30am – 10:30am: Devoxx4Kids for Parents Tutorial [TUT1878]
12:30pm – 1:30pm: Lessons learned from real-life Java EE 7 Deployments [CON2450]
2:30pm – 4pm: Java EE Hackergarten
6pm – 9pm: Oracle Authors Appreciation Party
7pm – 9pm: JavaOne IGNITE
7pm – 10pm: PartyOne
7pm – 9:30: Java Champions Social
8pm – 8:45pm: Technology Evangelists Gathering [BOF12166]

Wednesday, Oct 1

1pm – 1:30pm: Book signing on Java EE and HTML5 Enterprise Application Development book (OOW bookstore in Moscone South, Upper Hall Lobby)
4pm – 6:30pm: #JavaOneStreak meetup, Hilton San Francisco Union Square, Sutter

Thursday, Oct 2

11:50: Broadening JCP Program Participation [CON9775]

I’ll also be running my own “hallway track” and so feel free to meet there. Of course, you can catch me at Red Hat booth as well!

There are lots of Red Hat speakers and sessions at the conference as well. And if you are not able to attend a Red Hat session then you can check out the mini-sessions in the exhibit hall.

See ya there!

Advise to Microsoft on Mojang and Minecraft

Microsoft bought Mojang for $2.5 billion, wow! Here is official press release by Microsoft.

minecraft-logo

The game is extremely popular within 8-14 years of age range, but also within other ages, including adults, as well. The education community has been extremely excited because of all the opportunities it provides to engage kids at an early age and teach them Java programming, object-oriented, and mathematical concepts by “modding” the game. The community is highly engaged, passionate and diverse. This “global phenomenon” indeed binds the community very well and gives them a common language to talk with each other. My son has been attending Minecraft-themed birthday parties for last 3 years. There are halloween costumes, 3d printed Minecraft worlds, tshirts, hoodies,  hats, slippers, swimming trunks, plates, spoons, and you name it, its all there!

On a personal level, My son and I’ve personally delivered multiple Minecraft Modding workshops around the San Francisco Bay Area. This workshop has also been delivered around the world by Devoxx4Kids volunteers, and even translated in German, Dutch, and French.

My first reaction to this purchase was a grandpa company that is desperate to be innovative just used their cash power to buy a company behind one of the most innovative game. I felt really miserable, especially knowing that the game is written in Java. Microsoft has no significant history of delivering or maintaining Java programs particularly. I may be wrong, but Microsoft J Sharp is dated 2006. And Visual J# was removed from Visual Studio a few years ago as well. Heck, you even need to install JDK on a Microsoft Windows machine.

Microsoft is known to provide tight integration within their portfolio. So another thought that came was that Microsoft will start integrating Silverlight, .NET, Office 365, Exchange integration, and their complete slew of Windows-specific technologies in the game. May be all backed Microsoft Access, Sharepoint, and Azure, oh no!

Another thought came to mind was that the newer features of the game will be released on XBox first, and then probably limp along on PC and other platforms later. May be make the game exclusive on Windows-based mobile phones, I hope not!

In general, the younger generation seems to not be very excited with Microsoft ecosystem. Anything ranging from virus-infected Windows, legacy Internet Explorer, to mobile phones. At least, that’s the reaction I’ve seen and heard from my family, friends, and hackathons around around the world. Players play Minecraft if they have XBox, they don’t buy XBox because they want to play Minecraft. The experience on PC/Desktop is pretty good IMHO. Although you can easily host a server and then join from any device, which is the cool part about the game.

I seriously hope, I’m wrong on all these initial, may be somewhat emotional, reactions. I really hope so!

Phil Spencer (head of Xbox, @XboxP3) has made it clear that “we plan to continue to make Minecraft available across platforms – including iOS, Android and PlayStation, in addition to Xbox and PC. ” I hope they stick to their promise on PC at the least 😉

Notch (@notch) has left Mojang already, and so have other co-founders. Minecraft was not intended to grow this big but it turned out to be, and he does not want to be responsible for it now. I respect that he likes to enjoy building games, and would continue to do so. The BIG payoff is accidental, and will allow him to focus his energy on what he is good at.

As father of an avid modder, an educator, Java evangelist, Java Champion, JUG leader, software engineer, here is my wish list for Microsoft to help with Minecraft:

  1. Maintain Minecraft on PC/desktop as a first class game. Make sure the latest snapshots are always available on PC first than any other platforms.
  2. Mojang has talked about delivering an official modding API for the past 2+ years but the status is unclear. It has been very disappointing to see Bukkit dying but fortunately there is Forge and other modding platforms. Deliver a formal modding API within next one year would really allow Microsoft to gain huge favors.
  3. Provide simpler tools/IDE that allow to create mods easily. Eclipse, IntelliJ, and NetBeans are too complex to be used by young developers. Please do not require Visual Studio or any other similar heavy weight tools to be downloaded in order to facilitate it though.
  4. Start bundling JDK with Windows machine so that Minecraft can run out-of-the-box instead of requiring to download it separately. Work on your relationship with Oracle, and help developers instead of getting stuck in your own rut.
  5. Keep Minecon as a separate conference. Do NOT mix it with other Microsoft shows. And organize it more frequently around the worlds.
  6. Start a formal Minecraft User Group (MUG) community where players can open local user groups and exchange ideas.
  7. MVP could now also embrace Minecraft Valueable Player.
  8. Open source Minecraft ?
  9. Do not introduce any Microsoft technologies in the game, keep it true Java on PC.
  10. Mojang launched Realms a few months. Make it more widely accessible.

If there is one thing Microsoft need to do about Minecraft, that is to at least maintain the same experience of the game on PC, or only make it better. DON’T screw up there, otherwise you’ll completely loose the community.

I’m happy that a big company is behind the game now. Hopefully, you’ll take the game to new heights, empower the community more, and truly help address the issues with your experience.

Good luck Microsoft!