The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Configuring a JXTA Peer in Spring

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Vanessa Williams

Posts: 273
Nickname: vwilliams
Registered: May, 2003

Vanessa Williams is CTO and Chief Architect of oponia networks
Configuring a JXTA Peer in Spring Posted: Jul 6, 2006 7:13 PM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by Vanessa Williams.
Original Post: Configuring a JXTA Peer in Spring
Feed Title: fridgebuzz
Feed URL: http://feeds.feedburner.com/fridgebuzz
Feed Description: Pointers on software, art, math, noise, and other obsessions.
Latest Agile Buzz Posts
Latest Agile Buzz Posts by Vanessa Williams
Latest Posts From fridgebuzz

Advertisement

The new net.jxta.platform.NetworkConfigurator class provides a clean and straightforward way to configure an instance of the JXTA platform without a UI. It can be used programmatically (see the main() method for an example of stand-alone use) or—because it is a Java Bean—declaratively deployed inside containers like Spring.

Read the full post for a brief JXTA/Spring tutorial.

Categories: ,

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.

Read: Configuring a JXTA Peer in Spring

Topic: Customizing your image Previous Topic   Next Topic Topic: On benchmarking

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use