-
Notifications
You must be signed in to change notification settings - Fork 2
/
Main.java
56 lines (45 loc) · 1.98 KB
/
Main.java
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
55
56
package org.infinispan.microservices;
import java.io.File;
import java.net.URISyntaxException;
import java.util.UUID;
import org.infinispan.client.hotrod.RemoteCacheManager;
import org.infinispan.client.hotrod.configuration.ConfigurationBuilder;
public class Main {
private static final String SSL_REALM_1 = "client-1-truststore.jks";
private static final String SSL_REALM_2 = "client-2-truststore.jks";
public static void main(String[] args) throws Exception {
ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
configurationBuilder
.addServers("transactions-repository-1-myproject.192.168.0.17.nip.io:443")
.connectionPool()
.maxTotal(1)
.maxActive(1)
.maxWait(0)
.maxIdle(0)
.maxRetries(0)
.security()
.ssl()
.enable()
.sniHostName("transactions-repository-1-myproject.192.168.0.17.nip.io")
.trustStoreFileName(getFilePath(SSL_REALM_2))
.trustStorePassword("secret".toCharArray())
;
RemoteCacheManager remoteCacheManager = new RemoteCacheManager(configurationBuilder.build());
boolean cacheAvailable1 = isCacheAvailable(remoteCacheManager, "cache-1");
boolean cacheAvailable2 = isCacheAvailable(remoteCacheManager, "cache-2");
Thread.sleep(100);
System.out.println("cache-1: " + cacheAvailable1);
System.out.println("cache-2: " + cacheAvailable2);
}
public static boolean isCacheAvailable(RemoteCacheManager remoteCacheManager, String cacheName) {
try {
remoteCacheManager.getCache(cacheName).put(UUID.randomUUID().toString(), "1");
return true;
} catch (Exception e) {
return false;
}
}
public static String getFilePath(String fieName) throws URISyntaxException {
return new File(Main.class.getClassLoader().getResource(fieName).toURI()).getAbsolutePath();
}
}