Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 219
  • Last Modified:

Java process isolation (for a COM object)

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
amp834
Asked:
amp834
  • 13
  • 7
  • 4
1 Solution
 
objectsCommented:
0
 
CEHJCommented:
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
 
amp834Author Commented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
amp834Author Commented:
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
 
CEHJCommented:
>>... 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
 
amp834Author Commented:
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
 
CEHJCommented:
>> 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
 
amp834Author Commented:
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
 
CEHJCommented:
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
 
amp834Author Commented:
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
 
amp834Author Commented:
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
 
amp834Author Commented:
One more call for answers, any way to pick random ports?
0
 
objectsCommented:
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
 
amp834Author Commented:
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
 
objectsCommented:
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
 
amp834Author Commented:
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
 
objectsCommented:
Well I'd know whats running on what ports
Also thats why we use standard ports for different services
0
 
amp834Author Commented:
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
 
objectsCommented:
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
 
amp834Author Commented:
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
 
objectsCommented:
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
 
amp834Author Commented:
I think we're going in circles!  I will close the question now.
0
 
amp834Author Commented:
Thanks for the suggestions, I think it will work ok despite my initial hesitations!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 13
  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now