Giter Site home page Giter Site logo

event-registry's Introduction

The event-registry

Simple registry that uses Zookeeper to keep track of event types, topics etc. It is implemented as a simple wrapper around the apache curator zookeeper library that adds a simple model and zookeeper manipulation operations.

Each update to the registry can generate events that different listeners can receive. So, for exmaple, when a new EventType is registered a router component could receive this update and create any necessary topics. Likewise when a component expresses an interest in a type of event (via an @Consumes annotation, connections to the correct topic can be made.

Connecting to the Registry

To use the registry, make a connection to a running zookeeper server and start the connection:

RegistryConnetion connection = new RegistryConnection("localhost:2181");
connection.setBaseKey("/streamzi")
connection.connect();

The connection is created with a base key argument which attaches to the specified point in the Zookeeper data. All operations are then relative to that base key.

Updating the Registry

When a registry connection has been made, updates are made via RegistryOperations. These can either run asynchronously or synchronously. For example, to register a new EventType synchronously:

connection.executeSync(new CreateEventType(new EventType("MeterReading"));

or

connection.execute(new CreateEventType(new EventType("MeterReading")).thenRun(
	new Runnable(){
		public void run(){
			System.out.println("Event type added");
		}
	}

);

for an async operation.

Listening to changes

Registry listeners can be created to listen for changes to specific object types. For example to listen for changes to EventTypes:

	RegistryKeyListener<EventType> listner = connection.addKeyListener(new RegistryKeyListener<>(){
		@Override
		public void objectAdded(EventType value){
		}
		
		@Override
		public void objectRemoved(EventType value){
		}
	
		@Override
		public void objectChanged(EventType value({
		}
	
	});

Listeners are attached to a specific key in the Zookeeper tree and listen for child events on that key. They also keep a cache of the current state, so can be iterrogated directly:

	List<EventType> eventTypes = listener.getValues();

will return the locally cached list of event types.

event-registry's People

Contributors

hhiden avatar matzew avatar

Watchers

James Cloos avatar

Forkers

sjwoodman

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.