Book Image

Storm Blueprints: Patterns for Distributed Real-time Computation

Book Image

Storm Blueprints: Patterns for Distributed Real-time Computation

Overview of this book

Table of Contents (17 chapters)
Storm Blueprints: Patterns for Distributed Real-time Computation
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Implementing the architecture


Let's now delve into the details of the implementation. For example purposes, the following code assumes the topology is running locally. We use an in-memory queue instead of a persistent queue, and a hash map as our storage mechanism. In a real production implementation, we would most likely use a durable queuing system such as Kafka and a distributed storage mechanism such as Cassandra.

The data model

We will look at each of the topologies in depth, but first, let's have a look at the data model. To simplify things, we've encapsulated the game logic and the data model into two classes: Board and GameState.

The following is a listing of the Board class:

public class Board implements Serializable {
public static final String EMPTY = ' ';
   public String[][] board = { { EMPTY, EMPTY, EMPTY },
{ EMPTY, EMPTY, EMPTY }, { EMPTY, EMPTY, EMPTY } };
    
public List<Board> nextBoards(String player) {
        List<Board> boards = new ArrayList<Board>...