This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information

--Addressing the Server via JNDI

Documents for the development of and with JVx.

--Addressing the Server via JNDI

Postby Development@SIB » Fri Sep 17, 2010 1:38 pm



This article is outdated - please use our new system at

https://doc.sibvisions.com




The server for JVx clients is instantiated either at the current JVM or at the application server (e.g. Tomcat, JBoss). In the current VM the call

Code: Select all
Server server = new Server();

is sufficient to create a server instance. However, this creates that risk that multiple server instances are created (which may well be desirable). The following method is available to treat the server as a singleton:

Code: Select all
Server server = Server.getInstance();

In doing so we additionally attempt to address a server instance via JNDI

A new instance of the server is created at the application server using ServletServer. This is accomplished by the following call:

Code: Select all
Server server = Server.getInstance();

If the server is available as a JNDI resource, the application server handles the instantiation of the server. This way one server instance could be used for all applications of an application server.


A global JNDI resource for the application server Tomcat is configured as follows:

conf/server.xml:

Code: Select all
<GlobalNamingResources>
  ...
  ...
  ...
  <Resource auth="Container"
            factory="org.apache.naming.factory.BeanFactory"
            name="globalserver"
            type="com.sibvisions.rad.server.Server"/>
   
</GlobalNamingResources>

<DefaultContext>
  <ResourceLink name="jvx/server"
                global="globalserver"
                type="com.sibvisions.rad.server.Server" />
</DefaultContext>


The ResourceLink in the DefaultContext can also be defined in the META-INF/context.xml of the respective web application. This always depends on the configuration of the server or the web application. One possible example:

Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<Context>
   <ResourceLink name="jvx/server"
                 global="globalserver"
                 type="com.sibvisions.rad.server.Server" />         
</Context>


To only make the server available for single web applications via JNDI, it should be configured as follows:

META-INF/context.xml:

Code: Select all
<?xml version="1.0" encoding="UTF-8"?>

<Context>
  <Resource name="jvx/server" auth="Container"
            type="com.sibvisions.rad.server.Server"
            factory="org.apache.naming.factory.BeanFactory"/>
</Context>


We always recommend the configuration of the deployment descriptor, whether the server is provided for all applications or only for single web applications:

Code: Select all
<web-app ...>
  ...
  ...
  ...
  <resource-ref>
   <description>Object factory for Server instances.</description>
   <res-ref-name>jvx/server</res-ref-name>
   <res-ref-type>com.sibvisions.rad.server.Server</res-ref-type>
   <res-auth>Container</res-auth>
  </resource-ref>

</web-app>

In the case of a global server, the deployment descriptor would not have to be adapted, although it is recommended to better manage the utilized resources.


Note

If the server is configured globally, we also have to provide all of the application data, such as the rad directory, .class files, etc., globally, since the applications class loader is not used!
User avatar
Development@SIB
 
Posts: 325
Joined: Mon Sep 28, 2009 1:54 pm

Return to Documentation