home‎ > ‎Programming‎ > ‎Comparing NoSQL Data Stores‎ > ‎

Hazelcast

A zipped version of my Hazelcast project is attached below.

I downloaded the latest version (currently), namely 3.1. I simply unzipped the distribution onto my C drive

To use the console you also need apache-tomcat installed

The Hazelcast dependency
        <dependency>
            <groupId>com.hazelcast</groupId>
            <artifactId>hazelcast-all</artifactId>
            <version>3.1</version>
        </dependency>
was added manually.

Server setup

I set up HAZELCAST_HOME as a system env variable (set to C:/hazelcast-3.1)

I therefore modified server.bat as follows (it used relative paths originally)

java -server -Xms1G -Xmx1G -cp %HAZELCAST_HOME%/lib/hazelcast-3.1.jar;%HAZELCAST_HOME%/lib/hazelcastpricing.jar com.hazelcast.examples.StartServer

I added all my classes to the lib directory. The jar was called hazelcastpricing.jar. I simply zipped the files under target/classes (under my maven project structure) and renamed the zip as the above jar (I did not bother with the jar cvf ... command)

I also enabled the console mode by making the following change to hazelcast.xml under the bin directory

    <management-center enabled="true">http://localhost:8080/mancenter-3.1</management-center>

Once you have made these changes, you can start the server

Configuration files

hazelcast.xml sits under %HAZELCAST_HOME%/bin

Apart from the above change to the management-center tag - I did not have to make any further modifications.

Take the mancentre-3.1.war in the root folder and drop it into your tomcat webapps folder. Once you start tomcat, you will notice that the war explodes into a mancenter-3.1 folder.

Make sure that you add the "-3.1" to the management centre URL since the original entry is just localhost:8080/mancenter

Alternatively, you can change the war file to mancenter.war before placing it in tomcat

NOTE: This war deployment is only required if you want to use the command line feature to check cache sizes and other features

Hazelcast documentation is easy to follow and well written - please consult this if you have any further issues.

Data Population

The following two lines occur in all the test methods under MarketDataCreatorTest and TradeDataCreatorTest

        ClientConfig cfg = new ClientConfig();
        HazelcastInstance hzcl = HazelcastClient.newHazelcastClient(cfg);

Cache put was used to populate Trade and Market data

For market data
  • testInsetTestMarketData - will insert one test data (for effective date 15-May-1998)
  • testInsertMarketDataForDates - will insert market data for two other dates
For trade data
  • testInsertTestTradeData - will insert the one test trade (for effective date 15-May-1998)
  • testNextTradeData - will insert a trade with random parameters (within tolerance)

Querying and Filtering

Hazelcast uses an SqlPredicate object that takes in SQL like queries where a "where-like" clause is passed in to filter the objects that match this criteria for that cache.

The cache is an IMap object and SQLPredicate when passed through a values method of the IMap, returns the "values" that match the criteria

For MarketData
        IMap<String, EquityMarketData> markets = hzcl.getMap("marketdata");

        SqlPredicate query = new SqlPredicate("effectiveDate = '" + effectiveDate + "'");

        ArrayList<EquityMarketData> emdList = (ArrayList<EquityMarketData>) markets.values(query);


For TradeData
        IMap<String, EquityTradeData> trades = hzcl.getMap("tradedata");

        SqlPredicate query = new SqlPredicate("strikeDate = '" + strikeDate + "' AND isCall = " + Boolean.FALSE);
        ArrayList<EquityTradeData> putOptions = (ArrayList<EquityTradeData>)trades.values(query);


ċ
Raj Subramani,
13 Nov 2013, 10:03