Cassandra 1.2 beta3 on Mac OSX

Running Cassandra’s latest instalment on Snow Leopard was simpler than dealing with the Windows dependencies.

The first challenge was updating the Java jdk from the default 1.6 to 1.7 (I choose to go for Oracle because of the .dmg install package). You can upgrade by downloading the installer from Oracle’s website, mounting and then installing the JDK inside.

Java 7 will now be installed in the default location, you can check by using the which command.

$ which java
/usr/bin/java //default location!

Next you need to create the log file Cassandra will use for it’s logging. Navigate to /var/log and create the cassandra folder after which create the log file named system.log

$ cd /var/log/
$ sudo mkdir cassandra
$ cd cassandra/; sudo touch system.log

This is where I faced my first problem, Cassandra did not have permissions to read the file, running it as the root user would solve the problem however we could just change the permissions for the log file and run it as the current user.

$ chown `whoami` /var/log/cassandra/system.log
$ chmod chmod u+wrx /var/log/cassandra/system.log

Cassandra is now ready to run:

cd To Cassandra location
$ bin/cassandra -f

And there we go!

Running Cassandra 1.2

Setting up Cassandra 1.2′s third beta release set out to be simple but because of the error messages given when something does go wrong, it was confusing to work out.

I started out by cloning and building the latest Cassandra available using git and Ant. That’s where the first problem came along. I didn’t specify the correct location to my JDK and ant complained that it was missing tools.jar, so I just dumped the jar into the JRE location.

After that the build succeeded and I was ready to run cassandra, except when trying to do so i got the following error:

Exception in thread ‘main’ java.lang.NoSuchMethodError: main Exception in thread “main”

Turns out that Cassandra 1.2 did not like java 6, so after changing the jdk to 1.7 I have it another shot which came up with this error:

Error: Main method not found in class org.apache.cassandra.service.CassandraDaemon, please define the main method as:    public static void main(String[] args)

This turned out to be a environment variable problem. My CASSANDRA_HOME variable was pointing to my old installation of cassandra. Changing this variable to the correct path fixed the problem.

They say third time’s the charm, and it certainly was in this case. On my third run I finally got the “Listening for thrift clients…” message meaning the server is running!

Twitter clone using Cassandra & Hector for Java

A exploration into the NoSql world using the highly scalable database known as Cassandra.

Usage of NoSql databases, NoSql meaning not-only SQL, and the non-relational world is growing rapidly, mostly thanks to its scaling capabilities and blistering I/O speeds and as every true software architect I love learning and using new technology, its all about progress!

Cassandra, one of the most well-known NoSql databases gaining its fame thanks to its usage in Facebook, Digg and  Twitter, is know for high write speeds and excellent scalability but its biggest advantage is that Cassandra was designed to never fail, meaning that if one of the nodes does fail, the whole cluster can maintain the full dataset required all queries to be answerable.

My exploration into the NoSql world starts with Cassandra as the back-end database, Java as the programming language of choice, Glassfish as the server for handling requests and serving webpages and Hector as the Cassandra client API.

The exploration will start off with simple blog, where a user can register, and post their thoughs. Pretty basic right… The aim is to start small and grow out, or as its known in the NoSql world scale!

The project will be opensource and can be found on github.

Freeing up port 80 for server

Windows seems to have a problem with port management, mainly because it tries to simplify port management for the user. This is a good thing for most users but complicates things for developers.Recently my troubles began when I was trying to set up a glassfish server to run on port 80 so that when a user navigates to my test website they wouldn’t see the port being used. The issue was IIS was constantly listening on port 80, and  glassfish was failing to start and would display an error message:

java.net.BindException: No free port within range 

First issue (user process is using the port)

The port is blocked because a user , aka non-system, process is listening in on and/or using port 80. The way to solve this problem is to work out which process is listening to the port and terminate it  by using the windows command line

First you need to workout what process is occupying the port and find its PID (process ID) We do this by starting a windows command prompt and trying to find any strings containing “:80″ or “LISTENING” in the netstat command (with additional arguments aon).

netstat -aon | findstr :80 | findstr LISTENING

We should get an output displaying either nothing, meaning the port is not being used by any processes at all, or a five column row where the last column is the process ID:

TCP  0.0.0.0:80  0.0.0.0:0  LISTENING  4653  //PID is 4653 

The next step is to kill (terminate) the process and free up the port for your desired process. Again in the command line, input the following:

taskkill /f /IM 4653 //where 4653 is the PID, and we see:
SUCCESS: The process with PID 4653 has been terminated. 


Terminating process blocking port 80

OR

You can kill the process by using windows’ task manager by finding the process by PID
Start the task manager (Ctrl + Shift + Esc) find the process under the Processes tab, and finally click on the process and select End Process.

Note* To display the PID column in the task manager, first select the “Processes Tab”, then from the top menu select “View”, next select the “Select Column…” option, after the pop-up dialogue appears tick “PID” (Process Identifier) and select “OK”

More to come soon on killing the process if it is a system process!

Second issue (system process is using the port)
The infamous PID 4 using port 80 problem…

Resolving this issue is a-bit trickier as we don’t explicitly have permissions to kill the process. This process (PID : 4) is typically IIS and in-order to stop it we need to edit registry values, but this method will work for all system level processes that cant be stopped with the first solution due to permission restrictions.
example of why solution 1 will fail to stop a system process

First launch the registry editor
(press the windows key then type regedit.exe and start the program)

Next step Navigate to:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HTTP

Finally change the value of “start”  to “4” (default value is 3 symbolising enabled and we are changing it to 4 meaning disabled)
Note* For the changed to take affect, we need to reboot our systems.

After the reboot, there shouldn’t be any processes listening to port 80 and the port will now be free for your webserver or application!

IE6 hover and the jQuerry fix

IE6 is now a eleven year old browser which as most web developers know is a nightmare to support. The :hover function is fairly useful for clarifying where the user’s mouse is located on the page. The problem is that :hover only works on the link , <a> , elements in Internet Explorer 6. The workaround came when I noticed that swapping classes can potentially have the same effect as changing the style of an element which is hovered over.

JS applying the hover style on a <tr> element:

//jQuerry used for hover to avoid IE6 issues
$(‘tr’).hover(function() {
$(this).addClass(‘hover’);
}, function() {
$(this).removeClass(‘hover’);
});

CSS

.hover { background-color:#9999CC; color: white; }

So by swapping the class of the element we are hovering over, we can change it’s style meaning that if implemented correctly, the jQuerry and CSS combination can be used to replace the HTML :hover tag.

A more detailed example can be found online at jsfiddle.

/(welcome.to).(my{1}|our{1}).(site).*/i

I’ve been studying programming for a while now, and one thing I’m definately thankful for is all the useful information that can be found online. Most of the things I know about programming come from personal research rather than the fundamentals that I’ve been taught at university, where the main focus is teaching us best practices and encouraging us to commit our time to further study.

I like to share my ideas and experiences and blogging seems like a fun way of doing so, and open-source is the way to go, so hopefully the solutions I find might guide others facing similar problems or provide a good read.


No-matter what the outcome, hope you can enjoy the posts!

int main ( )
{

printf(“hello, world\n); //now say hi!

}

public static void main ( String [ ] args )
{

System.out.print(“Hello World!”);   // and pick your poison,

}