Upload
sven-ruppert
View
99
Download
1
Embed Size (px)
Citation preview
prepare for…
Functional-Reactive…with Core Java 8/9
@SvenRuppert has been coding java since 1996
2
@SvenRuppert has been coding java since 1996
Projects in the field of:•Automobile-industry•Energy•Finance / Leasing•Space- Satellit-•Government / UN / World-bank
Where?
•Europe•Asia - from India up to Malaysia
2
Small AddOns
based on Java8
@SvenRuppert
4
@SvenRuppertJava8 - Optional<T>
4
@SvenRuppertJava8 - Optional<T>
4
@SvenRuppertJava8 - Optional<T>
4
@SvenRuppertJava8 - Optional<T>
4
@SvenRuppertJava8 - Optional<T>
4
@SvenRuppertJava8 - Optional<T>
Optional - [ Int, Double, Long ]
5
@SvenRuppertJava8 - Functional Interfaces
5
@SvenRuppertJava8 - Functional Interfaces
5
@SvenRuppertJava8 - Functional Interfaces
6
@SvenRuppertJava8 - Functional Interfaces
7
@SvenRuppertJava8 - Functional Interfaces
7
@SvenRuppertJava8 - Functional Interfaces
7
@SvenRuppertJava8 - Functional Interfaces
7
@SvenRuppertJava8 - Functional Interfaces
7
@SvenRuppertJava8 - Functional Interfaces
7
@SvenRuppertJava8 - Functional Interfaces
7
@SvenRuppertJava8 - Functional Interfaces
8
@SvenRuppertJava8 - Functional Interfaces
8
@SvenRuppertJava8 - Functional Interfaces
8
@SvenRuppertJava8 - Functional Interfaces
9
@SvenRuppertJava9 - Functional Interfaces
Java9 - JEP213
Functions
how use Functions…
@SvenRuppert
Functions - Java8
11
@SvenRuppert
Functions - Java8
11
@SvenRuppert
Functions - Java8
11
@SvenRuppert
Functions - Java8
11
@SvenRuppert
Functions - Java8
11
@SvenRuppert
Functions - Java8
11
@SvenRuppert
Functions - Java8
12
@SvenRuppert
Functions - Java8
12
@SvenRuppert
Functions - Java8
12
@SvenRuppert
Functions - Java8
12
@SvenRuppert
Functions - Java8
12
@SvenRuppert
Functions - Java8
12
@SvenRuppert
Functions - Java8
12
@SvenRuppert
Functions - Java8
12
@SvenRuppert
Functions - Java8
12
@SvenRuppert
Functions - Java8
13
@SvenRuppert
Functions - Java8
13
@SvenRuppert
Functions - Java8
13
@SvenRuppert
Functions - Java8
13
@SvenRuppert
Functions - Java8
13
@SvenRuppert
Functions - Java8
13
@SvenRuppert
Functions - Java8
14
@SvenRuppert
Functions - Java8
14
@SvenRuppert
Functions - Java8
15
@SvenRuppert
Functions - Java8
15
@SvenRuppert
Functions - Java8
15
@SvenRuppert
Functions - Java8
16
@SvenRuppert
Functions - Java8
16
@SvenRuppert
Functions - Java8
17
@SvenRuppert
Refactoring example
based on Java8
@SvenRuppert
19
@SvenRuppertJava8 - Functional Interfaces - Example
typical legacy implementation
20
@SvenRuppertJava8 - Functional Interfaces - Example
typical legacy implementation
21
@SvenRuppertJava8 - Functional Interfaces - Example
21
@SvenRuppertJava8 - Functional Interfaces - Example
21
@SvenRuppertJava8 - Functional Interfaces - Example
21
@SvenRuppertJava8 - Functional Interfaces - Example
21
@SvenRuppertJava8 - Functional Interfaces - Example
21
@SvenRuppertJava8 - Functional Interfaces - Example
22
@SvenRuppertJava8 - Functional Interfaces - Example
22
@SvenRuppertJava8 - Functional Interfaces - Example
22
@SvenRuppertJava8 - Functional Interfaces - Example
22
@SvenRuppertJava8 - Functional Interfaces - Example
22
@SvenRuppertJava8 - Functional Interfaces - Example
23
@SvenRuppertJava8 - Functional Interfaces - Example
23
@SvenRuppertJava8 - Functional Interfaces - Example
23
@SvenRuppertJava8 - Functional Interfaces - Example
24
@SvenRuppertJava8 - Functional Interfaces - Example
24
@SvenRuppertJava8 - Functional Interfaces - Example
24
@SvenRuppertJava8 - Functional Interfaces - Example
24
@SvenRuppertJava8 - Functional Interfaces - Example
25
@SvenRuppertJava8 - Functional Interfaces - Example
25
@SvenRuppertJava8 - Functional Interfaces - Example
26
@SvenRuppertJava8 - Functional Interfaces - Example
Sourcecode is on github
26
@SvenRuppertJava8 - Functional Interfaces - Example
Sourcecode is on github
Pattern in Java 8/9
how pattern will change…
@SvenRuppert
Virtual Proxy
28
@SvenRuppert
Virtual Proxy
28
@SvenRuppert
public class ServiceProxy implements Service { private Service service = new ServiceImpl(); public String work(String txt) { return service.work(txt); }}
Virtual Proxy
28
@SvenRuppert
public class ServiceProxy implements Service { private Service service = new ServiceImpl(); public String work(String txt) { return service.work(txt); }}
What could we
change now ?
Virtual Proxy
28
@SvenRuppert
public class ServiceProxy implements Service { private Service service = new ServiceImpl(); public String work(String txt) { return service.work(txt); }}
What could we
change now ? Virtual Proxy:
create the Delegator later
Virtual Proxy
28
@SvenRuppert
public class ServiceProxy implements Service { private Service service = new ServiceImpl(); public String work(String txt) { return service.work(txt); }}
What could we
change now ? Virtual Proxy:
create the Delegator later
public class VirtualService implements Service { private Service service = null; public String work(String txt) { if(service == null) { service = new ServiceImpl(); } return service.work(txt); }}
Virtual Proxy
28
@SvenRuppert
public class ServiceProxy implements Service { private Service service = new ServiceImpl(); public String work(String txt) { return service.work(txt); }}
What could we
change now ? Virtual Proxy:
create the Delegator later
public class VirtualService implements Service { private Service service = null; public String work(String txt) { if(service == null) { service = new ServiceImpl(); } return service.work(txt); }}
Virtual Proxy
28
@SvenRuppert
public class ServiceProxy implements Service { private Service service = new ServiceImpl(); public String work(String txt) { return service.work(txt); }}
What could we
change now ? Virtual Proxy:
create the Delegator later
public class VirtualService implements Service { private Service service = null; public String work(String txt) { if(service == null) { service = new ServiceImpl(); } return service.work(txt); }}
Virtual Proxy
29
@SvenRuppert
public class VirtualService implements Service { private Service service = null; public String work(String txt) { if(service == null) { service = new ServiceImpl(); }
return service.work(txt); }}
Virtual Proxy
29
@SvenRuppert
public class VirtualService implements Service { private Service service = null; public String work(String txt) { if(service == null) { service = new ServiceImpl(); }
return service.work(txt); }}
Virtual Proxy
29
@SvenRuppert
public class VirtualService implements Service { private Service service = null; public String work(String txt) { if(service == null) { service = new ServiceImpl(); }
return service.work(txt); }}
This is NOT ThreadSafe
Virtual Proxy
29
@SvenRuppert
public class VirtualService implements Service { private Service service = null; public String work(String txt) { if(service == null) { service = new ServiceImpl(); }
return service.work(txt); }}
This is NOT ThreadSafe
Virtual Proxy
29
@SvenRuppert
public class VirtualService implements Service { private Service service = null; public String work(String txt) { if(service == null) { service = new ServiceImpl(); }
return service.work(txt); }}
This is NOT ThreadSafefixed decision for
an implementation
Virtual Proxy
29
@SvenRuppert
public class VirtualService implements Service { private Service service = null; public String work(String txt) { if(service == null) { service = new ServiceImpl(); }
return service.work(txt); }}
This is NOT ThreadSafefixed decision for
an implementation
Virtual Proxy
29
@SvenRuppert
public class VirtualService implements Service { private Service service = null; public String work(String txt) { if(service == null) { service = new ServiceImpl(); }
return service.work(txt); }}
This is NOT ThreadSafefixed decision for
an implementation
how to combine it with a FactoryPattern ?
Virtual Proxy
30
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }
Virtual Proxy
30
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }
Virtual Proxy
30
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }
public interface ServiceFactory { Service createInstance();}
Virtual Proxy
30
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }
public interface ServiceFactory { Service createInstance();}
Virtual Proxy
30
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }
public interface ServiceFactory { Service createInstance();}
public interface ServiceStrategyFactory { Service realSubject(ServiceFactory factory);}
Virtual Proxy - Not - ThreadSafe
31
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }
Virtual Proxy - Not - ThreadSafe
31
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }
Virtual Proxy - Not - ThreadSafe
31
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }
private ServiceFactory serviceFactory = ServiceImpl::new;
Virtual Proxy - Not - ThreadSafe
31
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }
private ServiceFactory serviceFactory = ServiceImpl::new;
Virtual Proxy - Not - ThreadSafe
31
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }
public class ServiceStrategyFactoryImpl implements ServiceStrategyFactory { Service realSubject; public Service realSubject(final ServiceFactory factory) { if (realSubject == null) { realSubject = factory.createInstance(); } return realSubject; }}
private ServiceFactory serviceFactory = ServiceImpl::new;
Virtual Proxy - Not - ThreadSafe
32
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }
Virtual Proxy - Not - ThreadSafe
32
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }
public class ServiceProxy implements Service {
Virtual Proxy - Not - ThreadSafe
32
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }
public class ServiceProxy implements Service {private ServiceFactory serviceFactory = ServiceImpl::new;
Virtual Proxy - Not - ThreadSafe
32
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }
public class ServiceProxy implements Service {private ServiceFactory serviceFactory = ServiceImpl::new;private ServiceStrategyFactory strategyFactory = new ServiceStrategyFactoryImpl();
Virtual Proxy - Not - ThreadSafe
32
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }
public class ServiceProxy implements Service {private ServiceFactory serviceFactory = ServiceImpl::new;private ServiceStrategyFactory strategyFactory = new ServiceStrategyFactoryImpl();
public String work(String txt) {
Virtual Proxy - Not - ThreadSafe
32
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }
public class ServiceProxy implements Service {private ServiceFactory serviceFactory = ServiceImpl::new;private ServiceStrategyFactory strategyFactory = new ServiceStrategyFactoryImpl();
public String work(String txt) {
}}
Virtual Proxy - Not - ThreadSafe
32
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }
public class ServiceProxy implements Service {private ServiceFactory serviceFactory = ServiceImpl::new;private ServiceStrategyFactory strategyFactory = new ServiceStrategyFactoryImpl();
public String work(String txt) {return
}}
Virtual Proxy - Not - ThreadSafe
32
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }
public class ServiceProxy implements Service {private ServiceFactory serviceFactory = ServiceImpl::new;private ServiceStrategyFactory strategyFactory = new ServiceStrategyFactoryImpl();
public String work(String txt) {return strategyFactory
}}
Virtual Proxy - Not - ThreadSafe
32
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }
public class ServiceProxy implements Service {private ServiceFactory serviceFactory = ServiceImpl::new;private ServiceStrategyFactory strategyFactory = new ServiceStrategyFactoryImpl();
public String work(String txt) {return strategyFactory .realSubject(
}}
Virtual Proxy - Not - ThreadSafe
32
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }
public class ServiceProxy implements Service {private ServiceFactory serviceFactory = ServiceImpl::new;private ServiceStrategyFactory strategyFactory = new ServiceStrategyFactoryImpl();
public String work(String txt) {return strategyFactory .realSubject(serviceFactory
}}
Virtual Proxy - Not - ThreadSafe
32
@SvenRuppert
if(service == null) { service = new ServiceImpl(); }
public class ServiceProxy implements Service {private ServiceFactory serviceFactory = ServiceImpl::new;private ServiceStrategyFactory strategyFactory = new ServiceStrategyFactoryImpl();
public String work(String txt) {return strategyFactory .realSubject(serviceFactory).work(txt);
}}
Virtual Proxy - Show some code….
33
@SvenRuppert
Virtual Proxy - Show some code….
33
@SvenRuppert
Virtual Proxy - Show some code….
33
@SvenRuppert
Virtual Proxy - Show some code….
33
@SvenRuppert
Virtual Proxy - Show some code….
34
@SvenRuppert
Virtual Proxy - Show some code….
34
@SvenRuppert
Virtual Proxy - Show some code….
34
@SvenRuppert
Virtual Proxy - Show some code….
34
@SvenRuppert
Virtual Proxy - Show some code….
35
@SvenRuppert
Virtual Proxy - Show some code….
35
@SvenRuppert
Virtual Proxy - Show some code….
35
@SvenRuppert
Virtual Proxy - Show some code….
35
@SvenRuppert
Virtual Proxy - Show some code….
36
@SvenRuppert
Virtual Proxy - Show some code….
36
@SvenRuppert
Virtual Proxy - Show some code….
37
@SvenRuppert
Virtual Proxy - Show some code….
37
@SvenRuppert
Virtual Proxy - Show some code….
37
@SvenRuppert
Virtual Proxy - Show some code….
37
@SvenRuppert
Virtual Proxy - Show some code….
37
@SvenRuppert
Virtual Proxy - Show some code….
38
@SvenRuppert
Virtual Proxy - Show some code….
38
@SvenRuppert
Virtual Proxy - Show some code….
39
@SvenRuppert
Virtual Proxy - Show some code….
39
@SvenRuppert
Virtual Proxy - Show some code….
40
@SvenRuppert
Virtual Proxy - Show some code….
40
@SvenRuppert
Virtual Proxy - Show some code….
41
@SvenRuppert
Virtual Proxy - Show some code….
41
@SvenRuppert
Virtual Proxy - Show some code….
42
@SvenRuppert
Virtual Proxy - Show some code….
42
@SvenRuppert
Interpreter - pre Java8
43
@SvenRuppert
Interpreter - pre Java8
44
@SvenRuppert
Interpreter - pre Java8
44
@SvenRuppert
Interpreter - pre Java8
44
@SvenRuppert
Interpreter - pre Java8
45
@SvenRuppert
Interpreter - pre Java8
45
@SvenRuppert
Interpreter - pre Java8
45
@SvenRuppert
Interpreter - pre Java8
46
@SvenRuppert
Interpreter - pre Java8
46
@SvenRuppert
Interpreter - pre Java8
46
@SvenRuppert
Interpreter - pre Java8
46
@SvenRuppert
Interpreter - Java8 - Java9
47
@SvenRuppert
Interpreter - Java8 - Java9
47
@SvenRuppert
Interpreter - Java8 - Java9
47
@SvenRuppert
Interpreter - Java8 - Java9
48
@SvenRuppert
Main Idea - DataStructure to Function
Interpreter - Java8 - Java9
48
@SvenRuppert
Main Idea - DataStructure to Function
Interpreter - Java8 - Java9
48
@SvenRuppert
Main Idea - DataStructure to Function
Interpreter - Java8 - Java9
49
@SvenRuppert
Interpreter - Java8 - Java9
49
@SvenRuppert
Memoizing
pure functional behavior - show Source code
@SvenRuppert
@SvenRuppert
Memoizing @SvenRuppert
@SvenRuppert
Memoizing @SvenRuppert
@SvenRuppert
Memoizing @SvenRuppert
@SvenRuppert
Memoizing @SvenRuppert
@SvenRuppert
Memoizing @SvenRuppert
@SvenRuppert
Memoizing @SvenRuppert
@SvenRuppert
Memoizing @SvenRuppert
@SvenRuppert
Memoizing @SvenRuppert
@SvenRuppert
Memoizing @SvenRuppert
@SvenRuppert
Memoizing @SvenRuppert
@SvenRuppert
Memoizing @SvenRuppert
Reactive stuff
how use Functions… async…
@SvenRuppert
Observer
63
@SvenRuppert
Observer
63
@SvenRuppert
Observer
63
@SvenRuppert
Observer
63
@SvenRuppert
Observer
63
@SvenRuppert
64
@SvenRuppertJava8 - Concurrency - CompletableFuture
64
@SvenRuppertJava8 - Concurrency - CompletableFuture
Process
64
@SvenRuppertJava8 - Concurrency - CompletableFuture
Process
Thread
64
@SvenRuppertJava8 - Concurrency - CompletableFuture
Process
Thread
Fiber
64
@SvenRuppertJava8 - Concurrency - CompletableFuture
Process
Thread
Fiber
64
@SvenRuppertJava8 - Concurrency - CompletableFuture
Process
Thread
Fiber
CompletionStage
64
@SvenRuppertJava8 - Concurrency - CompletableFuture
Process
Thread
Fiber
CompletionStage
64
@SvenRuppertJava8 - Concurrency - CompletableFuture
Process
Thread
Fiber
CompletionStage
64
@SvenRuppertJava8 - Concurrency - CompletableFuture
Process
Thread
Fiber
CompletionStage CompletionStage
64
@SvenRuppertJava8 - Concurrency - CompletableFuture
Process
Thread
Fiber
CompletionStage CompletionStage
64
@SvenRuppertJava8 - Concurrency - CompletableFuture
Process
Thread
Fiber
CompletionStage CompletionStage CompletionStage
65
@SvenRuppertJava8 - Concurrency - CompletableFuture
66
@SvenRuppertJava8 - Concurrency - CompletableFuture
66
@SvenRuppertJava8 - Concurrency - CompletableFuture
Value A
66
@SvenRuppertJava8 - Concurrency - CompletableFuture
Value A Value B
66
@SvenRuppertJava8 - Concurrency - CompletableFuture
Value A Value B
66
@SvenRuppertJava8 - Concurrency - CompletableFuture
Value A Value B
66
@SvenRuppertJava8 - Concurrency - CompletableFuture
Operator 1
Value A Value B
66
@SvenRuppertJava8 - Concurrency - CompletableFuture
Operator 1
Value A Value B
66
@SvenRuppertJava8 - Concurrency - CompletableFuture
Operator 1
Value A
Operator 2a
Value B
66
@SvenRuppertJava8 - Concurrency - CompletableFuture
Operator 1
Value A
Operator 2a
Value B Value C
66
@SvenRuppertJava8 - Concurrency - CompletableFuture
Operator 1
Value A
Operator 2a
Value B Value C
66
@SvenRuppertJava8 - Concurrency - CompletableFuture
Operator 1
Value A
Operator 2a
Value B Value C
66
@SvenRuppertJava8 - Concurrency - CompletableFuture
Operator 1
Value A
Operator 2a
Result
Value B Value C
67
@SvenRuppertJava8 - Concurrency - CompletableFuture
67
@SvenRuppertJava8 - Concurrency - CompletableFuture
67
@SvenRuppertJava8 - Concurrency - CompletableFuture
68
@SvenRuppertJava8 - Concurrency - CompletableFuture
68
@SvenRuppertJava8 - Concurrency - CompletableFuture
68
@SvenRuppertJava8 - Concurrency - CompletableFuture
69
@SvenRuppertJava8 - Concurrency - CompletableFuture
69
@SvenRuppertJava8 - Concurrency - CompletableFuture
70
@SvenRuppertJava8 - Concurrency - CompletableFuture
70
@SvenRuppertJava8 - Concurrency - CompletableFuture
70
@SvenRuppertJava8 - Concurrency - CompletableFuture
71
@SvenRuppertJava8 - Concurrency - CompletableFuture
71
@SvenRuppertJava8 - Concurrency - CompletableFuture
71
@SvenRuppertJava8 - Concurrency - CompletableFuture
72
@SvenRuppertJava8 - Concurrency - CompletableFuture
72
@SvenRuppertJava8 - Concurrency - CompletableFuture
72
@SvenRuppertJava8 - Concurrency - CompletableFuture
73
@SvenRuppertJava8 - Concurrency - CompletableFuture
73
@SvenRuppertJava8 - Concurrency - CompletableFuture
74
@SvenRuppertJava8 - Concurrency - CompletableFuture
74
@SvenRuppertJava8 - Concurrency - CompletableFuture
74
@SvenRuppertJava8 - Concurrency - CompletableFuture
74
@SvenRuppertJava8 - Concurrency - CompletableFuture
75
@SvenRuppertJava8 - Concurrency - CompletableFuture
Operator 1
Value A
Operator 2a
Result
Value B Value C
Java 9
some nice news…
@SvenRuppert
Java9 - Optional
77
@SvenRuppert
Java9 - Optional
77
@SvenRuppert
Java9 - Optional
77
@SvenRuppert
Java9 - Optional
77
@SvenRuppert
Java9 - Optional
77
@SvenRuppert
Java9 - JEP266
78
@SvenRuppert
Java9 - JEP266
78
@SvenRuppert
we got Publisher / Subscriber
Java9 - JEP266
78
@SvenRuppert
we got Publisher / Subscriber
Summary
79
@SvenRuppert
places to read more about it
Summary
79
@SvenRuppert
places to read more about it
www.functional-reactive.org
Summary
79
@SvenRuppert
places to read more about it
www.functional-reactive.org
Summary
79
@SvenRuppert
places to read more about it
www.functional-reactive.org
www.java-9.org
Summary
80
@SvenRuppert
Now it is time to relax again ;-)
Summary
81
@SvenRuppert
please, follow me ;-)
@SvenRuppert
Summary
81
@SvenRuppert
please, follow me ;-)
@SvenRuppert
Thank You !!!