-
Notifications
You must be signed in to change notification settings - Fork 0
/
import io.vavr.control.Try;
56 lines (37 loc) · 1.19 KB
/
import io.vavr.control.Try;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import io.vavr.control.Try;
package io.vavr.a2;
import io.vavr.control.Try;
/**
*
* @author armdev
*/
public class Resource {
private final BackendA backendA = new BackendA();
private final BackendB backendB = new BackendB();
public void loadBackend() {
}
public String connectToBackendA() throws Exception {
return backendA.loadService();
}
public String connectToBackendB() {
return backendB.loadService();
}
public Try<String> someStandaloneConnection() {
return Try.of(() -> connectToBackendA());
}
public Try<String> connectToMainBackend() {
return Try.of(() -> connectToBackendA()).recover((throwable) -> connectToBackendB());
}
public static void main(String args[]) {
Resource resource = new Resource();
Try<String> connect = resource.connectToMainBackend();
if (connect.isSuccess()) {
System.out.println("Connection is success: " + connect.get());
Try.success(connect);
}
if (connect.isFailure()) {
System.out.println("Connection is fail: " + connect.get());
Try.success(connect);
}
}
}