Full HTML for

Basic foilset CORBA and distributed Objects using JavaIDL

Given by Nancy McCracken, Chao Wei Ou, Geoffrey Fox at ARL Database Tutorial and CPS616 on February 98. Foils prepared 5 Feb 98
Outside Index Summary of Material


We overview CORBA in general and then describe its use with Java Clients and Servers using the simple ORB available from the JavaIDL JDK 1.2 release from Sun.
We give two simple examples : Hello world and the simple counter also shown with Visigenic ORB
The JavaIDL ORB is not production quality but can be used to develop Java language CORBA objects which can then be used with other more sophisticated ORB's in production mode.
Note the Java Language CORBA IDL is common to all ORB's
JavaIDL respects this IDL binding and provides both a client or server implementation which respect IIOP and so interfaces with other vendor systems
JavaIDL is a "JORB" -- a Java server implementation of CORBA

Table of Contents for full HTML of CORBA and distributed Objects using JavaIDL

Denote Foils where Image Critical
Denote Foils where Image has important information
Denote Foils where HTML is sufficient
denotes presence of Additional linked information which is greyed out if missing

1 CORBA using Java IDL CPS616 Spring 98 and ARL Workshop February 1998
2 CORBA Java IDL Abstract
3 CORBA Architecture Overview
4 Invocation Model (I)
5 Invocation Model (II)
6 Invocation Model (III)
7 Invocation Model (IV)
8 Invocation Model (V)
9 JavaIDL Clients
10 Structure of A Client
11 Object Implementation
12 Structure of an Object Implementation
13 Object Reference
14 Obtaining Object References
15 Client Stubs
16 CORBA Interface Repository
17 CORBA Implementation Repository
18 Static Invocation (I)
19 Static Invocation (II)
20 Dynamic Invocation
21 Narrowing
22 Creation and Deletion
23 Servers for Transient CORBA Objects
24 Servant and Servant Base Classes
25 CORBA IDL Structure
26 Mapping CORBA IDL to Java - I
27 Mapping CORBA IDL To Java - II
28 An IDL Example - hello.idl
29 Compile An IDL file
30 Example Server - Hello
31 Example Server I - HelloServant
32 Methods in Server Class
33 Example Server II - HelloServer
34 Example Application Client
35 Example Client - Hello
36 HTML page to lauch Typical Applet to invoke Visigenic NOT JavaIDL Count on Client Side Example 2: Counter/Timer
37 Common Count IDL for Visigenic and JavaIDL Example 2: IDL Specification
38 List of Files for JavaIDL Count Remote Object Classes Generated by idltojava
39 List of Files for JavaIDL Count Remote Object Example2: Class Descriptions I
40 List of Files for JavaIDL Count Remote Object Example2: Class Descriptions II
41 List of Files for JavaIDL Count Remote Object Example2: Development Process
42 Java Interface generated for Count by JavaIDL Example 2: Java Interface
43 Client Stub generated for Count by JavaIDL Example 2: Client-side Stub
44 Client Side Helper generated for Count by JavaIDL Example 2: Client-side Helper
45 Client Side Holder generated for Count by JavaIDL Example 2: Client-side Holder
46 Server Side Implementation Base generated for Count by JavaIDL Example 2: Server-side Skeleton
47 Example 2: Import Packages
48 User Provided Client generated for Count in JavaIDL Example 2: Client-side Java Code
49 User Provided Server and Servant generated for Count in JavaIDL Example 2: Server-side Java Code I
50 User Provided Server and Servant generated for Count in JavaIDL Example 2: Server-side Java Code II

Outside Index Summary of Material



HTML version of Basic Foils prepared 5 Feb 98

Foil 1 CORBA using Java IDL CPS616 Spring 98 and ARL Workshop February 1998

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
Geoffrey Fox, Nancy McCracken, Chao-Wei Ou
Northeast Parallel Architectures Center at Syracuse University
111 College Place, Syracuse, NY 13244
http://www.npac.syr.edu/

HTML version of Basic Foils prepared 5 Feb 98

