Cassandra Client

Leave a comment

  1. For quick introduction of Cassandra Data Model : Cassandra Data Model of Max Version
  2. CLI API Exercise :Note 1 – For every command or statement you enter into the CLI, make sure you enter a semicolon at the end before hitting the return key. If you forget to do this, the CLI echos an ellipsis ( . . . ), which indicates that the CLI expects more input – such as a semicolon, or names and values in other cases.

Connect to “Test Cluster”

$ ./cassandra-cli -host localhost -port 9160

Create KeySpace

[default@unknown] create keyspace twissandra with replication_factor=1and placement_strategy=’org.apache.cassandra.locator.SimpleStrategy’;
More reference of KeySpace, you could find in the following link – Cluster about Key Spacing

Creating a Column Family

[default@unknown] use twissandra;
Authenticated to keyspace: twissandra
[default@twissandra] create column family users with comparator = UTF8Type
…     and column_metadata = [{column_name: password, validation_class:
…     UTF8Type}];
[cc792bbc-5ecb-11e0-9ff3-f038a2a19b21] <= output schema of password

Similar commands to create the columns families for Twissandra tweets, followers, userline and timeline would look like the following:

[default@twissandra] create column family tweets with comparator = UTF8Type and column_metadata = [{column_name: body, validation_class:UTF8Type}, {column_name: username, validation_class: UTF8Type}];
[5385025d-5ecc-11e0-9ff3-f038a2a19b21] <= output schema of tweets

[default@twissandra] create column family friends with comparator = UTF8Type;
[61c0f5ee-5ecc-11e0-9ff3-f038a2a19b21]<= output schema of friends

[default@twissandra] create column family followers with comparator = UTF8Type;
[6d62ddaf-5ecc-11e0-9ff3-f038a2a19b21]<= output schema of followers

[default@twissandra] create column family userline with comparator = LongType and default_validation_class = TimeUUIDType;
[78bac420-5ecc-11e0-9ff3-f038a2a19b21]<=output schema of userline

[default@twissandra] create column family timeline with comparator = LongType and default_validation_class = TimeUUIDType;
[8504d2c1-5ecc-11e0-9ff3-f038a2a19b21]<=output schema of timeline

Inserting and Retrieving Columns

[default@twissandra] set users[‘jsmith’][‘password’]=’ch@ngem3′;
Value inserted.
[default@twissandra] get users[‘jsmith’];
=> (column=password, value=ch@ngem3, timestamp=1301929424925000)
Returned 1 results.

Note 2 – For all CLI write and read operations such as these example commands, the consistency level is ONE. Different consistency levels are not available with the CLI, though all levels are available when writing/reading programatically.


Cassandra Cluster

Leave a comment

1, Installation Cassandra on Windows Host

As configuration location will be read out via Environment variable CASSANDRA_HOME, so in linux or windows environment, please set CASSANDRA_HOME in running process accordingly.

2, Cluster Configuration

* tokens calculation for new adding nodes
python version [in python 3.2]

def tokens(nodes):
for x in range(nodes):
print (2**127/nodes*x)

Java version – BigInteger [stored in virtual ubuntu system]

import java.math.BigInteger;

