The core JNDI interface used by client applications is javax.naming.Context, which represents the initial naming context used to resolve names to Bean proxies. To obtain an initial naming context, initialize a java.util.Properties instance and set the properties listed in Table 7-2. Pass the properties instance to the javax.naming.InitialContext constructor. The code fragment below shows a typical call sequence:
import javax.naming.*; static public Context getInitialContext() throws Exception { java.util.Properties p = new java.util.Properties(); // Sybase implementation of InitialContextFactory p.put(Context.INITIAL_CONTEXT_FACTORY, "com.sybase.ejb.InitialContextFactory"); // URL for the Server’s IIOP port p.put(Context.PROVIDER_URL, "iiop://myhost:9000"); // Username "pooh", password is "tigger2" p.put(Context.SECURITY_PRINCIPAL, "pooh"); p.put(Context.SECURITY_CREDENTIALS, "tigger2"); // Now create an InitialContext that uses the properties return new InitialContext(p); }
EJB servers from different vendors require different InitialContext property settings. If you are creating a client application that must be portable to other EJB servers, use an external mechanism to specify properties rather than hard-coding values in the source code. For example, in a Java application use command-line arguments or a serialized Java properties file.
The Sybase InitialContext implementation recognizes the properties in the following table. You can create multiple contexts with different properties. For example, you might create one context for proxies that connect with plain IIOP and another for proxies that connect using SSL.
Property name |
Description |
---|---|
java.naming.factory. initial |
Specifies the fully qualified Java class
name of the class that returns javax.naming.InitialContext instances
that interact with the naming provider. Use |
java.naming.provider. url |
Specifies the URL to connect to the EJB name server. Set the value to a URL with the following format:
where:
If you do not set this property, the default is |
java.naming.security. principal |
Specifies the user name for the EJB Server session. Required if user name/password authentication is enabled for your EJB Server. |
java.naming.security. credentials |
Specifies the password for the EJB Server session. Required if user name/password authentication is enabled for your EJB Server. |
com.sybase.ejb. RetryCount |
Specify the number of times to retry when the initial attempt to connect to the server fails. The default is 5. |
com.sybase.ejb. RetryDelay |
Specify the delay, in milliseconds, between retry attempts when the initial attempt to connect to the server fails. The default is 2000. |
com.sybase.ejb. socketReuseLimit |
Specify the number of times that a network connection may be reused to call methods from one server. The default is 0, which indicates no limit. The default is ideal for short-lived clients. In Sybase testing, settings between 10 and 30 proved to be a good starting point. If the reuse limit is too low, client performance degrades. |
com.sybase.ejb. GCInterval |
Specifies how often the ORB forces deallocation (Java garbage collection) of unused class references. Though this property is set on an individual ORB instance, it affects all ORB instances. The default is 30 seconds. The default is appropriate unless you have set an idle connection timeout of less than 30 seconds. In that case, you should specify a lower value for the garbage collection interval, since connections are only closed while performing garbage collection. In other words, the effective idle connection timeout ranges from the idle connection timeout setting to the smallest integral multiple of the garbage collection interval. |
com.sybase.ejb. IdleConnectionTimeout |
Specifies the time, in seconds, that a connection is allowed to sit idle. When the timeout expires, the ORB closes the connection. The default is 0, which specifies that connections can never timeout. The connection timeout does not affect the life of proxy instance references; the ORB may close and reopen connections transparently between proxy method calls. Specifying a finite timeout for your client applications can improve server performance. If many instances of the client run simultaneously, a finite client connection timeout limits the number of server connections that are devoted to idle clients. |