Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Getting Started with Hazelcast, Second Edition
Getting Started with Hazelcast, Second Edition

Getting Started with Hazelcast, Second Edition: Get acquainted with the highly scalable data grid, Hazelcast, and learn how to bring its powerful in-memory features into your application

Arrow left icon
Profile Icon Matthew Johns
Arrow right icon
S$12.99 S$42.99
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.3 (3 Ratings)
eBook Jul 2015 162 pages 1st Edition
eBook
S$12.99 S$42.99
Paperback
S$52.99
Subscription
Free Trial
Arrow left icon
Profile Icon Matthew Johns
Arrow right icon
S$12.99 S$42.99
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.3 (3 Ratings)
eBook Jul 2015 162 pages 1st Edition
eBook
S$12.99 S$42.99
Paperback
S$52.99
Subscription
Free Trial
eBook
S$12.99 S$42.99
Paperback
S$52.99
Subscription
Free Trial

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Getting Started with Hazelcast, Second Edition

Chapter 2. Getting off the Ground

We can think of Hazelcast as a library technology—a JAR file that we bring into our application's classpath and integrate with in order to harness its data distribution capabilities. Now, we can go about setting up an application in the many ways that allow us to use various third-party libraries and dependencies. Most modern IDEs can do this for you. Dependency management or build tools such as Maven, Ant, or Gradle can automate these IDEs, and we can manually sort it out ourselves. However, it's now time to jump in at the deep end. In this chapter, we shall study the following topics:

  • Downloading Hazelcast
  • Creating a basic application with Hazelcast
  • Exploring the various simple storage collections
  • Fetching and searching stored data
  • Setting limits and understanding what happens when we reach the limits

Let's get started

First things first, let's create a working directory for our project.

Navigate to Hazelcast's download page. To download Hazelcast, visit www.hazelcast.org/download/.

The following image shows what the download page looks like:

Let's get started

We will use the latest version, in this case, Version 3.5.

Note

While there is nothing stopping you from working with Hazelcast Enterprise, there is nothing within this book that requires it. For our purposes, the community version will do just fine.

When you unzip the archive, you will find a lib/ directory. This contains the various library JAR files that we can use within our application. For now, let's copy lib/hazelcast-3.5.jar to the working directory.

Showing off straightaway

Within the Hazelcast JAR file, there is a very useful ConsoleApp utility class (this class was previously known as TestApp, but the name was a little deceptive as it can be used for operations beyond just testing). It is great in that it provides a simple text console for easy access to the distributed collections.

To fire this up, we need to run this class using the Hazelcast JAR file as the classpath. Alternatively, we can also use the console scripts that were provided in the demo/ directory.

$ java -cp hazelcast-3.5.jar com.hazelcast.console.ConsoleApp

This should bring up a fair amount of verbose logging, but a reassuring section to look for so that we can see that a cluster has been formed, is the following output:

Members [1] {
    Member [127.0.0.1]:5701 this
}

The output lets us know that a new cluster comprising a node has been created. The current node is indicated by this. The configuration, which is the default built-in JAR, was used to start up the instance...

Mapping back to the real world

Having briefly explored Hazelcast's distributed capabilities via a test console, let's have a look at how we are more likely to interact with a cluster in the real world. Let's create a new SimpleMapExample class with a main method to spin up and manipulate a named distributed map called capitals. Hazelcast refers to these named collections as a namespace. These collections must be uniquely named across the cluster, as follows:

import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import java.util.Map;

