SlideShare a Scribd company logo
1 of 53
Download to read offline
‹#›© 2016 Pivotal Software, Inc. All rights reserved. ‹#›© 2016 Pivotal Software, Inc. All rights reserved.
Cloud Foundry Java Client 2.0
Toshiaki Maki (@making)
Cloud Foundry Tokyo Meetup #1
2016-03-31
© 2016 Pivotal Software, Inc. All rights reserved.
Who am I ?
• Toshiaki Maki (@making)
• Sr. Solutions Architect
• Spring Framework enthusiast
Spring
Framework
徹底入門
(Coming Soon)
Perfect
Java EE
(Coming Soon)
© 2016 Pivotal Software, Inc. All rights reserved.
Agenda
•How CF Java Client V1 was 😟
•How CF Java Client V2 looks 😎
© 2016 Pivotal Software, Inc. All rights reserved.
Cloud Foundry Java Client V1
CloudCredentials credentials =
new CloudCredentials("username", "password");

CloudFoundryClient client =
new CloudFoundryClient(credentials,
URI.create("https://api.run.pivotal.io").toURL());

client.login();
// cf apps
List<CloudApplication> apps =
client.getApplications();
// cf app hello
CloudApplication app = client.getApplication("hello");
© 2016 Pivotal Software, Inc. All rights reserved.
Cloud Foundry Java Client V1
// cf push hello -p foo.jar -m 512m -i 2
client.createApplication("hello", new Staging(), 512,
singletonList("hello.cfapps.io"), emptyList());

client.uploadApplication("hello", new File("foo.jar"));

client.updateApplicationInstances("hello", 2);

client.startApplication("hello");
// cf logs
client.streamLogs("hello", new ApplicationLogListener() {

public void onMessage(ApplicationLog log) {
System.out.println(log.getMessage());

}

public void onComplete() {}

public void onError(Throwable exception) {}

});
© 2016 Pivotal Software, Inc. All rights reserved.
Problems in V1
•Monolithic implementation
•No separation between API and Command
•Dependency on Spring Framework (RestTemplate)
•Blocking, Inefficient use of CC API
CF Java Client 2.0 design
© 2016 Pivotal Software, Inc. All rights reserved.
Too many overloading…😫
© 2016 Pivotal Software, Inc. All rights reserved.
130+ methods…😫
© 2016 Pivotal Software, Inc. All rights reserved.
I don’t need MVC…😫
© 2016 Pivotal Software, Inc. All rights reserved.
Cloud Foundry Java Client V1
// cf apps
client.getApplications();
// cf app hello
client.getApplication("hello");
// cf push
client.createApplication(...);

client.uploadApplication(...);

client.updateApplicationInstances(...);

client.startApplication(...);
Blocking 😫
Blocking 😫
Blocking 😫
© 2016 Pivotal Software, Inc. All rights reserved.
Cloud Foundry Java Client V2
https://lists.cloudfoundry.org/archives/list/cf-dev@lists.cloudfoundry.org/thread/W4455NML53LLSUSP25J2OXIYP2FNWUI4/
© 2016 Pivotal Software, Inc. All rights reserved.
Project Structure in V2
cloudfoundry-client
cloudfoundry-operations
cloudfoundry-client-spring
Implements
Uses
CLI (cf ...)
REST API (CC API)
low level
high level
© 2016 Pivotal Software, Inc. All rights reserved.
Class Diagram
CloudFoundryOperations
DefaultCloudFoundryOperations
CloudFoundryClient
SpringCloudFoundryClient
Uses
LoggingClient
SpringLoggingClient
Uses
Uses
© 2016 Pivotal Software, Inc. All rights reserved.
In Future?
CloudFoundryClient
SpringCloudFoundryClient
RetrofitCloudFoundryClient
AndroidCloudFoundryClient
for non-Spring user
for Android user
© 2016 Pivotal Software, Inc. All rights reserved.
SpringCloudFoundryClient cloudfoundryClient =
SpringCloudFoundryClient.builder()

.host("api.run.pivotal.io")
.username("user")
.password("password")

.build();
LoggingClient loggingClient = SpringLoggingClient.builder()
.cloudFoundryClient(cloudFoundryClient)

.build();
CloudFoundryOperations operations =
new CloudFoundryOperationsBuilder()

.cloudFoundryClient(cloudFoundryClient)

.target("org", "space")

.loggingClient(loggingClient)

.build();
Builder Pattern
© 2016 Pivotal Software, Inc. All rights reserved.
// cf apps
operations.applications().list();
// cf app hello
operations.applications()
.get(GetApplicationRequest.builder()

.name("hello").build());
// cf push hello -p foo.jar -m 512m -i 2
operations.applications()

.push(PushApplicationRequest.builder()

.name("hello").path("foo.jar")

.memory(512).instances(2).build());
// cf logs hello
operations.applications().logs(LogsRequest.builder()
.name("hello").build());
© 2016 Pivotal Software, Inc. All rights reserved.
Problems in V1
•Monolithic implementation
•No separation between API and Command
•Dependency on Spring Framework (RestTemplate)
•Blocking, Inefficient use of CC API
CF Java Client 2.0 design
😄
😄
😄
What about this?
© 2016 Pivotal Software, Inc. All rights reserved.
Non-Blocking!! Non-Blocking!!
•Go reactive! 😎
•Move imperative logic to async, event-driven,
functional-style code
© 2016 Pivotal Software, Inc. All rights reserved.
Why Reactive?
http://www.slideshare.net/SpringCentral/reactive-web-applications-53170985
http://www.slideshare.net/SpringCentral/introduction-to-reactive-programming
© 2016 Pivotal Software, Inc. All rights reserved.
Why Reactive?
https://spring.io/blog/2016/03/11/reactor-core-2-5-becomes-a-unified-
reactive-foundation-on-java-8#comment-2564120598
© 2016 Pivotal Software, Inc. All rights reserved.
V2 supports Reactive Streams!!
•Non-Blocking APIs
// cf apps
Publisher<ApplicationSummary> apps
= operations.applications().list();

