Book Image

Getting Started with Hazelcast

By : Matthew Johns
Book Image

Getting Started with Hazelcast

By: Matthew Johns

Overview of this book

Table of Contents (18 chapters)
Getting Started with Hazelcast
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Moving data around the place


The final listener is very useful as it lets our application know when Hazelcast is rebalancing the data within the cluster. This allows us the opportunity to prevent or even block the shutdown of a node as we might be in a period of increased data resilience risk. The interface used for this case is MigrationListener and will notify our application as partitions are migrated from one node to another and when they have completed.

public class ClusterMigrationListener implements MigrationListener {

  @Override
  public void migrationStarted(MigrationEvent migrationEvent) {
    System.err.println("Started: " + migrationEvent);
  }

  @Override
  public void migrationCompleted(MigrationEvent migrationEvent) {
    System.err.println("Completed: " + migrationEvent);
  }

  @Override
  public void migrationFailed(MigrationEvent migrationEvent) {
    System.err.println("Failed: " + migrationEvent);
  }
}

In registering this cluster listener in our example application...