Foil 2 CORBA Java IDL Abstract

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
We overview CORBA in general and then describe its use with Java Clients and Servers using the simple ORB available from the JavaIDL JDK 1.2 release from Sun.
We give two simple examples : Hello world and the simple counter also shown with Visigenic ORB
The JavaIDL ORB is not production quality but can be used to develop Java language CORBA objects which can then be used with other more sophisticated ORB's in production mode.
Note the Java Language CORBA IDL is common to all ORB's
JavaIDL respects this IDL binding and provides both a client or server implementation which respect IIOP and so interfaces with other vendor systems
JavaIDL is a "JORB" -- a Java server implementation of CORBA

HTML version of Basic Foils prepared 5 Feb 98

Foil 3 CORBA Architecture Overview

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
CORBA objects differ from typical programming language objects in these ways:
  • CORBA objects can be located anywhere on a network.
  • CORBA objects (like Java objects) can run on any platform.
  • CORBA objects can be written in any of several languages.
CORBA object developers need know nothing of where their clients will be, what hardware or OS they will run on, or what language they will be written in.
CORBA objects approach universal accessibility.
The CORBA specification has been written by the Object Management Group, a consortium of some 700 software vendor and user organizations.

HTML version of Basic Foils prepared 5 Feb 98

Foil 4 Invocation Model (I)

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
Client
Object Implementation
Request
ORB
An Object Invocation from a JavaIDL Client

HTML version of Basic Foils prepared 5 Feb 98

Foil 5 Invocation Model (II)

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
Client
Object Implementation
ORB Core
ORB Dependent Interface
IDL
Stubs
ORB
Interface
Static IDL
Skeleton
Implementation
Support Interface
The Structure of Object Request Broker Interfaces

HTML version of Basic Foils prepared 5 Feb 98

Foil 6 Invocation Model (III)

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
Client
ORB Core
ORB Dependent Interface
IDL
Stubs
Request
A Client using the Stub Interface

HTML version of Basic Foils prepared 5 Feb 98

Foil 7 Invocation Model (IV)

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
Object Implementation
ORB Core
ORB Dependent Interface
ORB
Interface
Static IDL
Skeleton
Implementation
Support Interface
An Object Implementation Receiving a Request

HTML version of Basic Foils prepared 5 Feb 98

Foil 8 Invocation Model (V)

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
IDL
Definition
Implementation
Installation
Stubs
Skeleton
Interface
Repository
Implementation
Repository
Client
Object Implementation
Interface and Implementation Repositories

HTML version of Basic Foils prepared 5 Feb 98

Foil 9 JavaIDL Clients

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
A client of an object has access to an object reference for the object, and invokes operations on the object. A client knows only the logical structure of the object according to its interface and experiences the behavior of the object through invocations.
JavaIDL clients see objects and ORB interfaces through the perspective of the Java language mapping, bringing the ORB right up to the programmer's level. Clients are maximally portable.
Client code has no knowledge of the implementation of the object or which ORB is used to access the implementation.

HTML version of Basic Foils prepared 5 Feb 98

Foil 10 Structure of A Client

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
Language and ORB Dependent Object Invocation
ORB Object References
Stubs for
Interface A
Stubs for
Interface B
Clients
Client
Side
Stubs
for Remote Objects
User Provided
Generated by ORB from IDL

HTML version of Basic Foils prepared 5 Feb 98

Foil 11 Object Implementation

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
An object implementation provides the semantics of the object, usually by defining data for the object instance and code for the object's methods.
Often the implementation will use other objects or additional software to implement the behavior of the object. In some cases, the primary function of the object is to have side-effects on other things that are not formal CORBA objects.
  • Note "anything" (Web Page to CGI script to online medical instrument) is really an object and can be made a formal CORBA object by a suitable wrapper.
Note that a client of one ORB (say JavaIDL) can access objects from other ORB's (say Visigenic) as IIOP provides interoperability

HTML version of Basic Foils prepared 5 Feb 98

Foil 12 Structure of an Object Implementation

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
Methods for
Interface A
Skeleton for
Interface A
Up-Call to Methods
User Provided
Generated by ORB from IDL