© 2016 Pivotal Software, Inc. All rights reserved.
Reactive Streams
•Standard interfaces for asynchronous stream
processing with non-blocking back pressure
•De facto standard for interop between reactive
libraries
•Implemented by
• Akka Streams
• Reactor
• RxJava
• etc…
http://www.reactive-streams.org/
‹#›© 2016 Pivotal Software, Inc. All rights reserved.
Reactive Streams has 4 interfaces
public interface Publisher<T> {
public void subscribe(Subscriber<? super T> s);
}
public interface Subscription {
public void request(long n);
public void cancel();
}
public interface Subscriber<T> {
public void onSubscribe(Subscription s);
public void onNext(T t);
public void onError(Throwable t);
public void onComplete();
}
public interface Processor<T, R> extends
Publisher<T>, Subscriber<R> {}
© 2016 Pivotal Software, Inc. All rights reserved.
Subscription SubscriberPublisher Application
© 2016 Pivotal Software, Inc. All rights reserved.
Subscription SubscriberPublisher Application
subscribe(Subscriber)
© 2016 Pivotal Software, Inc. All rights reserved.
Subscription SubscriberPublisher Application
onSubscribe(Subscription)
subscribe(Subscriber)
© 2016 Pivotal Software, Inc. All rights reserved.
Subscription SubscriberPublisher Application
onSubscribe(Subscription)
request(1)
subscribe(Subscriber)
© 2016 Pivotal Software, Inc. All rights reserved.
Subscription SubscriberPublisher Application
onSubscribe(Subscription)
request(1)
onNext(●)
subscribe(Subscriber)
© 2016 Pivotal Software, Inc. All rights reserved.
Subscription SubscriberPublisher Application
onSubscribe(Subscription)
request(1)
onNext(●)
request(2)
subscribe(Subscriber)
© 2016 Pivotal Software, Inc. All rights reserved.
Subscription SubscriberPublisher Application
onSubscribe(Subscription)
request(1)
onNext(●)
request(2)
onNext(●)
subscribe(Subscriber)
© 2016 Pivotal Software, Inc. All rights reserved.
Subscription SubscriberPublisher Application
onSubscribe(Subscription)
request(1)
onNext(●)
request(2)
onNext(●)
onNext(●)
subscribe(Subscriber)
© 2016 Pivotal Software, Inc. All rights reserved.
Subscription SubscriberPublisher Application
onSubscribe(Subscription)
request(1)
onNext(●)
request(2)
onNext(●)
onNext(●)
request(4)
subscribe(Subscriber)
© 2016 Pivotal Software, Inc. All rights reserved.
Subscription SubscriberPublisher Application
onSubscribe(Subscription)
request(1)
onNext(●)
request(2)
onNext(●)
onNext(●)
request(4)
onNext(●)
subscribe(Subscriber)
© 2016 Pivotal Software, Inc. All rights reserved.
Subscription SubscriberPublisher Application
onSubscribe(Subscription)
request(1)
onNext(●)
request(2)
onNext(●)
onNext(●)
request(4)
onNext(●)
onNext(●)
subscribe(Subscriber)
© 2016 Pivotal Software, Inc. All rights reserved.
Subscription SubscriberPublisher Application
onSubscribe(Subscription)
request(1)
onNext(●)
request(2)
onNext(●)
onNext(●)
request(4)
onNext(●)
onNext(●)
onComplete()
subscribe(Subscriber)
© 2016 Pivotal Software, Inc. All rights reserved.
Reactive Streams with CF Java Client
// cf apps
Publisher<ApplicationSummary> apps = operations.applications()
.list();

© 2016 Pivotal Software, Inc. All rights reserved.
Reactive Streams with CF Java Client
// cf apps
Publisher<ApplicationSummary> apps = operations.applications()
.list();

services.subscribe(new Subscriber<ServiceInstance>() {

Subscription s;

public void onSubscribe(Subscription subscription) {

this.s = subscription;

subscription.request(1);

}

public void onNext(ServiceInstance i) {

System.out.println(i.getName() + " : " + i.getService());

this.s.request(1); // one by one

}

public void onError(Throwable throwable) {}

public void onComplete() {}

});
© 2016 Pivotal Software, Inc. All rights reserved.
Reactive Streams with CF Java Client
// cf apps
Publisher<ApplicationSummary> apps = operations.applications()
.list();

services.subscribe(new Subscriber<ServiceInstance>() {

Subscription s;

public void onSubscribe(Subscription subscription) {

this.s = subscription;

subscription.request(1);

}

public void onNext(ServiceInstance i) {

System.out.println(i.getName() + " : " + i.getService());

this.s.request(1); // one by one

}

public void onError(Throwable throwable) {}

public void onComplete() {}

});
😟
No higher level abstractions
like composition
© 2016 Pivotal Software, Inc. All rights reserved.
Reactive eXtensions
• A pattern for composing potentially asynchronous and
event-based programs by using sequences or elements.
• On the JVM
• RxJava is the most used implementation
• Reactor Core is the main alternative
• Also for other languages, for example RxJava
• Some composition libraries doesn't follow closely RxPattern
(Akka) https://speakerdeck.com/sdeleuze/a-lite-rx-api-for-the-jvm?slide=9
http://reactivex.io/
© 2016 Pivotal Software, Inc. All rights reserved.
Reactor
• Yet Another Rx library on the JVM
• Natively built on top of Reactive Streams
• Developed by Pivotal
• Reactor Core provides lite Rx API
• Flux / Mono
• CF Java Client V2 embraces Reactor Core
https://projectreactor.io/
© 2016 Pivotal Software, Inc. All rights reserved.
Flux / Mono
• Both implement Publisher with Rx API
• Flux for 0..N elements
• Mono for 0..1 element
© 2016 Pivotal Software, Inc. All rights reserved.
Flux
Flux<Integer> stream1 = Flux.just(1, 2, 3)
.map(x -> x * 2)
.filter(x -> x > 2); // 4, 6
Flux<String> stream2 = Flux.just("a", "b", "c");
Flux.zip(stream1, stream2)

.consume(t -> System.out.println(t.t1 + ":" + t.t2));
Flux.merge(stream1, stream2)

.consume(x -> System.out.println(x));
© 2016 Pivotal Software, Inc. All rights reserved.
Flux
Flux<Integer> stream1 = Flux.just(1, 2, 3)
.map(x -> x * 2)
.filter(x -> x > 2); // 4, 6
Flux<String> stream2 = Flux.just("a", "b", "c");
Flux.zip(stream1, stream2)

.consume(t -> System.out.println(t.t1 + ":" + t.t2));
Flux.merge(stream1, stream2)

