Using this library, and writing a few lines of code, you can manage your own domain objects in ZooKeeper

Overview

Zookeeper Repository

Tests Coverage Duplicated Lines (%) Vulnerabilities Security Rating Reliability Rating Maintainability Rating Technical Debt Quality Gate Status JitPack

Using this library, and writing a few lines of code, you can manage your own domain objects in ZooKeeper. It provides CRUD operations and change notifications out of the box.

Who should use it?

There are many relational and NoSQL data stores you can use for persisting data, but the main purpose of ZooKeeper is for distributed coordination and configuration. So it makes sense to ask why should I use ZooKeeper as a persistence store? That's right. In most cases ZooKeeper is not a good choice for this reason, but for specific class of problems, we have found it useful, when you have a problem that met all of these conditions:

  • You need online change notifications. Most relational and NoSQL databases do not provide a native push notification feature. One solution is to simulate push notification by periodic polls. But in ZooKeeper, you can simply listen for the changes.
  • There are limited number of objects (i.e., thousands not billions). This library is supposed to handle all objects in memory. It even provides a method that gets the whole snapshot of objects in a Map data structure.
  • You do not need facilities to check or force constraints like foreign keys. You can have multiple type of objects as different parallel repositories but you do not get automatic constraint checks about relations between objects.

Sample usage

As an example, suppose you have a simple data type (e.g., Car) and you want to persist it using ZkRepository. At first, you should extend your data type and implement two methods: a method that identifies the ID of a given object (that is used as node name in ZK), and a method that is used for validation of objects before persistence on add and update operations.

public class Car implements ZkRepositoryItem<Car> {
  private int id;
  private String model;
  private String color;
  ...

  @Override
  int getId() {
    return id;
  }

   @Override
   public void validate(ZkRepository<Car> repository) {
     if (isEmptyOrNull(model)) {
         throw ValidationException("Car model is empty!");
     }
  }
}

Note that by default, a JSON representation of the objects will be stored in ZooKeeper. You can change the default serialization/deserialization mechanism by overriding serialize() and deserialize() methods.

After defining the car class, then implement the car repository by extending the general repository. You should call the super constructor by the ZK server addresses, and the root node in ZooKeeper in which the data objects should be kept:

public class CarRepository extends ZkRepository<Car> {
   public CarRepository(String zkAddresses) {
      super(zkAddresses, "apps_root/cars");
   }
}

Now you are ready to use it:

