Sagewire Logo

mapping JAVA => C++ objects

3 Message(s) by 2 Author(s) originally posted in java corba


From: Jason Stelzer Date:   Wednesday, August 01, 2007
Hello, I'm rather new to corba so if this is a faq, I will happily go
read the relevant docs or url. I just need a nudge.

My situation is this. The company I'm at has a JAVA app running in
jboss that they need to integrate into a legacy distributed perl app. I
chose corba because this is going to be used in a performance critical
piece of code and web services simply have too much overhead. So at
this point I'm using jacorb on the JAVA side and omniORB on the C/perl
side.

Since I'm using jboss and the way they support corba is via annotations
in the JAVA class file s combined with reflection at deployment time to
expose things, this means I need to generate IDL from the class files
then create C++ stub code. I have done this and have things working.

I have written a C++ library with C wrappers and a perl module in C to
use them. I have a fairly complicated data structure to return, so I
created a custom type but I have come into a minor bit of difficulty. I'm
not clear on how to map a 'traditional' pojo in corba. Something like:

public class Foo {
private String val;
public String getVal(){
return val;
}
public void setVal(String s){
val = s;
}
...
}

When I used idl generated by rmic for this type of bean, I'd get
back an object ref that'd consistently return an empty
CORBA ::WStringValue object. After examining the objects in gdb, I'm
reasonably sure what is happening is that the 'private' string is not
being returned by getVal(). Its there. I see it marshaled, the accessor
just is not returning what I thought it should. The problem is, I'm not
sure what the generated IDL should look like as this is the first time
I have done something like this.

In the interim, what I have done is create a class in JAVA that is
essentially a glorified C style struct.

public class Foo {
public String val;
...
}

I populate the member variables of a Foo with all the values I need to
return and on the C++ side it is unmarshaled exactly as I'd expect.
After that its pretty boring. I just need to copy the data I need into
perl side data structures, release references and do cleanup.

I'd really like to be able to use the former style pojo as the latter
makes the other JAVA developers twitch.

I have only spent a few days working on this, and I'm still reading quite
a bit and learning how stuff gets marshalled. If anyone has example IDL
I could look at that'd be great. I have done ok with fixing up a lot of
the busted crap that rmic generates, but I seriously lack experience at
this stuff.

As it stands, I'm at least feature complete from a prototype
perspective. I can make the calls I need to from perl and get the right
data back. I'm sure I have a bit of tweaking to do to ensure there are
no leaks, but things work.

--
J.


From: arun.darra Date:   Sunday, August 12, 2007
wrote in message:
Hello, I'm rather new to corba so if this is a faq, I will happily go
read the relevant docs or url. I just need a nudge.
My situation is this. The company I'm at has a JAVA app running in
jboss that they need to integrate into a legacy distributed perl app. I
chose corba because this is going to be used in a performance critical
piece of code and web services simply have too much overhead. So at
this point I'm using jacorb on the JAVA side and omniORB on the C/perl
side.
Since I'm using jboss and the way they support corba is via annotations
in the JAVA class files combined with reflection at deployment time to
expose things, this means I need to generate IDL from the class files
then create C++ stub code. I have done this and have things working.
I have written a C++ library with C wrappers and a perl module in C to
use them. I have a fairly complicated data structure to return, so I
created a custom type but I have come into a minor bit of difficulty. I'm
not clear on how to map a 'traditional' pojo in corba. Something like:
public class Foo {
private String val;
public String getVal(){
return val;
}
public void setVal(String s){
val = s;
}
...
}
When I used idl generated by rmic for this type of bean, I'd get
back an object ref that'd consistently return an empty
CORBA::WStringValue object. After examining the objects in gdb, I'm
reasonably sure what is happening is that the 'private' string is not
being returned by getVal(). Its there. I see it marshaled, the accessor
just is not returning what I thought it should. The problem is, I'm not
sure what the generated IDL should look like as this is the first time
I have done something like this.
In the interim, what I have done is create a class in JAVA that is
essentially a glorified C style struct.
public class Foo {
public String val;
...
}
I populate the member variables of a Foo with all the values I need to
return and on the C++ side it is unmarshaled exactly as I'd expect.
After that its pretty boring. I just need to copy the data I need into
perl side data structures, release references and do cleanup.
I'd really like to be able to use the former style pojo as the latter
makes the other JAVA developers twitch.
I have only spent a few days working on this, and I'm still reading quite
a bit and learning how stuff gets marshalled. If anyone has example IDL
I could look at that'd be great. I have done ok with fixing up a lot of
the busted crap that rmic generates, but I seriously lack experience at
this stuff.
As it stands, I'm at least feature complete from a prototype
perspective. I can make the calls I need to from perl and get the right
data back. I'm sure I have a bit of tweaking to do to ensure there are
no leaks, but things work.
--
J.Hi,