.consume(x -> System.out.println(x));
4:a
6:b
4
6
a
b
c
© 2016 Pivotal Software, Inc. All rights reserved.
Mono
Mono<Boolean> result = Mono.just(true);

result.consume(x -> System.out.println("result=" + x));

Mono<String> delayed = Mono
.delay(Duration.ofSeconds(1))

.after(() -> Mono.just("Hi"));

delayed.consume(x -> System.out.println("result=" + x));



Mono<Void> noValue = Mono.empty();

noValue
.doOnSuccess(x -> System.out.println("finished!"))

.subscribe();
© 2016 Pivotal Software, Inc. All rights reserved.
Type comparison
No value Single value Multiple values
Sync
(JDK)
void T
Future<T>
Iterable<T>
Collection<T>
java.util.stream.Stream<T>
Async
(JDK)
CompletableFuture<Void> CompletableFuture<T> CompletableFuture<List<T>>
Reactive
Streams
Publisher<Void> Publisher<T> Publisher<T>
RxJava Observable<Void>
Completable
Single<T> Observable<T>
Reactor Mono<Void> Mono<T> Flux<T>
© 2016 Pivotal Software, Inc. All rights reserved.
Reactor with CF Java Client
// cf apps
Flux<ApplicationSummary> apps = operations
.applications().list();
apps.map(app -> app.getName())
.consume(x -> System.out.println("name=" + x));
// cf app
Mono<ApplicationDetail> app = operations
.applications().get(GetApplicationRequest.builder()

.name("hello").build());
app.map(app -> app.getName())
.consume(x -> System.out.println("name=" + x));
© 2016 Pivotal Software, Inc. All rights reserved.
Reactor with CF Java Client
// cf push hello -p foo.jar -m 512m -i 2
Mono<Void> pushed = operations.applications()
.push(PushApplicationRequest.builder()

.name("hello").path("foo.jar")

.memory(512).instances(2).build());
pushed.doOnSuccess(x -> System.out.println("pushed!!"))
.subscribe();
// cf logs hello
Flux<LogMessage> logs = operations.applications()
.logs(LogsRequest.builder()
.name("hello").build());
© 2016 Pivotal Software, Inc. All rights reserved.
logs
.filter(log -> "RTR".equals(log.getSourceName()))
.map(LogMessage::getMessage)
.filter(msg -> msg.contains(" 500 ")) // 500 error
.userTimer(Timer.create())
.buffer(Duration.ofSeconds(10))
.map(List::size)
.filer(x -> x.size() > 5) // 5 errors in 10 sec
.consume(x -> {
System.out.println(x +" errors in 10 seconds!");
// some alerts
});
Simple log monitor
© 2016 Pivotal Software, Inc. All rights reserved.
Prefer former simple one?
😟
© 2016 Pivotal Software, Inc. All rights reserved.
Going Non-Blocking is difficult
Blocking API Non-Blocking API
😎
😭
difficult
easy
© 2016 Pivotal Software, Inc. All rights reserved.
to Blocking is Easy
Mono<ApplicationDetail> app = ...;
ApplicationDetail detail = app.get();
Flux<ApplicationSummary> apps = ...;
Iterable<ApplicationSummary> summaries =
apps.toIterable();
© 2016 Pivotal Software, Inc. All rights reserved.
Enjoy Reactive Programming with
CF Java Client V2
😘
© 2016 Pivotal Software, Inc. All rights reserved.
Further Reading
• CF Java Client

https://github.com/cloudfoundry/cf-java-client
• CF Java Client 2.0 design

https://docs.google.com/document/d/1Ui-67dBPYoADltErL80xXYEr_INPqdNJG9Va4gPBM-I/
edit?pref=2&pli=1#heading=h.7gypq7vjwrk2
• A lite Rx API for the JVM

https://speakerdeck.com/sdeleuze/a-lite-rx-api-for-the-jvm
• Reactor Core 2.5 becomes a unified Reactive Foundation
on Java 8

https://spring.io/blog/2016/03/11/reactor-core-2-5-becomes-a-unified-reactive-foundation-on-java-8

More Related Content

What's hot

What's hot (20)

Concourse x Spinnaker #concourse_tokyo
Concourse x Spinnaker #concourse_tokyoConcourse x Spinnaker #concourse_tokyo
Concourse x Spinnaker #concourse_tokyo
 
Implement Service Broker with Spring Boot #cf_tokyo
Implement Service Broker with Spring Boot #cf_tokyoImplement Service Broker with Spring Boot #cf_tokyo
Implement Service Broker with Spring Boot #cf_tokyo
 
Spring Cloud Netflixを使おう #jsug
Spring Cloud Netflixを使おう #jsugSpring Cloud Netflixを使おう #jsug
Spring Cloud Netflixを使おう #jsug
 
From Spring Boot 2.2 to Spring Boot 2.3 #jsug
From Spring Boot 2.2 to Spring Boot 2.3 #jsugFrom Spring Boot 2.2 to Spring Boot 2.3 #jsug
From Spring Boot 2.2 to Spring Boot 2.3 #jsug
 
Spring Cloud Servicesの紹介 #pcf_tokyo
Spring Cloud Servicesの紹介 #pcf_tokyoSpring Cloud Servicesの紹介 #pcf_tokyo
Spring Cloud Servicesの紹介 #pcf_tokyo
 
Why PCF is the best platform for Spring Boot
Why PCF is the best platform for Spring BootWhy PCF is the best platform for Spring Boot
Why PCF is the best platform for Spring Boot
 
Spring Cloud Function & Project riff #jsug
Spring Cloud Function & Project riff #jsugSpring Cloud Function & Project riff #jsug
Spring Cloud Function & Project riff #jsug
 
#jjug_ccc #ccc_gh5 What's new in Spring Framework 4.3 / Boot 1.4 + Pivotal's ...
#jjug_ccc #ccc_gh5 What's new in Spring Framework 4.3 / Boot 1.4 + Pivotal's ...#jjug_ccc #ccc_gh5 What's new in Spring Framework 4.3 / Boot 1.4 + Pivotal's ...
#jjug_ccc #ccc_gh5 What's new in Spring Framework 4.3 / Boot 1.4 + Pivotal's ...
 
Microservices with Spring and Cloud Foundry
Microservices with Spring and Cloud FoundryMicroservices with Spring and Cloud Foundry
Microservices with Spring and Cloud Foundry
 
