要实现_TestImplBase.java 用idlj -fall -oldImplBase Test.idl 就可以了
解决方案 »
- 求助:JPA复合主键其中一个作为外键,不再新建一个外键列的配置?
- 求推荐一本spring的书吧。
- java从入门到精通要看那些书籍,各位高手来说说
- 有用过FCKEDITOR的兄弟进来帮忙
- 急 !急 !急!!struts怎么在页面提交list 或者多个表单 在线等
- 请问哪位有用jsp写的个人网站源码啊?
- 如果用自己定制的WebAppClassLoader来取代tomcat 默认的 WebAppClassLoader?
- 有用过——国产——嵌入实时操作系统——DeltaOS——的,进来谈谈感受。进者有分。:)
- 关于web应用程序在Tomcat中的配置和打包问题
- 这样描述下面的ejb看对不对?
- 如何使Applt中的组件占满Applet?(高分)
- applet 中用的包应该放在客户端的什么地方?
来调用。但是我在实验rmi-iiop to Corba的时候,rmi客户端是用jndi找到远程对象的。可是Corba端的Naming service如何实现?
Now let's see how to use the POA to develop a CORBA application. The application that we will develop here is an array adder: the client provides two arrays and the server adds them together and sends the result back to the client. We will develop two versions of the application: a transient server and a persistent server. Array Adder: Transient Server
The first step in developing any CORBA application is to define the interface in the OMG Interface Definition Language (IDL). The IDL interface for the array adder is shown in Code Sample 1. Here I define a module ArithApp (which is equivalent to a Java package), an interface Add that contains a constant, a new data type array (which is a synonym for an array of longs and an operation addArrays that takes in two arrays as input (specified using the in) and another array as the output holder (specified using the out). Code Sample 1: Add.idl module ArithApp {
interface Add {
const unsigned short SIZE=10;
typedef long array[SIZE];
void addArrays(in array a, in array b,
out array result);
};
};You can now compile this IDL interface to map it to Java and generate stubs and skeletons. This can be done using the idlj compiler. When you run this tool you can request it to generate client stubs only, server side skeletons only, or both. Here you want to generate both, client stubs and server skeletons. To do so use the following command: prompt> idlj -fall Add.idl
This command will generate several files. Check the local directory where you run the command from to see the files. You will notice that a new subdirectory with the name ArithApp has been created. This is because an OMG IDL module is mapped to a Java package. For more information on the idlj compiler and the options you can use, please see the IDL-to-Java Compiler.
--------------------------------------------------------------------------------
Note: The new idlj compiler in J2SE 1.4 generates server-side mappings for the Portable Object Adapter (POA). The new compiler is, however, backward compatible with earlier releases since it provides the -ImplBase flag that can be used to generate server-side mappings for existing applications that have been created using J2SE 1.3 or earlier versions. Therefore, in order to talk to existing applications that have been created using J2SE 1.3 or earlier, you need to use the -ImplBase flag to generate server-side mappings. New applications do not need to generate these deprecated server-side mappings.
--------------------------------------------------------------------------------The next step is to implement the IDL interface in Code Sample 1. An implementation is shown in Code Sample 2. The AddImpl class is a subclass of AddPOA, which is generated by the idlj compiler from the IDL interface. Note the third parameter to the addArrays operation. Here I am using an array holder simply because I am using the out parameter as a holder for the output array. Code Sample 2: AddImpl.java import ArithApp.*;
import org.omg.CORBA.*;class AddImpl extends AddPOA {
private ORB orb;
public AddImpl(ORB orb) {
this.orb = orb;
} // implement the addArrays() method
public void addArrays(int a[], int b[],
ArithApp.AddPackage.arrayHolder result) { result.value = new int[ArithApp.Add.SIZE]; for(int i=0; i<ArithApp.Add.SIZE; i++) {
result.value[i] = a[i] + b[i];
}
}
}The next step is to develop the server. A sample server is shown in Code Sample 3. The server performs the following tasks: Creates and initializes the ORB.
Creates an instance of the interface implementation and registers it with the ORB.
Gets a reference to the RootPOA and activates the POAManager.
Gets an object reference from the servant.
Gets the root naming context from the naming service and registers the new object under the name "Add".
Waits for invocations from clients.
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA;
import org.omg.CosNaming.NamingContextPackage.*;public class AddServer { public static void main(String args[]) {
try{
// create and initialize the ORB
ORB orb = ORB.init(args, null); // create an implementation and register it with the ORB
AddImpl impl = new AddImpl(orb); // get reference to rootpoa & activate the POAManager
POA rootpoa = POAHelper.narrow(
orb.resolve_initial_references("RootPOA"));
rootpoa.the_POAManager().activate(); // get object reference from the servant
org.omg.CORBA.Object ref =
rootpoa.servant_to_reference(impl);
Add href = AddHelper.narrow(ref);
// get the root naming context
// NameService invokes the name service
org.omg.CORBA.Object objRef =
orb.resolve_initial_references("NameService");
// Use NamingContextExt which is part of the Interoperable
// Naming Service (INS) specification.
NamingContextExt ncRef =
NamingContextExtHelper.narrow(objRef); // bind the Object Reference in Naming
String name = "Add";
NameComponent path[] = ncRef.to_name( name );
ncRef.rebind(path, href); System.out.println("AddServer
ready to add up your arrays ...."); // wait for invocations from clients
orb.run();
} catch (Exception e) {
System.err.println("ERROR: " + e);
e.printStackTrace(System.out);
}
System.out.println("AddServer Exiting ....");
}
}Now, implement the client. A sample client is shown in Code Sample 4. The client code performs the following tasks: Creates and initializes the ORB.
Obtains a reference to the root naming context.
Looks up the "Add" object in the naming context and obtains a reference to it.
Invokes the addArrays method and prints the results.
Code Sample 4: AddClient.java import ArithApp.*;
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;public class AddClient { 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"); // Use NamingContextExt instead of NamingContext. This is
// part of the Interoperable Naming Service.
NamingContextExt ncRef =
NamingContextExtHelper.narrow(objRef);
// resolve the Object Reference in Naming
String name = "Add";
Add impl = AddHelper.narrow(ncRef.resolve_str(name)); System.out.println("Handle
obtained on server object: " + impl); // the arrays to be added
int a[] = {6, 6, 6, 6, 6, 6, 6, 6, 6, 6};
int b[] = {7, 7, 7, 7, 7, 7, 7, 7, 7, 7};
// the result will be saved in this new array
ArithApp.AddPackage.arrayHolder c =
new ArithApp.AddPackage.arrayHolder(); // invoke the method addArrays()
impl.addArrays(a, b, c);
// print the new array
System.out.println("The sum of the two arrays is: ");
for(int i=0;i<ArithApp.Add.SIZE;i++) {
System.out.println(c.value[i]);
} } catch (Exception e) {
System.out.println("ERROR : " + e) ;
e.printStackTrace(System.out);
}
}
}Now you can compile the classes AddImpl, AddServer, AddClient, and the stubs and skeletons that were generated by the idlj compiler. This is done using the javac compiler as follows: prompt> javac *.java ArithApp/*.java
To run the application: Start the orbd, which is a name server:
prompt> orbd -ORBInitialPort 2500
The number 2500 is the port number where you want the orbd to run. Note that the -ORBInitialPort is a require command-line argument.
Start the AddServer:
prompt> java AddServer -ORBInitialPort 2500
This command starts the server as shown in Figure 2. Figure 2: Starting the AddServer
(click to enlarge)
Here we are assuming that both the AddServer and orbd are running on the same host. If the orbd is running on a different host, use the -ORBInitialHost argument to inform the server where to find the orbd.
Start the AddClient:
prompt> java AddClient -ORBInitialPort 2500
You should see the sum of the two arrays as shown in Figure 3. Figure 3: Starting the AddClient
(click to enlarge)