本站首页    管理页面    写新日志    退出


«September 2025»
123456
78910111213
14151617181920
21222324252627
282930


公告

戒除浮躁,读好书,交益友


我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:邢红瑞的blog
日志总数:523
评论数量:1142
留言数量:0
访问次数:9704812
建立时间:2004年12月20日




[java语言]jgroup使用RpcDispatcher和自身进行通讯的例子
原创空间,  软件技术,  电脑与网络

邢红瑞 发表于 2006/5/28 11:05:29

主要是callRemoteMethods的调用 import org.jgroups.*;import org.jgroups.util.RspList;import org.jgroups.util.Util;import org.jgroups.blocks.RpcDispatcher;import org.jgroups.blocks.GroupRequest; import java.util.Vector;public class RpcDispatcherSimpleClient implements ChannelListener {    public void print(String a, String b) {        System.out.println(a + b);    }     Channel channel;    RpcDispatcher disp;    RspList rsp_list;    private String props =      "UDP:"      + "PING(num_initial_members=2;timeout=3000):"      + "FD:"      + "pbcast.PBCAST(gossip_interval=5000;gc_lag=50):"      + "UNICAST:"      + "FRAG:"      + "pbcast.GMS:"      + "pbcast.STATE_TRANSFER";     public void start(int num, long interval) throws Exception {        channel = new JChannel(props);        channel.setOpt(Channel.AUTO_RECONNECT, Boolean.TRUE);        disp = new RpcDispatcher(channel, null, null, this);        channel.addChannelListener(this);        channel.connect("RpcDispatcherTestGroup");         for (int i = 0; i < num; i++) {            System.out.println("Requesting num=" + num + ", interval=" + interval);             View v = channel.getView();            Vector members = new Vector(v.getMembers());            System.out.println("sending to " + members);             Util.sleep(interval);             if (members.size() > 1) {                members.remove(0);                 rsp_list = disp.callRemoteMethods(members, "print", new Object[]{"Key_" + i, "Value_" + i}, new Class[]{String.class, String.class}, GroupRequest.GET_ALL, 30000);                System.out.println("Responses: " + rsp_list);            }        }        System.out.println("Closing channel");        channel.close();        System.out.println("Closing channel: -- done");         System.out.println("Stopping dispatcher");        disp.stop();        System.out.println("Stopping dispatcher: -- done");    }     public static void main(String[] args) {        int num = 10;        long interval = 1000;        for (int i = 0; i < args.length; i++) {            if (args[i].equals("-num")) {                num = Integer.parseInt(args[++i]);                continue;            }            if (args[i].equals("-interval")) {                interval = Long.parseLong(args[++i]);                continue;            }            help();            return;        }         try {            new RpcDispatcherSimpleClient().start(num, interval);        }        catch (Exception e) {            System.err.println(e);        }    }     private static void help() {        System.out.println("RpcDispatcherTest [-help] [-num <number of msgs>] [-interval <sleep in ms between calls>]");    }     public void channelConnected(Channel channel) {        //To change body of implemented methods use File | Settings | File Templates.    }     public void channelDisconnected(Channel channel) {        //To change body of implemented methods use File | Settings | File Templates.    }     public void channelClosed(Channel channel) {        //To change body of implemented methods use File | Settings | File Templates.    }     public void channelShunned() {        //To change body of implemented methods use File | Settings | File Templates.    }     public void channelReconnected(Address address) {        //To change body of implemented methods use File | Settings | File Templates.    }}以上代码 没有用于启明星辰任何产品中(包括UTM)。


阅读全文(5319) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.313 second(s), page refreshed 144782100 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号