Here is a simple example of a Spring context file, applicationContext-rdv.xml, which configures a Rendezvous Server:
<bean id="netConfig" class="net.jxta.platform.NetworkConfigurator">
<!--
Location of the home directory
-->
<property name="home"><value>.jxta</value></property>
<!--
Modes determine node properties. 2572 corresponds to a
Rendezvous Server node. See NetworkConfigurator javadocs
for details.
-->
<property name="mode"><value>2752</value></property>
<!--
This is a managed RDV, so the peer ID is hard-coded in order to
maintain synch with rendezvousACL.xml
-->
<property name="peerId">
<value>urn:jxta:uuid-XXXXXXXXXXXXXXXXXXXXXXXXXX...</value></property>
<!--
Details of private Net Peer Group
-->
<property name="infrastructureID">
<value>uuid-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</value>
</property>
<property name="infrastructureName"><value>MyNetPG</value></property>
<property name="infrastructureDescription">
<value>My Infrastructure Group</value><
/property>
<!--
Some basic information about the Node
-->
<property name="name"><value>com.mycompany RDV1</value></property>
<property name="description"><value>Rendezvous Node</value></property>
<property name="principal"><value>user</value></property>
<property name="password"><value>pwd</value></property>
<!--
Because it's a managed peer, we may want control over the exact
ports being used.
-->
<property name="httpPort"><value>9700</value></property>
<property name="tcpPort"><value>9701</value></property>
</bean>
<bean id="myJxtaBean" class="com.mycompany.MyJxtaBean">
<property name="netConfig"><ref bean="netConfig"/></property>
</bean
And here's what MyJxtaBean.java might look like, in part:
public class MyJxtaBean {
private NetworkConfigurator netConfig;
private PeerGroup infrastructureGroup;
public MyJxtaBean() {}
public setNetConfig(NetworkConfigurator netConfig) {
this.netConfig = netConfig;
}
public synchronized void start() {
/*
* Simplest case, we don't overwrite an existing configuration, nor
* do we load and alter/ammend it. Only if there is no PlatformConfig
* available, construct a new one using the bean's properties.
*/
if (!netConfig.exists()) {
try {
netConfig.save();
} catch (IOException io) {
System.out.println("Error saving PlatformConfig");
}
}
try {
infrastructureGroup = PeerGroupFactory.newNetPeerGroup();
} catch (PeerGroupException pge) {
System.out.println("Couldn't create NetPeerGroup");
System.exit(1);
}
}
}
Now all your applicaton has to do is get the MyJxtaBean from the context and call start() to start the JXTA platform.
applicationContext =
new ClassPathXmlApplicationContext("applicationContext-rdv.xml");
myPlatform = (MyJxtaBean)applicationContext.getBean("myJxtaBean");
myPlatform.start();
There's more to writing a JXTA application, of course, but I hope this example demonstrates how NetworkConfigurator takes some of the mystery out of JXTA plaform configuration, while making it easy to combine JXTA and Spring.