Fixed build

This commit is contained in:
Jaime Freire
2023-11-25 08:18:02 +01:00
parent db9bb4ccdf
commit 789a5f6abc
141 changed files with 3259 additions and 2957 deletions

View File

@ -94,12 +94,16 @@ public class RunStandardExamples {
private static String usage() {
return "Select and run (usually in a seperate terminal window) \n"
+ "one of the the standard Examples,\n" + " 1. StandAloneNode\n"
+ " 2. StandAloneNodeCrdtOrSet\n" + " 3. StandAlonePNCounter\n"
+ " 4. StandAloneDatacenterAndRack\n" + "(See README.md in this modules)\n" + "\n"
+ "Usage: mvn exec:java -Dexec.mainClass=org.apache.gossip.examples.RunStandardExamples -Dexec.args=\"s c\"\n"
+ "where...\n" + " s - int - the example number from above\n"
+ " c - int - the channel number: 0, 1, or 2\n";
+ "one of the the standard Examples,\n"
+ " 1. StandAloneNode\n"
+ " 2. StandAloneNodeCrdtOrSet\n"
+ " 3. StandAlonePNCounter\n"
+ " 4. StandAloneDatacenterAndRack\n"
+ "(See README.md in this modules)\n"
+ "\n"
+ "Usage: mvn exec:java -Dexec.mainClass=org.apache.gossip.examples.RunStandardExamples -Dexec.args=\"s c\"\n"
+ "where...\n"
+ " s - int - the example number from above\n"
+ " c - int - the channel number: 0, 1, or 2\n";
}
}

View File

