Methods Summary |
---|
public void | init()
try {
//Discover and join (or start) the default peergroup
netpg = PeerGroupFactory.newNetPeerGroup();
} catch (PeerGroupException e) {
//Couldn't initialize; can't continue
System.out.println("Fatal error : creating the NetPeerGroup");
System.exit(1);
}
makeStub();
publishAdv();
|
public static void | main(java.lang.String[] args)
RMIServiceImpl rsi = new RMIServiceImpl();
rsi.init();
System.out.println("RMIService waiting for requests...");
// If we exit, rsi becomes eligible for GC, which means
// it could no longer handle requests
synchronized(rsi) {
rsi.wait();
}
|
private void | makeStub()
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(UnicastRemoteObject.exportObject(this));
oos.close();
stub = new String(URLBase64.encode(baos.toByteArray()));
|
public boolean | publishAdv()
try {
DiscoveryService disco = netpg.getDiscoveryService();
ModuleClassAdvertisement mca = (ModuleClassAdvertisement)
AdvertisementFactory.newAdvertisement(
ModuleClassAdvertisement.getAdvertisementType());
mca.setName("JXTAMOD:RMIService:HelloService");
mca.setDescription("Sample RMI-as-JXTA Service");
ModuleClassID mcID = IDFactory.newModuleClassID();
mca.setModuleClassID(mcID);
disco.publish(mca, DiscoveryService.ADV);
disco.remotePublish(mca, DiscoveryService.ADV);
ModuleSpecAdvertisement msa = (ModuleSpecAdvertisement)
AdvertisementFactory.newAdvertisement(
ModuleSpecAdvertisement.getAdvertisementType());
msa.setName("JXTASPEC:RMIService:HelloService");
msa.setVersion("Version 1.0");
msa.setCreator("sun.com");
msa.setSpecURI("http://www.jxta.org/tutorial/RMIService.jar");
msa.setModuleSpecID(IDFactory.newModuleSpecID(mcID));
StructuredTextDocument doc = (StructuredTextDocument)
StructuredDocumentFactory.newStructuredDocument(
new MimeMediaType("text/xml"), "Parm");
Element e = doc.createElement("Stub", stub);
doc.appendChild(e);
msa.setParam(doc);
disco.publish(msa, DiscoveryService.ADV);
disco.remotePublish(msa, DiscoveryService.ADV);
System.out.println("Created the RMI advertisement");
} catch (Exception e) {
System.out.println(e);
e.printStackTrace();
return false;
}
return true;
|
public java.lang.String | sayHello()
return "Hello";
|