Using the JaguarORB object
To create a CORBA-compatible client, you can use the JaguarORB
object instead of the Connection object to establish the connection
to the server. The JaguarORB object allows you to access EAServer
from PowerBuilder clients in the same way as C++ clients.
Two techniques
The JaguarORB object supports two techniques for accessing
component interfaces, using its String_To_Object
and Resolve_Initial_References functions.
Using the String_To_Object function works
in the same way that the ConnectToServer and CreateInstance functions
on the Connection object do internally. The String_To_Object
function allows you to instantiate a proxy instance by passing a
string argument that describes how to connect to the server that
hosts the component. The disadvantage of this approach is that you lose
the benefits of server address abstraction that are provided by
using the naming service API explicitly.
If you want to use the Jaguar naming service API, you can
use the Resolve_Initial_References function to
obtain the initial naming context. However, this technique is not
recommended because it requires use of a deprecated SessionManager::Factory
create method. Most PowerBuilder clients do not need to use the
CORBA naming service explicitly. Instead, they can rely on the name
resolution that is performed automatically when they create EAServer
component instances using the CreateInstance and Lookup functions
of the Connection object.
About the naming service
The Jaguar naming service is an implementation of the CORBA
CosNaming component, which is a collection of interfaces that provide
support for object binding and lookup. For more information about
the CosNaming module, see the EAServer interface repository documentation.
The interface repository documentation can be viewed in a Web browser
by connecting to your server with the URL http://yourhost:yourport/ir/ where yourhost is
the server’s host name and yourport is
the HTTP port number.
Instantiation using String_To_Object
Obtaining proxies for SessionManager interfaces
To instantiate a proxy without explicitly using the CORBA
Naming Service, you use the String_To_Object function
of the JaguarORB object in conjunction with interfaces defined in
the SessionManager module. Before using the Manager, Session, and
Factory interfaces, you need to use the EAServer Proxy wizard to
create a proxy library project for the SessionManager module, build the
project, and include the generated proxy library in the library
list for the client target.
Identifying the server
You use the SessionManager::Manager interface to interact
with the server. You can identify the server using its Interoperable
Object Reference (IOR) or its URL. The IOR string encodes the server’s
host address and the port at which the server accepts IIOP requests.
Each time a server is started, it writes a hex-encoded IOR string
with standard encoding to two files for each listener, one containing
the IOR string by itself, and the other containing the IOR as part
of an HTML PARAM definition that can be inserted into an APPLET
tag. The files reside in the HTML subdirectory of the EAServer
directory. You can code the client to obtain the IOR string from
one of these files.
Creating an authenticated session
After initializing the ORB and obtaining the IOR or URL of
the server, use the String_To_Object function
to convert the string to a CORBA object reference that you can convert
to a reference to the Manager interface using the _Narrow function.
Then use the createSession method of the Manager interface to create an
authenticated session between the client application and the server.
Creating a reference to the component’s interface
Use the session’s lookup method to return a factory
for proxy object references to the component you want to call. Then
call the create method of the Factory object to obtain proxies for
the component. The create method returns a CORBA object reference
that you can convert into a reference to the component’s
interface using the _Narrow function.
A component’s default name is the package name and
the component name, separated by a slash, as in calculator/calc.
However, you can specify a different name with the component’s
com.sybase.jaguar.component.naming property. For example, you can
specify a logical name, such as USA/MyCompany/FinanceServer/Payroll.
For more information on configuring the naming service, see the
section on naming services in the EAServer System Administration
Guide
.
Examples
In this example, the first argument to the String_To_Object
function includes the URLs for two servers in a cluster:
1 |
// PowerBuilder objects<br /> JaguarORB my_JaguarORB<br /> CORBAObject my_corbaobj<br /> n_bank_acct my_acct<br /> <br /> // Proxy objects<br /> Manager my_manager<br /> Session my_session<br /> Factory my_factory<br /> <br /> long ll_return<br /> my_JaguarORB = CREATE JaguarORB<br /> <br /> // Initialize the ORB<br /> ll_return = my_JaguarORB.init("ORBRetryCount=3,<br /> ORBRetryDelay=1000")<br /> <br /> // Convert a URL string to an object reference<br /> ll_return = my_JaguarORB.String_To_Object<br /> (''iiop://JagOne:9000;iiop://JagTwo:9000'',<br /> my_corbaobj)<br /> <br /> // Narrow the object reference to the Manager interface<br /> ll_return = my_corbaobj._narrow(my_manager,<br /> "SessionManager/Manager")<br /> <br /> // Create a session object reference<br /> my_session = my_manager.createSession("jagadmin", "")<br /> <br /> // Create a Factory for proxy object references to<br /> // the remote interface<br /> my_corbaobj = my_session.lookup("Bank/n_bank_acct ")<br /> my_corbaobj._narrow(my_Factory, "SessionManager/Factory")<br /> <br /> // Obtain a proxy, narrow it to the remote<br /> // interface, and call a method<br /> my_corbaobj = my_Factory.create()<br /> my_corbaobj._narrow(my_acct, "Bank/n_bank_acct")<br /> my_acct.withdraw(1000.0) |
In this example, the component is an EJB component. The Home
interface effectively performs the same role for the EJB that the
Factory interface does for a CORBA component:
1 |
JaguarORB my_orb<br /> CORBAObject my_corbaobj<br /> Manager my_mgr<br /> Session my_session<br /> CartHome my_cartHome<br /> Cart my_cart<br /> <br /> my_orb = CREATE JaguarORB<br /> my_orb.init("ORBLogFile='c: emporblog'")<br /> my_orb.String_to_Object("iiop://svr1:9000", &<br /> my_corbaObj)<br /> my_corbaObj._narrow(my_mgr, "SessionManager/Manager" )<br /> my_Session = my_mgr.createSession("jagadmin", "")<br /> my_corbaObj = my_session.lookup("Cart")<br /> my_corbaObj._narrow(my_CartHome, "shopping/CartHome") my_corbaObj = my_CartHome.create()<br /> my_Cart.addItem() |
Using a Connection object In PowerBuilder 8, you can use the Lookup function on the
Connection object to obtain a reference to the Home interface of
an EJB component. See “Invoking an EJB component
method”.
Instantiation using the naming service API
Obtaining proxies for CosNaming and SessionManager interfaces
To instantiate a proxy using the CORBA naming service API,
you need to generate proxies for the naming service interface and
include these proxies in the library list for the client. Use the
EAServer Proxy wizard to create a proxy project for the CosNaming
module, build the project to create a proxy library, and add the
proxy library to the client target’s library list. You
also need a proxy for the SessionManager module.
Getting an initial naming context
After initializing the ORB, call the Resolve_Initial_References
function to obtain an initial naming context and use _Narrow
to convert it to a reference to the CORBA naming context interface.
You must identify the CosNaming package by including omg.orb in
the class name as shown in the example below.
Resolving the naming context
You need to resolve the naming context to obtain a reference
to a Factory object for the component and then narrow that reference
to the SessionManager::Factory interface. The resolve method takes
a name parameter, which is a sequence of NameComponent structures.
Each NameComponent structure has an id attribute
that identifies the component and a kind attribute
that can be used to describe the component. In the example below,
the name has only one component.
Creating a reference to the component’s interface
Call the create method of the Factory object to obtain proxies
for the component. The create method returns a CORBA object reference
that you can convert into a reference to the component’s
interface using the _Narrow function.
Example
The NamingContext and NameComponent types used in the example
are proxies imported from the CosNaming package in EAServer, and
the Factory type is imported from the SessionManager package:
1 2 |
CORBAObject my_corbaobj<br /> JaguarORB my_orb<br /> NamingContext my_nc<br /> NameComponent the_name[]<br /> Factory my_Factory<br /> n_jagcomp my_jagcomp<br /> <br /> my_orb = CREATE JaguarORB<br /> // Enclose the name of the URL in single quotes<br /> my_orb.init("ORBNameServiceURL='iiop://server1:9000'")<br /> <br /> my_orb.<i>Resolve_Initial_References</i> ("NameService", &<br /> my_corbaobj)<br /> my_corbaobj._narrow(my_nc, &<br /> "omg.org/CosNaming/NamingContext")<br /> <br /> the_name[1].id = "mypackage/n_jagcomp"<br /> the_name[1].kind = ""<br /> <br /> my_corbaobj = my_nc.resolve(the_name)<br /> my_corbaobj._narrow(my_Factory, &<br /> "SessionManager/Factory")<br /> my_corbaobj = my_Factory.create("jagadmin","")<br /> my_corbaobj._narrow(my_jagcomp,<br /> "mypackage/n_jagcomp")<br /> <br /> my_jagcomp.getdata() |