HTML version of Basic Foils prepared 5 Feb 98

Foil 13 Object Reference

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
An Object Reference is the information needed to specify an object within an ORB. Both clients and object implementations have an opaque notion of object references according to the Java language mapping, and thus are insulated from the actual representation of them.
The representation of an object reference handed to a client is only valid for the lifetime of that client.
The language mapping also provides additional ways to access object references in a typed way for the convenience of the programmer.
There is a distinguished object reference, the null reference, guaranteed to be different from all object references, that denotes no object. In Java, this is a Java null.

HTML version of Basic Foils prepared 5 Feb 98

Foil 14 Obtaining Object References

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
To invoke a CORBA object, you need a reference for the object. There are two ways to get a reference for a CORBA object:
  • from another object, such as a factory or a name service
  • from a string that was specially created from an object reference
It's common to encounter CORBA objects whose operations return references to other objects.

HTML version of Basic Foils prepared 5 Feb 98

Foil 15 Client Stubs

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
There is a Java interface to the stubs for each interface type.
The stubs present access to the OMG IDL-defined operations on an object in a way that is easy for programmers to predict once they are familiar with OMG IDL and the language mapping.
  • The stubs make calls on the rest of the ORB using interfaces that are private to JavaIDL.

HTML version of Basic Foils prepared 5 Feb 98

Foil 16 CORBA Interface Repository

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
The Interface Repository is a service that provides persistent objects that represent the IDL information in a form available at runtime.
The JavaIDL runtime does not include an implementation of an Interface Repository and one is not generally required by clients at runtime.
JavaIDL depends on a separate ORB, generally the one managing the services that the JavaIDL client is trying to access, to provide one if needed.

HTML version of Basic Foils prepared 5 Feb 98

Foil 17 CORBA Implementation Repository

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
The Implementation Repository contains information that allows the ORB to locate and activate implementations of objects.
Ordinarily, installation of implementations and control of policies related to the activation and execution of object implementations is done through operations on the Implementation Repository.
In addition to its role in the functioning of the ORB, the Implementation Repository is a common place to store additional information associated with implementations of ORB objects. (e.g., debugging information, administrative control, resource allocation, security, etc)
The Implementation Repository supports the implementation of object servers. It is not needed by clients in order to access servers.

HTML version of Basic Foils prepared 5 Feb 98

Foil 18 Static Invocation (I)

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
To statically invoke an operation on a CORBA object, a Java client needs two things:
  • An object reference, an opaque handle that identifies the particular CORBA object to be invoked; clients don't create object references but obtain them typically from other objects, such as factories or a naming contexts.
  • A stub, which is a Java object that is a local proxy for a type of CORBA object.
Of these, the client developer is only interested in the object reference; the stub class is generated automatically and its instances are created and invoked automatically.

HTML version of Basic Foils prepared 5 Feb 98

Foil 19 Static Invocation (II)

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
For each interface defined in an IDL module, the generated package (by idltojava) contains the following items of interest to the client programmer: (e.g., Foo.idl)
  • A Java interface defining the methods that correspond to the IDL operations; from the developer's point of view, an object reference for a CORBA object implements this interface. (e.g., Foo)
  • A Java class that defines auxiliary methods, notably narrow() which is the CORBA counterpart of Java casting. (e.g., FooHelper)
  • A Java class which defines methods for setting and getting the values of holders. Holders are required for CORBA operations that take out or inout arguments, which, unlike CORBA in arguments, don't map directly to Java's call-by-value semantics. (e.g., FooHolder)

HTML version of Basic Foils prepared 5 Feb 98

Foil 20 Dynamic Invocation

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
CORBA dynamic invocation uses an object called a request to hold everything pertinent to an invocation: the object reference, the name of the operation, its parameters, and space for the result. The client builds a request object describing an operation, then calls the request's invoke method, which dispatches the request just as a stub would. When the invoke method returns, the result is available in the request object.
The key to dynamic invocation is the ability of requests to hold self-describing data. This facility enables a request object to represent any invocation of any operation, regardless of its parameters are.