Introduction to Spring WebFlux #jsug #sf_a1
Introduction to Spring WebFlux #jsug #sf_a1Introduction to Spring WebFlux #jsug #sf_a1
Introduction to Spring WebFlux #jsug #sf_a1
 
2017年のLINEのマイクロサービスを支えるSpring
2017年のLINEのマイクロサービスを支えるSpring2017年のLINEのマイクロサービスを支えるSpring
2017年のLINEのマイクロサービスを支えるSpring
 
Spring Boot Actuator 2.0 & Micrometer
Spring Boot Actuator 2.0 & MicrometerSpring Boot Actuator 2.0 & Micrometer
Spring Boot Actuator 2.0 & Micrometer
 
Spring Boot 1.3 News #渋谷Java
Spring Boot 1.3 News #渋谷JavaSpring Boot 1.3 News #渋谷Java
Spring Boot 1.3 News #渋谷Java
 
Serverless with Spring Cloud Function, Knative and riff #SpringOneTour #s1t
Serverless with Spring Cloud Function, Knative and riff #SpringOneTour #s1tServerless with Spring Cloud Function, Knative and riff #SpringOneTour #s1t
Serverless with Spring Cloud Function, Knative and riff #SpringOneTour #s1t
 
Short Lived Tasks in Cloud Foundry #cfdtokyo
Short Lived Tasks in Cloud Foundry #cfdtokyoShort Lived Tasks in Cloud Foundry #cfdtokyo
Short Lived Tasks in Cloud Foundry #cfdtokyo
 
BOSH / CF Deployment in modern ways #cf_tokyo
BOSH / CF Deployment in modern ways #cf_tokyoBOSH / CF Deployment in modern ways #cf_tokyo
BOSH / CF Deployment in modern ways #cf_tokyo
 
Spring Cloud Stream with Kafka
Spring Cloud Stream with KafkaSpring Cloud Stream with Kafka
Spring Cloud Stream with Kafka
 
A realtime infrastructure for Android apps: Firebase may be what you need..an...
A realtime infrastructure for Android apps: Firebase may be what you need..an...A realtime infrastructure for Android apps: Firebase may be what you need..an...
A realtime infrastructure for Android apps: Firebase may be what you need..an...
 
REST API に疲れたあなたへ贈る GraphQL 入門
REST API に疲れたあなたへ贈る GraphQL 入門REST API に疲れたあなたへ贈る GraphQL 入門
REST API に疲れたあなたへ贈る GraphQL 入門
 
Bootiful Development with Spring Boot and React - UberConf 2018
Bootiful Development with Spring Boot and React - UberConf 2018Bootiful Development with Spring Boot and React - UberConf 2018
Bootiful Development with Spring Boot and React - UberConf 2018
 

Viewers also liked

Consumer Driven Contractsで REST API/マイクロサービスをテスト #m3tech
Consumer Driven Contractsで REST API/マイクロサービスをテスト #m3techConsumer Driven Contractsで REST API/マイクロサービスをテスト #m3tech
Consumer Driven Contractsで REST API/マイクロサービスをテスト #m3tech
Toshiaki Maki
 
Reactive Webアプリケーション - そしてSpring 5へ #jjug_ccc #ccc_ef3
Reactive Webアプリケーション - そしてSpring 5へ #jjug_ccc #ccc_ef3Reactive Webアプリケーション - そしてSpring 5へ #jjug_ccc #ccc_ef3
Reactive Webアプリケーション - そしてSpring 5へ #jjug_ccc #ccc_ef3
Toshiaki Maki
 
最近のSpringFramework2013 #jjug #jsug #SpringFramework
最近のSpringFramework2013 #jjug #jsug #SpringFramework最近のSpringFramework2013 #jjug #jsug #SpringFramework
最近のSpringFramework2013 #jjug #jsug #SpringFramework
Toshiaki Maki
 
Spring Bootキャンプ @関ジャバ #kanjava_sbc
Spring Bootキャンプ @関ジャバ #kanjava_sbcSpring Bootキャンプ @関ジャバ #kanjava_sbc
Spring Bootキャンプ @関ジャバ #kanjava_sbc
Toshiaki Maki
 
Spring Frameworkの今 (2013年版) #jjug_ccc #ccc_r17 #springframework
Spring Frameworkの今 (2013年版) #jjug_ccc #ccc_r17 #springframeworkSpring Frameworkの今 (2013年版) #jjug_ccc #ccc_r17 #springframework
Spring Frameworkの今 (2013年版) #jjug_ccc #ccc_r17 #springframework
Toshiaki Maki
 
Spring4とSpring Bootで作る次世代Springアプリケーション #jjug #jsug
Spring4とSpring Bootで作る次世代Springアプリケーション #jjug #jsugSpring4とSpring Bootで作る次世代Springアプリケーション #jjug #jsug
Spring4とSpring Bootで作る次世代Springアプリケーション #jjug #jsug
Toshiaki Maki
 
Spring Bootで変わる Javaアプリ開発! #jsug
Spring Bootで変わる Javaアプリ開発! #jsugSpring Bootで変わる Javaアプリ開発! #jsug
Spring Bootで変わる Javaアプリ開発! #jsug
Toshiaki Maki
 

Viewers also liked (18)

Concourse CI Meetup Demo
Concourse CI Meetup DemoConcourse CI Meetup Demo
Concourse CI Meetup Demo
 
Introduction to Concourse CI #渋谷Java
Introduction to Concourse CI #渋谷JavaIntroduction to Concourse CI #渋谷Java
Introduction to Concourse CI #渋谷Java
 
Install Concourse CI with BOSH
Install Concourse CI with BOSHInstall Concourse CI with BOSH
Install Concourse CI with BOSH
 
Consumer Driven Contractsで REST API/マイクロサービスをテスト #m3tech
Consumer Driven Contractsで REST API/マイクロサービスをテスト #m3techConsumer Driven Contractsで REST API/マイクロサービスをテスト #m3tech
Consumer Driven Contractsで REST API/マイクロサービスをテスト #m3tech
 
Introduction to Cloud Foundry #JJUG
Introduction to Cloud Foundry #JJUGIntroduction to Cloud Foundry #JJUG
Introduction to Cloud Foundry #JJUG
 
