com.teamdev.xpcom
Class ProxyManager

java.lang.Object
  extended by com.teamdev.xpcom.ProxyManager

public class ProxyManager
extends java.lang.Object

A proxy, in this context, is a stub object which enables a method of any class which is derived from nsISupports and has a typelib to be called on any in-process thread. The main reason for nsISupports Proxies is that java and UI are on a single thread. When one is busy, the other is blocked. A good example of this is the old install.js scripts that were used in XPInstall in older Mozilla versions. They from the majority of JavaScript code, which is small and can be quickly run. XPInstall installation scripts are sometimes very complex and can require long execution time due to unzipping or native file system actions. If XPInstall ran on the UI thread, the product would appear frozen until the script was complete. This is definitely bad. Because of this, XPInstall was moved to its own thread. Now XPInstall can do its installations while the product renders, but now XPInstall can not access UI elements such as a progress meter or a confirmation dialog. How can a separate non-UI thread act as if it was on the UI thread? Herein lays the utility of nsISupports Proxies.


Method Summary
<T extends org.mozilla.interfaces.nsISupports>
T
createComponetProxy(java.lang.String coid, java.lang.Class<T> proxyClass, boolean threadSafe)
          Creates proxied XPCOM object identified by XPCOM contract ID.
static ProxyManager getInstance()
           
<T extends org.mozilla.interfaces.nsISupports>
T
getProxiedService(java.lang.String contractID, java.lang.Class<T> serviceClass)
          Creates thread safe proxied instance of XPCOM service identified by XPCOM contract ID
<T extends org.mozilla.interfaces.nsISupports>
T
proxyForObject(org.mozilla.interfaces.nsISupports object, java.lang.Class<T> proxyClass, boolean threadSafe)
          Returns proxied instance for an existed XPCOM object or service.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static ProxyManager getInstance()

proxyForObject

public <T extends org.mozilla.interfaces.nsISupports> T proxyForObject(org.mozilla.interfaces.nsISupports object,
                                                                       java.lang.Class<T> proxyClass,
                                                                       boolean threadSafe)
Returns proxied instance for an existed XPCOM object or service.

Type Parameters:
T - the Xpcom interface type
Parameters:
object - the instance of Xpcom object or service
proxyClass - the java class of Xpcom interface type
threadSafe - whether proxied object should be executed in xpcom main thread. In most cases should be true
Returns:
proxied XPCOM instance

getProxiedService

public <T extends org.mozilla.interfaces.nsISupports> T getProxiedService(java.lang.String contractID,
                                                                          java.lang.Class<T> serviceClass)
Creates thread safe proxied instance of XPCOM service identified by XPCOM contract ID

Type Parameters:
T - the Xpcom interface type
Parameters:
contractID - the XPCOM service contract ID
serviceClass - the java class of Xpcom interface type
Returns:
thread safe proxied instance

createComponetProxy

public <T extends org.mozilla.interfaces.nsISupports> T createComponetProxy(java.lang.String coid,
                                                                            java.lang.Class<T> proxyClass,
                                                                            boolean threadSafe)
Creates proxied XPCOM object identified by XPCOM contract ID.

Type Parameters:
T - the XPCOM interface type
Parameters:
coid - the XPCOM contract ID
proxyClass - the java class of Xpcom interface type
threadSafe - whether proxied object should be executed in xpcom main thread. In most cases should be true
Returns:
new-created XPCOM object