HTML version of Basic Foils prepared 5 Feb 98

Foil 21 Narrowing

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
OMG IDL supports inheritance; the top of the hierarchy is Object in OMG IDL, org.omg.CORBA.Object in Java. (Note that both CORBA and Java define Object, but they are the tops of different type hierarchies.)
Some operations, notably name lookup and unstringifying, return org.omg.CORBA.Objects, which you narrow (using a helper class generated by idltojava) to the derived type you want the object to be. CORBA objects must be explicitly narrowed because the Java runtime cannot always know the exact type of a CORBA object.

HTML version of Basic Foils prepared 5 Feb 98

Foil 22 Creation and Deletion

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
To create a Java object you use the new() operator; to delete a Java object you do nothing; the garbage collector reclaims it for you. CORBA clients never create CORBA objects, only servers do.
As a client, to create a CORBA object, you invoke another object which is the factory for the type of object you want created; the factory returns an object reference for you to use to invoke the new object. Typically the factory is implemented by the same server that implements the object type.
Neither is there any standard way to delete a CORBA object. Because a CORBA object may be shared by many clients around a network, it is hard to know when an object has, in Java terms, become garbage. In general, only the object server is in a position to know, and then only if the server developer provides a "destroy" operation for the object.

HTML version of Basic Foils prepared 5 Feb 98

Foil 23 Servers for Transient CORBA Objects

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
A transient CORBA object has the same lifetime as the execution of the server process that creates it. When a server terminates, its transient objects disappear with it. Transient objects are often used to effect asynchronous communication between applications and objects.
By contrast, a persistent object lives until it is explictly destroyed. If a client has a reference to a persistent CORBA object, that reference can be used even if the object's server is not running--an ORB will start the server when it (the ORB) receives an invocation on the object.
At present, Java IDL supports only transient object servers. Although persistent object servers can't yet be written in JavaIDL, Java applets and applications can be clients of persistent CORBA objects with different ORB's -- which can of course be written in Java language

HTML version of Basic Foils prepared 5 Feb 98

Foil 24 Servant and Servant Base Classes

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
To implement a server for transient CORBA objects of some type, you write a Java class called a servant, which inherits from a class called the servant base; servant base classes are optionally generated by the idltojava compiler.
An instance of a transient CORBA object is implemented by an instance of its servant class.
The servant base class is the CORBA type-specific interface between the ORB and the servant code for the type. It unmarshals incoming parameters, invokes servant methods, marshals results, and directs the ORB to return results to the client ORB.
A servant class extends its servant base with a method for each operation in the IDL interface definition it implements.

HTML version of Basic Foils prepared 5 Feb 98

Foil 25 CORBA IDL Structure

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
module <identifier>
{
<type declaration>
<constant declaration>
<exception declaration>
interface <identifier> [:<inheritance>]
{
<type declaration>
<constant declaration>
<exception declaration>
[<op_type>] <identifier> (<parameters>) [raises exception] [context];
:
};
interface <identifier> [:<inheritance>]
:
};

HTML version of Basic Foils prepared 5 Feb 98

Foil 26 Mapping CORBA IDL to Java - I

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
boolean
char/wchar
octet
string/wstring
short/unsigned short
long/unsigned long
long long/unsigned long long
float
double
boolean
char
byte
java.lang.String
short
int
long
float
double
IDL Type
Java Type

HTML version of Basic Foils prepared 5 Feb 98

Foil 27 Mapping CORBA IDL To Java - II

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
module
interface
enum
struct
union
sequence/array
any
exception
typedef
package
interface with an additional helper
final class with enum values
final class with the same name
final class with the same name
array
class CORBA.any
class extends CORBA.UserException
Use original name
IDL Type
Java Type

HTML version of Basic Foils prepared 5 Feb 98

Foil 28 An IDL Example - hello.idl

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
module HelloApp
{
interface hello;
{
string sayHello();
};
};

HTML version of Basic Foils prepared 5 Feb 98

