当前位置: 技术问答>java相关
CORBA in JDK 1.4 idlj -fall 后没有服务器框架,倒有一个POA类,好像就是服务器框架,不知如何使用。请看!!
来源: 互联网 发布时间:2017-03-21
本文导语: 我在jdk1.4下写Corba 定义一个idl文件,用idlj -fall Test.idl生成那几个文件,偏偏没有_TestImplBase.java即服务器框架类,倒是有一个TestPOA.java的文件, 我看了和_TestImplBase.java差不多,应该就是服务器框架类。但是这个类继...
我在jdk1.4下写Corba
定义一个idl文件,用idlj -fall Test.idl生成那几个文件,偏偏没有_TestImplBase.java即服务器框架类,倒是有一个TestPOA.java的文件,
我看了和_TestImplBase.java差不多,应该就是服务器框架类。但是这个类继承org.omg.PortableServer.Servant ,并不是继承org.omg.CORBA.protable.ObjectImpl
但是这两各类的实现接口都一样。
而java.lang.Object是org.omg.PortableServer.Servant 的超类,org.omg.CORBA.protable.ObjectImpl实现的是org.omg.CORBA.Object接口
所以在rebind的时候,无法绑定。怎么回事?是不是到了1.4,Corba的绑定方法变了?
求教!
定义一个idl文件,用idlj -fall Test.idl生成那几个文件,偏偏没有_TestImplBase.java即服务器框架类,倒是有一个TestPOA.java的文件,
我看了和_TestImplBase.java差不多,应该就是服务器框架类。但是这个类继承org.omg.PortableServer.Servant ,并不是继承org.omg.CORBA.protable.ObjectImpl
但是这两各类的实现接口都一样。
而java.lang.Object是org.omg.PortableServer.Servant 的超类,org.omg.CORBA.protable.ObjectImpl实现的是org.omg.CORBA.Object接口
所以在rebind的时候,无法绑定。怎么回事?是不是到了1.4,Corba的绑定方法变了?
求教!
|
Programming Example: Array Adder
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
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