File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Distributed Java and the fly likes Java web application communication and call back with C/C++ programming language API Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "Java web application communication and call back with C/C++ programming language API" Watch "Java web application communication and call back with C/C++ programming language API" New topic
Author

Java web application communication and call back with C/C++ programming language API

Rama Krishna
Ranch Hand

Joined: Oct 16, 2007
Posts: 110
I need to leverage a C API that communicates with a brokerage firm using socket communication. The forum suggests using RMI-IIOP to communicate with C API. Should be able to handle the call backs too as asynchronous, i.e., their C API should have a call back functionality, be able to call an onEvent method of some eventHandler class on Java JVM side with minimal changes or modifications on the C side because of the lack of understanding or time spent learning C (IDL ?).

Is using RMI-IIOP to provide stubs on either end to make asynchronous calls the best bet?

There are beautiful RMI plugins for eclipse IDE (Genady) to quickly develop RMI based communication between JVMs, trying to run RMI examples based on security policies and RMI servers using command prompt attributes/flags is a pain. Are there similar tools to start quickly writing these stubs or for that matter, anything for Spring to quickly host or invoke Remote methods via IIOP? Where can I get started?

Thanks
Krishna
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
Since you say "web application" let me raise the question of multiple "simultaneous" requests.

If you have a single instance of the C program running, what will you do if additional requests come in?

If you let multiple requests access the C program, is the C api designed to handle this? Any instance variables that might get confused?

You might be better off writing your socket stuff in Java.

Bill
Rama Krishna
Ranch Hand

Joined: Oct 16, 2007
Posts: 110
William Brogden wrote:Since you say "web application" let me raise the question of multiple "simultaneous" requests.

If you have a single instance of the C program running, what will you do if additional requests come in?

If you let multiple requests access the C program, is the C api designed to handle this? Any instance variables that might get confused?

You might be better off writing your socket stuff in Java.

Bill


Not sure how C program would handle multiple requests or multi-threading, if there is no easy way, I can always queue them from a common Java class that does the calling.

"You might be better off writing your socket stuff in Java." to do what?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
"to do what?" why make the socket call to the brokerage service of course!

Bill
Rama Krishna
Ranch Hand

Joined: Oct 16, 2007
Posts: 110
William Brogden wrote:"to do what?" why make the socket call to the brokerage service of course!

Bill


The C API does the communication with the brokerage firm, so I was not sure whether you meant socket communication with C API or the brokerage itself. Rather than re-writing their whole API again in Java, you meant communicate with the C API via JAVA using socket communication rather than RMI-IIOP?

But then using socket communication, I have to serialize, deserialize in a common protocol/standard or is there a simpler way to achieve this. Again, could you guide me to a location to get started?

Thanks
Krishna
Rama Krishna
Ranch Hand

Joined: Oct 16, 2007
Posts: 110
Any examples of Java - C programming language socket communication?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
There is nothing C specific or Java specific about socket communication, just opening sockets and sending bytes according to the well documented APIs. The only thing to watch out for is byte-order.

You have apparently concluded that the API the C program is using to talk to the brokerage service is too complex to duplicate in java.

What interface does the C program present for RMI-IIOP or any other communication technique?

You will certainly be better off using the highest level API that is well documented.

Bill
Rama Krishna
Ranch Hand

Joined: Oct 16, 2007
Posts: 110
There is nothing C specific or Java specific about socket communication, just opening sockets and sending bytes according to the well documented APIs. The only thing to watch out for is byte-order.

I know and can quickly design a thread safe handling of java - java socket communication. However, I will not be able to serialize/deserialize my java POJOs as it is C on the other side, so have to consider another common format similar to String/XML bytes (parse/format) that both can understand. Wonder why byte-order is important.


You have apparently concluded that the API the C program is using to talk to the brokerage service is too complex to duplicate in java.

That is true, they gave a pretty big static library and two header files to start with. The goal therefore is to re-use it and as you said, socket communication makes sense.


What interface does the C program present for RMI-IIOP or any other communication technique?

You will certainly be better off using the highest level API that is well documented.

None, they only gave us their C API and that is it. We will have to figure out how to call their API from our Java application.

I was therefore wondering if there were any examples where they have discussed cross language socket communication.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
Wonder why byte-order is important.

here is a nice discussion of the significance of byte order.

How much of what kind of data does the C program take as input?

Ditto for what it puts out?

IF the C has to run as a separate program, hiding the details of this sort of inter-app communication is what SOAP and RPC was invented for. Maybe the brokerage has implemented a SOAP or RESTful interface like Amazon, Google and many others.

On the other hand, is there some reason you can't have the C code loaded as a library by Java and talk to it with Java Native Interface methods?

Bill
Rama Krishna
Ranch Hand

Joined: Oct 16, 2007
Posts: 110
William Brogden wrote:
Wonder why byte-order is important.

here is a nice discussion of the significance of byte order.

How much of what kind of data does the C program take as input?

Ditto for what it puts out?

IF the C has to run as a separate program, hiding the details of this sort of inter-app communication is what SOAP and RPC was invented for. Maybe the brokerage has implemented a SOAP or RESTful interface like Amazon, Google and many others.

On the other hand, is there some reason you can't have the C code loaded as a library by Java and talk to it with Java Native Interface methods?

Bill


Figured out that Strings and socket communication in some cases do not have this problem which is good as we can now communicate by exchanging java POJOs/C STRUCTS formatted as String/XML likes.

They say that they have an XML based API but that only using MQ series and we were interested in open source solutions only. We are now looking at open source JMS options to queue incoming and outgoing messages, are these open source JMS cross programming language compatible or we better write our own socket communication code ?

Underestimated JNI, right now looking at limitations of JNI, because as long as you have one entry point into the C code and vice-versa, that is all you need. Could not find related example base anywhere though.

Thanks
Rama
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
are these open source JMS cross programming language compatible or we better write our own socket communication code ?


It is my understanding that JMS and MQ series are compatible since IBM was a big contributor during development of the API. In any case, I would certainly try JMS first.

Using messaging will also handle "simultaneous" query problems since presumably the utility you are trying to work with will only accept messages at a rate it can handle. Also of course you could have multiple clients using the same mechanism.

Bill
Rama Krishna
Ranch Hand

Joined: Oct 16, 2007
Posts: 110
William Brogden wrote:
are these open source JMS cross programming language compatible or we better write our own socket communication code ?


It is my understanding that JMS and MQ series are compatible since IBM was a big contributor during development of the API. In any case, I would certainly try JMS first.

Using messaging will also handle "simultaneous" query problems since presumably the utility you are trying to work with will only accept messages at a rate it can handle. Also of course you could have multiple clients using the same mechanism.

Bill


Awesome, started looking into Apache ActiveMQ, as it seems to support directly both Java (OpenWire wire protocol) and C (Stomp wire protocol) based clients, as both producers and consumers, using TCP protocol.

There seem a ton of projects using ActiveMQ
http://activemq.apache.org/projects-using-activemq.html

Are there any cross-language clients based example some one can suggest or a place we can start looking into, especially to configure the C side of the producer/consumer?

Thanks Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java web application communication and call back with C/C++ programming language API