Skip to content

Commit

Permalink
Added SiteMasters to UnicastDistRpc and UPerf
Browse files Browse the repository at this point in the history
  • Loading branch information
belaban committed Nov 20, 2012
1 parent 1f5cac7 commit 8f2e7e0
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 12 deletions.
5 changes: 5 additions & 0 deletions src/org/jgroups/protocols/relay/SiteUUID.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.jgroups.util.Util;

import java.io.*;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
Expand Down Expand Up @@ -52,6 +53,10 @@ public static void replaceInCache(short site, String name) {
site_cache.put(site, name);
}

public static Collection<String> cacheValues() {return site_cache.values();}

public static boolean hasCacheValues() {return !site_cache.isEmpty();}

public static String getSiteName(short site) {
return site_cache.get(site);
}
Expand Down
17 changes: 16 additions & 1 deletion tests/other/org/jgroups/tests/UnicastTestRpc.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.jgroups.*;
import org.jgroups.blocks.*;
import org.jgroups.jmx.JmxConfigurator;
import org.jgroups.protocols.relay.SiteMaster;
import org.jgroups.protocols.relay.SiteUUID;
import org.jgroups.util.Buffer;
import org.jgroups.util.Util;

Expand Down Expand Up @@ -259,7 +261,20 @@ void printView() {

private Address getReceiver() {
try {
List<Address> mbrs=channel.getView().getMembers();
List<Address> mbrs=new ArrayList<Address>(channel.getView().getMembers());

if(SiteUUID.hasCacheValues()) {
for(String site_master: SiteUUID.cacheValues()) {
try {
SiteMaster sm=new SiteMaster(site_master);
mbrs.add(sm);
}
catch(Throwable t) {
System.err.println("failed creating site master: " + t);
}
}
}

System.out.println("pick receiver from the following members:");
int i=0;
for(Address mbr: mbrs) {
Expand Down
56 changes: 45 additions & 11 deletions tests/perf/org/jgroups/tests/perf/UPerf.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.jgroups.jmx.JmxConfigurator;
import org.jgroups.protocols.UNICAST;
import org.jgroups.protocols.UNICAST2;
import org.jgroups.protocols.relay.SiteMaster;
import org.jgroups.protocols.relay.SiteUUID;
import org.jgroups.stack.Protocol;
import org.jgroups.util.*;

Expand All @@ -28,11 +30,12 @@
* @author Bela Ban
*/
public class UPerf extends ReceiverAdapter {
private JChannel channel;
private Address local_addr;
private RpcDispatcher disp;
static final String groupname="uperf";
private final List<Address> members=new ArrayList<Address>();
private JChannel channel;
private Address local_addr;
private RpcDispatcher disp;
static final String groupname="uperf";
protected final List<Address> members=new ArrayList<Address>();
protected final List<Address> site_masters=new ArrayList<Address>();


// ============ configurable properties ==================
Expand Down Expand Up @@ -94,7 +97,7 @@ public class UPerf extends ReceiverAdapter {
}


public void init(String props, String name) throws Throwable {
public void init(String props, String name, boolean xsite) throws Throwable {
channel=new JChannel(props);
if(name != null)
channel.setName(name);
Expand All @@ -108,6 +111,18 @@ public Method findMethod(short id) {
channel.connect(groupname);
local_addr=channel.getAddress();

if(xsite) {
if(SiteUUID.hasCacheValues())
for(String site_master: SiteUUID.cacheValues()) {
try {
site_masters.add(new SiteMaster(site_master));
}
catch(Throwable t) {
System.err.println("failed creating SiteMaster(" + site_master + "): " + t);
}
}
}

try {
MBeanServer server=Util.getMBeanServer();
JmxConfigurator.registerChannel(channel, server, "jgroups", channel.getClusterName(), true);
Expand Down Expand Up @@ -145,11 +160,23 @@ public void viewAccepted(View new_view) {
System.out.println("** view: " + new_view);
members.clear();
members.addAll(new_view.getMembers());
addSiteMastersToMembers();
}

protected void addSiteMastersToMembers() {
if(!site_masters.isEmpty()) {
for(Address sm: site_masters)
if(!members.contains(sm))
members.add(sm);
}
}

// =================================== callbacks ======================================

public Results startTest() throws Throwable {

addSiteMastersToMembers();

System.out.println("invoking " + num_msgs + " RPCs of " + Util.printBytes(msg_size) +
", sync=" + sync + ", oob=" + oob + ", use_anycast_addrs=" + use_anycast_addrs);
int total_gets=0, total_puts=0;
Expand Down Expand Up @@ -234,6 +261,8 @@ public ConfigOptions getConfig() {
public void eventLoop() throws Throwable {
int c;

addSiteMastersToMembers();

while(true) {
c=Util.keyPress("[1] Send msgs [2] Print view [3] Print conns " +
"[4] Trash conn [5] Trash all conns" +
Expand Down Expand Up @@ -401,7 +430,7 @@ void setAnycastCount() throws Exception {


void printView() {
System.out.println("\n-- view: " + channel.getView() + '\n');
System.out.println("\n-- view: " + members + '\n');
try {
System.in.skip(System.in.available());
}
Expand Down Expand Up @@ -704,8 +733,9 @@ private static byte[] booleanBuffer(short type, Boolean arg) {


public static void main(String[] args) {
String props=null;
String name=null;
String props=null;
String name=null;
boolean xsite=true;


for(int i=0; i < args.length; i++) {
Expand All @@ -717,14 +747,18 @@ public static void main(String[] args) {
name=args[++i];
continue;
}
if("-xsite".equals(args[i])) {
xsite=Boolean.valueOf(args[++i]);
continue;
}
help();
return;
}

UPerf test=null;
try {
test=new UPerf();
test.init(props, name);
test.init(props, name, xsite);
test.eventLoop();
}
catch(Throwable ex) {
Expand All @@ -735,7 +769,7 @@ public static void main(String[] args) {
}

static void help() {
System.out.println("UPerf [-props <props>] [-name name]");
System.out.println("UPerf [-props <props>] [-name name] [-xsite <true | false>]");
}


Expand Down

0 comments on commit 8f2e7e0

Please sign in to comment.