public class PythonCal{
public static void main(String[] args){
int iCodes = Integer.parseInt(args[0]);
BigInteger t = BigInteger.valueOf(2).pow(127).divide(BigInteger.valueOf(iCodes));
for(int i=0; i<iCodes; i++){

* seeds – ip address of the initial tokens server
* listen_address and rpc_address will be filled with

3, load balance – $CASSANDAR_HOME/bin/nodetool -h -p 8080 ring
Current status

Starting NodeTool
Address Status State Load Owns Token
122378085476254521922132626725931733214 Up Normal 10.88 KB 28.07% 0 Up Normal 6.54 KB 71.93% 122378085476254521922132626725931733214

Next two steps :
1, Load balance for clusterCluster operations
Refer to Ban,Black’s presetation –

Final solution is based on development wiki – Cluster Maintenance
* $CASSANDRA_HOME\bin\nodetool -h -p
* Autobootstrap & Automatic token assginement
* $CASSANDRA_HOME\bin\nodetool -h -p loadbalance [ -> result as follow ]

Starting NodeTool
Address Status State Load Owns Token
122378085476254521922132626725931733214 Up Normal 15.27 KB 50.00% 37307493746019906056288974867989680350 Up Normal 10.9 KB 50.00% 122378085476254521922132626725931733214

Pay attention to Token of initial_tokens : 0 node

* $CASSANDRA_HOME\bin\nodetool -h -p netstat [ -> previous : streams – in/out stream for ring ]

Starting NodeTool
Mode: Normal
Not sending any streams.
Not receiving any streams.
Pool Name Active Pending Completed
Commands n/a 0 1
Responses n/a 0 2476

Regarding ring’s maintanence, refer to section – Bootstrap & node token in ring

2, Next Steps: Cassandra Clients
* Java: Hector Client API
Hector provides Java developers with features lacking in Thrift, including connection pooling, JMX integration, failover and exentsive logging.
* Python: Pycassa Client API
Pycassa is a Python client API with features such as connection pooling, SuperColumn support, and a method to map existing classes to Cassandra column families.
* PHP: Phpycassa Client API
Phpycassa is a PHP client API with features such as connection pooling, a method for counting rows, and support for secondary indexes.

mongoDB 1.8.0 via git source

Leave a comment

As reference of cassandra, mongoDB is a kind of No-SQL database based on JSON documentation storage.mongoDB Main Release is based on C++ implementation, feature lists:
1, Document-oriented storage » JSON-style with dynaimic schemas
Schema Design run on top of BSON format.
2, Full Index Support » Indexes enhance query performance, often dramatically.
3, Replication & High Availability » Master-Slave Replication & Replica Sets
4, Auto-Sharding » scales horizontally via an auto-sharding architecture.
5, Querying » fast query based on Query Expression Objects, and multi-external Query language interface support – Java, Perl, PHP, Python, Ruby, C# etc
6, Fast In-Place Updates » MongoDB supports atomic, in-place updates as well as more traditional updates for replacing an entire document.
7, Map/Reduce » batch processing of data and aggregation operations.
8. GridFS » specification for storing large files in MongoDB.

As a very simple start, I downloaded via Git source control of mongoDB into my virtual ubuntu 10.10 system [/home/app/08_mongoDB]. Using 1.8.0 stable version.
1, the building reference could be found as following link : Buiding for Linux
2, Before you try to start mongoDB, please check with Quickstart with Unix.
A little bit difference with traditional Database installation, the major db file location should be manually created as linux user access right.

In principle, as source code is avaiable, /home/app/08_mongoDB/mongo/version_20110320.txt could be considered as the version checking-up documentation and good example of distributed database implementation.

Take care! I preferred to cassandra as major open source example. Regarding mongoDB, it will be a good references when the topic – How multi-language will be supported.

Collaboration Timer and Task skeleton in C#

Leave a comment

Question : if I try to construct a heartbeat thread to monitor certain thread/process is alive, furthermore, if the such artifacts don’t exist any more, the host thread/process will be terminated accordingly.
My apporach : Task with CancellationToken and Timer controller, the code skeletion has been attached as follow.
Further informaiton could be found in Jerry, Richter’s version 3.0’s introdution, However, my approach isn’t so good. As there is no inner mechnaism for Timer object to receieve asynchronous/synchronus event.
To-Do Action : estabish a inner Timer ojbect, which could be controller via any relevant outer thread.
Discussion : How Reinhold think bout this affair?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//TODO : CancellationTokenSource
using System.Threading;
//TODO : Task
using System.Threading.Tasks;

namespace TaskCancelThread
class Program


private static int iDuration = 2000;



class StatusChecker
private System.Threading.Timer _controller;

public System.Threading.Timer Controller{
return this._controller;
System.Diagnostics.Debug.Assert(value != null);
this._controller = value;



private int _iProcessId;

public StatusChecker(int _iProId)
this._iProcessId = _iProId;

// This method is called by the timer delegate.
public void CheckProcessAlive(object timerObject)
CancellationTokenSource cts = timerObject as CancellationTokenSource;
System.Diagnostics.Debug.WriteLine("Task Status - " + cts.Token.CanBeCanceled);
if (!cts.Token.CanBeCanceled)
if (this._controller != null)
catch (Exception ex)

static int Main(string[] args)
CancellationTokenSource cts = new CancellationTokenSource();

Task _test = new Task(() =>
//TODO : call long running thread
catch (Exception ex)
System.Diagnostics.Debug.WriteLine(" **** " + ex + " **** ");
return 0;
}, cts.Token);

StatusChecker tcb = new StatusChecker(System.Diagnostics.Process.GetCurrentProcess().Id);
System.Threading.Timer stateTimer = new System.Threading.Timer(tcb.CheckProcessAlive, cts, iDuration, iDuration);
tcb.Controller = stateTimer;


int nRet = -1;
//TODO : Waiting for Token termination
nRet = _test.Result;
catch (Exception ex)
System.Diagnostics.Debug.WriteLine("**** Thread Process Return Value - " + nRet + " ****");
return nRet;

JBoss 6.0 Configuration

Leave a comment

1, Jboss lean installation file location : offical community download site
The http port changes for the latest version :
Port configuration : Port configuration file
Start Stop JBoss 6.0 application server
A quit link guide for Jboss part – Change default http port directly

2, Jboss startup issues :
14:01:38,977 WARNING [FileConfigurationParser] AIO wasn’t located on this platform, it will fall back to using pure Java NIO. If your platform is Linux, install LibAIO to enable the AIO journal
to enable LibAIO part.

C# interceptors concept

Leave a comment

This afternoon, looking back for EJB @Interceptors, turn back to C#.
Is it possible for us to implement interpector for profiling? I hates to manually add startTime, endTime and code path string around my code!!!

1, AOP idea sponsor – Entrance passage for C# interpector
IL Emit foundation interpector
Interceptors in Unity
Aspect-Oriented Programming, Interception and Unity 2.0
Castle Project
Castle’s DynamicProxy for .NET

Regarding the code, I decided to add into my implementation of PDI for test automation part, this will be discussed with Reinhold. I think he’ll be interested with a new path to clean code.

By the way, in my blog, I also posted an another passage about Emit, please check the category…

DevPad Development Notes

Leave a comment

SharpDevelop will be used as foundational framework, the useful technical links are listed as follow:

1, Welcome to the SharpDevelop Wiki!

2, Using the texteditor

3, Code Completion

4, SharpDevelop – AddIn Writing Help

The current three core concepts required to be verified, are :

1, AvalonEdit – Synatic hightlighting, Code Completion, language support, region support

2, Simple Compilation and Run Appliation

3, Debugging

Section 1 – Create Git Windows Server Environment

Older Entries