public class SimpleMapExample {
  public static void main(String[] args) {
    HazelcastInstance hz = Hazelcast.newHazelcastInstance();

    Map<String, String> capitals = hz.getMap("capitals");
    capitals.put("GB", "London");
    capitals.put("FR", "Paris");
    capitals.put("US", "Washington DC");
    capitals.put("AU", "Canberra...

Sets, lists, and queues

In the previous examples, we looked at key-value storage provided by Hazelcast maps. However, there are a number of other collections that provide keyless groups of objects. Two of these additional types are distributed versions of collections that you may be already familiar with—sets and lists.

The primary difference between these two collections is that lists allow for multiple entries and a set does not. So, if we add them to the previous map example, we will get the following code:

Set<String> cities = hz.getSet("cities");
cities.addAll(captials.values());
cities.add("London");
cities.add("Rome");
cities.add("New York");

List<String> countries = hz.getList("countries");
countries.addAll(captials.keySet());
countries.add("CA");
countries.add("DE");
countries.add("GB"); // duplicate entry

When using the test console again to interact with these new collections, we...

Many things at a time

We have previously seen that Hazelcast provides us with a generic key-value map. However, this capability is popularly used to create a key/list-of-values map. While there is nothing stopping us from defining these ourselves using the standard Java generics, we will have to manually handle the initialization of each key entry. Hazelcast has luckily gone out of its way to make our lives easier by handling this case for us by using the specialized MultiMap collection.

Let's have a look at the following example:

public class MultiMapExample {
  public static void main(String[] args) {
    HazelcastInstance hz = Hazelcast.newHazelcastInstance();

    Map<String, List<String>> manualCities =
      hz.getMap("manualCities");

    List<String> gbCities = new ArrayList<String>();
    manualCities.put("GB", gbCities);

    gbCities = manualCities.get("GB");
    gbCities.add("London");
    manualCities.put(&quot...

Searching and indexing

When creating a clean storage that is based on key-values, we may find that we have lost some of the extra searching capabilities that traditional databases offer. Mainly, we now can't find records within a dataset without knowing the primary key to the entry. However, fear not. Hazelcast provides similar capabilities that allow you to search its maps using predefined indexes. These can be either ordered (ascending) or unordered, depending on our particular data needs. However, keep in mind that indexing doesn't come for free. The internal lookup table that is used to quickly search the reads is maintained as we make changes to the map. This will add latency to every write operation in the namespace.

So firstly, let's create a new plain old Java object (POJO) to represent a city, as follows:

import java.io.Serializable;

public class City implements Serializable, Comparable<City> {
  private String name;
  private String country;
  private int population...

Let's get started


First things first, let's create a working directory for our project.

Navigate to Hazelcast's download page. To download Hazelcast, visit www.hazelcast.org/download/.

The following image shows what the download page looks like:

We will use the latest version, in this case, Version 3.5.

Note

While there is nothing stopping you from working with Hazelcast Enterprise, there is nothing within this book that requires it. For our purposes, the community version will do just fine.

When you unzip the archive, you will find a lib/ directory. This contains the various library JAR files that we can use within our application. For now, let's copy lib/hazelcast-3.5.jar to the working directory.

Showing off straightaway


Within the Hazelcast JAR file, there is a very useful ConsoleApp utility class (this class was previously known as TestApp, but the name was a little deceptive as it can be used for operations beyond just testing). It is great in that it provides a simple text console for easy access to the distributed collections.

To fire this up, we need to run this class using the Hazelcast JAR file as the classpath. Alternatively, we can also use the console scripts that were provided in the demo/ directory.

$ java -cp hazelcast-3.5.jar com.hazelcast.console.ConsoleApp

This should bring up a fair amount of verbose logging, but a reassuring section to look for so that we can see that a cluster has been formed, is the following output:

Members [1] {
    Member [127.0.0.1]:5701 this
}

The output lets us know that a new cluster comprising a node has been created. The current node is indicated by this. The configuration, which is the default built-in JAR, was used to start up the instance...

Left arrow icon Right arrow icon

Description

This book is a great introduction for Java developers, software architects, or DevOps looking to enable scalable and agile data within their applications. Providing in-memory object storage, cluster-wide state and messaging, or even scalable task execution, Hazelcast helps solve a number of issues that have troubled technologists for years.

Who is this book for?

This book is a great introduction for Java developers, software architects, or DevOps looking to enable scalable and agile data within their applications. Providing in-memory object storage, cluster-wide state and messaging, or even scalable task execution, Hazelcast helps solve a number of issues that have troubled technologists for years.

What you will learn

  • Learn and store numerous data types in different distributed collections
  • Set up a cluster from the ground up
  • Work with truly distributed queues and topics for clusterwide messaging
  • Make your application more resilient by listening into cluster internals
  • Run tasks within and alongside our stored data
  • Filter and search our data using MapReduce jobs
  • Discover the new JCache standard and one of its first implementations

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jul 30, 2015
Length: 162 pages
Edition : 1st
Language : English
ISBN-13 : 9781783554058
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Jul 30, 2015
Length: 162 pages
Edition : 1st
Language : English
ISBN-13 : 9781783554058
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just S$6 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just S$6 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total S$ 164.97
Getting Started with Hazelcast, Second Edition
S$52.99
Blueprints Visual Scripting for Unreal engine
S$44.99
Learning Reactive Programming With Java 8
S$66.99
Total S$ 164.97 Stars icon
Banner background image

Table of Contents

13 Chapters
1. What is Hazelcast? Chevron down icon Chevron up icon
2. Getting off the Ground Chevron down icon Chevron up icon
3. Going Concurrent Chevron down icon Chevron up icon
4. Divide and Conquer Chevron down icon Chevron up icon
5. Listening Out Chevron down icon Chevron up icon
6. Spreading the Load Chevron down icon Chevron up icon
7. Gathering Results Chevron down icon Chevron up icon
8. Typical Deployments Chevron down icon Chevron up icon
9. From the Outside Looking In Chevron down icon Chevron up icon
10. Going Global Chevron down icon Chevron up icon
11. Playing Well with Others Chevron down icon Chevron up icon
A. Configuration Summary Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.3
(3 Ratings)
5 star 33.3%
4 star 33.3%
3 star 0%
2 star 0%
1 star 33.3%
Chris Everett Sep 08, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is a great introduction for Java developers, software architects, or DevOps looking to enable scalable and agile data within their applications. Hands-on examples to progressively walk you through all the powerful features and capabilities on offer. Book also covers distributed task execution, in-place data manipulations and big data analytical processing using MapReduce.
Amazon Verified review Amazon
Dustin Marx Aug 22, 2015
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
The second edition of "Getting Started with Hazelcast" (2015) adds three new chapters that cover trendy topics such as Big Data; Cloud; use of Hazelcast with popular frameworks such as Spring and Hibernate, and JMX, and how to use Hazelcast as an implementation of JCache (JSR 107). The book's title is apropos as the book is focused on "getting started with Hazelcast." The book serves as a nice complement for the Hazelcast Documentation (Reference Manual) and "Mastering Hazelcast" (a download available from Hazelcast for those who provide their name and email address)."Getting Started with Hazelcast" provides a narrative of what makes a technology like Hazelcast desirable and how Hazelcast meets different needs. In this way, the book helps familiarize the reader with concepts and vernacular of Hazelcast. Greater details on Hazelcast can be found online in forums and blogs and in "Mastering Hazelcast." "Getting Started with Hazelcast" does not cover the differences between standard Hazelcast and Hazelcast Enterprise.
Amazon Verified review Amazon
kalyan Nov 17, 2017
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
This book does not cover all topics , neither any topic in detail.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.