Foil 29 Compile An IDL file

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
To use idltojava to compile the "hello" example IDL code as
idltojava -fclient -fserver hello.idl
Two sets of Java codes will be generated:
  • Client Java codes:
    • _helloStub.java
    • hello.java
    • hellohelper.java
    • helloHolder.java
  • Server Java code - _helloImplBase.java

HTML version of Basic Foils prepared 5 Feb 98

Foil 30 Example Server - Hello

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
The example server consists of two classes, the servant and the server.
The servant, HelloServant, is the implementation of the Hello IDL interface.
Each Hello instance is implemented by a HelloServant instance.
The servant is a subclass of _HelloImplBase, which is generated by the idltojava compiler from the example IDL.
The servant contains one method for each IDL operation.

HTML version of Basic Foils prepared 5 Feb 98

Foil 31 Example Server I - HelloServant

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
import HelloApp.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
class HelloServant extends _HelloImplBase
{
public String sayHello()
{
return "\nHello world !!\n";
}
}

HTML version of Basic Foils prepared 5 Feb 98

Foil 32 Methods in Server Class

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
Creates an ORB instance
Creates a servant instance (the implementation of one CORBA Hello object) and tells the ORB about it
Gets a CORBA object reference for a naming context in which to register the new CORBA object
Registers the new object in the naming context under the name "Hello"
Waits for invocations of the new object

HTML version of Basic Foils prepared 5 Feb 98

Foil 33 Example Server II - HelloServer

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
public class HelloServer {
public static void main(String args[]) {
try{
// create and initialize the ORB
ORB orb = ORB.init(args, null);
// create servant and register it with the ORB
HelloServant HelloRef = new HelloServant(); orb.connect(HelloRef);
// get the root naming context
org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
NamingContext ncRef = NamingContextHelper.narrow(objRef);
// bind the Object Reference in Naming
NameComponent nc = new NameComponent("Hello", "");
NameComponent path[] = {nc}; ncRef.rebind(path, HelloRef);
// wait for invocations from clients
java.lang.Object sync = new java.lang.Object();
synchronized (sync) {
sync.wait();
}
} catch (Exception e) {
System.err.println("ERROR: " + e);
e.printStackTrace(System.out);
}
}
}

HTML version of Basic Foils prepared 5 Feb 98

Foil 34 Example Application Client

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
The example application client that follows:
Creates an ORB
Obtains a reference to the naming context
Looks up "Hello" in the naming context and receives a reference to that CORBA object
Invokes the object's sayHello() operation and prints the result

HTML version of Basic Foils prepared 5 Feb 98

Foil 35 Example Client - Hello

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
import HelloApp.*;
import org.omg.CosNaming.*;
import org.omg.CORBA.*;
public class HelloClient {
public static void main(String args[]) {
try{ // create and initialize the ORB
ORB orb = ORB.init(args, null);
// get the root naming context
org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
NamingContext ncRef = NamingContextHelper.narrow(objRef);
// resolve the Object Reference in Naming
NameComponent nc = new NameComponent("Hello", "");
NameComponent path[] = {nc};
Hello HelloRef = HelloHelper.narrow(ncRef.resolve(path));
// call the Hello server object and print results
String Hello = HelloRef.sayHello();
System.out.println(Hello);
} catch (Exception e) {
System.out.println("ERROR : " + e) ;
e.printStackTrace(System.out);
}
}
}

HTML version of Basic Foils prepared 5 Feb 98

Foil 36 Example 2: Counter/Timer

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index HTML page to lauch Typical Applet to invoke Visigenic NOT JavaIDL Count on Client Side
The server exports two methods InitSum and Increment methods simply initialize varaible sum and increments it by one, respectively. Then return the value of sum to the client.
The Client increments the sum to 1000 and keeps tracking of the elapsed time. The output the average time per increment. (Roughly, this can be treated as the average time for ping command on IIOP.)

HTML version of Basic Foils prepared 5 Feb 98