you can use "attribute 's" to represent ur simple bean.
Ur IDL will look something like this:

sample.idl :

interface Sample
{
attribute String val;
};

when this idl file is compiled by a idl compiler it'll generate
automatically a getter and a setter (like your bean).

I have used omniORB its pretty cool and easy to use,
but I have one question for u - howcome ur using JacORB (on JAVA side)
instead the std SunORB (that comes as part of the JDK), any specific
reason?

Regards,
Arun


From: Jason Stelzer Date:   Tuesday, August 14, 2007
On 2007-08-12 16:27:13 -0400, "arun.darra@xxxxxxxxxxx"
<arun.darra@xxxxxxxxxxx> said:
Hi,
you can use "attribute's" to represent ur simple bean.
Ur IDL will look something like this:
sample.idl :
interface Sample
{
attribute String val;
};
when this idl file is compiled by a idl compiler it'll generate
automatically a getter and a setter (like your bean).Actually , that generates the declaration for a getter/setter which


then needs to be implemented in my Impl class. Thats fine, but its just
a bunch of boiler plate code to write.

I have used omniORB its pretty cool and easy to use,
but I have one question for u - howcome ur using JacORB (on JAVA side)
instead the std SunORB (that comes as part of the JDK), any specific
reason?



We're mainly using it as it is what jboss uses as its orb in their
application server. So far it performs well enough and is fairly
painless to use. I have heard mixed reviews about sun's orb
implementation on a few lists. I have yet to hear a compelling enough
reason to push for a reconfiguration of our app servers.



Next Message: help to get start: where find a good tutorial?


Blogs related to mapping JAVA => C++ objects

Paper 1
Ans ) Remote method invocation : java only. uses JRMP to communication between java objects Common object request broker architecture : platform independent. Uses IIOP to communicate between objects. 32.What are the services in RMI ? ...

Java 6.0 Features
Simply put, it is a Mapping Technology for Java and XML Documents. Using JAXB, one can Generate XML Documents from Java Objects and also they can Construct Java Objects from one or more XML Documents. In JAXB terms, Marshalling refers ...

How to get started with Java ActionPack
Java Actionpack will create some wiring for you. It will provide the following mappings by default: /{controller}/{action}/{id} /{controller}/{action}. That will provide the familiar mapping of what controller you want, which action on ...

The Java Interview Guide---Questions u face in ur interviews
66 Q What is hashCode? A The hashcode of a Java Object is simply a number (32-bit signed int) that allows an object to be managed by a hash-based data structure. A hashcode should be, equal for equal object (this is mandatory! ...

Java Interview Q's
The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources can be reclaimed and reused. A Java object is subject to garbage collection when it becomes unreachable ...

paper 1
What are the files generated after using IDL to Java Compilet ? What is the protocol used by server and client ? Can I modify an object in CORBA ? What is the functionality stubs and skeletons ? What is the mapping mechanism used by ...


Programming | Sports | Autos

copyright 2006
Valid XHTML 1.0 Transitional