Reactive Webアプリケーション - そしてSpring 5へ #jjug_ccc #ccc_ef3
Reactive Webアプリケーション - そしてSpring 5へ #jjug_ccc #ccc_ef3Reactive Webアプリケーション - そしてSpring 5へ #jjug_ccc #ccc_ef3
Reactive Webアプリケーション - そしてSpring 5へ #jjug_ccc #ccc_ef3
 
Data Microservices with Spring Cloud Stream, Task, and Data Flow #jsug #spri...
Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #spri...Data Microservices with Spring Cloud Stream, Task,  and Data Flow #jsug #spri...
Data Microservices with Spring Cloud Stream, Task, and Data Flow #jsug #spri...
 
112 ◄ التفسير ◄ سُــورَة الإخْــلاص 4-4
112 ◄ التفسير ◄ سُــورَة الإخْــلاص   4-4112 ◄ التفسير ◄ سُــورَة الإخْــلاص   4-4
112 ◄ التفسير ◄ سُــورَة الإخْــلاص 4-4
 
今すぐ始めるCloud Foundry #hackt #hackt_k
今すぐ始めるCloud Foundry #hackt #hackt_k今すぐ始めるCloud Foundry #hackt #hackt_k
今すぐ始めるCloud Foundry #hackt #hackt_k
 
最近のSpringFramework2013 #jjug #jsug #SpringFramework
最近のSpringFramework2013 #jjug #jsug #SpringFramework最近のSpringFramework2013 #jjug #jsug #SpringFramework
最近のSpringFramework2013 #jjug #jsug #SpringFramework
 
Spring Bootキャンプ @関ジャバ #kanjava_sbc
Spring Bootキャンプ @関ジャバ #kanjava_sbcSpring Bootキャンプ @関ジャバ #kanjava_sbc
Spring Bootキャンプ @関ジャバ #kanjava_sbc
 
どこよりも早い Spring Boot 1.2 解説 #渋谷Java
どこよりも早い Spring Boot 1.2 解説 #渋谷Javaどこよりも早い Spring Boot 1.2 解説 #渋谷Java
どこよりも早い Spring Boot 1.2 解説 #渋谷Java
 
Spring Frameworkの今 (2013年版) #jjug_ccc #ccc_r17 #springframework
Spring Frameworkの今 (2013年版) #jjug_ccc #ccc_r17 #springframeworkSpring Frameworkの今 (2013年版) #jjug_ccc #ccc_r17 #springframework
Spring Frameworkの今 (2013年版) #jjug_ccc #ccc_r17 #springframework
 
SpringOne 2GX 2014 参加報告 & Spring 4.1について #jsug
SpringOne 2GX 2014 参加報告 & Spring 4.1について #jsugSpringOne 2GX 2014 参加報告 & Spring 4.1について #jsug
SpringOne 2GX 2014 参加報告 & Spring 4.1について #jsug
 
REST with Spring Boot #jqfk
REST with Spring Boot #jqfkREST with Spring Boot #jqfk
REST with Spring Boot #jqfk
 
Grails 3.0先取り!? Spring Boot入門ハンズオン #jggug_boot
Grails 3.0先取り!? Spring Boot入門ハンズオン #jggug_bootGrails 3.0先取り!? Spring Boot入門ハンズオン #jggug_boot
Grails 3.0先取り!? Spring Boot入門ハンズオン #jggug_boot
 
Spring4とSpring Bootで作る次世代Springアプリケーション #jjug #jsug
Spring4とSpring Bootで作る次世代Springアプリケーション #jjug #jsugSpring4とSpring Bootで作る次世代Springアプリケーション #jjug #jsug
Spring4とSpring Bootで作る次世代Springアプリケーション #jjug #jsug
 
Spring Bootで変わる Javaアプリ開発! #jsug
Spring Bootで変わる Javaアプリ開発! #jsugSpring Bootで変わる Javaアプリ開発! #jsug
Spring Bootで変わる Javaアプリ開発! #jsug
 

Similar to Cloud Foundy Java Client V 2.0 #cf_tokyo

