Version 2

    Configuration the Naming Service Using POJOs

    With the upcoming release of the 5.0.0.GA JBossNS, the core beans have been updated to better work with the JBoss Microcontainer POJO style of deployments.

     

    InitialContextFactory for Local Server

    The LocalContextOnlyFactory implementation of the InitialContextFactory can be used to create an InitialContext that is connected to the in memory naming server without any network transport.

    Initializing JNDI Bindings

    The BindingsInitializer pojo can be used to setup bindings in a naming server.

    In Memory Naming Server

    The org.jnp.server.NamingBeanImpl is a POJO that provides an org.jnp.interfaces.Naming implementation that is used by the org.jnp.interfaces.NamingContext. This is the JBossNS naming server implementation. The following jboss-beans.xml deployment illustrates the configuration of the LocalContextOnlyFactory, BindingsInitializer and NamingBeanImpl.

    <deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_2_0.xsd"
        xmlns="urn:jboss:bean-deployer:2.0">
    
        <bean name="InitialContextFactory" class="org.jboss.naming.InitialContextFactoryBean">
            <property name="env">
                <map class="java.util.Properties" keyClass="java.lang.String" valueClass="java.lang.String">
                    <entry>
                        <key>java.naming.factory.initial</key>
                        <value>org.jnp.interfaces.LocalOnlyContextFactory</value>
                    </entry>
                    <entry>
                        <key>java.naming.factory.url</key>
                        <value>org.jboss.naming:org.jnp.interfaces</value>
                    </entry>
                </map>
            </property>
            <depends>testLocaNamingBeanImpl</depends>
        </bean>
        <bean name="JndiBindings" class="org.jboss.naming.BindingsInitializer">
            <property name="ctx">
                <inject bean="InitialContextFactory" property="ctx"/>
            </property>
            <property name="bindings">
                <map keyClass="java.lang.String">
                    <entry>
                        <key>ints/1</key>
                        <value class="java.lang.Integer">1</value>
                    </entry>
                    <entry>
                        <key>strings/1</key>
                        <value class="java.lang.String">String1</value>
                    </entry>
                    <entry>
                        <key>bigint/1</key>
                        <value class="java.math.BigInteger">123456789</value>
                    </entry>
                    <entry>
                        <key>env-props</key>
                        <value>
                            <map class="java.util.Properties" keyClass="java.lang.String" valueClass="java.lang.String">
                            <entry>
                                <key>java.naming.factory.initial</key>
                                <value>org.jnp.interfaces.LocalOnlyContextFactory</value>
                            </entry>
                            <entry>
                                <key>java.naming.factory.url</key>
                                <value>org.jboss.naming:org.jnp.interfaces</value>
                            </entry>
                            </map>
                        </value>
                    </entry>
                </map>
            </property>
        </bean>
        <bean name="testLocaNamingBeanImpl" class="org.jnp.server.NamingBeanImpl">
            <!-- Install this bean as the global JVM NamingServer -->
            <property name="installGlobalService">true</property>
            
            <property name="useGlobalService">false</property>
        </bean>
    
    </deployment>
    

     

     

    Remotely Accessible Naming Server

    The org.jnp.server.Main POJO wraps a Naming interface implementation in a proxy for remote access. This uses the JDK rmi transport layer by default. The following jboss-beans.xml deployment sets up a naming service listening on port 1099 on the interface defined by the jboss.bind.address system property if available, or localhost by default:

    <deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_2_0.xsd"
        xmlns="urn:jboss:bean-deployer:2.0">
    
        <bean name="InitialContextFactory" class="org.jboss.naming.InitialContextFactoryBean">
            <property name="env">
                <map class="java.util.Properties" keyClass="java.lang.String" valueClass="java.lang.String">
                    <entry>
                        <key>java.naming.factory.initial</key>
                        <value>org.jnp.interfaces.LocalOnlyContextFactory</value>
                    </entry>
                    <entry>
                        <key>java.naming.factory.url</key>
                        <value>org.jboss.naming:org.jnp.interfaces</value>
                    </entry>
                </map>
            </property>
            <depends>testLocaNamingBeanImpl</depends>
        </bean>
        <bean name="JndiBindings" class="org.jboss.naming.BindingsInitializer">
            <property name="ctx">
                <inject bean="InitialContextFactory" property="ctx"/>
            </property>
            <property name="bindings">
                <map keyClass="java.lang.String">
                    <entry>
                        <key>ints/1</key>
                        <value class="java.lang.Integer">1</value>
                    </entry>
                    <entry>
                        <key>strings/1</key>
                        <value class="java.lang.String">String1</value>
                    </entry>
                    <entry>
                        <key>bigint/1</key>
                        <value class="java.math.BigInteger">123456789</value>
                    </entry>
                    <entry>
                        <key>env-props</key>
                        <value>
                            <map class="java.util.Properties" keyClass="java.lang.String" valueClass="java.lang.String">
                            <entry>
                                <key>java.naming.factory.initial</key>
                                <value>org.jnp.interfaces.LocalOnlyContextFactory</value>
                            </entry>
                            <entry>
                                <key>java.naming.factory.url</key>
                                <value>org.jboss.naming:org.jnp.interfaces</value>
                            </entry>
                            </map>
                        </value>
                    </entry>
                </map>
            </property>
        </bean>
    
        <bean name="LookupPool">
            <constructor factoryMethod="newFixedThreadPool"
                factoryClass="java.util.concurrent.Executors">
                <!-- At least 2 threads are required -->
                <parameter>2</parameter>
            </constructor>
        </bean>
        <bean name="testLocaNamingBeanImpl" class="org.jnp.server.NamingBeanImpl">
            <!-- Install this bean as the global JVM NamingServer -->
            <property name="installGlobalService">true</property>
            
            <property name="useGlobalService">false</property>
        </bean>
        <bean name="jboss:service=Naming" class="org.jnp.server.Main">
            <property name="namingInfo"><inject bean="testLocaNamingBeanImpl" /></property>
            <!-- The call by value mode. true if all lookups are unmarshalled using
                the caller's TCL, false if in VM lookups return the value by reference.
            -->
            <property name="callByValue">false</property>
            
            <!-- The listening port for the bootstrap JNP service. Set this to -1
                to run the NamingService without the JNP invoker listening port.
            -->
            <property name="port">1099</property>
    
            <!-- The bootstrap JNP server bind address. This also sets the default
                RMI service bind address. Empty == all addresses
            -->
            <property name="bindAddress">${jboss.bind.address:localhost}</property>
            <!-- The port of the RMI naming service, 0 == anonymous -->
            <property name="rmiPort">0</property>
            <!-- The RMI service bind address. Empty == all addresses
            -->
            <property name="rmiBindAddress">${jboss.bind.address:localhost}</property>
            <!-- Set the java.rmi.server.hostname system property to rmiBindAddress -->
            <property name="enableRmiServerHostname">true</property>
            <!-- The thread pool service used to control the bootstrap lookups -->
            <property name="lookupExector"><inject bean="LookupPool"/></property>
        </bean>
    
    </deployment>