|
Lines 12-18
Link Here
|
| 12 |
**************************************************************************/ |
12 |
**************************************************************************/ |
| 13 |
package org.eclipse.emf.internal.cdo; |
13 |
package org.eclipse.emf.internal.cdo; |
| 14 |
|
14 |
|
| 15 |
import org.eclipse.emf.cdo.CDOChangeSubscriptionPolicy; |
15 |
import org.eclipse.emf.cdo.CDOAdapterPolicy; |
| 16 |
import org.eclipse.emf.cdo.CDOFeatureAnalyzer; |
16 |
import org.eclipse.emf.cdo.CDOFeatureAnalyzer; |
| 17 |
import org.eclipse.emf.cdo.CDONotification; |
17 |
import org.eclipse.emf.cdo.CDONotification; |
| 18 |
import org.eclipse.emf.cdo.CDOObject; |
18 |
import org.eclipse.emf.cdo.CDOObject; |
|
Lines 64-69
Link Here
|
| 64 |
import org.eclipse.net4j.util.WrappedException; |
64 |
import org.eclipse.net4j.util.WrappedException; |
| 65 |
import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump; |
65 |
import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump; |
| 66 |
import org.eclipse.net4j.util.collection.CloseableIterator; |
66 |
import org.eclipse.net4j.util.collection.CloseableIterator; |
|
|
67 |
import org.eclipse.net4j.util.collection.HashBag; |
| 67 |
import org.eclipse.net4j.util.concurrent.RWLockManager; |
68 |
import org.eclipse.net4j.util.concurrent.RWLockManager; |
| 68 |
import org.eclipse.net4j.util.om.trace.ContextTracer; |
69 |
import org.eclipse.net4j.util.om.trace.ContextTracer; |
| 69 |
import org.eclipse.net4j.util.ref.ReferenceType; |
70 |
import org.eclipse.net4j.util.ref.ReferenceType; |
|
Lines 124-129
Link Here
|
| 124 |
|
125 |
|
| 125 |
private CDOResourceImpl rootResource; |
126 |
private CDOResourceImpl rootResource; |
| 126 |
|
127 |
|
|
|
128 |
private ChangeSubscriptionManager changeSubscriptionManager = createChangeSubscriptionManager(); |
| 129 |
|
| 130 |
private ViewAdapterManager adapterPolicyManager = createAdapterManager(); |
| 131 |
|
| 132 |
private CDOAdapterPolicy changeSubscriptionPolicy = CDOAdapterPolicy.NONE; |
| 133 |
|
| 134 |
private CDOAdapterPolicy adapterReferencePolicy = CDOAdapterPolicy.NONE; |
| 135 |
|
| 127 |
@ExcludeFromDump |
136 |
@ExcludeFromDump |
| 128 |
private transient CDOID lastLookupID; |
137 |
private transient CDOID lastLookupID; |
| 129 |
|
138 |
|
|
Lines 133-148
Link Here
|
| 133 |
/** |
142 |
/** |
| 134 |
* @since 2.0 |
143 |
* @since 2.0 |
| 135 |
*/ |
144 |
*/ |
| 136 |
private ChangeSubscriptionManager changeSubscriptionManager = new ChangeSubscriptionManager(); |
|
|
| 137 |
|
| 138 |
/** |
| 139 |
* @since 2.0 |
| 140 |
*/ |
| 141 |
private CDOChangeSubscriptionPolicy changeSubscriptionPolicy = CDOChangeSubscriptionPolicy.NONE; |
| 142 |
|
| 143 |
/** |
| 144 |
* @since 2.0 |
| 145 |
*/ |
| 146 |
public CDOViewImpl(InternalCDOSession session, int viewID) |
145 |
public CDOViewImpl(InternalCDOSession session, int viewID) |
| 147 |
{ |
146 |
{ |
| 148 |
this.session = session; |
147 |
this.session = session; |
|
Lines 339-345
Link Here
|
| 339 |
/** |
338 |
/** |
| 340 |
* @since 2.0 |
339 |
* @since 2.0 |
| 341 |
*/ |
340 |
*/ |
| 342 |
public CDOChangeSubscriptionPolicy getChangeSubscriptionPolicy() |
341 |
public CDOAdapterPolicy getChangeSubscriptionPolicy() |
| 343 |
{ |
342 |
{ |
| 344 |
return changeSubscriptionPolicy; |
343 |
return changeSubscriptionPolicy; |
| 345 |
} |
344 |
} |
|
Lines 347-357
Link Here
|
| 347 |
/** |
346 |
/** |
| 348 |
* @since 2.0 |
347 |
* @since 2.0 |
| 349 |
*/ |
348 |
*/ |
| 350 |
public void setChangeSubscriptionPolicy(CDOChangeSubscriptionPolicy subscriptionPolicy) |
349 |
public void setChangeSubscriptionPolicy(CDOAdapterPolicy subscriptionPolicy) |
| 351 |
{ |
350 |
{ |
| 352 |
if (subscriptionPolicy == null) |
351 |
if (subscriptionPolicy == null) |
| 353 |
{ |
352 |
{ |
| 354 |
subscriptionPolicy = CDOChangeSubscriptionPolicy.NONE; |
353 |
subscriptionPolicy = CDOAdapterPolicy.NONE; |
| 355 |
} |
354 |
} |
| 356 |
|
355 |
|
| 357 |
if (changeSubscriptionPolicy != subscriptionPolicy) |
356 |
if (changeSubscriptionPolicy != subscriptionPolicy) |
|
Lines 364-369
Link Here
|
| 364 |
/** |
363 |
/** |
| 365 |
* @since 2.0 |
364 |
* @since 2.0 |
| 366 |
*/ |
365 |
*/ |
|
|
366 |
public CDOAdapterPolicy getStrongReferencePolicy() |
| 367 |
{ |
| 368 |
return adapterReferencePolicy; |
| 369 |
} |
| 370 |
|
| 371 |
/** |
| 372 |
* @since 2.0 |
| 373 |
*/ |
| 374 |
public void setStrongReferencePolicy(CDOAdapterPolicy adapterPolicy) |
| 375 |
{ |
| 376 |
if (adapterPolicy == null) |
| 377 |
{ |
| 378 |
adapterPolicy = CDOAdapterPolicy.NONE; |
| 379 |
} |
| 380 |
|
| 381 |
if (adapterReferencePolicy != adapterPolicy) |
| 382 |
{ |
| 383 |
adapterReferencePolicy = adapterPolicy; |
| 384 |
adapterPolicyManager.reset(); |
| 385 |
} |
| 386 |
} |
| 387 |
|
| 388 |
/** |
| 389 |
* @since 2.0 |
| 390 |
*/ |
| 367 |
public CDORevisionPrefetchingPolicy getRevisionPrefetchingPolicy() |
391 |
public CDORevisionPrefetchingPolicy getRevisionPrefetchingPolicy() |
| 368 |
{ |
392 |
{ |
| 369 |
return revisionPrefetchingPolicy; |
393 |
return revisionPrefetchingPolicy; |
|
Lines 1213-1219
Link Here
|
| 1213 |
*/ |
1237 |
*/ |
| 1214 |
public void handleChangeSubscription(Collection<CDORevisionDelta> deltas, Collection<CDOID> detachedObjects) |
1238 |
public void handleChangeSubscription(Collection<CDORevisionDelta> deltas, Collection<CDOID> detachedObjects) |
| 1215 |
{ |
1239 |
{ |
| 1216 |
if (getChangeSubscriptionPolicy() != CDOChangeSubscriptionPolicy.NONE) |
1240 |
if (getChangeSubscriptionPolicy() != CDOAdapterPolicy.NONE) |
| 1217 |
{ |
1241 |
{ |
| 1218 |
if (deltas != null) |
1242 |
if (deltas != null) |
| 1219 |
{ |
1243 |
{ |
|
Lines 1253-1258
Link Here
|
| 1253 |
/** |
1277 |
/** |
| 1254 |
* @since 2.0 |
1278 |
* @since 2.0 |
| 1255 |
*/ |
1279 |
*/ |
|
|
1280 |
protected ChangeSubscriptionManager createChangeSubscriptionManager() |
| 1281 |
{ |
| 1282 |
return new ChangeSubscriptionManager(); |
| 1283 |
} |
| 1284 |
|
| 1285 |
/** |
| 1286 |
* @since 2.0 |
| 1287 |
*/ |
| 1288 |
public ViewAdapterManager getAdapterManager() |
| 1289 |
{ |
| 1290 |
return adapterPolicyManager; |
| 1291 |
} |
| 1292 |
|
| 1293 |
/** |
| 1294 |
* @since 2.0 |
| 1295 |
*/ |
| 1296 |
protected ViewAdapterManager createAdapterManager() |
| 1297 |
{ |
| 1298 |
return new ViewAdapterManager(); |
| 1299 |
} |
| 1300 |
|
| 1301 |
/** |
| 1302 |
* @since 2.0 |
| 1303 |
*/ |
| 1304 |
public void handleAddAdapter(InternalCDOObject eObject, Adapter adapter) |
| 1305 |
{ |
| 1306 |
if (!FSMUtil.isNew(eObject)) |
| 1307 |
{ |
| 1308 |
subscribe(eObject, adapter); |
| 1309 |
} |
| 1310 |
|
| 1311 |
adapterPolicyManager.attachAdapter(eObject, adapter); |
| 1312 |
} |
| 1313 |
|
| 1314 |
/** |
| 1315 |
* @since 2.0 |
| 1316 |
*/ |
| 1317 |
public void handleRemoveAdapter(InternalCDOObject eObject, Adapter adapter) |
| 1318 |
{ |
| 1319 |
if (!FSMUtil.isNew(eObject)) |
| 1320 |
{ |
| 1321 |
unsubscribe(eObject, adapter); |
| 1322 |
} |
| 1323 |
|
| 1324 |
adapterPolicyManager.detachAdapter(eObject, adapter); |
| 1325 |
} |
| 1326 |
|
| 1327 |
/** |
| 1328 |
* @since 2.0 |
| 1329 |
*/ |
| 1256 |
public void subscribe(EObject eObject, Adapter adapter) |
1330 |
public void subscribe(EObject eObject, Adapter adapter) |
| 1257 |
{ |
1331 |
{ |
| 1258 |
changeSubscriptionManager.subscribe(eObject, adapter); |
1332 |
changeSubscriptionManager.subscribe(eObject, adapter); |
|
Lines 1492-1497
Link Here
|
| 1492 |
* @author Simon McDuff |
1566 |
* @author Simon McDuff |
| 1493 |
* @since 2.0 |
1567 |
* @since 2.0 |
| 1494 |
*/ |
1568 |
*/ |
|
|
1569 |
protected class ViewAdapterManager |
| 1570 |
{ |
| 1571 |
protected Set<CDOObject> objects = new HashBag<CDOObject>(); |
| 1572 |
|
| 1573 |
public ViewAdapterManager() |
| 1574 |
{ |
| 1575 |
} |
| 1576 |
|
| 1577 |
protected synchronized void attachObject(CDOObject object) |
| 1578 |
{ |
| 1579 |
int count = 0; |
| 1580 |
for (Adapter adapter : object.eAdapters()) |
| 1581 |
{ |
| 1582 |
if (adapterReferencePolicy.isValid(object, adapter)) |
| 1583 |
{ |
| 1584 |
count++; |
| 1585 |
} |
| 1586 |
} |
| 1587 |
|
| 1588 |
for (int i = 0; i < count; i++) |
| 1589 |
{ |
| 1590 |
objects.add(object); |
| 1591 |
} |
| 1592 |
} |
| 1593 |
|
| 1594 |
protected synchronized void detachObject(CDOObject object) |
| 1595 |
{ |
| 1596 |
while (objects.remove(object)) |
| 1597 |
{ |
| 1598 |
// Do nothing |
| 1599 |
} |
| 1600 |
} |
| 1601 |
|
| 1602 |
protected synchronized void attachAdapter(CDOObject object, Adapter adapter) |
| 1603 |
{ |
| 1604 |
if (getStrongReferencePolicy().isValid(object, adapter)) |
| 1605 |
{ |
| 1606 |
objects.add(object); |
| 1607 |
} |
| 1608 |
} |
| 1609 |
|
| 1610 |
protected synchronized void detachAdapter(CDOObject object, Adapter adapter) |
| 1611 |
{ |
| 1612 |
if (getStrongReferencePolicy().isValid(object, adapter)) |
| 1613 |
{ |
| 1614 |
objects.add(object); |
| 1615 |
} |
| 1616 |
} |
| 1617 |
|
| 1618 |
public synchronized void reset() |
| 1619 |
{ |
| 1620 |
// Keep the object in memory |
| 1621 |
Set<CDOObject> oldObject = objects; |
| 1622 |
objects = new HashBag<CDOObject>(); |
| 1623 |
if (getStrongReferencePolicy() != CDOAdapterPolicy.NONE) |
| 1624 |
{ |
| 1625 |
InternalCDOObject objects[] = getObjectsArray(); |
| 1626 |
for (int i = 0; i < objects.length; i++) |
| 1627 |
{ |
| 1628 |
InternalCDOObject object = objects[i]; |
| 1629 |
attachObject(object); |
| 1630 |
} |
| 1631 |
} |
| 1632 |
|
| 1633 |
oldObject.clear(); |
| 1634 |
} |
| 1635 |
}; |
| 1636 |
|
| 1637 |
/** |
| 1638 |
* @author Simon McDuff |
| 1639 |
* @since 2.0 |
| 1640 |
*/ |
| 1495 |
protected class ChangeSubscriptionManager |
1641 |
protected class ChangeSubscriptionManager |
| 1496 |
{ |
1642 |
{ |
| 1497 |
private Map<CDOID, SubscribeEntry> subscriptions = new HashMap<CDOID, SubscribeEntry>() |
1643 |
private Map<CDOID, SubscribeEntry> subscriptions = new HashMap<CDOID, SubscribeEntry>() |
|
Lines 1518-1524
Link Here
|
| 1518 |
{ |
1664 |
{ |
| 1519 |
subscriptions.clear(); |
1665 |
subscriptions.clear(); |
| 1520 |
List<CDOID> cdoIDs = new ArrayList<CDOID>(); |
1666 |
List<CDOID> cdoIDs = new ArrayList<CDOID>(); |
| 1521 |
if (changeSubscriptionPolicy != CDOChangeSubscriptionPolicy.NONE) |
1667 |
if (changeSubscriptionPolicy != CDOAdapterPolicy.NONE) |
| 1522 |
{ |
1668 |
{ |
| 1523 |
for (InternalCDOObject cdoObject : getObjectsArray()) |
1669 |
for (InternalCDOObject cdoObject : getObjectsArray()) |
| 1524 |
{ |
1670 |
{ |
|
Lines 1605-1611
Link Here
|
| 1605 |
{ |
1751 |
{ |
| 1606 |
for (Adapter adapter : object.eAdapters()) |
1752 |
for (Adapter adapter : object.eAdapters()) |
| 1607 |
{ |
1753 |
{ |
| 1608 |
if (changeSubscriptionPolicy.shouldSubscribe(object, adapter)) |
1754 |
if (changeSubscriptionPolicy.isValid(object, adapter)) |
| 1609 |
{ |
1755 |
{ |
| 1610 |
count++; |
1756 |
count++; |
| 1611 |
} |
1757 |
} |
|
Lines 1620-1626
Link Here
|
| 1620 |
{ |
1766 |
{ |
| 1621 |
synchronized (subscriptions) |
1767 |
synchronized (subscriptions) |
| 1622 |
{ |
1768 |
{ |
| 1623 |
if (getChangeSubscriptionPolicy().shouldSubscribe(eObject, adapter)) |
1769 |
if (getChangeSubscriptionPolicy().isValid(eObject, adapter)) |
| 1624 |
{ |
1770 |
{ |
| 1625 |
InternalCDOObject internalCDOObject = FSMUtil.adapt(eObject, CDOViewImpl.this); |
1771 |
InternalCDOObject internalCDOObject = FSMUtil.adapt(eObject, CDOViewImpl.this); |
| 1626 |
if (internalCDOObject.cdoView() != CDOViewImpl.this) |
1772 |
if (internalCDOObject.cdoView() != CDOViewImpl.this) |
|
Lines 1648-1654
Link Here
|
| 1648 |
} |
1794 |
} |
| 1649 |
|
1795 |
|
| 1650 |
// Notification need to be enable to send correct value to the server |
1796 |
// Notification need to be enable to send correct value to the server |
| 1651 |
if (getChangeSubscriptionPolicy() != CDOChangeSubscriptionPolicy.NONE) |
1797 |
if (getChangeSubscriptionPolicy() != CDOAdapterPolicy.NONE) |
| 1652 |
{ |
1798 |
{ |
| 1653 |
request(Collections.singletonList(id), false, true); |
1799 |
request(Collections.singletonList(id), false, true); |
| 1654 |
} |
1800 |
} |
|
Lines 1666-1672
Link Here
|
| 1666 |
subscriptions.remove(id); |
1812 |
subscriptions.remove(id); |
| 1667 |
|
1813 |
|
| 1668 |
// Notification need to be enable to send correct value to the server |
1814 |
// Notification need to be enable to send correct value to the server |
| 1669 |
if (getChangeSubscriptionPolicy() != CDOChangeSubscriptionPolicy.NONE) |
1815 |
if (getChangeSubscriptionPolicy() != CDOAdapterPolicy.NONE) |
| 1670 |
{ |
1816 |
{ |
| 1671 |
request(Collections.singletonList(id), false, false); |
1817 |
request(Collections.singletonList(id), false, false); |
| 1672 |
} |
1818 |
} |