When referencing Java objects from COM clients using J-Integra®'s DCOM mode, the COM client will obtain a reference to the Java object and each subsequent access to the Java object results in at least one round trip communication between the client and the server. In the case of many objects being accessed by the COM client, a significant performance overhead may occur.
To avoid this J-Integra® also offers the possibility to treat a Java object as a COM struct. This means that public members of the Java object will be passed by value to the COM client, not by reference, and access to these data members by the COM client requires no further network communication. This is the case for both single Java objects and arrays of Java objects.
Currently the following restrictions apply to the members of a Java class which may be passed by value:
The member must be defined as a public variable.
The member must be a primitive Java type (boolean, int, long, byte, short, double, float, char) or of type java.lang.String or java.util.Date.
The member cannot be an array.
Other restrictions include:
Under Windows NT, service pack 4 or greater must be installed.
The type library obtained by running java2com and then compiling the generated IDL must be registered on the client machine.
This example is not a complete step-by-step example, it presumes that you have already used J-Integra® to access Java objects from Visual Basic using early binding and that you are familiar with the steps. If this is not the case then you should attempt this first. Once you have completed a Visual Basic to Java early binding example, the following should make sense.
If you wish to pass Java classes by value to Visual Basic clients, this outlines how to proceed. There is also a C++ example in the J-Integra® Knowledge Base.
Run java2com with the following Syntax:
java -DJINTEGRA_CLASSES_BY_VALUE=<classes
to be passed by value> com.linar.java2com.Main
where <classes to be passed by value> is a semicolon separated
list of classes which you require to be passed by value.
Assuming I have the following Java class:
public
class Person { |
I would run java2com
as follows:
java -DJINTEGRA_CLASSES_BY_VALUE=Person com.linar.java2com.Main
Use java2com as usual, and compile all the generated IID*.java files.
Also compile the generated
IDL file using midl, use the /mktyplib203 option:
midl /mktyplib203 MyIDL.idl
Copy the generated type library (.tlb file) to the machine where the COM client resides and register the type library using the regtlb command.
Assuming I have the following Java class whose methods return Java objects of type Person:
public class PeopleFinder
{ |
Then my Visual Basic code to use this class to obtain the Person Java objects returned by the methods getOldestPerson and getAllPeople by value could look like:
Set Finder = GetObject("myjvm:PeopleFinder") |