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 EAServer documentation.
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:2000;iiop://JagTwo:2000'',<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("admin", "")<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:2000", &<br>    my_corbaObj)<br>my_corbaObj._narrow(my_mgr, "SessionManager/Manager" )<br>my_Session = my_mgr.createSession("admin", "")<br>my_corbaObj = my_session.lookup("Cart")<br>my_corbaObj._narrow(my_CartHome, "shopping/CartHome") my_corbaObj = my_CartHome.create()<br>my_Cart.addItem() |
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”.