JEE and NoSQL on OpenShift

Sign up code: judconbr13wk

Presented by:

Steven Citron-Pousty

@TheSteve0 on Twitter, IRC, and Github


  1. Learn a bit about PaaS
  2. A little about OpenShift
  3. Write some code


  1. You like writing code rather than managing servers
  2. You can use command line, git, and ssh

But I know EC2...

One Source to Bind Them All




But wait - there's more

  1. Free! No time limit
  2. 3 gears (like servers) - each 512 Mb RAM, 1 Gb disk
  3. Auto-scaling
  4. Simple pricing
  5. We are coming out of developer preview this summer


Now it's your turn

  1. Install the rhc command line tools (or the eclipse plugin)
  2. Make (or change to a dir. where you want the source code to end up
  3. Make a JBoss EAP 6 app with Mongo
    rhc app create javaws jbosseap-6 mongodb-2.2
  4. Go into the git repo and look around. Then go into the src / main / webapp dir
  5. Edit the snoop.jsp page on <h1> element to say something else
  6. Push the changes to OpenShift
    git commit -am "Your message"
    git push
  7. SSH in and look around


  • Context Dependency Injection - allows you to make classes availble whenever you need them and let the calling class decide which class it wants
  • JAX-RS - the antiSOAP (three cheers). Makes it super easy to write REST like architectures

On to NoSQL and Mongo


Types of NoSQL datastores

TYPEDocumentKey-ValueGraphData ProcessingMisc
EXAMPLE MongoDB, Couchbase Redis, Riak, Memcahe Neo4J Hadoop, Cassandra, Voldemort Lucene/Solr/ElasticSearch, VoltDB
USE-CASE Document storage and search Caching or Object Store Relationships between "things" Large data processing Depends

A bit about MongoDB

  • A document is just a bunch of attributes and values - think of it like HashMap
  • Can be nested - helps avoid joins
  • Schemaless
  • Really good at fast writes - but you give up immediate consistency
  • Easy to horizontally scale

Now some spatial

The spatial functionality Mongo currently has is:

  1. Near
  2. Containment

It is all laid out here:

Geospatial Indexes and Queries

and here:

Geospatial Index Internals

Good to Know

  • Assumes coords. are between [-180 and 180)
  • Can handle any 2D coordinates
  • Has methods to handle curvature of the earth (spherical)

How do you make it work

1. Put coordinates into an array

{ loc : [ 50 , 30 ] }
{ loc : { x : 50 , y : 30 } }
{ loc : { foo : 50 , y : 30 } }
{ loc : { lon : 40.739037, lat: 73.992964 } }
                    If you use spherical make sure to put [lon, lat]

2. Make a 2D index

				    	db.places.ensureIndex( { loc : "2d" } )

Let's look at some code

Let's wrap it up

  1. Openshift makes life great for you
  2. Spatial is easy and fun with MongoDB
  3. Free!

Come hang out with us:
#openshift on freenode irc