Sunday, May 17, 2015

I still like Java

Ok I am a crusty old Java programmer. The trouble is that I started out as a crusty old Perl programmer, and when I realized there was a language out there that was both performant AND readable, I jumped on the bandwagon and stayed there happily.

Fifteen years later I'm reading stuff like this: http://tech.jonathangardner.net/wiki/Why_Java_Sucks and weeping. In the intervening 15 years I've enjoyed experimenting with quite heavily in other languages such as C#, Objective C, and Javascript (in particular, Node).

My heart *still* belongs to Java, because of its clarity, emphasis on maintainability, support by the best IDEs, and huge developer/library/tooling ecosystem.

I'm still new to Java 8 and its idioms, but the new lambdas and stream language features are really nice:

List<Challenge> challenges = lobbyDAO.getChallengesFor( challengedPlayer );
Optional<Challenge> first =
        challenges
        .stream()
        .filter(challengeID -> {
            if (challengeID.isChallengeExpired()) {
                removeExpiredChallenge(challengeID.getChallengeID());
                return false;
            } else {
                return true;
            }
        })
        .findFirst();


I am looking forward to learning more about the Java 8 features, including native support for Javascript (aka Nashorn). The future on the JVM seems bright to me, regardless of very vocal detractors!

Saturday, May 16, 2015

Tic Tac Toe Service Design - The Lobby

I'm going to start this simple. Basic idea is that players discover other players who are looking at the Lobby. Clients poll the Lobby for challenges and responses to challenges. When a challenge is accepted, the Lobby contacts the Game service and creates a matchID. Both players get the matchID and either player can start the match.

Yes yes I know, polling is evil. But I wanted to build a RESTful service and didn't want to create yet another task app. In real life I would implement this as websockets or some such technology, and that conversion might be an interesting topic in the future.

I'm using websequencediagrams.com (this is the awesomeness) to draft out the ideas.




Here's the "source code":

title Tic Tac Toe Service - starting a game
Player1 -> Lobby: joinPlayer2 -> Lobby: join
Player1 -> Lobby: challenge Player1loop challenge polling, until timeout or challenge response received  Player1 -> Lobby: challenge response?  opt accept    Lobby -> Game: create matchID    Game -> Lobby: matchID    Lobby -> Player1: accept: matchID    Player1 -> Game: start match: matchID  end  opt reject    Lobby -> Player1: reject    Player1 -> Player: stop challenge polling  end  opt timeout    Player1 -> Player: stop challenge polling  endend
loop match polling, until challenge performed  Player2 -> Lobby: any challenges pending?  Lobby -> Player2: challenge available  opt accept    Player2 -> Lobby: accept    Lobby -> Lobby: prepare accept    Lobby -> Player2: matchID  end  opt reject    Player2 -> Lobby: reject    Lobby -> Lobby: prepare reject  endend
Player1 -> Game: start game: matchIDGame -> Game: prepare game
How the Game service should go about orchestrating a match is the subject of my next post.

Tic Tac Toe - a microservices adventure

In my day job, I wrote a modestly popular microservices container in NodeJS (https://www.npmjs.com/package/jive-sdk).

I'm gonna embark on a tangent now, and build a microservice stitching together the following tech:
  • Dropwizard (http://www.dropwizard.io/)
  • Guice (specifically dropwizard-guice: http://www.codingricky.com/dropwizard-and-guice-integration/)
  • Docker (http://www.docker.com/
  • AWS (http://aws.amazon.com/)
  • Shippable (http://www.shippable.com/)
  • Selenium (http://www.seleniumhq.org/) and Selenium Grid
... for the servier.

For the client, I am planning initially on Cordova (https://cordova.apache.org/) because I am too lazy to write a native client ;) but that might change.

My buddy and all around mensch Jesse is experimenting with Cordova, so I thought I might go this route as well.

The game plan is to build up a continuously integrated backend service in AWS, deployed as a Docker container. Then build a simple client for folks to try it.

This is gonna be fun...!