Thursday, December 16, 2010

How to create a custom ClockResolution in Hector (0.7.0-x)


Create your own ClockResolution in Hector (as of 0.7.0-22) is easy. We have modified the code a bit to allow Hector clients to define their own implementation if needed. Let's assume we want to create a clock resolution class that generates negative numbers (this is not a useful example. It is only to show how it is possible).
The way to do it is by creating a class that implements me.prettyprint.hector.api.ClockResolution



    // Define my own clock resolution.
    class SequentialClockResolution implements ClockResolution {
        @Override
        public long createClock() {
            return System.currentTimeMillis() * -1;
        }
    }

And now we have to tell Hector to use it.

    CassandraHostConfigurator cassandraHostConfigurator = new CassandraHostConfigurator("localhost");

    cassandraHostConfigurator.setClockResolution(new SequentialClockResolution());

As an additional information, this is the class diagram involved in ClockResolution.

5 comments:

Anonymous said...

hi, new to the site, thanks.

Carolyn said...

hi, new to the site, thanks.

mightystudents said...

You haven't been updating your blog since ages and I'm one of your readers who a bit disappointed waiting on your new article. :( When will it be??

Patricio Echag├╝e said...

@mightystudents very soon! Thanks for the reminder. :)

aliya seen said...

Well! First I appreciate the effort of author. But we also have vertical analysis balance sheet that is very different from others. You can get very clear info through it.Vertical analysis percentage expresses results as a percentage of total assets at the time the analysis was done