Speaking at SpringOne2GX 2010

14 July, 2010

 Several weeks ago, I got a nice advance birthday gift by learning that I will be speaking at SpringOne2GX. The conference happens to start on the same day as my birthday. I'll be presenting "Griffon for the Enterprise" at 1630h(4:30P) on Thursday the 21st. Make sure to catch the other Griffon sessions presented by Andres Almiray at 12:45 and 1445(2:45P) that same day.

If you haven't signed up yet, do it now before the price jumps up. Register here

0 comment(s)

Griffon at Chicago Groovy Users Group

18 May, 2010

Next month, on June 8th, I'll be presenting at the Chicago Groovy Users Group on Griffon. I'll be covering the basics of Griffon development and give some tips on how to port legacy applications from Java. Come one, come all.

You can sign up to attend here.

0 comment(s)

Motej with Groovy

14 May, 2010

In my presentation at GeeCon 2010, I showed how you could use Groovy to interact with the Nintendo Wiimote, here is the code and a little explanation from one of my demos.

  • Install OS specific native Bluetooth libraries
  • Grab the jars for the Java JSR 82 implementation. Either BlueCove or Aventa. Note that Aventa only has a 14day trial and BlueCove requires linking to an extra gpl jar if you use it on Linux. Mac users on Snow Leopard will have to compile Bluecove from source.
  • Grab slf4j-api-1.5.8.jar and slf4j-simple-1.5.8.jar.

Open a Groovy console and add all the jars (bluecove-2.1.0.jar, bluecove-gpl-2.1.0.jar [if on Linux] and the slf4j jars) to the classpath using Script -> Add Jar to classpath.
Copy the following code into the console.

import motej.*
import motej.event.*

def listener = [moteFound:{Mote mote ->
      println("Found mote: " + mote.getBluetoothAddress())
      mote.setPlayerLeds([false, true, false, true] as boolean[])
      mote.rumble(2000l)
      Thread.sleep(10000l)
      mote.disconnect()
   }
] as MoteFinderListener        
                
MoteFinder finder = MoteFinder.getMoteFinder()
finder.addMoteFinderListener(listener)
                
finder.startDiscovery()
Thread.sleep(30000l)
finder.stopDiscovery()

The above code starts discovery for controllers, registers a listener that rumbles the wiimote and changes the LEDs, and disconnects and stops discovery after a delay. You can activate your Wiimote for discovery by pressing the 1 & 2 buttons at the same time.

You can also download the source and libs in a ready-made project here.

0 comment(s)

MongoSF videos

10 May, 2010

 If you weren't able to attend MongoSF, you can now view the videos and slides from some of the sessions here. All the videos haven't been uploaded yet so check that link and often over the next week or so to see what's new.

Below is the video from my afternoon session. The morning session went without a hitch so karma fated this one to have technical difficulties (oh well). Enjoy!

 

0 comment(s)

Using MongoDB with Morphia and Groovy

05 May, 2010

As I mentioned in this post, I live coded a blog site using Morphia and MongoDB in my workshop session at MongoSF. I used Grails as the platform to quickly scaffold the application. One might wonder why I didn't use the Grails plugin. I used Morphia because it aligns with traditional Java paradigms and didn't want to have too many new items by using a full Groovy stack.

Setup

After installing MongoDB, you will need a version of the Java driver and the Morphia library. Make sure to use the latest snapshot.

Creating the mapped objects

Morphia uses Java annotations to describe how to persist objects in the database. The following annotations are available:

  • @Id - marks the MongoDB id field to be autogenerated
  • @Entity - marks the class to be persisted as an object and optionally the collection
  • @Embedded - tells Morphia to embed this object in another
  • @Reference - analogous to MongoDB DBRef
  • @Indexed - prepare an index for this property
  • @Serialized - store as BSON
  • @Property - indicates that the property name in MongoDB will be different than in the object
  • @Transient - doesn't persist the property

As you may already know, Groovy adds a few properties to objects. You will get an error that it won't persist the unmapped fields but it doesn't inhibit execution. Our BlogEntry class contains a title field, date it was created, content, a MongoDB document id and an embedded list of comments.

import com.google.code.morphia.annotations.*

