Init example project with JavaFX

This commit is contained in:
ChronosX88 2023-12-11 17:41:06 +03:00
parent 08912a6f67
commit b4659d9dbe
11 changed files with 2 additions and 156 deletions

View File

@ -1,2 +1,4 @@
rootProject.name = 'JGUN' rootProject.name = 'JGUN'
include 'examples:chat'
findProject(':examples:chat')?.name = 'chat'

View File

@ -13,7 +13,6 @@ import io.github.chronosx88.JGUN.storage.StorageManager;
import java.util.*; import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.util.stream.Stream;
public class PathReference { public class PathReference {
private final List<String> path = new ArrayList<>(); private final List<String> path = new ArrayList<>();

View File

@ -6,7 +6,6 @@ import io.github.chronosx88.JGUN.models.graph.NodeValue;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.List;
import java.util.UUID; import java.util.UUID;
public class NodeBuilder { public class NodeBuilder {

View File

@ -1,40 +0,0 @@
package io.github.chronosx88.JGUN.examples;
import io.github.chronosx88.JGUN.api.Gun;
import io.github.chronosx88.JGUN.api.graph.ArrayBuilder;
import io.github.chronosx88.JGUN.api.graph.NodeBuilder;
import io.github.chronosx88.JGUN.models.Result;
import io.github.chronosx88.JGUN.network.NetworkNode;
import io.github.chronosx88.JGUN.storage.MemoryStorage;
import io.github.chronosx88.JGUN.storage.Storage;
import java.net.Inet4Address;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.util.concurrent.ExecutionException;
public class MainClient {
public static void main(String[] args) throws URISyntaxException, UnknownHostException, ExecutionException, InterruptedException {
Storage storage = new MemoryStorage();
NetworkNode peer = new NetworkNode(Inet4Address.getByAddress(new byte[]{127, 0, 0, 1}), 5054, storage);
Gun gun = new Gun(storage, peer);
Result result = gun.get("person").put(new NodeBuilder()
.add("firstName", "Test")
.build()).get();
System.out.println(result);
result = gun.get("person").get("address").put(new NodeBuilder()
.add("city", "Dallas")
.build()).get();
System.out.println(result);
result = gun.get("person").get("homeAddress").put(gun.get("person").get("address")).get();
System.out.println(result);
result = gun.get("person").get("homeAddress").put(new NodeBuilder()
.add("city", "New YORK CITY")
.build()).get();
System.out.println(result);
}
}

View File

@ -1,43 +0,0 @@
package io.github.chronosx88.JGUN.examples;
//public class MainClientServer {
// public static void main(String[] args) {
// GunSuperPeer gunSuperNode = new GunSuperPeer(21334, new MemoryStorage());
// gunSuperNode.start();
// Runnable task = () -> {
// Gun gun = null;
// try {
// gun = new Gun(Inet4Address.getByAddress(new byte[]{127, 0, 0, 1}), 21334, new MemoryStorage());
// } catch (UnknownHostException e) {
// e.printStackTrace();
// }
// gun.get("random").on(data -> {
// if(data != null) {
// System.out.println("New change in \"random\"! " + data.toString(2));
// }
// });
// gun.get("random").get("dVFtzE9CL").on(data -> {
// if(data != null) {
// System.out.println("New change in \"random/dVFtzE9CL\"! " + data.toString(2));
// } else {
// System.out.println("Now random/dVFtzE9CL is null!");
// }
//
// });
// gun.get("random").get("dVFtzE9CL").map(((key, value) -> {
// System.out.println("[Map] New change in \"random/dVFtzE9CL\"! " + key + " : " + value.toString());
// }));
// gun.get("random").map(((key, value) -> {
// System.out.println("[Map] New change in \"random\"! " + key + " : " + value);
// }));
// System.out.println("[FuturePut] Success: " + gun.get("random").get("dVFtzE9CL").put(new JSONObject().put("hello", "world")).await());
// System.out.println("[FuturePut] Putting an item again: " + gun.get("random").get("dVFtzE9CL").put(new JSONObject().put("hello", "123")).await());
// System.out.println("Deleting an item random/dVFtzE9CL");
// gun.get("random").get("dVFtzE9CL").put(null).await();
// gun.get("random").put(new JSONObject().put("hello", "world")).await();
// };
//
// Executor executorService = Executors.newSingleThreadExecutor();
// executorService.execute(task);
// }
//}

View File

@ -1,60 +0,0 @@
package io.github.chronosx88.JGUN.examples;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import io.github.chronosx88.JGUN.api.Gun;
import io.github.chronosx88.JGUN.api.NodeChangeListener;
import io.github.chronosx88.JGUN.api.graph.ArrayBuilder;
import io.github.chronosx88.JGUN.api.graph.NodeBuilder;
import io.github.chronosx88.JGUN.models.Result;
import io.github.chronosx88.JGUN.models.graph.Node;
import io.github.chronosx88.JGUN.network.GatewayNetworkNode;
import io.github.chronosx88.JGUN.network.NetworkNode;
import io.github.chronosx88.JGUN.storage.MemoryStorage;
import io.github.chronosx88.JGUN.storage.Storage;
import java.net.Inet4Address;
import java.util.concurrent.ExecutionException;
public class MainServer {
public static void main(String[] args) throws ExecutionException, InterruptedException {
Storage storage = new MemoryStorage();
GatewayNetworkNode peer = new GatewayNetworkNode(5054, storage);
Gun gun = new Gun(storage, peer);
Result result = gun.get("person").put(new NodeBuilder()
.add("firstName", "John")
.add("lastName", "Smith")
.add("age", 25)
.add("address", new NodeBuilder()
.add("streetAddress", "21 2nd Street")
.add("city", "New York")
.add("state", "NY")
.add("postalCode", "10021"))
.add("phoneNumber", new ArrayBuilder()
.add(new NodeBuilder()
.add("type", "home")
.add("number", "212 555-1234"))
.add(new NodeBuilder()
.add("type", "fax")
.add("number", "646 555-4567")))
.build()).get();
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new Jdk8Module());
gun.get("person").on(node -> {
try {
System.out.println(mapper.writeValueAsString(node));
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
});
gun.get("person").get("address").on(node -> {
try {
System.out.println(mapper.writeValueAsString(node));
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
});
System.out.println(result.isOk());
}
}

View File

@ -1,13 +1,7 @@
package io.github.chronosx88.JGUN.models; package io.github.chronosx88.JGUN.models;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import io.github.chronosx88.JGUN.models.acks.Ack;
import io.github.chronosx88.JGUN.models.acks.GetAck;
import io.github.chronosx88.JGUN.models.requests.GetRequest;
import io.github.chronosx88.JGUN.models.requests.PutRequest;
import lombok.Data; import lombok.Data;
import lombok.experimental.SuperBuilder; import lombok.experimental.SuperBuilder;

View File

@ -3,9 +3,7 @@ package io.github.chronosx88.JGUN.models.graph;
import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.extern.jackson.Jacksonized;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;

View File

@ -5,7 +5,6 @@ import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.extern.jackson.Jacksonized; import lombok.extern.jackson.Jacksonized;
import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;

View File

@ -9,7 +9,6 @@ import com.fasterxml.jackson.databind.JsonNode;
import io.github.chronosx88.JGUN.models.graph.values.*; import io.github.chronosx88.JGUN.models.graph.values.*;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
public class NodeValueDeserializer extends JsonDeserializer<NodeValue> { public class NodeValueDeserializer extends JsonDeserializer<NodeValue> {
@Override @Override

View File

@ -9,7 +9,6 @@ import io.github.chronosx88.JGUN.models.graph.NodeValue;
import io.github.chronosx88.JGUN.models.graph.values.NodeLinkValue; import io.github.chronosx88.JGUN.models.graph.values.NodeLinkValue;
import io.github.chronosx88.JGUN.models.requests.GetRequestParams; import io.github.chronosx88.JGUN.models.requests.GetRequestParams;
import io.github.chronosx88.JGUN.network.NetworkManager; import io.github.chronosx88.JGUN.network.NetworkManager;
import io.github.chronosx88.JGUN.utils.Pair;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;