Skip to content

Commit

Permalink
Add Google Guice example docs
Browse files Browse the repository at this point in the history
  • Loading branch information
patricioe committed Sep 3, 2012
1 parent a8075dc commit b94d597
Show file tree
Hide file tree
Showing 33 changed files with 467 additions and 24 deletions.
Binary file added build/doctrees/content/guice_integration.doctree
Binary file not shown.
Binary file modified build/doctrees/content/poolArchitecture.doctree
Binary file not shown.
Binary file modified build/doctrees/content/virtual_keyspaces.doctree
Binary file not shown.
Binary file modified build/doctrees/documentation.doctree
Binary file not shown.
Binary file modified build/doctrees/environment.pickle
Binary file not shown.
89 changes: 89 additions & 0 deletions build/html/_sources/content/guice_integration.txt
@@ -0,0 +1,89 @@
.. highlight:: java

.. index:: guice

Guice Integration
*****************

The folliwing is just a simple example on how you can inject Hector keyspaces through Google `Guice <http://http://code.google.com/p/google-guice/>`_

HectorModule example
======================

This example assume there is a app.properties file in the path ::

public class HectorModule extends AbstractModule {

private static final Logger log = LoggerFactory.getLogger(DAOModule.class);

private static final String PROP_CASSANDRA_HOST_PORT = "CASSANDRA_HOST_PORT";

private static final String DEFAULT_CASSANDRA_HOST_PORT = "127.0.0.1:9160";
private static final String KEYSPACE = "RIQ";
private static final String CLUSTER_NAME = "Test Cluster";

private String propertyFileSuffix;
private Properties properties;

// private static Properties props;

public HectorModule() {}

@Override
protected void configure() {

// load properties
properties = ConfigLoader.loadProperties(propertyFileSuffix);

// bind so we can retrieve them elsewhere
Names.bindProperties(binder(), properties);
}

@Singleton
@Provides
Properties provideProperties() {
return properties;
}


@Singleton
@Provides
Keyspace provideKeyspace() {
CassandraHostConfigurator chc = null;
// Create the cluster
if (properties.getProperty(PROP_CASSANDRA_HOST_PORT) != null || !properties.getProperty(PROP_CASSANDRA_HOST_PORT).equals("")) {
chc = new CassandraHostConfigurator(properties.getProperty(PROP_CASSANDRA_HOST_PORT));
} else {
log.error("Unable to load cassandra host/port from properties; defaulting to " + DEFAULT_CASSANDRA_HOST_PORT);
chc = new CassandraHostConfigurator(DEFAULT_CASSANDRA_HOST_PORT);
}

chc.setAutoDiscoverHosts(true);
chc.setRetryDownedHosts(true);

Cluster cluster = HFactory.getOrCreateCluster(CLUSTER_NAME, chc);

// Create the long-life Keyspace object
Keyspace keyspace = HFactory.createKeyspace(KEYSPACE, cluster);

ConfigurableConsistencyLevel cp = new ConfigurableConsistencyLevel();
cp.setDefaultReadConsistencyLevel(HConsistencyLevel.QUORUM);
cp.setDefaultWriteConsistencyLevel(HConsistencyLevel.QUORUM);
keyspace.setConsistencyLevelPolicy(cp);

return keyspace;
}

}

And you would typically have a DAO like this ::

public class MyDAO extends MyIFaceDAO {

protected final Keyspace keyspace;

@Inject
public MyDAO(Keyspace keyspace) {
this.keyspace = keyspace;
}
}
1 change: 1 addition & 0 deletions build/html/_sources/documentation.txt
Expand Up @@ -19,6 +19,7 @@ Hector documentation contents:
content/virtual_keyspaces
content/security
content/speed4j
content/guice_integration
content/HOM/hector-object-mapper

Indices and tables
Expand Down
4 changes: 2 additions & 2 deletions build/html/_static/basic.css
Expand Up @@ -79,11 +79,11 @@ div.sphinxsidebar input {
font-size: 1em;
}

div.sphinxsidebar input[type="text"] {
div.sphinxsidebar #searchbox input[type="text"] {
width: 170px;
}

div.sphinxsidebar input[type="submit"] {
div.sphinxsidebar #searchbox input[type="submit"] {
width: 30px;
}

Expand Down
2 changes: 1 addition & 1 deletion build/html/content/FAQ.html
Expand Up @@ -181,7 +181,7 @@ <h3>Navigation</h3>
</div>
<div class="footer">
&copy; Copyright 2011, Patricio Echague (patricioe), Nate McCall (zznate).
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion build/html/content/HOM/hector-object-mapper.html
Expand Up @@ -564,7 +564,7 @@ <h3>Navigation</h3>
</div>
<div class="footer">
&copy; Copyright 2011, Patricio Echague (patricioe), Nate McCall (zznate).
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion build/html/content/api.html
Expand Up @@ -177,7 +177,7 @@ <h3>Navigation</h3>
</div>
<div class="footer">
&copy; Copyright 2011, Patricio Echague (patricioe), Nate McCall (zznate).
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion build/html/content/community.html
Expand Up @@ -183,7 +183,7 @@ <h3>Navigation</h3>
</div>
<div class="footer">
&copy; Copyright 2011, Patricio Echague (patricioe), Nate McCall (zznate).
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion build/html/content/composite_with_templates.html
Expand Up @@ -262,7 +262,7 @@ <h3>Navigation</h3>
</div>
<div class="footer">
&copy; Copyright 2011, Patricio Echague (patricioe), Nate McCall (zznate).
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion build/html/content/consistency_level.html
Expand Up @@ -186,7 +186,7 @@ <h3>Navigation</h3>
</div>
<div class="footer">
&copy; Copyright 2011, Patricio Echague (patricioe), Nate McCall (zznate).
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion build/html/content/cql_basics.html
Expand Up @@ -285,7 +285,7 @@ <h3>Navigation</h3>
</div>
<div class="footer">
&copy; Copyright 2011, Patricio Echague (patricioe), Nate McCall (zznate).
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion build/html/content/getting_started.html
Expand Up @@ -290,7 +290,7 @@ <h3>Navigation</h3>
</div>
<div class="footer">
&copy; Copyright 2011, Patricio Echague (patricioe), Nate McCall (zznate).
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion build/html/content/getting_started_sample.html
Expand Up @@ -149,7 +149,7 @@ <h3>Navigation</h3>
</div>
<div class="footer">
&copy; Copyright 2011, Patricio Echague (patricioe), Nate McCall (zznate).
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
</div>
</body>
</html>

0 comments on commit b94d597

Please sign in to comment.