本文整理汇总了Java中net.jxta.membership.MembershipService类的典型用法代码示例。如果您正苦于以下问题:Java MembershipService类的具体用法?Java MembershipService怎么用?Java MembershipService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MembershipService类属于net.jxta.membership包,在下文中一共展示了MembershipService类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: joinToGroup
import net.jxta.membership.MembershipService; //导入依赖的package包/类
public static void joinToGroup(PeerGroup group) //This method will join to either found group or created group
{
StructuredDocument creds = null;
logger.debug("Joining into " + group.getPeerGroupName() + "...");
try{
//Athenticate and join to group
AuthenticationCredential authCred = new AuthenticationCredential(group,null,creds);
MembershipService membership = group.getMembershipService();
Authenticator auth = membership.apply(authCred);
if(auth.isReadyForJoin()){
Credential myCred = membership.join(auth);
logger.debug("===== Group Details =====");
StructuredTextDocument doc = (StructuredTextDocument)myCred.getDocument(new MimeMediaType("text/plain"));
StringWriter out = new StringWriter();
doc.sendToWriter(out);
//System.out.println(out.toString());
if(logger.isTraceEnabled()){
logger.trace(out.toString());
}
//Publishing Peer Advertisements.
DiscoveryService groupDiscoveryService = group.getDiscoveryService();
logger.debug("Peer Name : " + group.getPeerName() + " is now online :-)");
logger.debug("Obtaining SaEeDGroup Services.");
logger.debug("Publishing Peer Advertisement.");
groupDiscoveryService.publish(group.getPeerAdvertisement());
groupDiscoveryService.remotePublish(group.getPeerAdvertisement());
logger.debug("[===========================]\n");
}
else{
logger.fatal("[!!]Fatal Error: Cannot Join to The Group!");
//System.exit(-1);
}
}catch(Exception e){
logger.fatal("[!]Fatal Error: " + e.getMessage());
e.printStackTrace();
//System.exit(-1);
}
}