diff options
author | BJ Hargrave | 2011-06-01 19:49:30 +0000 |
---|---|---|
committer | BJ Hargrave | 2011-06-01 19:49:30 +0000 |
commit | da6a6fa50ecdd710127ecfe2f1e6ec8d524b4687 (patch) | |
tree | ce728b57b15f76f132e84e37979de8b6d98c9ee4 /bundles/org.eclipse.equinox.wireadmin | |
parent | f7496eea4ecd7a5fcfcc014e57be0d796c88e975 (diff) | |
download | rt.equinox.bundles-da6a6fa50ecdd710127ecfe2f1e6ec8d524b4687.tar.gz rt.equinox.bundles-da6a6fa50ecdd710127ecfe2f1e6ec8d524b4687.tar.xz rt.equinox.bundles-da6a6fa50ecdd710127ecfe2f1e6ec8d524b4687.zip |
The fix "primes the pump" by setting the first value passed to the wire as
the previous value even if that value is not actually passed to the consumer.
The fix also makes the proper distinction between lastValue, which is the
last value provided by the Producer, and previousValue, which is the previous
value supplied to the Consumer. When wire flow control is in effect, these 2
values are often different since some values are not actually supplied to the
consumer.
Finally the fix adds finally blocks to properly set lastValue and/or
previousValue due to early return from the method.
Diffstat (limited to 'bundles/org.eclipse.equinox.wireadmin')
-rw-r--r-- | bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/internal/wireadmin/WireImpl.java | 81 |
1 files changed, 45 insertions, 36 deletions
diff --git a/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/internal/wireadmin/WireImpl.java b/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/internal/wireadmin/WireImpl.java index 07a45f037..cb80b3ccd 100644 --- a/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/internal/wireadmin/WireImpl.java +++ b/bundles/org.eclipse.equinox.wireadmin/src/org/eclipse/equinox/internal/wireadmin/WireImpl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 1997, 2008 by ProSyst Software GmbH + * Copyright (c) 1997, 2011 by ProSyst Software GmbH and others. * http://www.prosyst.com * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -8,6 +8,7 @@ * * Contributors: * ProSyst Software GmbH - initial API and implementation + * IBM Corporation - bug fix 347974 *******************************************************************************/ package org.eclipse.equinox.internal.wireadmin; @@ -38,8 +39,10 @@ class WireImpl implements Wire, ServiceListener { private Class[] flavors; - /** Holds the last value passed through this <code>Wire</code>. */ + /** Holds the last value passed to this <code>Wire</code> by the <code>Producer</code>. */ private Object lastValue; + /** Holds the previous value passed through this <code>Wire</code> to the <code>Consumer</code>. */ + private Object previousValue; private Vector envelopes; @@ -51,8 +54,8 @@ class WireImpl implements Wire, ServiceListener { private Filter filter = null; - /** Holds the time of last <code>Consumer</code> update in milliseconds */ - private long lastUpdateTime = -1; + /** Holds the time of previous <code>Consumer</code> update in milliseconds */ + private long previousUpdateTime = -1; /** Holds the available wire values (filter attributes) */ private Hashtable wireValues; @@ -150,46 +153,51 @@ class WireImpl implements Wire, ServiceListener { } } - if (filter != null) { - - wireValues.put(WireConstants.WIREVALUE_CURRENT, value); - - // #3329 - if (lastValue != null) { - wireValues.put(WireConstants.WIREVALUE_PREVIOUS, lastValue); - wireValues.put(WireConstants.WIREVALUE_ELAPSED, new Long(System.currentTimeMillis() - lastUpdateTime)); - } + try { + if (filter != null) { + wireValues.put(WireConstants.WIREVALUE_CURRENT, value); + + // #3329 + if (previousValue != null) { + wireValues.put(WireConstants.WIREVALUE_PREVIOUS, previousValue); + wireValues.put(WireConstants.WIREVALUE_ELAPSED, new Long(System.currentTimeMillis() - previousUpdateTime)); + } else { + previousValue = value; // this is to "prime the pump" + } - if (Number.class.isInstance(value) && Number.class.isInstance(lastValue)) { - double val = ((Number) value).doubleValue(); - double lastVal = ((Number) lastValue).doubleValue(); + if (Number.class.isInstance(value) && Number.class.isInstance(previousValue)) { + double val = ((Number) value).doubleValue(); + double prevVal = ((Number) previousValue).doubleValue(); - wireValues.put(WireConstants.WIREVALUE_DELTA_ABSOLUTE, new Double(Math.abs(val - lastVal))); - // #3328 - wireValues.put(WireConstants.WIREVALUE_DELTA_RELATIVE, new Double(Math.abs(1 - lastVal / val))); - } else { - wireValues.remove(WireConstants.WIREVALUE_DELTA_ABSOLUTE); - wireValues.remove(WireConstants.WIREVALUE_DELTA_RELATIVE); - } + wireValues.put(WireConstants.WIREVALUE_DELTA_ABSOLUTE, new Double(Math.abs(val - prevVal))); + // #3328 + wireValues.put(WireConstants.WIREVALUE_DELTA_RELATIVE, new Double(Math.abs(1 - prevVal / val))); + } else { + wireValues.remove(WireConstants.WIREVALUE_DELTA_ABSOLUTE); + wireValues.remove(WireConstants.WIREVALUE_DELTA_RELATIVE); + } - if (!filter.match(wireValues)) { - if (Activator.LOG_DEBUG) { - Activator.log.debug(0, 10012, filter + " / " + value, null, false); + if (!filter.match(wireValues)) { + if (Activator.LOG_DEBUG) { + Activator.log.debug(0, 10012, filter + " / " + value, null, false); + } + return; } - return; } - } - if (consumer != null) { - try { - consumer.updated(this, value); - } catch (Throwable t) { - parent.notifyListeners(this, WireAdminEvent.CONSUMER_EXCEPTION, t); - return; + if (consumer != null) { + try { + consumer.updated(this, value); + } catch (Throwable t) { + parent.notifyListeners(this, WireAdminEvent.CONSUMER_EXCEPTION, t); + } finally { + previousValue = value; + previousUpdateTime = System.currentTimeMillis(); + parent.notifyListeners(this, WireAdminEvent.WIRE_TRACE, null); + } } + } finally { lastValue = value; - lastUpdateTime = System.currentTimeMillis(); - parent.notifyListeners(this, WireAdminEvent.WIRE_TRACE, null); } } @@ -503,6 +511,7 @@ class WireImpl implements Wire, ServiceListener { consumer = null; lastValue = null; + previousValue = null; parent = null; filter = null; wireValues = null; |