@Entity
public class BlogEntry implements Comparable{
	@Id  private String id
	
	String title
	Date dateCreated = new Date()
	String content
	
	@Embedded
	List<comment> comments = [ ] 	 	  	
}

Similarly, our Comment object contains properties for the name, dateCreated, and content. Please note that both places that refer to Comment need the @Embedded annotation.

import com.google.code.morphia.annotations.*

@Embedded
public class Comment {
	String name
	Date dateCreated = new Date()
	String content
}

While you can marshal/unmarshal objects from POJO/POGOs to BasicDBObjects and persist them to a collection by hand, it is much simpler to use a data access object(DAO) which provides all the CRUD functions for you.

import com.mongodb.Mongo
import com.google.code.morphia.*

public class EntryDAO extends DAO {
    public EntryDAO(Morphia morphia, Mongo mongo) {
       super(mongo,morphia, "entries")
    }
}

In this snippet, I initialize a DAO object, create BlogEntry and Comment objects, persist them to the DAO, and read them back out to prove they were stored. Please excuse the Java-ness of the code but I didn't want to blow people's minds with too much Groovy.

import com.mongodb.*
import com.google.code.morphia.Morphia

mongo = new Mongo()
morphia = new Morphia()
dao = new EntryDAO(morphia, mongo)

entry = new BlogEntry()
entry.setTitle("Test Entry")
entry.setDateCreated(new Date())
entry.setContent("This is a test entry.")

comment = new Comment()
comment.setDateCreated(new Date())
comment.setContent("Test comment")

entry.comments = []
entry.comments.add(comment)

dao.save(entry)
entries = dao.find()
entries.each {
    println it.properties
}

With a running instance of MongoDB, you could run all these bits in a Groovy console and see it in action. In the next post, I'll cover how to integrate these classes into a Grails application.

 

4 comment(s)

Java at MongoSF

03 May, 2010

As has come to be expected the 10gen-ers have put on a great conference. It's almost like a MongoDB world domination tour with the NoSQL Live in Boston this March, MongoSF and MongoNYC this month and MongoEU this summer. There seemed to be bigger numbers of Ruby and Python devs but that wasn't so surprising given that they tend be early adopters compared to Java devs. Because of that I believe the path to reach Java developers is to show them that they don't have to throw away all their code to use MongoDB. My morning session capitalized on that and used Grails to show how you could quickly wire up persistence using DAOs with Morphia and MongoDB.The afternoon session that was a bit more high level primer for what was covered in the morning. 

 
The schwag was well thought out too. Speakers got really snazzy embroidered MongoDB polos. There was an update of the mugs from NoSQL Live featuring the MongoDB branding on the one side with 10gen branding on the other. 
 
Slides from the conference are here. Videos from the sessions should be coming soon. Check the 10gen blog for updates.
 
 
It was also great news to learn that there are several books on MongoDB set to release this fall. 
 
 

0 comment(s)

Presenting at GeeCon 2010

22 March, 2010

I'm happy to announce that I'll be in Poland this May to present at GeeCon. I'll be giving a preso titled "Game Programming with Groovy." While it's isn't mentioned in the title, there will definitely be a Griffon component.

GeeCon takes place on May 12-14 in Poznan, Poland. You can find out more information about the conference or register here.

0 comment(s)

NoSQL Live 2010 recap and MongoSF

18 March, 2010

Last week, I attended NoSQL Live in Boston. The conference was organized by 10gen and Hashrocket. Besides the normal plights of a conference (wifi), it was really well put together event. Check out the 10gen blog for other posts and media from the event.

Due to a last minute cancellation, I gave a lightning talk titled "Using MongoDB with Groovy." (slideshare) I highlighted how Groovy's metaprogramming and post-Java nature makes it a philosophical match for the post-relational and schemaless nature of MongoDB. Though there was video streaming of the event, a server crash caused those files to be lost. However Christian Scholz recorded MP3s of the event available at the 10gen link above.

10gen has decided to have another one-day conference in San Francisco on April 30th. This time the focus for all sessions will be MongoDB. I will be giving a talk on Java development with MongoDB. You can find out more information here or register for the event here. Early bird pricing of $50 ends on April 9th.

0 comment(s)