Giter Site home page Giter Site logo

jetcd's Introduction

a simple etcd client for java

watch auto notify for change,easy to use


model


simple setting config operation

	String key = "/testKey";
	EtcdResult result = client.get(key);
	result = client.set(key, "11111111");
	result = client.set(key, null, 10);
	Thread.sleep(11000);
	result = client.get(key);
	result = client.set(key, "222222");
	result = client.get(key);
	result = client.del(key);
	result = client.get(key);

cas operation

String key = "/testCas";
client.cas(key, "testCas-1", false);
EtcdResult result = client.get(key);
client.cas(key, "testCas-2", false);
result = client.get(key);
client.cas(key, "testCas-2", true);
result = client.get(key);

use watch call back for change notify

String key = "/testCallback";
EtcdResult result = client.get(key);
result = client.set(key, "11111111", false);
result = client.get(key);
System.out.println("set:" +JSONUtils.toJSON(result));
client.watch(key, new EtcdWatchCallback() {
	public void onChange(EtcdChangeResult future) {
		EtcdResult etcdResult = future.getResult();
		if(etcdResult!=null){
			System.out.println("change:" +JSONUtils.toJSON(etcdResult));
		}
	}
});

dir operation

String dirKey = "/dirTestKey";
//delete dir
EtcdResult result = client.delDir(dirKey, true);
//create dir
result = client.dir(dirKey);
//add sub dir
result = client.dir(dirKey+"/subdir1");
result = client.dir(dirKey+"/subdir2");
result = client.children(dirKey, true, false);
result = client.delDir(dirKey+"/subdir2", true);
result = client.children(dirKey, true, false);
result = client.delDir(dirKey, true);
result = client.children(dirKey, true, false);

suquence ordered queue for lock

String queue = "/testQueue";
//queue name is a directory
client.delDir(queue, true);
EtcdResult result = client.queue(queue, "job1");
result = client.queue(queue, "job2");
EtcdResult job2 = result;
result = client.queue(queue, "job3");
String delJob3 = result.getNode().getKey();
result = client.children(queue, true, true);
result = client.queue(queue, "job-ttl",10);
result = client.children(queue, true, true);
Thread.currentThread().sleep(10000);
result = client.children(queue, true, true);
//set key ttl
EtcdResult etcdResult = client.set(job2.getNode().getKey(), job2.getNode().getValue(), 6);
Thread.currentThread().sleep(10000);
result = client.children(queue, true, true);
client.del(delJob3);
result = client.children(queue, true, true);

jetcd's People

Contributors

lindzh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.