DataStax | DSE Production-Certified Cassandra on Pivotal Cloud Foundry (Ben L...
DataStax | DSE Production-Certified Cassandra on Pivotal Cloud Foundry (Ben L...DataStax | DSE Production-Certified Cassandra on Pivotal Cloud Foundry (Ben L...
DataStax | DSE Production-Certified Cassandra on Pivotal Cloud Foundry (Ben L...
DataStax
 

Similar to Cloud Foundy Java Client V 2.0 #cf_tokyo (20)

How to Architect and Develop Cloud Native Applications
How to Architect and Develop Cloud Native ApplicationsHow to Architect and Develop Cloud Native Applications
How to Architect and Develop Cloud Native Applications
 
Manchester geek night pcf 101
Manchester geek night   pcf 101Manchester geek night   pcf 101
Manchester geek night pcf 101
 
High Performance Cloud Native APIs Using Apache Geode
High Performance Cloud Native APIs Using Apache Geode High Performance Cloud Native APIs Using Apache Geode
High Performance Cloud Native APIs Using Apache Geode
 
SpringOnePlatform2017 recap
SpringOnePlatform2017 recapSpringOnePlatform2017 recap
SpringOnePlatform2017 recap
 
DataStax | DSE Production-Certified Cassandra on Pivotal Cloud Foundry (Ben L...
DataStax | DSE Production-Certified Cassandra on Pivotal Cloud Foundry (Ben L...DataStax | DSE Production-Certified Cassandra on Pivotal Cloud Foundry (Ben L...
DataStax | DSE Production-Certified Cassandra on Pivotal Cloud Foundry (Ben L...
 
Migrating to Angular 5 for Spring Developers
Migrating to Angular 5 for Spring DevelopersMigrating to Angular 5 for Spring Developers
Migrating to Angular 5 for Spring Developers
 
Developer Insights for Application Upgrade to ColdFusion 2016
Developer Insights for Application Upgrade to ColdFusion 2016Developer Insights for Application Upgrade to ColdFusion 2016
Developer Insights for Application Upgrade to ColdFusion 2016
 
Mobile Cloud Demo
Mobile Cloud DemoMobile Cloud Demo
Mobile Cloud Demo
 
Where is cold fusion headed
Where is cold fusion headedWhere is cold fusion headed
Where is cold fusion headed
 
Migrating to Angular 4 for Spring Developers
Migrating to Angular 4 for Spring Developers Migrating to Angular 4 for Spring Developers
Migrating to Angular 4 for Spring Developers
 
Getting Started with Apache Geode
Getting Started with Apache GeodeGetting Started with Apache Geode
Getting Started with Apache Geode
 
Angular JS 2.0 & React with Kendo UI
Angular JS 2.0 & React with Kendo UIAngular JS 2.0 & React with Kendo UI
Angular JS 2.0 & React with Kendo UI
 
How to build unified Batch & Streaming Pipelines with Apache Beam and Dataflow
How to build unified Batch & Streaming Pipelines with Apache Beam and DataflowHow to build unified Batch & Streaming Pipelines with Apache Beam and Dataflow
How to build unified Batch & Streaming Pipelines with Apache Beam and Dataflow
 
Building a full-stack app with Golang and Google Cloud Platform in one week
Building a full-stack app with Golang and Google Cloud Platform in one weekBuilding a full-stack app with Golang and Google Cloud Platform in one week
Building a full-stack app with Golang and Google Cloud Platform in one week
 
Building Web Apps & APIs With Node JS
Building Web Apps & APIs With Node JSBuilding Web Apps & APIs With Node JS
Building Web Apps & APIs With Node JS
 
Splunk bangalore user group 2020-06-01
Splunk bangalore user group   2020-06-01Splunk bangalore user group   2020-06-01
Splunk bangalore user group 2020-06-01
 
[2015-11월 정기 세미나] Cloud Native Platform - Pivotal
[2015-11월 정기 세미나] Cloud Native Platform - Pivotal[2015-11월 정기 세미나] Cloud Native Platform - Pivotal
[2015-11월 정기 세미나] Cloud Native Platform - Pivotal
 
Securing a Cloud Migration
Securing a Cloud MigrationSecuring a Cloud Migration
Securing a Cloud Migration
 
Securing a Cloud Migration
Securing a Cloud MigrationSecuring a Cloud Migration
Securing a Cloud Migration
 
Cisco Managed Private Cloud in Your Data Center: Public cloud experience on ...
Cisco Managed Private Cloud in Your Data Center:  Public cloud experience on ...Cisco Managed Private Cloud in Your Data Center:  Public cloud experience on ...
Cisco Managed Private Cloud in Your Data Center: Public cloud experience on ...
 

Recently uploaded

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Recently uploaded (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 

Cloud Foundy Java Client V 2.0 #cf_tokyo

  • 1. ‹#›© 2016 Pivotal Software, Inc. All rights reserved. ‹#›© 2016 Pivotal Software, Inc. All rights reserved. Cloud Foundry Java Client 2.0 Toshiaki Maki (@making) Cloud Foundry Tokyo Meetup #1 2016-03-31
  • 2. © 2016 Pivotal Software, Inc. All rights reserved. Who am I ? • Toshiaki Maki (@making) • Sr. Solutions Architect • Spring Framework enthusiast Spring Framework 徹底入門 (Coming Soon) Perfect Java EE (Coming Soon)
  • 3. © 2016 Pivotal Software, Inc. All rights reserved. Agenda •How CF Java Client V1 was 😟 •How CF Java Client V2 looks 😎
  • 4. © 2016 Pivotal Software, Inc. All rights reserved. Cloud Foundry Java Client V1 CloudCredentials credentials = new CloudCredentials("username", "password");
 CloudFoundryClient client = new CloudFoundryClient(credentials, URI.create("https://api.run.pivotal.io").toURL());
 client.login(); // cf apps List<CloudApplication> apps = client.getApplications(); // cf app hello CloudApplication app = client.getApplication("hello");
  • 5. © 2016 Pivotal Software, Inc. All rights reserved. Cloud Foundry Java Client V1 // cf push hello -p foo.jar -m 512m -i 2 client.createApplication("hello", new Staging(), 512, singletonList("hello.cfapps.io"), emptyList());
 client.uploadApplication("hello", new File("foo.jar"));
 client.updateApplicationInstances("hello", 2);
 client.startApplication("hello"); // cf logs client.streamLogs("hello", new ApplicationLogListener() {
 public void onMessage(ApplicationLog log) { System.out.println(log.getMessage());
 }
 public void onComplete() {}
 public void onError(Throwable exception) {}
 });
  • 6. © 2016 Pivotal Software, Inc. All rights reserved. Problems in V1 •Monolithic implementation •No separation between API and Command •Dependency on Spring Framework (RestTemplate) •Blocking, Inefficient use of CC API CF Java Client 2.0 design
  • 7. © 2016 Pivotal Software, Inc. All rights reserved. Too many overloading…😫
  • 8. © 2016 Pivotal Software, Inc. All rights reserved. 130+ methods…😫
  • 9. © 2016 Pivotal Software, Inc. All rights reserved. I don’t need MVC…😫
  • 10. © 2016 Pivotal Software, Inc. All rights reserved. Cloud Foundry Java Client V1 // cf apps client.getApplications(); // cf app hello client.getApplication("hello"); // cf push client.createApplication(...);
 client.uploadApplication(...);
 client.updateApplicationInstances(...);
 client.startApplication(...); Blocking 😫 Blocking 😫 Blocking 😫
  • 11. © 2016 Pivotal Software, Inc. All rights reserved. Cloud Foundry Java Client V2 https://lists.cloudfoundry.org/archives/list/cf-dev@lists.cloudfoundry.org/thread/W4455NML53LLSUSP25J2OXIYP2FNWUI4/
  • 12. © 2016 Pivotal Software, Inc. All rights reserved. Project Structure in V2 cloudfoundry-client cloudfoundry-operations cloudfoundry-client-spring Implements Uses CLI (cf ...) REST API (CC API) low level high level
  • 13. © 2016 Pivotal Software, Inc. All rights reserved. Class Diagram CloudFoundryOperations DefaultCloudFoundryOperations CloudFoundryClient SpringCloudFoundryClient Uses LoggingClient SpringLoggingClient Uses Uses
  • 14. © 2016 Pivotal Software, Inc. All rights reserved. In Future? CloudFoundryClient SpringCloudFoundryClient RetrofitCloudFoundryClient AndroidCloudFoundryClient for non-Spring user for Android user
  • 15. © 2016 Pivotal Software, Inc. All rights reserved. SpringCloudFoundryClient cloudfoundryClient = SpringCloudFoundryClient.builder()
 .host("api.run.pivotal.io") .username("user") .password("password")
 .build(); LoggingClient loggingClient = SpringLoggingClient.builder() .cloudFoundryClient(cloudFoundryClient)
 .build(); CloudFoundryOperations operations = new CloudFoundryOperationsBuilder()
 .cloudFoundryClient(cloudFoundryClient)
 .target("org", "space")
 .loggingClient(loggingClient)
 .build(); Builder Pattern
  • 16. © 2016 Pivotal Software, Inc. All rights reserved. // cf apps operations.applications().list(); // cf app hello operations.applications() .get(GetApplicationRequest.builder()
 .name("hello").build()); // cf push hello -p foo.jar -m 512m -i 2 operations.applications()
 .push(PushApplicationRequest.builder()
 .name("hello").path("foo.jar")
 .memory(512).instances(2).build()); // cf logs hello operations.applications().logs(LogsRequest.builder() .name("hello").build());
  • 17. © 2016 Pivotal Software, Inc. All rights reserved. Problems in V1 •Monolithic implementation •No separation between API and Command •Dependency on Spring Framework (RestTemplate) •Blocking, Inefficient use of CC API CF Java Client 2.0 design 😄 😄 😄 What about this?
  • 18. © 2016 Pivotal Software, Inc. All rights reserved. Non-Blocking!! Non-Blocking!! •Go reactive! 😎 •Move imperative logic to async, event-driven, functional-style code
  • 19. © 2016 Pivotal Software, Inc. All rights reserved. Why Reactive? http://www.slideshare.net/SpringCentral/reactive-web-applications-53170985 http://www.slideshare.net/SpringCentral/introduction-to-reactive-programming
  • 20. © 2016 Pivotal Software, Inc. All rights reserved. Why Reactive? https://spring.io/blog/2016/03/11/reactor-core-2-5-becomes-a-unified- reactive-foundation-on-java-8#comment-2564120598
  • 21. © 2016 Pivotal Software, Inc. All rights reserved. V2 supports Reactive Streams!! •Non-Blocking APIs // cf apps Publisher<ApplicationSummary> apps = operations.applications().list();

  • 22. © 2016 Pivotal Software, Inc. All rights reserved. Reactive Streams •Standard interfaces for asynchronous stream processing with non-blocking back pressure •De facto standard for interop between reactive libraries •Implemented by • Akka Streams • Reactor • RxJava • etc… http://www.reactive-streams.org/
  • 23. ‹#›© 2016 Pivotal Software, Inc. All rights reserved. Reactive Streams has 4 interfaces public interface Publisher<T> { public void subscribe(Subscriber<? super T> s); } public interface Subscription { public void request(long n); public void cancel(); } public interface Subscriber<T> { public void onSubscribe(Subscription s); public void onNext(T t); public void onError(Throwable t); public void onComplete(); } public interface Processor<T, R> extends Publisher<T>, Subscriber<R> {}
  • 24. © 2016 Pivotal Software, Inc. All rights reserved. Subscription SubscriberPublisher Application
  • 25. © 2016 Pivotal Software, Inc. All rights reserved. Subscription SubscriberPublisher Application subscribe(Subscriber)
  • 26. © 2016 Pivotal Software, Inc. All rights reserved. Subscription SubscriberPublisher Application onSubscribe(Subscription) subscribe(Subscriber)
  • 27. © 2016 Pivotal Software, Inc. All rights reserved. Subscription SubscriberPublisher Application onSubscribe(Subscription) request(1) subscribe(Subscriber)
  • 28. © 2016 Pivotal Software, Inc. All rights reserved. Subscription SubscriberPublisher Application onSubscribe(Subscription) request(1) onNext(●) subscribe(Subscriber)
  • 29. © 2016 Pivotal Software, Inc. All rights reserved. Subscription SubscriberPublisher Application onSubscribe(Subscription) request(1) onNext(●) request(2) subscribe(Subscriber)
  • 30. © 2016 Pivotal Software, Inc. All rights reserved. Subscription SubscriberPublisher Application onSubscribe(Subscription) request(1) onNext(●) request(2) onNext(●) subscribe(Subscriber)
  • 31. © 2016 Pivotal Software, Inc. All rights reserved. Subscription SubscriberPublisher Application onSubscribe(Subscription) request(1) onNext(●) request(2) onNext(●) onNext(●) subscribe(Subscriber)
  • 32. © 2016 Pivotal Software, Inc. All rights reserved. Subscription SubscriberPublisher Application onSubscribe(Subscription) request(1) onNext(●) request(2) onNext(●) onNext(●) request(4) subscribe(Subscriber)
  • 33. © 2016 Pivotal Software, Inc. All rights reserved. Subscription SubscriberPublisher Application onSubscribe(Subscription) request(1) onNext(●) request(2) onNext(●) onNext(●) request(4) onNext(●) subscribe(Subscriber)
  • 34. © 2016 Pivotal Software, Inc. All rights reserved. Subscription SubscriberPublisher Application onSubscribe(Subscription) request(1) onNext(●) request(2) onNext(●) onNext(●) request(4) onNext(●) onNext(●) subscribe(Subscriber)
  • 35. © 2016 Pivotal Software, Inc. All rights reserved. Subscription SubscriberPublisher Application onSubscribe(Subscription) request(1) onNext(●) request(2) onNext(●) onNext(●) request(4) onNext(●) onNext(●) onComplete() subscribe(Subscriber)
  • 36. © 2016 Pivotal Software, Inc. All rights reserved. Reactive Streams with CF Java Client // cf apps Publisher<ApplicationSummary> apps = operations.applications() .list();

  • 37. © 2016 Pivotal Software, Inc. All rights reserved. Reactive Streams with CF Java Client // cf apps Publisher<ApplicationSummary> apps = operations.applications() .list();
 services.subscribe(new Subscriber<ServiceInstance>() {
 Subscription s;
 public void onSubscribe(Subscription subscription) {
 this.s = subscription;
 subscription.request(1);
 }
 public void onNext(ServiceInstance i) {
 System.out.println(i.getName() + " : " + i.getService());
 this.s.request(1); // one by one
 }
 public void onError(Throwable throwable) {}
 public void onComplete() {}
 });
  • 38. © 2016 Pivotal Software, Inc. All rights reserved. Reactive Streams with CF Java Client // cf apps Publisher<ApplicationSummary> apps = operations.applications() .list();
 services.subscribe(new Subscriber<ServiceInstance>() {
 Subscription s;
 public void onSubscribe(Subscription subscription) {
 this.s = subscription;
 subscription.request(1);
 }
 public void onNext(ServiceInstance i) {
 System.out.println(i.getName() + " : " + i.getService());
 this.s.request(1); // one by one
 }
 public void onError(Throwable throwable) {}
 public void onComplete() {}
 }); 😟 No higher level abstractions like composition
  • 39. © 2016 Pivotal Software, Inc. All rights reserved. Reactive eXtensions • A pattern for composing potentially asynchronous and event-based programs by using sequences or elements. • On the JVM • RxJava is the most used implementation • Reactor Core is the main alternative • Also for other languages, for example RxJava • Some composition libraries doesn't follow closely RxPattern (Akka) https://speakerdeck.com/sdeleuze/a-lite-rx-api-for-the-jvm?slide=9 http://reactivex.io/
  • 40. © 2016 Pivotal Software, Inc. All rights reserved. Reactor • Yet Another Rx library on the JVM • Natively built on top of Reactive Streams • Developed by Pivotal • Reactor Core provides lite Rx API • Flux / Mono • CF Java Client V2 embraces Reactor Core https://projectreactor.io/
  • 41. © 2016 Pivotal Software, Inc. All rights reserved. Flux / Mono • Both implement Publisher with Rx API • Flux for 0..N elements • Mono for 0..1 element
  • 42. © 2016 Pivotal Software, Inc. All rights reserved. Flux Flux<Integer> stream1 = Flux.just(1, 2, 3) .map(x -> x * 2) .filter(x -> x > 2); // 4, 6 Flux<String> stream2 = Flux.just("a", "b", "c"); Flux.zip(stream1, stream2)
 .consume(t -> System.out.println(t.t1 + ":" + t.t2)); Flux.merge(stream1, stream2)
 .consume(x -> System.out.println(x));
  • 43. © 2016 Pivotal Software, Inc. All rights reserved. Flux Flux<Integer> stream1 = Flux.just(1, 2, 3) .map(x -> x * 2) .filter(x -> x > 2); // 4, 6 Flux<String> stream2 = Flux.just("a", "b", "c"); Flux.zip(stream1, stream2)
 .consume(t -> System.out.println(t.t1 + ":" + t.t2)); Flux.merge(stream1, stream2)
 .consume(x -> System.out.println(x)); 4:a 6:b 4 6 a b c
  • 44. © 2016 Pivotal Software, Inc. All rights reserved. Mono Mono<Boolean> result = Mono.just(true);
 result.consume(x -> System.out.println("result=" + x));
 Mono<String> delayed = Mono .delay(Duration.ofSeconds(1))
 .after(() -> Mono.just("Hi"));
 delayed.consume(x -> System.out.println("result=" + x));
 
 Mono<Void> noValue = Mono.empty();
 noValue .doOnSuccess(x -> System.out.println("finished!"))
 .subscribe();
  • 45. © 2016 Pivotal Software, Inc. All rights reserved. Type comparison No value Single value Multiple values Sync (JDK) void T Future<T> Iterable<T> Collection<T> java.util.stream.Stream<T> Async (JDK) CompletableFuture<Void> CompletableFuture<T> CompletableFuture<List<T>> Reactive Streams Publisher<Void> Publisher<T> Publisher<T> RxJava Observable<Void> Completable Single<T> Observable<T> Reactor Mono<Void> Mono<T> Flux<T>
  • 46. © 2016 Pivotal Software, Inc. All rights reserved. Reactor with CF Java Client // cf apps Flux<ApplicationSummary> apps = operations .applications().list(); apps.map(app -> app.getName()) .consume(x -> System.out.println("name=" + x)); // cf app Mono<ApplicationDetail> app = operations .applications().get(GetApplicationRequest.builder()
 .name("hello").build()); app.map(app -> app.getName()) .consume(x -> System.out.println("name=" + x));
  • 47. © 2016 Pivotal Software, Inc. All rights reserved. Reactor with CF Java Client // cf push hello -p foo.jar -m 512m -i 2 Mono<Void> pushed = operations.applications() .push(PushApplicationRequest.builder()
 .name("hello").path("foo.jar")
 .memory(512).instances(2).build()); pushed.doOnSuccess(x -> System.out.println("pushed!!")) .subscribe(); // cf logs hello Flux<LogMessage> logs = operations.applications() .logs(LogsRequest.builder() .name("hello").build());
  • 48. © 2016 Pivotal Software, Inc. All rights reserved. logs .filter(log -> "RTR".equals(log.getSourceName())) .map(LogMessage::getMessage) .filter(msg -> msg.contains(" 500 ")) // 500 error .userTimer(Timer.create()) .buffer(Duration.ofSeconds(10)) .map(List::size) .filer(x -> x.size() > 5) // 5 errors in 10 sec .consume(x -> { System.out.println(x +" errors in 10 seconds!"); // some alerts }); Simple log monitor
  • 49. © 2016 Pivotal Software, Inc. All rights reserved. Prefer former simple one? 😟
  • 50. © 2016 Pivotal Software, Inc. All rights reserved. Going Non-Blocking is difficult Blocking API Non-Blocking API 😎 😭 difficult easy
  • 51. © 2016 Pivotal Software, Inc. All rights reserved. to Blocking is Easy Mono<ApplicationDetail> app = ...; ApplicationDetail detail = app.get(); Flux<ApplicationSummary> apps = ...; Iterable<ApplicationSummary> summaries = apps.toIterable();
  • 52. © 2016 Pivotal Software, Inc. All rights reserved. Enjoy Reactive Programming with CF Java Client V2 😘
  • 53. © 2016 Pivotal Software, Inc. All rights reserved. Further Reading • CF Java Client
 https://github.com/cloudfoundry/cf-java-client • CF Java Client 2.0 design
 https://docs.google.com/document/d/1Ui-67dBPYoADltErL80xXYEr_INPqdNJG9Va4gPBM-I/ edit?pref=2&pli=1#heading=h.7gypq7vjwrk2 • A lite Rx API for the JVM
 https://speakerdeck.com/sdeleuze/a-lite-rx-api-for-the-jvm • Reactor Core 2.5 becomes a unified Reactive Foundation on Java 8
 https://spring.io/blog/2016/03/11/reactor-core-2-5-becomes-a-unified-reactive-foundation-on-java-8