Chariot Training Classes

Training Courses

I run Chariot's training and mentoring services. We provide training in AngularJS, HTML5, Spring, Hibernate, Maven, Scala, and more.

Chariot Education Services

Technology

Chariot Emerging Tech

Learn about upcoming technologies and trends from my colleagues at Chariot Solutions.

Resources

Chariot Conferences

Podcasts

Monday
Oct062008

Google Guice, First Look

This is the first in a series of articles on Google Guice. I've been working with Chariot Architect Lyle Anderson, who has done a lot of research on wiring together an application using this Inversion of Control framework.

Overview

Guice is an annotation-driven IoC framework, meaning that, once bootstrapped, Guice will inject classes based on annotated code, rather than XML files. There are advantages and disadvantages to each approach, so I'm not espousing either one, but if you're into XML-driven configuration, you should probably look at Spring or another XML-based platform.

A simple Maven build

To start building Guice, you need to construct a build file. I use Maven for much of my development, so I started with a very thin build file. An excerpt of the maven build file:


<project ...>

<modelVersion>4.0.0</modelVersion>
<groupId>com.rimple.guice.demo</groupId>
<artifactId>simpleguiceapp</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>guicewebapp Maven Webapp</name>
<url>http://maven.apache.org</url>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.guice</groupId>
<artifactId>guice</artifactId>
<version>1.0</version>
</dependency>

</dependencies>
</project>

Now, placing a simple file in src/main/com/rimple/guice/GuiceRunner.java, we can run the application under Maven using the exec:java goal:


mvn -e exec:java -Dexec.mainClass=com.rimple.guice.GuiceRunner

Now we have a simple test bed in which to place our test Guice application.

A Simple Guice configuration

Guice is bootstrapped by building an Injector. The Injector exposes a method, getInstance(Class) that is used to pull an initial bean out of the context. It is configured using the Guice.createInjector() method, which takes several parameters:


  • A Stage enum, which is either DEVELOPMENT or PRODUCTION. DEVELOPMENT provides quick startup, but will incur more overhead at runtime and log more details to the error logging system. PRODUCTION takes longer to load but performs diagnostic checks at startup in order to speed runtime performance.

  • A varargs list of Modules, which are units of configuration. Each module has its' own configuration which is defined using a Guice DSL defined in the configure() method. A sample configuraiton, from Lyle's calculator:


    public class CalculatorModule extends AbstractModule {
    @Override
    protected void configure() {
    bind(Calculator.class)
    .to(CalculatorImpl.class)
    .in(Scopes.SINGLETON);

    bind(PrintService.class)
    .to(PrintServiceImpl.class)
    .in(Scopes.SINGLETON);

    bind(MemoryService.class)
    .to(MemoryServiceImpl.class)
    .in(Scopes.SINGLETON);

    bind(CalculatorOperationDAO.class)
    .to(HbmCalculatorOperationDAO.class)
    .in(Scopes.SINGLETON);

    ... etc..

    So, to configure the Injector to include a CalculatorModule, you may bind it this way:


    Injector injector = Guice.createInjector(Stage.PRODUCTION, new CalculatorModule());

    To use a class configured within the injector, such as the PrintService, you need to call the injector's getInstance() method. From there, any annotated classes defined in the Injector will be wired in automatically. For example:


    PrintService printService = (PrintService) injector.getInstance(PrintService.class);

    Next Steps

    In part two, we'll cover the annotations themselves, and how they are used by the injector.

Monday
Oct062008

Chariot Techcast with Dan Diephouse of MuleSource

I've just edited and posted a podcast with Dan Diephouse of MuleSource on the Chariot Tech Cast site. We talk about SOA, specifically Apache XFire, CxF, and MuleSource's Mule. We also discuss REST -vs- the WS-* model.

You can listen to the podcast here or view the show notes here.

Enjoy,

Ken

Monday
Oct062008

Amazon Revs up Cloud Platform

It's been a busy month for the Amazon Web Services teams. In reading the October newsletter, I'm amazed at how much they have added recently:

If I had more time, I'd become proficient in all of these technologies. However, you and I can both benefit by meeting and listening to Amazon's Jeff Barr at our Fall Forecast Cloud Conference (shameless plug) held on October 17th in Malvern, PA. I'm wondering what Google has up their sleeves (they are there too!). Register now, time is getting short!

Saturday
Oct042008

Cloud Computing Conference, October 17th

Chariot Solutions is sponsoring a conference on Cloud Computing on Friday, October 17th at the Penn State Great Valley campus.

We have some big names attending:


  • Jeff Barr of Amazon.com speaking about Amazon's EC2 and S3 Cloud Computing platform

  • Joe Gregorio and Johnathan Rochelle of Google, talking about Google App Engine and Google Spreadsheets

  • Justin McCarthy and Britt Crawford of Cafe Press, the developers of HiveDB, a cloud-capable database platform

  • Prasaad Chakka of Facebook, speaking about data warehousing in the cloud with Hive

  • Chris Richardson, author of "POJOs in Action" and developer of CloudTools, a mechanism for deploying Java and Groovy applications in the cloud

  • Ezra Zygmuntowicz of Engine Yard, a Rubyist, developer of MERB (a high performance alternative to Ruby on Rails) and author of Vertebra, a cloud computing platform

There are several more sessions, including an hour-long panel talk hosted by yours truly on using Amazon and other cloud platforms with local experts Toby DiPasquale, Chis Cera, and Andrew Kortina. We are also in talks with Microsoft about their attendance, and they would like to get the word out on their new Windows Cloud Computing platform. Stay tuned!

If you're interested, the web site is http://www.cloudconeast.com. I hope to see you there!

Wednesday
Oct012008

Apple a little more open?

Must be the Google phone pushing open Apple's developer relationship...

Apple iPhone Developer NDA dropped!