Solved

Java process isolation (for a COM object)

Posted on 2011-03-25
24
195 Views
Last Modified: 2012-05-11
I have a Java program that uses an unstable/unreliable windows COM object--sometimes, the COM object causes the entire process to exit!  I would like to isolate the COM object into another process and communicate to the COM object across the process, and if the COM process dies, the main app can report an error without mysteriously dying!  

What are some ways of isolating a library (I call various functions from the COM library, for which I can write stubs), and calling it remotely.  If two instances of my app run, each should have its own copy of the COM process, they should not interfere with each other.

The simplest thing I can think of is below, but I'm looking for other ideas out of the blue!  
(I made the # points large so I can divide points between the various useful suggestions)

Simple idea:  can create a process and us the process's stdin/stdout to communicate (or use network protocols).  There may be a lot of work encoding/passing args back and forth.

0
Comment
Question by:amp834
  • 13
  • 7
  • 4
24 Comments
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 35218790
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35218859
Firstly, are you sure it's killing the whole java process and not just the main app thread? If it's the latter a simple dual thread approach might stop it happening
0
 

Author Comment

by:amp834
ID: 35219177
CEHJ, my main app has GUI and other threads, the entire app disappears and is no longer on the OS's process list.

objects, on first reading of the link, there seems to be a lot of setup needed:
1. write the COM object interface (as a class)--must be done anyway
2. supply an HTTP server so it can serve up the class?
3. How to create the server for my instance of my app?
4. How to tell if the server died
5. What network issues do I need to be aware of?  (what ports, firewalls, possible problems, in case the "program doesn't work", I can tell the end user to check for xxx)

I stayed away from RMI and RPC because there seems to be a lot of setup involved, but if you can provide some info or links to simple examples, they would definitely help in other parts of the app I'm working on as well!
0
 

Author Comment

by:amp834
ID: 35219349
I looked at additional RMI tutorials at
http://download.oracle.com/javase/1.3/docs/guide/rmi/getstart.doc.html
http://www.eg.bucknell.edu/~cs379/DistributedSystems/rmi_tut.html

This is what I figure so far, please chime in...

b1. must run:  rmiregistry  (the main app can do that; must find it in the jre/bin directory somehow)

b2. Main app can then run server (which I write using the Hello example), and have the server bind itself via:  Naming.rebind ("UniqueNameForThisProcess", new MyRmiServerClass (parm1,parm2));

b3. Not sure how to tell MyRmiServerClass to terminate, maybe just have one of the function calls be "CloseServer", which would exit.  Does it need to un-register itself?

b4. Main app can then connect to that UniqueNameForThisProcess
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35219606
>>... the entire app disappears and is no longer on the OS's process list.

The fact that it's not on the OS's process list is inconclusive.

>>CEHJ, my main app has GUI and other threads,

Yes, but that doesn't say much. The point is: do you start calling the COM routines from an explictly-created separate thread? If not, you might find that if you do, the thread in question will be terminated, but will leave the main thread, AND the java process, intact.
0
 

Author Comment

by:amp834
ID: 35219642
cehj,

>>The fact that it's not on the OS's process list is inconclusive.
I'm running on windows.  if it's not on the process list under task manager, and it used to be, are you saying it can still be running?

>>do you start calling the COM routines from an explictly-created separate thread?
The user presses a button (swing app), I start another thread that does processing; it is this processing thread that calls the COM routines.  And while processing, the entire app disappears (from the screen, from the windows task manager, from the explorer bar) when the COM object misbehaves badly.

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35219726
>> I start another thread that does processing; it is this processing thread that calls the COM routines.

In that case, it sounds as if you're explicitly multi-threading. I don't see how making it into some kind of server is going to help really. What does the Windows event log have to say about things?
0
 

Author Comment

by:amp834
ID: 35219853
cehj, I've had the same issue with this COM object using VB.  It's not Java, it's the COM object killing whatever process the COM object is loaded into.  That I know for sure.

I'm playing with RMI now, does anyone have a complete example on how to do a sample RMI client/server app using netbeans?  I'm running into having to generate stubs manually, which will be a pain!
0
 
LVL 92

Expert Comment

by:objects
ID: 35219874
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35219876
I'm wondering what the scenario is going to be. Let's say you get a server running the COM. It crashes and takes the server down, meaning the client can no longer communicate with it. What then?
0
 

Author Comment

by:amp834
ID: 35234895
cehj, I think you're going off on a tangent!  The client has a gui, and will report that it cannot do whatever it was trying to do, without the entire gui app mysteriously disappearing.


objects, I'm looking into this example, maybe it doesn't need to create stubs.  That would make it easier.
0
 

Author Comment

by:amp834
ID: 35236268
I'm almost there!  I found out more, and got a sample program working.
java 5 and above do not need stubs, you can register the interface dynamically.
http://download.oracle.com/javase/1.5.0/docs/guide/rmi/hello/hello-world.html

I'm not sure how to do the (name service) registry.  I create a registry via
            java.rmi.registry.LocateRegistry.createRegistry(1099);
But am not sure how to terminate it.  1099 is the standard port, I could use a different port for each instance, and then terminate the server process when I'm done.

How to pick a random port that's not used?
How can the server terminate itself when told to do by a call from the client?  (Just system exit its process?  Is anything left hanging?)
What is the scope of the registry, is it accessible by just this machine, or if someone else finds out the port #, they could connect to it from another machine?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:amp834
ID: 35302314
One more call for answers, any way to pick random ports?
0
 
LVL 92

Expert Comment

by:objects
ID: 35303073
sorry, missed your earlier post.

> But am not sure how to terminate it.  1099 is the standard port, I could use a different port for each instance, and then terminate the server process when I'm done.

you would only need one registry, and your sever(s) would bind to that registry
the client then use the registry to lookup available servers

> How to pick a random port that's not used?

you can't use a random port
0
 

Author Comment

by:amp834
ID: 35303144
Thanks, objects.

1. For the port, I mean I myself pick one beforehand, say 19,216, and use it for the client and the server.  What happens if port 19,216 happens to be used by some other program?
So how do I pick a port to use for my app?
(I may not be understanding how the port #'s work:  I'm thinking the client and server agree on a port beforehand.  And some apps use a config file to allow the end-user to override the port #, which makes installation even more cumbersome!  Whatever I can do so the end user doesn't have to configure anything would make things easier)
'
2. The "Create registry", does it create a process on the machine that runs it?  And is the registry process active when the program that created it terminates?  I'm a little lost on the mechanics.
0
 
LVL 92

Expert Comment

by:objects
ID: 35303444
you need to know beforehand what port is available

sounds like you're better off starting the registry seperately
http://stackoverflow.com/questions/99242/rmi-server-rmiregistry-or-locateregistry-createregistry
0
 

Author Comment

by:amp834
ID: 35317454
Perhaps there is hole in my understanding of TCP ports.  I'll try one or at most two more rounds, then I'll close the question.  You've already helped enough!

For an app running under JEE, I could assume that the registry server is already running, and if I can't connect to it, then I could tell the user something is wrong.  What I'm writing is a standalone app (Java SE), and to do the RMI calls, I can either pick a port and run a personal copy of rmiregistry, or see if there is already a standard one (on its well defined port) available beforehand (if there is, use it).  That's why the "how to pick a port" question comes up.

If YOU were going to write the app, would you just pick a port and hope no one else is using that port?  And what would you do when it fails for one of the 5,000 customers because that port was already being used by some other app?

(I've looked at jgroups.org, which does multicasting to find a server.  That's a cleaner method.  Perhaps there is something with RMI that makes it easier too)
0
 
LVL 92

Expert Comment

by:objects
ID: 35319449
Well I'd know whats running on what ports
Also thats why we use standard ports for different services
0
 

Author Comment

by:amp834
ID: 35320501
I'm sure you don't mean for 5,000 customers, you would know what's running on their ports?

Maybe I'm hearing "I would just use the standard port, I don't have a solution for assigning a custom port and have never done that myself in the past".  If that's the case, it's ok, I just want to know if there are any standard tricks I should consider.
0
 
LVL 92

Expert Comment

by:objects
ID: 35320513
you only need to know on the server, then the client connects to that port.
For example a web server typically listens on port 80, and clients connect to that port
0
 

Author Comment

by:amp834
ID: 35320748
That part I understand, and the "well known ports" concept (and list) as well.  The question is how do you choose (and "publish"/share) a port for your app if it's not a well-known service.  (And in this case, the server is the same machine as the client, and I would use "localhost")

Again, if you don't have experience or an answer for this, it's ok, I can close the question, I have enough info to continue for now.
0
 
LVL 92

Expert Comment

by:objects
ID: 35320771
the rmi registry does have a standard port 1099
the server specifies what port is being used and the client connects to that port. The client has nothing to do with picking what port is used. It needs to know in advance what port to connect to.
0
 

Author Comment

by:amp834
ID: 35324648
I think we're going in circles!  I will close the question now.
0
 

Author Closing Comment

by:amp834
ID: 35324663
Thanks for the suggestions, I think it will work ok despite my initial hesitations!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This video teaches viewers about errors in exception handling.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now