Archive for ◊ June, 2012 ◊

Monday, June 25th, 2012

Responsive web design term is related to the concept of developing a website design in a manner, that helps the lay out to get changed according to the user’s computer screen resolution. More precisely, the concept allows for an advanced 4 column layout 1292 pixels wide, on a 1025 pixel width screen, that auto-simplifies into 2 columns. Also it suitably fixes on the smartphone and computer tablet screen.

SignalR is an Async library for .NET to help build real-time, multi-user interactive web applications.
LESS extends CSS with dynamic behavior such as variables, mixins, operations and functions. LESS runs on both the client-side (Chrome, Safari, Firefox) and server-side, with Node.js and Rhino.
In this article, we’ll create a simple retrospective app using Responsive web design techniques, CSS3, LESS and SignalR that will allow multiple collaborators to review the same article in real-time.
1. Creating the html page.
Use the Less stylesheet language for creating the CSS for the website. you can download the less.js files from http://lesscss.org/ that is used in this article. You can define variables and classes using Less and then use them in the CSS files as:
@backgroundColor: #E6E6E6;
body {
background-color: @backgroundColor;
}
.shadow(@borderColor)
{
-moz-box-shadow: 3px 3px 4px @borderColor;
-webkit-box-shadow: 3px
3px 4px @borderColor;
box-shadow: 3px 3px 4px @borderColor;
}
.goodDataContent
{
.dataContent;
.shadow(@goodBorderColor);
background-color: @goodDataBackgroundColor;
margin-left: 50px;
}
2. Using media queries to render CSS based on screen preferences
Media queries are an excellent way to deliver different styles to different devices, providing the best experience for each type of user. A part of the CSS3 specification, media queries expand the role of the media attribute that controls how your styles are applied. For .e.g. in our app I have defined the image size and size of the contents by using media- ueries as given below.
@media all and (max-width: 700), (max-height: 500)
{
.goodImageContent
{
.imageContent(72);
background-image:url(Images/good_78x78.png);
}
.badImageContent
{
.imageContent(72);
background-image:url(Images/bad_72x72.png);
}
.betterImageContent
{
.imageContent(72);
background-image:url(Images/idea_72x72.png);
}
}
3. Creating the Retrospective manger Hub.
Hubs provide a higher level RPC framework over a PersistentConnection. If you have different types of messages that you want to send between server and client then hubs is recommended so you don’t have to do your own dispatching.  To get started using Hubs, create a class that derives from Hub.
[HubName("retrospectiveManager")]
public class RetrospectiveManager : Hub
{
[HubMethodName("newCharEntry")]
public void RegisterNewChar(string data, string content, string teamId, string browserIp)
{
switch (content)
{
case “Good”:
Clients.addGood(data, teamId, browserIp);
break;
case “Bad”:
Clients.addBad(data, teamId, browserIp);
break;
case “Better”:

Clients.addBetter(data, teamId, browserIp);
break;
default:
Clients.addMessage(data, teamId, browserIp);
break;
}
}
}
Our hub receives messages via the RegisterNewChar method and
broadcasts the data to addGood, addBad methods.
4. Using connections
Create a connection between the client and the server. When the connection has been started, we want to call the join method on the server.
retro = $.connection.retrospectiveManager;
$.connection.hub.start({ transport: ‘auto’ }, null);
retro.addGood = function (data, team, id) {
if (browserId != id && teamId == team) {
$(‘#goodDataContentDiv’).html(data);
}
};
5. HTML for the page
<div>
<div class=”sectionContent”>
<div class=”goodImageContent”>
div>
<div class=”goodDataContent” contenteditable=”true” accesskey=”G” id=”goodDataContentDiv” onkeyup=”sendGoodChar()”>
What went well in this sprint? <br /> 1.
div>
div>
<div class=”sectionContent”>
<div class=”badImageContent”>
div>
<div class=”badDataContent” contenteditable=”true” accesskey=”B” id=”badDataContentDiv” onkeyup=”sendBadChar()”>

What didn’t go well in this sprint?
<br />
1.
div>
div>
<div class=”sectionContent”>
<div class=”betterImageContent”>
div>
<div class=”betterDataContent” contenteditable=”true” accesskey=”I” id=”betterDataContentDiv” onkeyup=”sendBetterChar()”>

What can we do better next time?
<br /> 1.
div>
div>
div>
I have provided the app as free for distributed teams to use. You can use the app from the URL http://freeapps.agilecockpit.com/Retrospective.aspx. Use the teamId as the querystring for similar teams so that the teams with the same id can view data from other team members. For e.g. you can use any number as a team id and share it with other team members and start using it like http://freeapps.agilecockpit.com/Retrospective.aspx?teamId=22
Screen shots:
Category: .Net, Agile/Scrum | Tags: , ,  | 3 Comments
Wednesday, June 20th, 2012
SQLFire is a memory-optimized, distributed database management system designed for applications that have demanding scalability and availability requirements. SQLFire offers some of the best features usually only seen in NoSQL databases, such as horizontal scalability, shared-nothing persistence and built in fault tolerance, but does it all while providing a real SQL interface. Applications can manage database tables entirely in memory, or they can persist tables to disk to reload the data after restarting the system. A SQLFire distributed system can be easily scaled out using commodity hardware.
In this post we’ll see how to setup and start a cluster of multiple SQLFire servers.
A SQLFire deployment consists of distributed member processes that connect to each other to form a peer-to-peer network, also known as a distributed system or SQLFire cluster. A server is a process that hosts data and is a member of a peer-to-peer distributed system.   The connection management to the available servers is done using a locator. A locator maintains a list of available servers in the cluster, and updates that list as servers join and leave the cluster. Locators also load balance client connections across all available servers. To create a locator you can use the sqlf locator command as given below.
sqlf locator start -dir=MyServerLocator -peer-discovery-address=localhost
-peer-discovery-port=10101 -client-bind-address=localhost -client-port=1527
Where MyServerLocator is the folder created at the executing directory for the locator. By starting the locator member first, the locator can manage cluster membership from the start as new servers join and leave the distributed
system.
Use the sqlf server start command to start the servers and join them to the distributed system by specifying the locator as given below.
sqlf server start -dir=MyServer1 -locators=localhost[10101] -bind-address=localhost
-client-port=1528
sqlf server start -dir=MyServer2 -locators=localhost[10101] -bind-address=localhost
-client-port=1529

To connect to the SQLFire cluster using the JDBC thin client driver, use the connect client command and specify the host and port number of the SQLFire locator as

connect client ’localhost:1527′;


Category: PHP | Tags: , ,  | Leave a Comment
Wednesday, June 13th, 2012
One major difference between Cassandra and a traditional relational database is that Cassandra supports a variable amount of columns per rows in any given column family. In this post we will insert a column to the column family, “Tweets” The tweet column family is of contains one row with the text “sample tweet text1”. We will also see the test case for a null value insert exception.
[TestMethod]
public void InsertOnSubmitInsertsANewValueToTheColumnFamily()
{
var key = “1″.ToCassandraByte();
const string columnName = “text”;
const string value = “sample tweet text 1″;
using (var context = new CassandraContext(“localhost”, 9160, “Twitter”))
{
context.Column.DeleteOnSubmit(x => x.ColumnFamily == “Tweets” && x.Key == key);
context.SubmitChanges();
var column = new Column().SetNameValue(columnName, value);
context.InsertOnSubmit(“Tweets”, key, column);
context.SubmitChanges();
var tweet = (from x in context.ColumnList
.Where(x => x.ColumnFamily == “Tweets” && x.Key == key)
select x.ToObject<Tweet>()).FirstOrDefault();
Assert.AreEqual(value, tweet.text);
context.Column.DeleteOnSubmit(x => x.ColumnFamily == “Tweets” && x.Key == key);
context.SubmitChanges();
}
}
[TestMethod]
[ExpectedException(typeof(Thrift.TApplicationException))]
public void InsertNullValueTest()
{
var key = “1″.ToCassandraByte();
const string columnName = “text”;
using (var context = new CassandraContext(“localhost”, 9160, “Twitter”))
{
var column = new Column()
.SetNameValue(columnName, null);
context.InsertOnSubmit(“Tweet”, key, column);
context.SubmitChanges();
}
}
Category: .Net | Tags: , ,  | Leave a Comment
Monday, June 11th, 2012

Cassandra shows excellent performance in data distribution and availability. In Cassandra, consistency refers to how up-to-date and synchronized a row of data is on all of its replicas. Cassandra extends the concept of eventual consistency by offering tunable consistency. For any given read or write operation, the client application  decides how consistent the requested data should be. In addition to tunable consistency, Cassandra has a number of built-in repair mechanisms to ensure that data remains consistent across replicas.

Cassandra supports the following write consistency levels.
  • ANY, having the lowest consistency with high availability. This mentions that a write must be written to at least one node. If all replica nodes for the given row key are down, the write can still succeed once a hinted handoff has been written.
  • ALL, having the highest consistency with lowest availability. A write must be written to the commit log and memory table on all replica nodes in the cluster for that row key.
  • QUORUM is a good middle-ground ensuring strong consistency, yet still tolerating some level of failure. A write must be written to the commit log and memory table on a quorum of replica nodes.
  • ONE: A write must be written to the commit log and memory table of at least one replica node.
  • LOCAL_QUORUM: A write must be written to the commit log and memory table on a quorum of replica nodes in the same data center as the coordinator node. Avoids latency of inter-data center communication.
  • EACH_QUORUM: A write must be written to the commit log and memory table on a quorum of replica nodes in all data centers.

For read consistency Cassandra supports the below given levels

  • ONE:  If latency is a top priority, consider a consistency level of ONE (only one replica node must successfully respond to the read or write request). There is a higher  probability of stale data being read with this consistency level (as the replicas contacted for reads may not always have the most recent write).
  • ANY: If it is an absolute requirement that a write never fail, you may also consider a write consistency level of ANY. This consistency level has the highest probability of a read not returning the latest written values (see hinted handoff).
  • QUORUM: Returns the record with the most recent timestamp once a quorum of replicas has responded.

Creating a Cassandra connection configuration in .NET

[TestMethod]
public void CassandraConnectionConfigBuilderTest()
{
var hosts = new[] { “a”, “b”“c” };
var builder = new CassandraConnectionConfigBuilder
{
Hosts = hosts, Port = 9160,
ConsistencyLevel = ConsistencyLevel.QUORUM,
Timeout = TimeSpan.FromSeconds(100),
IsFramed = true,
};
var config = new CassandraConnectionConfig(builder);
CollectionAssert.AreEqual(hosts, config.Hosts);
Assert.AreEqual(9160, config.Port);
Assert.AreEqual(ConsistencyLevel.QUORUM, config.ConsistencyLevel);
Assert.AreEqual(TimeSpan.FromSeconds(100), config.Timeout);
Assert.AreEqual(true, config.IsFramed);
}
Category: .Net  | One Comment
Sunday, June 10th, 2012
With the uninterrupted growth of voluminous amount of unstructured and semi-structured computing data, storage of information, support and maintenance has been the biggest challenge. Data of this type would take too much time and cost too much money to load into a relational database for analysis. The demands of huge data and elastic scaling with desired performance has led to concept of big data. Although big data doesn’t refer to any specific quantity, the term is often used when speaking about petabytes and exabytes of data.
Apache Cassandra is a standout among the NoSQL/post-relational database solutions on the market for many reasons. Some of the core features of Cassandra are:
  • Highly scalable peer-to-peer architecture based on the best of Amazon Dynamo and Google BigTable. Cassandra is the considered as the NoSQL leader when it comes to comfortably scaling to terabytes or petabytes of data.
  • Increased database for both read and write operations via nodes and cluster. Data is replicated to multiple nodes to protect from loss during node failure, and new machines can be added incrementally while online to increase the capacity and data protection of your Cassandra cluster.
  • Ensure data safety due to its innovative append-only commit log. Users no longer have to trade off durability to keep up with immense write streams.
  • Transparent fault detection and recovery using gossip protocols to detect machine failure and recover when a machine is brought back into the cluster – all without your application noticing.
  • Cassandra offers support for multiple data centres
    by easy configuration options for setting copies of your data you want in each
    data centre.
  • Cassandra offers caching on each of its nodes enabling ease of development.
  • Incremental and dynamic expansion as Cassandra ring allows you to add nodes easily without manual migration of data needed from one to another.
  • Cassandra runs on commodity machines and requires no expensive or special hardware.

Cassandra’s data model

The Cassandra data model has 4 main concepts which are cluster, keyspace, column family and super column.
  • Cluster is the outermost structure in Cassandra (also called as ring). Cassandra database is specially designed to be spread across several machines functioning together that act as a single occurrence to the end user. Cassandra allocates data to nodes in the cluster by arranging them in a ring. Clusters contain many nodes (machines) and can contain multiple keyspaces.
  • A keyspace is the top level element of a schema.  A keysapce is a Container for column families to group multiple column families, typically one per application.
  • A column contains a name, value and timestamp. A column must have a name, and the name can be a static label (such as “name” or “email”) or it can be dynamically set when the column is created by your application.
  • A column family contains multiple columns referenced by a row keys. Column families can (and should) define metadata about the columns, but the actual columns that make up a row are determined by the client application. Each row can have a different set of columns.

Configuring Cassandra using DataStax OpsCenter

DataStax OpsCenter is a visual management and monitoring solution for big data platforms designed to manage and monitor Apache Cassandra™ database clusters. Through an intuitive point-and-click interface, a user can understand the state of one or more clusters through a centralized dashboard that provides an at-a-glance view of the status, activity, and issues across all monitored clusters. Users can easily create new database objects, manage maintenance activities, and perform other database tasks such as backups  in a visual manner. The opscenter interface looks like.

You can add a keyspace to the available cluster as given below.


After adding the keyspace you can add a column family as.

Later you can also use the CIL to change the schema structure or add new data to the column family as given below.



Accessing Cassandra in .NET
Now let’s write some code to access the posts we stored in the posts column family. We’ll be using Cassandraemon,  a LINQ client for Cassandra Apache.
[TestMethod]
public void OpenAConnectionTest()
{
using (var context = new CassandraContext(“localhost”, 9160, “Twitter”))
{
var products = fromin context.ColumnList
where x.ColumnFamily == “Tweets”
&& x.Column == “text”
select x.ToObject<Tweet>();
Assert.IsTrue(products.Count() > 0);
}
}
Category: .Net  | 2 Comments