snapshot = carRepo.getSnapshot(); assertEquals(ferrari, snapshot.get(ferrari.getId()); assertEquals(ford, snapshot.get(ford.getId()); // Remove operation: carRepo.remove(ferrari.getId()); Map snapshot = carRepo.getSnapshot(); assertNull(snapshot.get(ferrari.getId()); // Change notification: carRepo.registerChangeCallback( () -> System.out("Cars are changed. Current snapshot of values: %s", carRepo.getSnapshot().toString()));">
// Initializing the repository:
CarRepository carRepo = new CarRepository("zookeeper-server:2181");
carRepo.start(true);

// Add operation:
Car ferrari = new Car(1, "Ferrari", "Red");
Car ford = new Car(2, "Ford", "Blue");
carRepo.add(ferrari);
carRepo.add(ford);

// Get operation:
assertEquals(ferrari, carRepo.get(ferrari.getId());
assertEquals(ford, carRepo.get(ford.getId());

// Update operation:
ferrari.setColor("Gold");
carRepo.update(ferrari);
assertEquals("Gold", carRepo.get(ferrari.getId()).getColor());

// Snapshot:
Map<Integer, Car> snapshot = carRepo.getSnapshot();
assertEquals(ferrari, snapshot.get(ferrari.getId());
assertEquals(ford, snapshot.get(ford.getId());

// Remove operation:
carRepo.remove(ferrari.getId());
Map<Integer, Car> snapshot = carRepo.getSnapshot();
assertNull(snapshot.get(ferrari.getId());

// Change notification:
carRepo.registerChangeCallback(
   () -> System.out("Cars are changed. Current snapshot of values: %s", carRepo.getSnapshot().toString()));
You might also like...

Build your own Minecraft authentication system with Mojang authentication server support.

Build your own Minecraft authentication system with Mojang authentication server support. A fork of yushijinhun/authlib-injector.

Dec 17, 2022

Just-In-Time Access is an AppEngine application that lets you manage just-in-time privileged access to Google Cloud projects.

Just-In-Time Access is an AppEngine application that lets you manage just-in-time privileged access to Google Cloud projects.

Just-In-Time Access Just-In-Time Access is an AppEngine application that lets you manage just-in-time privileged access to Google Cloud projects. Syno

Jan 3, 2023

Java library to perform reverse Domain Name Service (rDNS) lookups with ease.

ipregistry-rdns Java library to perform reverse Domain Name Service (rDNS) lookups with ease. The library is async, thread-safe and has built-in suppo

Jul 18, 2022

⭐⭐⭐SpringBoot+Zookeeper+Dubbo打造分布式高并发商品秒杀系统

⭐⭐⭐SpringBoot+Zookeeper+Dubbo打造分布式高并发商品秒杀系统

分布式高并发商品秒杀系统 介绍 快速启动 TODO 压测结果 Q&A 介绍 本项目为另一个项目dis-seckill的压力测试版本,重点工作为优化秒杀接口性能,提高单机系统并发瓶颈。 完整项目dis-seckill扩展包括 项目基础技术点和流程图介绍; 接口安全优化; 系统限流与降级服务; Ngin

Sep 2, 2022

⭐⭐⭐⭐SpringBoot+Zookeeper+Dubbo打造分布式高并发商品秒杀系统

⭐⭐⭐⭐SpringBoot+Zookeeper+Dubbo打造分布式高并发商品秒杀系统

分布式高并发商品秒杀系统 介绍 快速启动 项目架构图 项目入门 TODO Q&A 参考资料 介绍 本项目是在dis-seckill上改进,项目名含义为分布式秒杀系统。采用微服务思想,意在提高秒杀系统的整体性能。 改进点: 优化秒杀流程,提高单机系统性能瓶颈。dis-seckill-test 接口安全

Jan 2, 2023

"Some" Utilities you can use for your Java projects "freely"! Files are compiled with Java-8 and above, but mostly Java-11.

✨ Java-SomeUtils 🚀 "Some" Utilities you can use for your Java projects "freely"! *"Freely"* forcing you to include the license into your program. Fil

Jan 6, 2023

A simple Plugin to allow server admins and user with Permissions to change fast and easy thier own Gamemode

A simple Plugin to allow server admins and user with Permissions to change fast and easy thier own Gamemode

A simple Plugin to allow server admins and user with Permissions to change fast and easy thier own Gamemode

Jan 17, 2022

The Apache Commons CSV library provides a simple interface for reading and writing CSV files of various types.

Apache Commons CSV The Apache Commons CSV library provides a simple interface for reading and writing CSV files of various types. Documentation More i

Dec 26, 2022

tuya-spring-boot-starter helps you efficiently create cloud development projects regarding the OpenAPI or message subscription capabilities. You can put all the focus on business logic without taking care of server-side programming nor relational databases.

English | 中文版 tuya-spring-boot-starter helps you efficiently create cloud development projects regarding the OpenAPI or message subscription capabilit

Dec 26, 2022
Comments
  • Bump jackson-databind from 2.13.0 to 2.13.2.1

    Bump jackson-databind from 2.13.0 to 2.13.2.1

    Bumps jackson-databind from 2.13.0 to 2.13.2.1.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • Bump jackson-databind from 2.9.4 to 2.9.10.7

    Bump jackson-databind from 2.9.4 to 2.9.10.7

    Bumps jackson-databind from 2.9.4 to 2.9.10.7.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • Bump jackson-databind from 2.13.0 to 2.13.4.1

    Bump jackson-databind from 2.13.0 to 2.13.4.1

    Bumps jackson-databind from 2.13.0 to 2.13.4.1.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
Releases(1.0.0)
Owner
Sahab
Sahab
A free opensource domain tracker with a breakdown of which countries players connected with for each domain versions 1.13+

A free opensource domain tracker with a breakdown of which countries players connected with for each domain versions 1.13+

Ricky Lafleur 8 Aug 4, 2022
Building your own Notepad Clone using Java Programming

Notepad Clone Using Java Getting Started Build your own Notepad using Java Programming Project Specifications A Notepad Clone in which the user inputs

Muhammad Asad 8 Nov 8, 2022
With react-native-update-in-app library you can easily implement in-app updates in your React Native app using CDN or any other file server

React Native In-App update With react-native-update-in-app library you can easily implement in-app updates in your React Native app using CDN or any o

Nepein Andrey 7 Dec 21, 2022
An assistance platform made using Spring framework that analyses your code, and helps you either to start a devops project, or to turn an existing project into a devops project using open source software (Git, Docker, Jenkins..)

DevOpsify Description An assistance platform made using Spring framework that analyses your code, and helps you either to start a devops project, or t

obaydah bouifadene 14 Nov 8, 2022
An API Library that provides the functionality to access, manage and store device topologies found in JSON files using Java and Maven Framework

Topology API ?? About An API library which provides the functionality to access, manage and store device topologies. ?? Description Read a topology fr

Abdelrahman Hamdy 2 Aug 4, 2022
Create your Java crypto trading bot in minutes. Our Spring boot starter takes care of exchange connections, accounts, orders, trades, and positions so you can focus on building your strategies.

Quick Start | Documentation | Discord | Twitter Create and run your java crypto trading bot in minutes Our Spring boot starter takes care of exchange

Cassandre 442 Jan 3, 2023
A smart personal voice assistant powered by Alan AI. Enjoy hands free application that can manage daily tasks

Todogenix A smart personal voice assistant using Alan AI. Intro Todogenix is a personal assistant app powered by Alan AI that helps store and manage o

Venu Sai Madisetti 8 Mar 15, 2022
A distributed lock that supports the use of Redis and Zookeeper, out of the box, fast and easy to use

lock-spring-boot-starter A distributed lock that supports the use of Redis and Zookeeper, out of the box, fast and easy to use 一款基于 Redis 和 Zookeeper

Pear Stack 9 Oct 15, 2022
Observing a sequence of objects that can be numerically ranked best and worst.

Optimal-Stopping The Secretary Problem from Optimal Stopping. https://en.wikipedia.org/wiki/Optimal_stopping Observing a sequence of objects that can

null 1 Feb 3, 2022
A minecraft minigame where you have to defend your bed and destroy the others. Once your bed is destroyed, you cannot respawn.

As from November 1st 2021 BedWars1058 by Andrei Dascălu becomes open source under GNU GPL 3.0 license. If you are a developer I would really appreciat

Andrei Dascălu 182 Dec 26, 2022