Foil 37 Example 2: IDL Specification

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index Common Count IDL for Visigenic and JavaIDL
module Counter{
interface Count {
attribute long sum;
void initSum(in long value);
long increment();
};
};
Note: This code is provided by developer and passed to idltojava pre-compiler

HTML version of Basic Foils prepared 5 Feb 98

Foil 38 Classes Generated by idltojava

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index List of Files for JavaIDL Count Remote Object
idltojava generates a Java package <userIDL> containing
Client-side Classes:
  • <user-interface>: Interface.
  • _<user-interface>Stub: Client's stub.
  • <user-interface>Helper: These include Any insert and extract operations for the type, getting the repository id, getting the typecode, and reading and writing the type from and to a stream.
  • <user-interface>Holder: Support for out and inout parameter passing modes requires the use of additional "holder" classes. These classes are available for all of the basic IDL datatypes in the org.omg.CORBA package and are generated for all named user defined types except those defined by typedefs.
Server-side Class:
  • _<user-interface>ImplBase: Server skeletons and implementation base code.

HTML version of Basic Foils prepared 5 Feb 98

Foil 39 Example2: Class Descriptions I

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index List of Files for JavaIDL Count Remote Object
Client's classes:
  • CounterClient - user's code for initializing client's ORB, getting reference, increment to 1000, outputting the average count time.
  • Counter.Count - generated interface.
  • Counter._CountStub - generated client stub.
  • Counter.CountHelper - generated class to get the repository id, get the typecode, and reading and writing the type from and to a stream.
  • Counter.CountHolder - generated class for out and inout parameter passing modes.
See: http://osprey7.npac.syr.edu:3768/reference-docs/cwou/JavaIDL/Counter/

HTML version of Basic Foils prepared 5 Feb 98

Foil 40 Example2: Class Descriptions II

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index List of Files for JavaIDL Count Remote Object
Server's Classes:
  • CounterServer - user's code for initializing server's ORB, getting root naming context reference, rebinding Counter object, waiting for invocations from clients
  • CountServantImpl - user's code to implement sum, initSum, increment methods.
  • Counter._CountImplBase - generated class to extend ObjectImpl and to implement interface Count and Skeleton.

HTML version of Basic Foils prepared 5 Feb 98

Foil 41 Example2: Development Process

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index List of Files for JavaIDL Count Remote Object
Count
CountHelper
CountHolder
_CountStub
_CountImplBase
(Skeleton and
Implementation)
CounterClient
CountServantImpl
CounterServer
idltojava compiler
User implements
Counter IDL
ORB Core
Client
Server

HTML version of Basic Foils prepared 5 Feb 98

Foil 42 Example 2: Java Interface

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index Java Interface generated for Count by JavaIDL
package Counter;
public interface Count extends org.omg.CORBA.Object {
int sum() throws org.omg.CORBA.SystemException;
void sum(int arg) throws org.omg.CORBA.SystemException;
void initSum(int value);
int increment();
}
Note: This code is created automatically by idltojava pre-compiler from the IDL spec.

HTML version of Basic Foils prepared 5 Feb 98

