jxta学习笔记3~jxta运行的基本步骤~
来源:互联网 发布:防火墙如何开启403端口 编辑:程序博客网 时间:2024/05/01 21:16
跑通了helloworld后,又运行了官网上的示例程序。现在总结下jxta运行的基本步骤:
1、创建一个组:
NetPeerGroupFatory factory = new NetPeerGroupFactory;
netPeerGroup = factory.getInterface( );//该方法返回一个PeerGroup对象
2、获取相应服务(发现服务,发现和发布广告):
首先在这里重新明确两个概念:
(1)广告:所有网络资源体现,以xml形式表现。
(2)管道服务:创建IN/OUT管道来接收发送消息。
OutPipe管道创建时会触发outputPipeEvent事件
InPipe有消息到来时会触发pipeMsgEvent事件
IN/OUT之间的联系通过广告,通过PipeID标识出来的管道建立联系。
discovery = netPeerGroup.getDiscoveryService( );//获得一个发现服务
rdv = netPeerGroup.getRendezVousService( );//集合点服务
3、通过注册服务监听器,在通过发现一个事件来获取广告。
discovery.addDisgoveryListener(this);//此处需要实现DiscoveryListener接口并实现其中的discoveryListener方法
API中的discoveryListener方法:
1、
public void discoveryEvent(DiscoveryEvent e) {
DiscoveryResponseMsg msg = e.getResponse();//获得DiscoveryService message "Response"
if (myQueryID == e.getQueryID()) {
int advCount = msg.getResponseCount();
}
}
由DiscoveryResponseMsg对象获取相应peer的广告:
PeerAdvertisement peerAdv =res.getPeerAdvetisement( );
2、通过服务直接获取广告
discovery.getRemoteAdvertisements(String peerid,int type,String attribute,String value,int threshold)
peerid
- peer的id 如果为空则传播到所有的与这个广告相匹配的peer,如果指定peerid则传到指定的peer。 type
- 发现的类型:可选项有 PEER, GROUP 或者 ADV。 attribute
- indexed element name 本人目前翻译水平有限,不做中文翻译了,看这段API: Returns the element names on which this advertisement should be indexed.
如果为空则说明可选项为任意指定广告。
value
- 广告的定义值,可以精确定义也可以模糊匹配。
threshold
- 极限,所有可以相应peer所拥有的最大广告数。
A threshold
of 0, and type
of PEER
has a special behaviour.
3、发布广告
本地发布:
void publish(Advertisement adv,
long lifetime,
long expiration)
throws IOException
远程发布:
void remotePublish(String peerid,
Advertisement adv)
- jxta学习笔记3~jxta运行的基本步骤~
- jxta学习笔记4~jxta协议~
- 新的起点,jxta学习笔记1~
- JXTA
- jxta
- jxta
- jxta学习笔记2~helloworld~
- JXTA学习笔记之二
- JXTA学习
- JXTA学习!!JXTA P2P 2.4
- jxta学习笔记5~开始研究myJXTA~
- JXTA学习:协议解释
- JXTA学习:Module
- 开始学习jxta
- jxta-P2P学习
- P2P的Jxta解决方案
- P2P的Jxta解决方案
- P2P的Jxta解决方案
- [AS3]registerClassAlias的用法
- 超级asp解密函数(问题)
- 发些今年的作品:网络斗地主
- 想清楚干点什么,比怎么干更重要--Leo读《不是孙振耀写的职场感言》(2)
- 8.01
- jxta学习笔记3~jxta运行的基本步骤~
- 08一级建造师的一道考题
- delphi 只运行一个程序
- 关于oracle安装的一些自己的体会(非安装教程)
- RMI使用概述(ZZ)
- Total Commander 7.04 inc key
- Opening
- DOS远程桌面连接命令
- ASP.NET(C#)修改FTP密码