boolean matchMatchEvent )
{
/* Save the pre-event state. Update the post-event state after
* applying the filter.
*/
ServiceItem oldItem;
ServiceItem oldFilteredItem;
synchronized(itemReg) {
oldItem = itemReg.item;
oldFilteredItem = itemReg.filteredItem;
if(itemReg.isDiscarded()) {
itemReg.item = newItem;//capture changes for discard
itemReg.filteredItem = null;//so filter will be retried
return;
}//endif
itemReg.addProxy(proxy);
}//end sync(itemReg)
/* For an explanation of the logic of the following if-else-block,
* refer to the method description above.
*/
boolean attrsChanged = false;
boolean versionChanged = false;
if( matchMatchEvent || sameVersion(newItem,oldItem) ) {
/* Same version, determine if the attributes have changed.
* But first, replace the new service proxy with the old
* service proxy so the client always uses the old proxy
* (at least, until the version is changed).
*/
newItem.service = oldItem.service;
/* Now compare attributes */
attrsChanged = !LookupAttributes.equal(newItem.attributeSets,
oldItem.attributeSets);
if(!attrsChanged) return;//no change, no need to filter
} else {//(!matchMatchEvent && !same version) ==> re-registration
versionChanged = true;
}//endif
/* Now apply the filter, and send events if appropriate */
ServiceItem newFilteredItem = filterMaybeDiscard
(newItem, proxy, true);
if(newFilteredItem != null) {
/* Passed the filter, okay to send event(s). */
if(attrsChanged) changeServiceNotify(newFilteredItem,
oldFilteredItem);