Foil 43 Example 2: Client-side Stub

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index Client Stub generated for Count by JavaIDL
package Counter;
public class _CountStub extends org.omg.CORBA.portable.ObjectImpl implements Counter.Count {
......
public int sum() throws org.omg.CORBA.SystemException {
long _n[] = new long[1];
java.lang.Object _o[] = new java.lang.Object[1];
_invoke(__ops[0], _n, _o);
return (int) (_n[0] & 0xFFFFFFFFL);
} ....
Detail can be found at
http://osprey7.npac.syr.edu:3768/reference-docs/cwou/JavaIDL/Counter/Counter/_CountStub.html

HTML version of Basic Foils prepared 5 Feb 98

Foil 44 Example 2: Client-side Helper

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index Client Side Helper generated for Count by JavaIDL
package Counter;
public final class CountHelper {
// It is useless to have instances of this
class private CountHelper() { }
public static void __write(org.omg.CORBA.portable.OutputStream out, Counter.Count that) {
out.write_Object(that);
}
.....
Details can be found at
http://osprey7.npac.syr.edu:3768/reference-docs/cwou/JavaIDL/Counter/Counter/CountHelper.html

HTML version of Basic Foils prepared 5 Feb 98

Foil 45 Example 2: Client-side Holder

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index Client Side Holder generated for Count by JavaIDL
package Counter;
public final class CountHolder implements org.omg.CORBA.portable.Streamable{
// instance variable
public Counter.Count value;
// constructors
public CountHolder() {
this(null);
}
public CountHolder(Counter.Count __arg) { ....
Details can be found at
http://osprey7.npac.syr.edu:3768/reference-docs/cwou/JavaIDL/Counter/Counter/CountHolder.html

HTML version of Basic Foils prepared 5 Feb 98

Foil 46 Example 2: Server-side Skeleton

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index Server Side Implementation Base generated for Count by JavaIDL
package Counter;
public abstract class _CountImplBase
extends org.omg.CORBA.portable.ObjectImpl
implements Counter.Count, org.omg.CORBA.portable.Skeleton {
static private org.omg.CORBA.portable.OperationDescriptor[][] _dispatch_table;
static {
_dispatch_table = new
org.omg.CORBA.portable.OperationDescriptor[1][0];
.........
Details can be found at
http://osprey7.npac.syr.edu:3768/reference-docs/cwou/JavaIDL/Counter/Counter/_CountImplBase.html

HTML version of Basic Foils prepared 5 Feb 98

Foil 47 Example 2: Import Packages

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index
The following packages used in developing the Counter/Timer example for both client and server codes:
import java.io.*;
import java.net.*;
import org.omg.CORBA.*;
import com.sun.CORBA.iiop.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import Counter.*;

HTML version of Basic Foils prepared 5 Feb 98

Foil 48 Example 2: Client-side Java Code

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index User Provided Client generated for Count in JavaIDL
public class CounterClient
{
public static org.omg.CORBA.ORB orb;
public static Counter.Count counter;
public static void main (String args[]) {
try {
orb = org.omg.CORBA.ORB.init(args, null);
org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
NamingContext ncRef = NamingContextHelper.narrow(objRef);
NameComponent nc = new NameComponent("Counter", "");
NameComponent path[] = {nc};
counter = Counter.CountHelper.narrow(ncRef.resolve(path));
counter.initSum((int)0);
long startTime = System.currentTimeMillis();
for (int i=0; i򒮨 i++) {
counter.increment();
}
long stopTime = System.currentTimeMillis();
System.out.println("Avg Ping = " + ((stopTime-startTime)/1000f) + "msecs");
System.out.println("Sum = " + counter.sum());
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

HTML version of Basic Foils prepared 5 Feb 98

Foil 49 Example 2: Server-side Java Code I

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index User Provided Server and Servant generated for Count in JavaIDL
class CountServantImpl extends Counter._CountImplBase {
private int sum_;
public CountServantImpl() {
System.out.println("Count Object Created");
sum_ = 0;
}
public int sum() {
return this.sum_;
}
public void initSum(int value) {
sum(value);
}
public int increment() {
this.sum_++;
return this.sum_;
}
}

HTML version of Basic Foils prepared 5 Feb 98

Foil 50 Example 2: Server-side Java Code II

From CORBA and distributed Objects using JavaIDL ARL Database Tutorial and CPS616 -- February 98. *
Full HTML Index User Provided Server and Servant generated for Count in JavaIDL
public class CounterServer {
public static org.omg.CORBA.ORB theORB;
static public void main(String[] args) {
try {
theORB = org.omg.CORBA.ORB.init(args, null);
CountServantImpl servant = new CountServantImpl();
theORB.connect(servant);
org.omg.CORBA.Object objRef = theORB.resolve_initial_references("NameService");
NamingContext ncRef = NamingContextHelper.narrow(objRef);
NameComponent nc = new NameComponent("Counter", "");
NameComponent path[] = {nc};
ncRef.rebind(path, servant);
java.lang.Object sync = new java.lang.Object();
synchronized (sync) {
sync.wait();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sun Nov 29 1998