Skip to content

Commit

Permalink
- Provide global views for RELAY2 (https://issues.redhat.com/browse/J…
Browse files Browse the repository at this point in the history
…GRP-2698)

- Moved Relay2Header out of RELAY2 into its own class
- Added site_cache to RELAY2 to suppress duplicate siteUp() notifications
- Added Topology component to RELAY2
  • Loading branch information
belaban committed Jun 19, 2023
1 parent 1f13edd commit eb9ca4e
Show file tree
Hide file tree
Showing 12 changed files with 637 additions and 329 deletions.
3 changes: 2 additions & 1 deletion conf/jg-magic-map.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<class id="76" name="org.jgroups.protocols.RSVP$RsvpHeader"/>
<class id="77" name="org.jgroups.tests.perf.MPerf$MPerfHeader"/>
<class id="78" name="org.jgroups.protocols.pbcast.NakAckHeader2"/>
<class id="80" name="org.jgroups.protocols.relay.RELAY2$Relay2Header"/>
<class id="80" name="org.jgroups.protocols.relay.Relay2Header"/>
<class id="82" name="org.jgroups.protocols.UnicastHeader3"/>
<class id="83" name="org.jgroups.protocols.FORK$ForkHeader"/>
<class id="84" name="org.jgroups.protocols.PERF$PerfHeader"/>
Expand All @@ -63,6 +63,7 @@
<class id="96" name="org.jgroups.protocols.BATCH2$Batch2Header"/>
<class id="97" name="org.jgroups.protocols.RTTHeader"/>
<class id="98" name="org.jgroups.protocols.ProtPerfHeader"/>
<class id="99" name="org.jgroups.protocols.relay.TopoHeader"/>

</magic-number-class-mapping>

3 changes: 3 additions & 0 deletions conf/jg-protocol-ids.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@

<class id="550" name="org.jgroups.protocols.OPEN_TELEMETRY" external="true"/>

<!-- Used to attach TopoHeader in RELAY2 -->
<class id="560" name="org.jgroups.protocols.relay.RELAY2" external="true"/>

<!-- User-defined protocols should use IDs >= 1024 -->

</protocol-ids>
23 changes: 17 additions & 6 deletions src/org/jgroups/demos/RelayDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import org.jgroups.*;
import org.jgroups.protocols.relay.RELAY2;
import org.jgroups.protocols.relay.RouteStatusListener;
import org.jgroups.protocols.relay.Topology;
import org.jgroups.util.ExtendedUUID;
import org.jgroups.util.UUID;
import org.jgroups.util.Util;

import java.util.List;

/** Demos RELAY. Create 2 *separate* clusters with RELAY as top protocol. Each RELAY has bridge_props="tcp.xml" (tcp.xml
* needs to be present). Then start 2 instances in the first cluster and 2 instances in the second cluster. They should
* find each other, and typing in a window should send the text to everyone, plus we should get 4 responses.
Expand All @@ -22,7 +25,7 @@ public class RelayDemo implements Receiver {
public static void main(String[] args) throws Exception {
String props="udp.xml";
String name=null;
boolean print_route_status=false, nohup=false;
boolean print_route_status=true, nohup=false;

for(int i=0; i < args.length; i++) {
if(args[i].equals("-props")) {
Expand Down Expand Up @@ -53,7 +56,7 @@ public void receive(Message msg) {
System.out.println("<< " + msg.getObject() + " from " + sender);
Address dst=msg.getDest();
if(dst == null) {
Message rsp=new BytesMessage(msg.getSrc(), "response");
Message rsp=new ObjectMessage(msg.getSrc(), "response");
try {
ch.send(rsp);
}
Expand Down Expand Up @@ -102,7 +105,8 @@ protected void eventLoop(JChannel ch) {
break;
if(process(line)) // see if we have a command, otherwise pass down
continue;
ch.send(null, line);
ObjectMessage msg=new ObjectMessage(null, line);
ch.send(msg);
}
catch(Throwable t) {
t.printStackTrace();
Expand All @@ -129,11 +133,18 @@ protected boolean process(String line) {
System.out.printf("configured sites: %s\n", relay.getSites());
return true;
}
if(line.equalsIgnoreCase("topo")) {
System.out.printf("\n%s\n", printTopology());
if(line.startsWith("topo")) {
String sub=line.substring("topo".length()).trim();
String site=null;
if(sub != null && !sub.isEmpty()) {
String[] tmp=sub.split(" ");
site=tmp.length > 0 && !tmp[0].isEmpty()? tmp[0].trim() : null;
}
Topology topo=relay.topo().removeAll(site != null? List.of(site) : null).refresh(site);
Util.sleep(100);
System.out.printf("\n%s\n", topo.print(site));
return true;
}

return false;
}

Expand Down
Loading

0 comments on commit eb9ca4e

Please sign in to comment.