Skip to content

Commit dfc0a97

Browse files
committed
Merge remote-tracking branch 'eugenp/master'
2 parents e820fbb + 7cb94f6 commit dfc0a97

22 files changed

Lines changed: 557 additions & 47 deletions

File tree

‎algorithms/pom.xml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
<artifactId>jenetics</artifactId>
3535
<version>3.7.0</version>
3636
</dependency>
37+
<dependency>
38+
<groupId>org.jgrapht</groupId>
39+
<artifactId>jgrapht-core</artifactId>
40+
<version>1.0.1</version>
41+
</dependency>
3742
</dependencies>
3843

3944
<build>

libraries/src/test/java/com/baeldung/jgrapht/CompleteGraphTest.java renamed to algorithms/src/test/java/com/baeldung/jgrapht/CompleteGraphTest.java

File renamed without changes.

libraries/src/test/java/com/baeldung/jgrapht/DirectedGraphTests.java renamed to algorithms/src/test/java/com/baeldung/jgrapht/DirectedGraphTests.java

File renamed without changes.

libraries/src/test/java/com/baeldung/jgrapht/EulerianCircuitTest.java renamed to algorithms/src/test/java/com/baeldung/jgrapht/EulerianCircuitTest.java

File renamed without changes.

‎atomix/.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

‎atomix/pom.xml‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.atomix.io</groupId>
5+
<artifactId>atomix</artifactId>
6+
<version>0.0.1-SNAPSHOT</version>
7+
8+
<parent>
9+
<groupId>com.baeldung</groupId>
10+
<artifactId>parent-modules</artifactId>
11+
<version>1.0.0-SNAPSHOT</version>
12+
</parent>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>io.atomix</groupId>
17+
<artifactId>atomix-all</artifactId>
18+
<version>1.0.0-rc9</version>
19+
</dependency>
20+
<dependency>
21+
<groupId>junit</groupId>
22+
<artifactId>junit</artifactId>
23+
<version>4.9</version>
24+
<scope>test</scope>
25+
</dependency>
26+
<dependency>
27+
<groupId>log4j</groupId>
28+
<artifactId>log4j</artifactId>
29+
<version>1.2.17</version>
30+
</dependency>
31+
</dependencies>
32+
<build>
33+
<plugins>
34+
<plugin>
35+
<artifactId>maven-compiler-plugin</artifactId>
36+
<version>3.7.0</version>
37+
<configuration>
38+
<source>1.8</source>
39+
<target>1.8</target>
40+
</configuration>
41+
</plugin>
42+
</plugins>
43+
</build>
44+
45+
46+
</project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.atomix.example;
2+
3+
import io.atomix.AtomixReplica;
4+
import io.atomix.catalyst.transport.Address;
5+
import io.atomix.catalyst.transport.netty.NettyTransport;
6+
import io.atomix.copycat.server.storage.Storage;
7+
import io.atomix.copycat.server.storage.StorageLevel;
8+
9+
import java.io.File;
10+
import java.util.concurrent.CompletableFuture;
11+
12+
public class BootstrapingCluster {
13+
14+
public static void main(String[] args) {
15+
Storage storage = Storage.builder()
16+
.withDirectory(new File("log"))
17+
.withStorageLevel(StorageLevel.DISK)
18+
.build();
19+
AtomixReplica replica = AtomixReplica.builder(new Address("localhost", 8700))
20+
.withStorage(storage)
21+
.withTransport(new NettyTransport())
22+
.build();
23+
24+
CompletableFuture<AtomixReplica> completableFuture = replica.bootstrap();
25+
completableFuture.join();
26+
}
27+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package com.atomix.example;
2+
3+
import io.atomix.AtomixReplica;
4+
import io.atomix.catalyst.transport.Address;
5+
import io.atomix.catalyst.transport.netty.NettyTransport;
6+
import io.atomix.concurrent.DistributedLock;
7+
import io.atomix.copycat.server.storage.Storage;
8+
import io.atomix.copycat.server.storage.StorageLevel;
9+
10+
import java.io.File;
11+
import java.util.Arrays;
12+
import java.util.List;
13+
14+
public class OtherNodes {
15+
16+
public static void main(String[] args) throws InterruptedException {
17+
List<Address> cluster = Arrays
18+
.asList(
19+
new Address("localhost", 8700),
20+
new Address("localhost", 8701),
21+
new Address("localhost", 8702));
22+
23+
Storage storage = Storage.builder()
24+
.withDirectory(new File("log"))
25+
.withStorageLevel(StorageLevel.DISK)
26+
.build();
27+
28+
AtomixReplica replica2 = AtomixReplica.builder(new Address("localhost", 8701))
29+
.withStorage(storage)
30+
.withTransport(new NettyTransport())
31+
.build();
32+
33+
WorkerThread WT1 = new WorkerThread(replica2, cluster);
34+
WT1.run();
35+
36+
AtomixReplica replica3 = AtomixReplica.builder(new Address("localhost", 8702))
37+
.withStorage(storage)
38+
.withTransport(new NettyTransport())
39+
.build();
40+
41+
WorkerThread WT2 = new WorkerThread(replica3, cluster);
42+
WT2.run();
43+
44+
Thread.sleep(6000);
45+
46+
DistributedLock lock = replica2.getLock("my-lock")
47+
.join();
48+
lock.lock()
49+
.thenRun(() -> System.out.println("Acquired a lock"));
50+
51+
replica2.getMap("map")
52+
.thenCompose(m -> m.put("bar", "Hello world!"))
53+
.thenRun(() -> System.out.println("Value is set in Distributed Map"))
54+
.join();
55+
}
56+
57+
private static class WorkerThread extends Thread {
58+
private AtomixReplica replica;
59+
private List<Address> cluster;
60+
61+
WorkerThread(AtomixReplica replica, List<Address> cluster) {
62+
this.replica = replica;
63+
this.cluster = cluster;
64+
}
65+
66+
public void run() {
67+
replica.join(cluster)
68+
.join();
69+
}
70+
}
71+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.atomix.exampletest;
2+
3+
import io.atomix.AtomixClient;
4+
import io.atomix.catalyst.transport.Address;
5+
import io.atomix.catalyst.transport.netty.NettyTransport;
6+
import org.junit.Test;
7+
8+
import java.util.Arrays;
9+
import java.util.List;
10+
import java.util.concurrent.ExecutionException;
11+
12+
import static org.junit.Assert.assertEquals;
13+
14+
public class AtomixClientLiveTest {
15+
16+
private final AtomixClient client = AtomixClient.builder()
17+
.withTransport(new NettyTransport())
18+
.build();
19+
20+
@Test
21+
public void whenBootstrap_thenShouldGet() throws InterruptedException, ExecutionException {
22+
List<Address> cluster = Arrays.asList(
23+
new Address("localhost", 8700),
24+
new Address("localhsot", 8701));
25+
26+
String value = client.connect(cluster)
27+
.thenRun(() -> System.out.println("Client Connected"))
28+
.thenCompose(c -> client.getMap("map"))
29+
.thenCompose(m -> m.get("bar"))
30+
.thenApply(a -> (String) a)
31+
.get();
32+
33+
assertEquals("Hello world!", value);
34+
}
35+
}

‎libraries/pom.xml‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -585,11 +585,6 @@
585585
<artifactId>fugue</artifactId>
586586
<version>3.0.0-m007</version>
587587
</dependency>
588-
<dependency>
589-
<groupId>org.jgrapht</groupId>
590-
<artifactId>jgrapht-core</artifactId>
591-
<version>1.0.1</version>
592-
</dependency>
593588
</dependencies>
594589
<repositories>
595590
<repository>

0 commit comments

Comments
 (0)