How do I close a java<->OOo bridge?

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
coolcaptcha
Posts: 1
Joined: Wed Apr 21, 2010 4:11 pm

How do I close a java<->OOo bridge?

Post by coolcaptcha »

Hi there,

I would like to close the bridge between Java and OOo without having to kill either program.
  • XComponent.dispose() alone makes the Java program hang after ending main (some connection reader thread is blocking)
  • System.exit(0) does not kill OOo but it stops (logically) the Java program.
  • XDesktop.terminate() kills OOo (even other open documents are being closed)
  • BootstrapPipeConnector.disconnect() kills open OOo as well.
Now I am out of ideas. Is there another way to close the bridge?
OOo 2.4 + Java6 on Debian Lenny
craig_wu
Posts: 1
Joined: Thu May 27, 2010 5:01 am

Re: How do I close a java<->OOo bridge?

Post by craig_wu »

I have the same problem too. Even the java is terminated, the soffice process(tow processes as show below ) still running.
14803 pts/3 S 0:00 /bin/sh /opt/openoffice.org3/program/soffice -nologo -nodefault -norestore -nocrashreport -nolockcheck -accept=pipe,name=uno1583999052068028538;urp;
14863 pts/3 Sl 0:02 /opt/openoffice.org3/program/soffice.bin -nologo -nodefault -norestore -nocrashreport -nolockcheck -accept=pipe,name=uno1583999052068028538;urp;
OpenOffice 2.4 on Ubuntu 9.04
jrhillery
Posts: 1
Joined: Sat Dec 09, 2017 5:59 pm

Re: How do I close a java<->OOo bridge?

Post by jrhillery »

I recently ran into this problem. It's hard to find the right bridge. After much digging, I found the local service manager had a reference. Here is a method I wrote that closes the connection, leaving both processes running. It is safe to call even when there is no connection.

Code: Select all

import static com.sun.star.uno.UnoRuntime.queryInterface;
import com.sun.star.bridge.XBridge;
import com.sun.star.bridge.XBridgeFactory;
import com.sun.star.comp.helper.Bootstrap;
import com.sun.star.lang.XComponent;

	/**
	 * Close our connection to the office process.
	 */
	public static void closeOfficeConnection() {
		try {
			// get the bridge factory from the local service manager
			XBridgeFactory bridgeFactory = queryInterface(XBridgeFactory.class,
				Bootstrap.createSimpleServiceManager()
					.createInstance("com.sun.star.bridge.BridgeFactory"));

			if (bridgeFactory != null) {
				for (XBridge bridge : bridgeFactory.getExistingBridges()) {
					// dispose of this bridge after closing its connection
					queryInterface(XComponent.class, bridge).dispose();
				}
			}
		} catch (Throwable e) {
			System.err.println("Exception disposing office process connection bridge:");
			e.printStackTrace(System.err);
		}

	} // end closeOfficeConnection()
LibreOffice 5.4.2.2 on Windows 10
Post Reply