diff options
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | changelog | 4 | ||||
-rw-r--r-- | debug.conf | 6 | ||||
-rw-r--r-- | org/freedesktop/dbus/AbstractConnection.java | 18 | ||||
-rw-r--r-- | org/freedesktop/dbus/ExportedObject.java | 10 |
5 files changed, 29 insertions, 11 deletions
@@ -1,6 +1,6 @@ ** check that the blocking is correct on DBusAsyncReply and add an explicit timeout value * named pipes under windows: http://www.koders.com/csharp/fid2CD89EB558B80CE4947D53BAC3D667F2F1188FB9.aspx - * document that if you don't hold a reference, I will lose it! + * document that if you don't hold a reference, I will lose it! (now not default) * Javadoc * document that we handle Introspect for you * add header checks to daemon @@ -6,7 +6,9 @@ Version 2.4: * Don't respond to Introspect/Ping except on the right interface (pointed out by Serkan Kaba <serkan_kaba -at- yahoo -dot- com>) * Automatically unexport objects which go out of scope in the - parent program (don't hold a strong reference). + parent program (don't hold a strong reference). This is now + optional and not the default for 1. sanity and 2. a possible + bug in the WeakReference workings in Sun. * Add fallback objects---a single object can be called for any object under a given path prefix. * Add support for localization of strings via gettext. @@ -1,5 +1,5 @@ -org.freedesktop.dbus.MessageReader = INFO -org.freedesktop.dbus.MessageWriter = INFO +org.freedesktop.dbus.MessageReader = ERR +org.freedesktop.dbus.MessageWriter = ERR org.freedesktop.dbus.Message = ERR org.freedesktop.dbus.MethodCall = ERR org.freedesktop.dbus.MethodTuple = ERR @@ -15,7 +15,7 @@ org.freedesktop.dbus.EfficientQueue = ERR org.freedesktop.dbus.Transport = ERR org.freedesktop.dbus.Transport$SASL = ERR org.freedesktop.dbus.Transport$SASL$Command = ERR -org.freedesktop.dbus.Marshalling = VERBOSE +org.freedesktop.dbus.Marshalling = ERR org.freedesktop.dbus.ObjectTree = ERR org.freedesktop.dbus.BusAddress = ERR org.freedesktop.dbus.RemoteInvocationHandler = ERR diff --git a/org/freedesktop/dbus/AbstractConnection.java b/org/freedesktop/dbus/AbstractConnection.java index 1916ba6..701a131 100644 --- a/org/freedesktop/dbus/AbstractConnection.java +++ b/org/freedesktop/dbus/AbstractConnection.java @@ -247,6 +247,7 @@ public abstract class AbstractConnection protected _sender sender; protected Transport transport; protected String addr; + protected boolean weakreferences = false; static final Pattern dollar_pattern = Pattern.compile("[$]"); public static final boolean EXCEPTION_DEBUG; static final boolean FLOAT_SUPPORT; @@ -279,7 +280,7 @@ public abstract class AbstractConnection importedObjects = new HashMap<DBusInterface,RemoteObject>(); _globalhandlerreference = new _globalhandler(); synchronized (exportedObjects) { - exportedObjects.put(null, new ExportedObject(_globalhandlerreference)); + exportedObjects.put(null, new ExportedObject(_globalhandlerreference, weakreferences)); } handledSignals = new HashMap<SignalTuple,Vector<DBusSigHandler<? extends DBusSignal>>>(); pendingCalls = new EfficientMap(PENDING_MAP_INITIAL_SIZE); @@ -372,6 +373,17 @@ public abstract class AbstractConnection return info; } + /** + * If set to true the bus will not hold a strong reference to exported objects. + * If they go out of scope they will automatically be unexported from the bus. + * The default is to hold a strong reference, which means objects must be + * explicitly unexported before they will be garbage collected. + */ + public void setWeakReferences(boolean weakreferences) + { + this.weakreferences = weakreferences; + } + /** * Export an object so that its methods can be called on DBus. * @param objectpath The path to the object we are exposing. MUST be in slash-notation, like "/org/freedesktop/Local", @@ -390,7 +402,7 @@ public abstract class AbstractConnection synchronized (exportedObjects) { if (null != exportedObjects.get(objectpath)) throw new DBusException(_("Object already exported")); - ExportedObject eo = new ExportedObject(object); + ExportedObject eo = new ExportedObject(object, weakreferences); exportedObjects.put(objectpath, eo); objectTree.add(objectpath, eo, eo.introspectiondata); } @@ -410,7 +422,7 @@ public abstract class AbstractConnection throw new DBusException(_("Must Specify an Object Path")); if (!objectprefix.matches(OBJECT_REGEX)||objectprefix.length() > MAX_NAME_LENGTH) throw new DBusException(_("Invalid object path: ")+objectprefix); - ExportedObject eo = new ExportedObject(object); + ExportedObject eo = new ExportedObject(object, weakreferences); fallbackcontainer.add(objectprefix, eo); } /** diff --git a/org/freedesktop/dbus/ExportedObject.java b/org/freedesktop/dbus/ExportedObject.java index 3677aa9..c7bb905 100644 --- a/org/freedesktop/dbus/ExportedObject.java +++ b/org/freedesktop/dbus/ExportedObject.java @@ -12,6 +12,7 @@ package org.freedesktop.dbus; import static org.freedesktop.dbus.Gettext._; +import java.lang.ref.Reference; import java.lang.ref.WeakReference; import java.lang.annotation.Annotation; @@ -138,11 +139,14 @@ class ExportedObject return m; } Map<MethodTuple,Method> methods; - WeakReference<DBusInterface> object; + Reference<DBusInterface> object; String introspectiondata; - public ExportedObject(DBusInterface object) throws DBusException + public ExportedObject(DBusInterface object, boolean weakreferences) throws DBusException { - this.object = new WeakReference<DBusInterface>(object); + if (weakreferences) + this.object = new WeakReference<DBusInterface>(object); + else + this.object = new StrongReference<DBusInterface>(object); introspectiondata = ""; methods = getExportedMethods(object.getClass()); introspectiondata += |