@@ -0,0 +1,2987 @@
+package org.jgroups.demos;%0A%0Aimport org.jgroups.*;%0Aimport org.jgroups.blocks.MethodCall;%0Aimport org.jgroups.blocks.Request;%0Aimport org.jgroups.blocks.RequestOptions;%0Aimport org.jgroups.blocks.RpcDispatcher;%0Aimport org.jgroups.util.ProxyAddress;%0Aimport org.jgroups.util.Rsp;%0Aimport org.jgroups.util.RspList;%0Aimport org.jgroups.util.Util;%0A%0Aimport java.lang.reflect.Method;%0A%0A/** Demos RELAY. Create 2 *separate* clusters with RELAY as top protocol. Each RELAY has bridge_props=%22tcp.xml%22 (tcp.xml%0A * needs to be present). Then start 2 instances in the first cluster and 2 instances in the second cluster. They should%0A * find each other, and typing in a window should send the text to everyone, plus we should get 4 responses.%0A * @author Bela Ban%0A */%0Apublic class RelayDemoRpc extends ReceiverAdapter %7B%0A    JChannel ch;%0A    RpcDispatcher disp;%0A    Address local_addr;%0A%0A%0A%0A%0A    public static void main(String%5B%5D args) throws Exception %7B%0A        String props=%22udp.xml%22;%0A        String name=null;%0A%0A%0A        for(int i=0; i %3C args.length; i++) %7B%0A            if(args%5Bi%5D.equals(%22-props%22)) %7B%0A                props=args%5B++i%5D;%0A                continue;%0A            %7D%0A            if(args%5Bi%5D.equals(%22-name%22)) %7B%0A                name=args%5B++i%5D;%0A                continue;%0A            %7D%0A            System.out.println(%22RelayDemo %5B-props props%5D %5B-name name%5D%22);%0A            return;%0A        %7D%0A        RelayDemoRpc demo=new RelayDemoRpc();%0A        demo.start(props, name);%0A    %7D%0A%0A    public void start(String props, String name) throws Exception %7B%0A        ch=new JChannel(props);%0A        if(name != null)%0A            ch.setName(name);%0A        disp=new RpcDispatcher(ch, null, this, this);%0A        ch.connect(%22RelayDemo%22);%0A        local_addr=ch.getAddress();%0A%0A        MethodCall call=new MethodCall(getClass().getMethod(%22handleMessage%22, String.class, Address.class));%0A        for(;;) %7B%0A            String line=Util.readStringFromStdin(%22: %22);%0A            call.setArgs(new Object%5B%5D%7Bline, local_addr%7D);%0A            RspList rsps=disp.callRemoteMethods(null, call, new RequestOptions(Request.GET_ALL, 5000).setAnycasting(true));%0A            for(Rsp rsp: rsps.values())%0A                System.out.println(%22%3C%3C %22 + rsp.getValue() + %22 from %22 + rsp.getSender());%0A        %7D%0A    %7D%0A%0A    public static String handleMessage(String msg, Address sender) %7B%0A        System.out.println(%22%3C%3C %22 + msg + %22 from %22 + sender);%0A        return %22this is a response%22;%0A    %7D%0A%0A%0A    public void viewAccepted(View new_view) %7B%0A        System.out.println(%22view: %22 + print(new_view));%0A    %7D%0A%0A%0A    static String print(View view) %7B%0A        StringBuilder sb=new StringBuilder();%0A        boolean first=true;%0A        sb.append(view.getViewId()).append(%22: %22);%0A        for(Address mbr: view.getMembers()) %7B%0A            if(first)%0A                first=false;%0A            else%0A                sb.append(%22, %22);%0A            sb.append(mbr);%0A            if(mbr instanceof ProxyAddress)%0A               sb.append(%22(p)%22);%0A        %7D%0A        return sb.toString();%0A    %7D%0A%7D%0A

Copy of RelayDemo using RPCs instead of messages