@ -32,17 +32,17 @@ import org.apache.gossip.manager.GossipManagerBuilder;
public class StandAloneDatacenterAndRack extends StandAloneExampleBase {
StandAloneDatacenterAndRack(String[] args) {
args = super.checkArgsForClearFlag(args);
initGossipManager(args);
}
public static void main(String[] args) throws InterruptedException, IOException {
StandAloneDatacenterAndRack example = new StandAloneDatacenterAndRack(args);
boolean willRead = true;
example.exec(willRead);
}
StandAloneDatacenterAndRack(String[] args) {
args = super.checkArgsForClearFlag(args);
initGossipManager(args);
}
void initGossipManager(String[] args) {
GossipSettings s = new GossipSettings();
s.setWindowSize(1000);
@ -55,11 +55,16 @@ public class StandAloneDatacenterAndRack extends StandAloneExampleBase {
Map<String, String> props = new HashMap<>();
props.put(DatacenterRackAwareActiveGossiper.DATACENTER, args[4]);
props.put(DatacenterRackAwareActiveGossiper.RACK, args[5]);
GossipManager manager = GossipManagerBuilder.newBuilder().cluster("mycluster")
.uri(URI.create(args[0])).id(args[1]).gossipSettings(s)
GossipManager manager =
GossipManagerBuilder.newBuilder()
.cluster("mycluster")
.uri(URI.create(args[0]))
.id(args[1])
.gossipSettings(s)
.gossipMembers(
Arrays.asList(new RemoteMember("mycluster", URI.create(args[2]), args[3])))
.properties(props).build();
Arrays.asList(new RemoteMember("mycluster", URI.create(args[2]), args[3])))
.properties(props)
.build();
manager.init();
setGossipService(manager);
}
@ -68,5 +73,4 @@ public class StandAloneDatacenterAndRack extends StandAloneExampleBase {
void printValues(GossipManager gossipService) {
return;
}
}

View File

@ -90,18 +90,20 @@ abstract class StandAloneExampleBase {
}
private void startMonitorLoop(GossipManager gossipService) {
new Thread(() -> {
while (true) {
optionallyClearTerminal();
printLiveMembers(gossipService);
printDeadMambers(gossipService);
printValues(gossipService);
try {
Thread.sleep(2000);
} catch (Exception ignore) {
}
}
}).start();
new Thread(
() -> {
while (true) {
optionallyClearTerminal();
printLiveMembers(gossipService);
printDeadMambers(gossipService);
printValues(gossipService);
try {
Thread.sleep(2000);
} catch (Exception ignore) {
}
}
})
.start();
}
private void printLiveMembers(GossipManager gossipService) {
@ -143,11 +145,16 @@ abstract class StandAloneExampleBase {
GossipSettings s = new GossipSettings();
s.setWindowSize(1000);
s.setGossipInterval(100);
GossipManager gossipService = GossipManagerBuilder.newBuilder().cluster("mycluster")
.uri(URI.create(args[0])).id(args[1])
.gossipMembers(Collections
.singletonList(new RemoteMember("mycluster", URI.create(args[2]), args[3])))
.gossipSettings(s).build();
GossipManager gossipService =
GossipManagerBuilder.newBuilder()
.cluster("mycluster")
.uri(URI.create(args[0]))
.id(args[1])
.gossipMembers(
Collections.singletonList(
new RemoteMember("mycluster", URI.create(args[2]), args[3])))
.gossipSettings(s)
.build();
setGossipService(gossipService);
}
@ -158,5 +165,4 @@ abstract class StandAloneExampleBase {
GossipManager getGossipManager() {
return this.gossipService;
}
}

View File

@ -18,23 +18,22 @@
package org.apache.gossip.examples;
import java.io.IOException;
import org.apache.gossip.manager.GossipManager;
public class StandAloneNode extends StandAloneExampleBase {
private static boolean WILL_READ = false;
public static void main(String[] args) throws InterruptedException, IOException {
StandAloneNode example = new StandAloneNode(args);
example.exec(WILL_READ);
}
StandAloneNode(String[] args) {
args = super.checkArgsForClearFlag(args);
super.initGossipManager(args);
}
public static void main(String[] args) throws InterruptedException, IOException {
StandAloneNode example = new StandAloneNode(args);
example.exec(WILL_READ);
}
@Override
void printValues(GossipManager gossipService) {
}

View File

@ -30,25 +30,76 @@ public class StandAloneNodeCrdtOrSet extends StandAloneExampleBase {
private static final String INDEX_KEY_FOR_COUNTER = "def";
StandAloneNodeCrdtOrSet(String[] args) {
args = super.checkArgsForClearFlag(args);
super.initGossipManager(args);
}
public static void main(String[] args) throws InterruptedException, IOException {
StandAloneNodeCrdtOrSet example = new StandAloneNodeCrdtOrSet(args);
boolean willRead = true;
example.exec(willRead);
}
StandAloneNodeCrdtOrSet(String[] args) {
args = super.checkArgsForClearFlag(args);
super.initGossipManager(args);
private static void listen(String val, GossipManager gossipManager) {
gossipManager.registerSharedDataSubscriber(
(key, oldValue, newValue) -> {
if (key.equals(val)) {
System.out.println(
"Event Handler fired for key = '" + key + "'! " + oldValue + " " + newValue);
}
});
}
private static void gcount(String val, GossipManager gossipManager) {
GrowOnlyCounter c = (GrowOnlyCounter) gossipManager.findCrdt(INDEX_KEY_FOR_COUNTER);
Long l = Long.valueOf(val);
if (c == null) {
c = new GrowOnlyCounter(new GrowOnlyCounter.Builder(gossipManager).increment((l)));
} else {
c = new GrowOnlyCounter(c, new GrowOnlyCounter.Builder(gossipManager).increment((l)));
}
SharedDataMessage m = new SharedDataMessage();
m.setExpireAt(Long.MAX_VALUE);
m.setKey(INDEX_KEY_FOR_COUNTER);
m.setPayload(c);
m.setTimestamp(System.currentTimeMillis());
gossipManager.merge(m);
}
private static void removeData(String val, GossipManager gossipService) {
@SuppressWarnings("unchecked")
OrSet<String> s = (OrSet<String>) gossipService.findCrdt(INDEX_KEY_FOR_SET);
SharedDataMessage m = new SharedDataMessage();
m.setExpireAt(Long.MAX_VALUE);
m.setKey(INDEX_KEY_FOR_SET);
m.setPayload(new OrSet<String>(s, new OrSet.Builder<String>().remove(val)));
m.setTimestamp(System.currentTimeMillis());
gossipService.merge(m);
}
private static void addData(String val, GossipManager gossipService) {
SharedDataMessage m = new SharedDataMessage();
m.setExpireAt(Long.MAX_VALUE);
m.setKey(INDEX_KEY_FOR_SET);
m.setPayload(new OrSet<String>(val));
m.setTimestamp(System.currentTimeMillis());
gossipService.merge(m);
}
void printValues(GossipManager gossipService) {
System.out.println("Last Input: " + getLastInput());
System.out.println("---------- Or Set " + (gossipService.findCrdt(INDEX_KEY_FOR_SET) == null
? "" : gossipService.findCrdt(INDEX_KEY_FOR_SET).value()));
System.out.println(
"---------- Or Set "
+ (gossipService.findCrdt(INDEX_KEY_FOR_SET) == null
? ""
: gossipService.findCrdt(INDEX_KEY_FOR_SET).value()));
System.out.println("********** " + gossipService.findCrdt(INDEX_KEY_FOR_SET));
System.out.println(
"^^^^^^^^^^ Grow Only Counter" + (gossipService.findCrdt(INDEX_KEY_FOR_COUNTER) == null
? "" : gossipService.findCrdt(INDEX_KEY_FOR_COUNTER).value()));
"^^^^^^^^^^ Grow Only Counter"
+ (gossipService.findCrdt(INDEX_KEY_FOR_COUNTER) == null
? ""
: gossipService.findCrdt(INDEX_KEY_FOR_COUNTER).value()));
System.out.println("$$$$$$$$$$ " + gossipService.findCrdt(INDEX_KEY_FOR_COUNTER));
}
@ -88,50 +139,4 @@ public class StandAloneNodeCrdtOrSet extends StandAloneExampleBase {
}
return (l >= 0);
}
private static void listen(String val, GossipManager gossipManager) {
gossipManager.registerSharedDataSubscriber((key, oldValue, newValue) -> {
if (key.equals(val)) {
System.out.println(
"Event Handler fired for key = '" + key + "'! " + oldValue + " " + newValue);
}
});
}
private static void gcount(String val, GossipManager gossipManager) {
GrowOnlyCounter c = (GrowOnlyCounter) gossipManager.findCrdt(INDEX_KEY_FOR_COUNTER);
Long l = Long.valueOf(val);
if (c == null) {
c = new GrowOnlyCounter(new GrowOnlyCounter.Builder(gossipManager).increment((l)));
} else {
c = new GrowOnlyCounter(c, new GrowOnlyCounter.Builder(gossipManager).increment((l)));
}
SharedDataMessage m = new SharedDataMessage();
m.setExpireAt(Long.MAX_VALUE);
m.setKey(INDEX_KEY_FOR_COUNTER);
m.setPayload(c);
m.setTimestamp(System.currentTimeMillis());
gossipManager.merge(m);
}
private static void removeData(String val, GossipManager gossipService) {
@SuppressWarnings("unchecked")
OrSet<String> s = (OrSet<String>) gossipService.findCrdt(INDEX_KEY_FOR_SET);
SharedDataMessage m = new SharedDataMessage();
m.setExpireAt(Long.MAX_VALUE);
m.setKey(INDEX_KEY_FOR_SET);
m.setPayload(new OrSet<String>(s, new OrSet.Builder<String>().remove(val)));
m.setTimestamp(System.currentTimeMillis());
gossipService.merge(m);
}
private static void addData(String val, GossipManager gossipService) {
SharedDataMessage m = new SharedDataMessage();
m.setExpireAt(Long.MAX_VALUE);
m.setKey(INDEX_KEY_FOR_SET);
m.setPayload(new OrSet<String>(val));
m.setTimestamp(System.currentTimeMillis());
gossipService.merge(m);
}
}

View File

@ -25,21 +25,24 @@ import org.apache.gossip.model.SharedDataMessage;
public class StandAlonePNCounter extends StandAloneExampleBase {
StandAlonePNCounter(String[] args) {
args = super.checkArgsForClearFlag(args);
super.initGossipManager(args);
}
public static void main(String[] args) throws InterruptedException, IOException {
StandAlonePNCounter example = new StandAlonePNCounter(args);
boolean willRead = true;
example.exec(willRead);
}
StandAlonePNCounter(String[] args) {
args = super.checkArgsForClearFlag(args);
super.initGossipManager(args);
}
void printValues(GossipManager gossipService) {
System.out.println("Last Input: " + getLastInput());
System.out.println("---------- " + (gossipService.findCrdt("myPNCounter") == null ? ""
: gossipService.findCrdt("myPNCounter").value()));
System.out.println(
"---------- "
+ (gossipService.findCrdt("myPNCounter") == null
? ""
: gossipService.findCrdt("myPNCounter").value()));
System.out.println("********** " + gossipService.findCrdt("myPNCounter"));
}
@ -94,5 +97,4 @@ public class StandAlonePNCounter extends StandAloneExampleBase {
m.setTimestamp(System.currentTimeMillis());
gossipManager.merge(m);
}
}
}