Skip to main content

New EasyCassandra 1.1.0:Work with mult-nodes and sample with Google Guice

Posted by otaviojava on October 3, 2012 at 2:38 AM PDT


    Launched the latest Easy-cassandra version, that come with improvements to manage multi-nodes. Use many node is very usefully in Cassandra because avoid bottlenecks, fault tolerance, elasticity.
    After have multi-nodes in Cassandra, the next step is divide task between their. Secondly join the databases like only one ( reply all information among their, read and write from consistency level, etc.).

    The main strategy that Easy-cassandra use is load balance, in other words, for each requisitions uses different client, there are two ways:
Sequential: Each node receives a crescent number, the order begin in 0 to N-1, in N is instance's number, then all answer of Cassandra (update, create, delete) is used a different client following the crescent order, for example:

  • First request is for Client 0 
  • Second request is for client 1 

     When the number reach to final, this order is come back to client number 0.

    Randomly: It is look like sequential way, give number for each Cassandra's client 0 to N-1, after that for each request is generated a random number.

   For do you these strategy on ORM is extremely simple:

  • First Do create instance's Cassandra 
  • Second Do include nodes in Cassandra 
  • Finally Do create either strategy, inform Keys space's name, if there is not It will create automatically. 

    For show those improvements will used a sample:  The main objective is only retract answer or all user for this question: “What do you think about Cassandra?”.

    For Do this model I will choose tomcat like server, JSF in the view layer and Google Guice like inject dependency.
The inject dependency is a standard for deployment very popular in Java's World, is ideal for stay lower accompaniment over layer's system. This mode the container does injection, some time the programmer doesn't know where come the resources. The Google Guice is a framework open source to injection dependency and the latest version is 3.0.
How the objective is store the user's name and his question, below modeling the object.

public class Post implements Serializable;
    private String nickName;
    private String text;

table1: Object with Easy-Cassandra's annotations

    I am using qualifiers of the Guice, the idea is from annotation be defined the persistence way, random or sequential, that shows in table 2.

@BindingAnnotation @Target({ FIELD, PARAMETER, METHOD }) @Retention(RUNTIME)
public @interface Random {}
@BindingAnnotation @Target({ FIELD, PARAMETER, METHOD }) @Retention(RUNTIME)
public @interface Sequencial {}

table2: using qualifiers with Google Guice

@Inject @Sequencial
    private ServiceClient sequencialClient;
    @Inject @Random
    private ServiceClient randomClient;

table2-a: Injeting with Google Guice
The first step for persistence is add the nodes in Easy-cassandra that shows in table 3. After that do call persistence.

        EasyCassandraManager.getPersistence("javabahia", "localhost", 9160);
        EasyCassandraManager.getPersistence("javabahia", "node2", 9160);
        EasyCassandraManager.getPersistence("javabahia", "node3", 9160);

table3: adding nodes in Easy-Cassandra

public class RandomService extends AbstractService{

public Persistence getPersistence() {
       return EasyCassandraManager.getPersistenceRandom("guice");


public class SequencialService extends AbstractService{

public Persistence getPersistence() {

       return EasyCassandraManager.getPersistenceSequencial("guice");


table4: return Random and sequencial persistence

    In this little post was showed two new strategies for persistence with multi-nodes in Easy-cassandra. The main objective was talk about jobs with other instances, also was talked about dependency injection, Google Guice and its works together with easy-cassandra.

Google Guice: