Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Property change notification doesn't work for Java
18-04-2012, 04:33 PM
Post: #1
Property change notification doesn't work for Java
If a Java control point tries to set a notification for a change to a single named property, the property change listener is never called. A workaround is to listen for changes to all properties (which does work), but this is inefficient if only one property has changed.

The fix is in the generated Java proxy code. In the constructor, instead of code like this for a property Foo:

Code:
iFooChanged = new PropertyChangeListener();
iFoo = new PropertyString("Foo", iFooChanged);
addProperty(iFoo);

the code should be like this:

Code:
iFooChanged = new PropertyChangeListener() {
    public void notifyChange() {
        fooPropertyChanged();
    }
};
iFoo = new PropertyString("Foo", iFooChanged);
addProperty(iFoo);
Find all posts by this user
18-04-2012, 04:40 PM
Post: #2
RE: Property change notification doesn't work for Java
Thanks for debugging this! I'll get a fix committed tomorrow.
Find all posts by this user
19-04-2012, 01:31 PM
Post: #3
RE: Property change notification doesn't work for Java
Unit tests get into stack overflowing loops after this change.

I updated the T4 template CpUpnpJava.tt with the generic version of the fix you suggested, rebuilt and ran TestDvDeviceJava. It gives pages of output of the form

Code:
at org.openhome.net.controlpoint.CpProxy.reportEvent(CpProxy.java:168)
        at org.openhome.net.controlpoint.proxies.CpProxyOpenhomeOrgTestBasic1.varUintProper​tyChanged(CpProxyOpenhomeOrgT
estBasic1.java:1600)
        at org.openhome.net.controlpoint.proxies.CpProxyOpenhomeOrgTestBasic1.access$000(Cp​ProxyOpenhomeOrgTestBasic1.ja
va:430)
        at org.openhome.net.controlpoint.proxies.CpProxyOpenhomeOrgTestBasic1$1.notifyChang​e(CpProxyOpenhomeOrgTestBasic
1.java:567)
        at org.openhome.net.controlpoint.CpProxy.reportEvent(CpProxy.java:168)
        at org.openhome.net.controlpoint.proxies.CpProxyOpenhomeOrgTestBasic1.varUintProper​tyChanged(CpProxyOpenhomeOrgT
estBasic1.java:1600)
        at org.openhome.net.controlpoint.proxies.CpProxyOpenhomeOrgTestBasic1.access$000(Cp​ProxyOpenhomeOrgTestBasic1.ja
va:430)
        at org.openhome.net.controlpoint.proxies.CpProxyOpenhomeOrgTestBasic1$1.notifyChang​e(CpProxyOpenhomeOrgTestBasic
1.java:567)
        at org.openhome.net.controlpoint.CpProxy.reportEvent(CpProxy.java:168)
Find all posts by this user
19-04-2012, 03:27 PM
Post: #4
RE: Property change notification doesn't work for Java
My apologies. The correct code is as follows:

Code:
iFooChanged = new PropertyChangeListener();
iFoo = new PropertyString("Foo",
           new PropertyChangeListener() {
               public void notifyChange() {
                   fooPropertyChanged();
               }
           }
       );
addProperty(iFoo);

I believe the previous code worked when the control point had set a change listener for the Foo property (which was the case that I tested), but not when the control point had only set a generic property change listener (as in the test case). I've tested this version of the code to make sure that it's OK in both cases.
Find all posts by this user
19-04-2012, 04:06 PM
Post: #5
RE: Property change notification doesn't work for Java
Thanks, that seems better.

I've committed this locally now. The changes will hopefully make it onto github this evening.
Find all posts by this user
20-04-2012, 02:27 PM
Post: #6
RE: Property change notification doesn't work for Java
(19-04-2012 04:06 PM)simonc Wrote:  Thanks, that seems better.

I've committed this locally now. The changes will hopefully make it onto github this evening.

Thanks very much for the quick fix!
Find all posts by this user


Forum Jump: