Skip to content

Instantly share code, notes, and snippets.

View benjchristensen's full-sized avatar

Ben Christensen benjchristensen

View GitHub Profile
@benjchristensen
benjchristensen / ObsurvableBind2.java
Created January 18, 2014 21:58
Observable example with just the `bind` operator and unit tests asserting behavior while exploring the best signature. This variant uses: Func1<Operator<R>, Operator<T>>
/**
* Copyright 2014 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@benjchristensen
benjchristensen / ObsurvableBind.java
Created January 18, 2014 05:03
Observable example with just the `bind` operator and unit tests asserting behavior while exploring the best signature.
/**
* Copyright 2014 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@benjchristensen
benjchristensen / Obsurvable.java
Last active January 31, 2017 09:45
Playing with Observable.bind
/**
* Copyright 2014 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@benjchristensen
benjchristensen / DATA-CONTRACTS.md
Last active December 20, 2015 02:29
Consumer Driven Contracts: notes, links, quotes and thoughts

Problem Statement

A service layer (Java API in this case) is backed by dozens of services (over the network in an SOA) and used by dozens of clients, each using different subsets of the overall API. In our case all client interaction happens within a single JVM so we can know which clients are accessing what services, fields and keys (versus a RESTful API over HTTP where this would be unknown).

Principally the API is functionality focused rather than system focused. A client should request data to serve a given use case and not need to concern themselves with the underlying implementation details of what backend system the data is coming from.

Today this is achieved through static typing and Java object modeling. Types from underlying services are decoupled from clients so that backend systems can change their implementations without impacting clients.

This means (assuming Java language environment):

@benjchristensen
benjchristensen / GitHubExample.java
Created July 16, 2013 19:59
Feign GitHubExample.java
/*
* Copyright 2013 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
public interface Observable<T> {
public Subscription subscribe(Observer<T> observer);
}
@benjchristensen
benjchristensen / SerializedObserver.java
Created May 11, 2013 14:55
Uses a queue instead of `synchronized` keywords to serialize events. This is slower than using `synchronized` for handling contended access (as it now has overhead of queue etc) but it may make sense when a sequence has long-running events where we'd rather pay the queueing cost rather than blocking threads.
/**
* Copyright 2013 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@benjchristensen
benjchristensen / a_readme.md
Last active December 16, 2015 21:21
Hystrix Dashboard Event Stream
@benjchristensen
benjchristensen / AtomicObserverMultiThreaded.java
Created April 16, 2013 23:54
AtomicObserverMultiThreaded
/**
* Copyright 2013 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@benjchristensen
benjchristensen / RxUsingJava8.java
Last active December 13, 2015 19:48
Example of RxJava being used with Java 8 lambdas
import rx.Observable;
import java.util.ArrayList;
import java.util.List;
public class RxUsingJava8 {
public static void main(String args[]) {
/*