[571812] ReconnectingCDOSessionImpl does not receive lock updates for open views after reconnection

https://bugs.eclipse.org/bugs/show_bug.cgi?id=571812
diff --git a/plugins/org.eclipse.emf.cdo.net4j/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.net4j/META-INF/MANIFEST.MF
index b8b9abf..501b638 100644
--- a/plugins/org.eclipse.emf.cdo.net4j/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.cdo.net4j/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
 Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.eclipse.emf.cdo.net4j; singleton:=true
-Bundle-Version: 4.4.1.qualifier
+Bundle-Version: 4.4.2.qualifier
 Bundle-ClassPath: .
 Bundle-Vendor: %providerName
 Bundle-Localization: plugin
@@ -10,11 +10,11 @@
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Require-Bundle: org.eclipse.emf.cdo;bundle-version="[4.0.0,5.0.0)";visibility:=reexport,
  org.eclipse.net4j;bundle-version="[4.0.0,5.0.0)";visibility:=reexport
-Export-Package: org.eclipse.emf.cdo.internal.net4j;version="4.4.1";x-friends:="org.eclipse.emf.cdo.tests,org.eclipse.emf.cdo.ui,org.eclipse.emf.cdo.examples",
- org.eclipse.emf.cdo.internal.net4j.bundle;version="4.4.1";x-friends:="org.eclipse.emf.cdo.tests",
- org.eclipse.emf.cdo.internal.net4j.messages;version="4.4.1";x-internal:=true,
- org.eclipse.emf.cdo.internal.net4j.protocol;version="4.4.1";x-friends:="org.eclipse.emf.cdo.tests,org.eclipse.emf.cdo.ui,org.eclipse.emf.cdo.examples",
- org.eclipse.emf.cdo.internal.net4j.testrecorder;version="4.4.1";x-internal:=true,
- org.eclipse.emf.cdo.net4j;version="4.4.1"
+Export-Package: org.eclipse.emf.cdo.internal.net4j;version="4.4.2";x-friends:="org.eclipse.emf.cdo.tests,org.eclipse.emf.cdo.ui,org.eclipse.emf.cdo.examples",
+ org.eclipse.emf.cdo.internal.net4j.bundle;version="4.4.2";x-friends:="org.eclipse.emf.cdo.tests",
+ org.eclipse.emf.cdo.internal.net4j.messages;version="4.4.2";x-internal:=true,
+ org.eclipse.emf.cdo.internal.net4j.protocol;version="4.4.2";x-friends:="org.eclipse.emf.cdo.tests,org.eclipse.emf.cdo.ui,org.eclipse.emf.cdo.examples",
+ org.eclipse.emf.cdo.internal.net4j.testrecorder;version="4.4.2";x-internal:=true,
+ org.eclipse.emf.cdo.net4j;version="4.4.2"
 Bundle-ActivationPolicy: lazy
 Automatic-Module-Name: org.eclipse.emf.cdo.net4j
diff --git a/plugins/org.eclipse.emf.cdo.net4j/pom.xml b/plugins/org.eclipse.emf.cdo.net4j/pom.xml
index 6dfd049..3bc222a 100644
--- a/plugins/org.eclipse.emf.cdo.net4j/pom.xml
+++ b/plugins/org.eclipse.emf.cdo.net4j/pom.xml
@@ -25,7 +25,7 @@
 
   <groupId>org.eclipse.emf.cdo</groupId>
   <artifactId>org.eclipse.emf.cdo.net4j</artifactId>
-  <version>4.4.1-SNAPSHOT</version>
+  <version>4.4.2-SNAPSHOT</version>
   <packaging>eclipse-plugin</packaging>
 
 </project>
diff --git a/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/internal/net4j/RecoveringCDOSessionImpl.java b/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/internal/net4j/RecoveringCDOSessionImpl.java
index ccb0999..1a07c23 100644
--- a/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/internal/net4j/RecoveringCDOSessionImpl.java
+++ b/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/internal/net4j/RecoveringCDOSessionImpl.java
@@ -21,6 +21,8 @@
 import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionManager;
 import org.eclipse.emf.cdo.transaction.CDOTransaction;
 
+import org.eclipse.emf.internal.cdo.view.CDOViewImpl;
+
 import org.eclipse.net4j.Net4jUtil;
 import org.eclipse.net4j.connector.IConnector;
 import org.eclipse.net4j.signal.heartbeat.HeartBeatProtocol;
@@ -288,23 +290,47 @@
    */
   private static final class OpenViewRunnable implements AfterRecoveryRunnable
   {
-    private int viewID;
+    private final int viewID;
 
-    private CDOBranchPoint branchPoint;
+    private final boolean transaction;
 
-    private boolean transaction;
+    private final String durableLockingID;
+
+    private final CDOBranchPoint branchPoint;
+
+    private final CDOViewImpl.OptionsImpl options;
 
     public OpenViewRunnable(InternalCDOView view)
     {
       viewID = view.getViewID();
-      branchPoint = CDOBranchUtil.copyBranchPoint(view);
       transaction = view instanceof CDOTransaction;
+
+      durableLockingID = view.getDurableLockingID();
+      if (durableLockingID == null)
+      {
+        branchPoint = CDOBranchUtil.copyBranchPoint(view);
+      }
+      else
+      {
+        branchPoint = null;
+      }
+
+      options = (CDOViewImpl.OptionsImpl)view.options();
     }
 
     @Override
     public void run(CDOSessionProtocol sessionProtocol)
     {
-      sessionProtocol.openView(viewID, !transaction, branchPoint);
+      if (durableLockingID != null)
+      {
+        sessionProtocol.openView(viewID, !transaction, durableLockingID);
+      }
+      else
+      {
+        sessionProtocol.openView(viewID, !transaction, branchPoint);
+      }
+
+      options.recoverView();
     }
   }
 
diff --git a/plugins/org.eclipse.emf.cdo.server/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.server/META-INF/MANIFEST.MF
index a96fdca..34052a8 100644
--- a/plugins/org.eclipse.emf.cdo.server/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.cdo.server/META-INF/MANIFEST.MF
@@ -1,7 +1,7 @@
 Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-SymbolicName: org.eclipse.emf.cdo.server;singleton:=true
-Bundle-Version: 4.12.0.qualifier
+Bundle-Version: 4.12.1.qualifier
 Bundle-Name: %pluginName
 Bundle-Vendor: %providerName
 Bundle-Localization: plugin
@@ -10,17 +10,17 @@
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Bundle-ClassPath: .
 Require-Bundle: org.eclipse.emf.cdo;bundle-version="[4.0.0,5.0.0)";visibility:=reexport
-Export-Package: org.eclipse.emf.cdo.internal.server;version="4.12.0";
+Export-Package: org.eclipse.emf.cdo.internal.server;version="4.12.1";
   x-friends:="org.eclipse.emf.cdo.server.db,
    org.eclipse.emf.cdo.server.net4j,
    org.eclipse.emf.cdo.tests,
    org.eclipse.emf.cdo.workspace,
    org.eclipse.emf.cdo.server.embedded",
- org.eclipse.emf.cdo.internal.server.bundle;version="4.12.0";x-internal:=true,
- org.eclipse.emf.cdo.internal.server.mem;version="4.12.0";x-friends:="org.eclipse.emf.cdo.tests",
- org.eclipse.emf.cdo.internal.server.messages;version="4.12.0";x-internal:=true,
- org.eclipse.emf.cdo.internal.server.syncing;version="4.12.0";x-friends:="org.eclipse.emf.cdo.tests",
- org.eclipse.emf.cdo.server;version="4.12.0",
- org.eclipse.emf.cdo.server.mem;version="4.12.0",
- org.eclipse.emf.cdo.spi.server;version="4.12.0"
+ org.eclipse.emf.cdo.internal.server.bundle;version="4.12.1";x-internal:=true,
+ org.eclipse.emf.cdo.internal.server.mem;version="4.12.1";x-friends:="org.eclipse.emf.cdo.tests",
+ org.eclipse.emf.cdo.internal.server.messages;version="4.12.1";x-internal:=true,
+ org.eclipse.emf.cdo.internal.server.syncing;version="4.12.1";x-friends:="org.eclipse.emf.cdo.tests",
+ org.eclipse.emf.cdo.server;version="4.12.1",
+ org.eclipse.emf.cdo.server.mem;version="4.12.1",
+ org.eclipse.emf.cdo.spi.server;version="4.12.1"
 Automatic-Module-Name: org.eclipse.emf.cdo.server
diff --git a/plugins/org.eclipse.emf.cdo.server/pom.xml b/plugins/org.eclipse.emf.cdo.server/pom.xml
index 754bcdb..16e656b 100644
--- a/plugins/org.eclipse.emf.cdo.server/pom.xml
+++ b/plugins/org.eclipse.emf.cdo.server/pom.xml
@@ -25,7 +25,7 @@
 
   <groupId>org.eclipse.emf.cdo</groupId>
   <artifactId>org.eclipse.emf.cdo.server</artifactId>
-  <version>4.12.0-SNAPSHOT</version>
+  <version>4.12.1-SNAPSHOT</version>
   <packaging>eclipse-plugin</packaging>
 
 </project>
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/View.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/View.java
index 486a332..717fb55 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/View.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/View.java
@@ -55,8 +55,10 @@
 
   private final int viewID;
 
-  private final int sessionID; // Needed here so we can compute the hashCode even after session becomes null due to
-  // deactivation!
+  /**
+   * Needed here so we can compute the hashCode even after session becomes null due to deactivation!
+   */
+  private final int sessionID;
 
   private CDOBranchPoint branchPoint;
 
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ReconnectingSessionTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ReconnectingSessionTest.java
index 9e416be..d9d5826 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ReconnectingSessionTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ReconnectingSessionTest.java
@@ -23,6 +23,7 @@
 import org.eclipse.emf.cdo.tests.config.impl.SessionConfig;
 import org.eclipse.emf.cdo.transaction.CDOTransaction;
 import org.eclipse.emf.cdo.view.CDOView;
+import org.eclipse.emf.cdo.view.CDOViewLocksChangedEvent;
 
 import org.eclipse.net4j.connector.IConnector;
 import org.eclipse.net4j.signal.RemoteException;
@@ -33,6 +34,9 @@
 import org.eclipse.net4j.util.event.IListener;
 import org.eclipse.net4j.util.io.IOUtil;
 import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.tests.TestListener;
+
+import org.eclipse.emf.spi.cdo.InternalCDOView;
 
 import java.util.concurrent.CountDownLatch;
 
@@ -105,6 +109,12 @@
         }
       });
 
+      CDOView viewWithLockNotifications = reconnectingSession.openView();
+      viewWithLockNotifications.options().setLockNotificationEnabled(true);
+
+      CDOResource resReconn = viewWithLockNotifications.getObject(resource1);
+      checkLockNotifications(resource1, resReconn);
+
       IConnector connector = (IConnector)reconnectingSession.options().getNet4jProtocol().getChannel().getMultiplexer();
       dumpEvents(connector);
 
@@ -132,14 +142,41 @@
       resource1.getContents().add(getModel1Factory().createCategory());
       commitAndSync(transaction, view);
       assertEquals(3, resource2.getContents().size());
+
+      checkLockNotifications(resource1, resReconn);
     }
     finally
+
     {
       LifecycleUtil.deactivate(reconnectingSession);
       LifecycleUtil.deactivate(acceptor);
     }
   }
 
+  private void checkLockNotifications(CDOResource resource1, CDOResource resReconn) throws Exception
+  {
+    CDOView viewReconn = resReconn.cdoView();
+    assertEquals(true, viewReconn.options().isLockNotificationEnabled());
+    assertNull(resReconn.cdoLockState().getWriteLockOwner());
+
+    TestListener listener = new TestListener(viewReconn);
+
+    resource1.cdoWriteLock().lock(1000);
+
+    listener.assertEvent(CDOViewLocksChangedEvent.class, e -> {
+      assertNotNull(resReconn.cdoLockState().getWriteLockOwner());
+      assertEquals(((InternalCDOView)resource1.cdoView()).getLockOwner(), resReconn.cdoLockState().getWriteLockOwner());
+    });
+
+    listener.clearEvents();
+
+    resource1.cdoWriteLock().unlock();
+
+    listener.assertEvent(CDOViewLocksChangedEvent.class, e -> {
+      assertNull(resReconn.cdoLockState().getWriteLockOwner());
+    });
+  }
+
   public void testReconnectTwice() throws Exception
   {
     disableConsole();
diff --git a/plugins/org.eclipse.emf.cdo/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo/META-INF/MANIFEST.MF
index e6c2af4..1040dbb 100644
--- a/plugins/org.eclipse.emf.cdo/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.cdo/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
 Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.eclipse.emf.cdo; singleton:=true
-Bundle-Version: 4.13.0.qualifier
+Bundle-Version: 4.13.1.qualifier
 Bundle-ClassPath: .
 Bundle-Vendor: %providerName
 Bundle-Localization: plugin
@@ -10,28 +10,28 @@
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Require-Bundle: org.eclipse.core.expressions;bundle-version="[3.4.0,4.0.0)";resolution:=optional,
  org.eclipse.emf.cdo.common;bundle-version="[4.0.0,5.0.0)";visibility:=reexport
-Export-Package: org.eclipse.emf.cdo;version="4.13.0",
- org.eclipse.emf.cdo.eresource;version="4.13.0",
- org.eclipse.emf.cdo.eresource.impl;version="4.13.0",
- org.eclipse.emf.cdo.eresource.util;version="4.13.0",
- org.eclipse.emf.cdo.eresource.validation;version="4.13.0",
- org.eclipse.emf.cdo.etypes;version="4.13.0",
- org.eclipse.emf.cdo.etypes.impl;version="4.13.0",
- org.eclipse.emf.cdo.etypes.util;version="4.13.0",
- org.eclipse.emf.cdo.session;version="4.13.0",
- org.eclipse.emf.cdo.session.remote;version="4.13.0",
- org.eclipse.emf.cdo.transaction;version="4.13.0",
- org.eclipse.emf.cdo.util;version="4.13.0",
- org.eclipse.emf.cdo.view;version="4.13.0",
- org.eclipse.emf.internal.cdo;version="4.13.0",
- org.eclipse.emf.internal.cdo.analyzer;version="4.13.0";
+Export-Package: org.eclipse.emf.cdo;version="4.13.1",
+ org.eclipse.emf.cdo.eresource;version="4.13.1",
+ org.eclipse.emf.cdo.eresource.impl;version="4.13.1",
+ org.eclipse.emf.cdo.eresource.util;version="4.13.1",
+ org.eclipse.emf.cdo.eresource.validation;version="4.13.1",
+ org.eclipse.emf.cdo.etypes;version="4.13.1",
+ org.eclipse.emf.cdo.etypes.impl;version="4.13.1",
+ org.eclipse.emf.cdo.etypes.util;version="4.13.1",
+ org.eclipse.emf.cdo.session;version="4.13.1",
+ org.eclipse.emf.cdo.session.remote;version="4.13.1",
+ org.eclipse.emf.cdo.transaction;version="4.13.1",
+ org.eclipse.emf.cdo.util;version="4.13.1",
+ org.eclipse.emf.cdo.view;version="4.13.1",
+ org.eclipse.emf.internal.cdo;version="4.13.1",
+ org.eclipse.emf.internal.cdo.analyzer;version="4.13.1";
   x-friends:="org.eclipse.emf.cdo.net4j,
    org.eclipse.emf.cdo.server,
    org.eclipse.emf.cdo.tests,
    org.eclipse.emf.cdo.ui",
- org.eclipse.emf.internal.cdo.bundle;version="4.13.0";x-friends:="org.eclipse.emf.cdo.ui",
- org.eclipse.emf.internal.cdo.messages;version="4.13.0";x-internal:=true,
- org.eclipse.emf.internal.cdo.object;version="4.13.0";
+ org.eclipse.emf.internal.cdo.bundle;version="4.13.1";x-friends:="org.eclipse.emf.cdo.ui",
+ org.eclipse.emf.internal.cdo.messages;version="4.13.1";x-internal:=true,
+ org.eclipse.emf.internal.cdo.object;version="4.13.1";
   x-friends:="org.eclipse.emf.cdo.net4j,
    org.eclipse.emf.cdo.server,
    org.eclipse.emf.cdo.tests,
@@ -40,12 +40,12 @@
    org.eclipse.emf.cdo.explorer,
    org.eclipse.emf.cdo.explorer.ui,
    org.eclipse.emf.cdo.edit",
- org.eclipse.emf.internal.cdo.query;version="4.13.0";
+ org.eclipse.emf.internal.cdo.query;version="4.13.1";
   x-friends:="org.eclipse.emf.cdo.net4j,
    org.eclipse.emf.cdo.server,
    org.eclipse.emf.cdo.tests,
    org.eclipse.emf.cdo.ui",
- org.eclipse.emf.internal.cdo.session;version="4.13.0";
+ org.eclipse.emf.internal.cdo.session;version="4.13.1";
   x-friends:="org.eclipse.emf.cdo.net4j,
    org.eclipse.emf.cdo.server,
    org.eclipse.emf.cdo.tests,
@@ -55,23 +55,23 @@
    org.eclipse.emf.cdo.security.ui,
    org.eclipse.emf.cdo.explorer,
    org.eclipse.emf.cdo.explorer.ui",
- org.eclipse.emf.internal.cdo.session.remote;version="4.13.0";
+ org.eclipse.emf.internal.cdo.session.remote;version="4.13.1";
   x-friends:="org.eclipse.emf.cdo.net4j,
    org.eclipse.emf.cdo.server,
    org.eclipse.emf.cdo.tests,
    org.eclipse.emf.cdo.ui",
- org.eclipse.emf.internal.cdo.transaction;version="4.13.0";
+ org.eclipse.emf.internal.cdo.transaction;version="4.13.1";
   x-friends:="org.eclipse.emf.cdo.net4j,
    org.eclipse.emf.cdo.server,
    org.eclipse.emf.cdo.tests,
    org.eclipse.emf.cdo.ui,
    org.eclipse.emf.cdo.explorer.ui",
- org.eclipse.emf.internal.cdo.util;version="4.13.0";
+ org.eclipse.emf.internal.cdo.util;version="4.13.1";
   x-friends:="org.eclipse.emf.cdo.net4j,
    org.eclipse.emf.cdo.server,
    org.eclipse.emf.cdo.tests,
    org.eclipse.emf.cdo.ui",
- org.eclipse.emf.internal.cdo.view;version="4.13.0";
+ org.eclipse.emf.internal.cdo.view;version="4.13.1";
   x-friends:="org.eclipse.emf.cdo.net4j,
    org.eclipse.emf.cdo.server,
    org.eclipse.emf.cdo.tests,
@@ -79,6 +79,6 @@
    org.eclipse.emf.cdo.ui.ide,
    org.eclipse.emf.cdo.explorer,
    org.eclipse.emf.cdo.explorer.ui",
- org.eclipse.emf.spi.cdo;version="4.13.0"
+ org.eclipse.emf.spi.cdo;version="4.13.1"
 Bundle-ActivationPolicy: lazy
 Automatic-Module-Name: org.eclipse.emf.cdo
diff --git a/plugins/org.eclipse.emf.cdo/pom.xml b/plugins/org.eclipse.emf.cdo/pom.xml
index 7b94b77..5a01ba2 100644
--- a/plugins/org.eclipse.emf.cdo/pom.xml
+++ b/plugins/org.eclipse.emf.cdo/pom.xml
@@ -25,7 +25,7 @@
 
   <groupId>org.eclipse.emf.cdo</groupId>
   <artifactId>org.eclipse.emf.cdo</artifactId>
-  <version>4.13.0-SNAPSHOT</version>
+  <version>4.13.1-SNAPSHOT</version>
   <packaging>eclipse-plugin</packaging>
 
 </project>
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java
index f2215b9..4597fc0 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java
@@ -2644,6 +2644,11 @@
       handleDetachedObjects(commitContext.getDetachedObjects().values());
     }
 
+    private boolean hasSubscriptions()
+    {
+      return !subscriptions.isEmpty();
+    }
+
     private void subscribe(EObject eObject, Adapter adapter)
     {
       subscribe(eObject, adapter, 1);
@@ -2661,6 +2666,7 @@
     {
       boolean policiesPresent = options().hasChangeSubscriptionPolicies();
       subscriptions.clear();
+
       List<CDOID> ids = new ArrayList<>();
       if (policiesPresent)
       {
@@ -3212,6 +3218,22 @@
     {
     }
 
+    public void recoverView()
+    {
+      if (lockNotificationsEnabled)
+      {
+        CDOSessionProtocol protocol = session.getSessionProtocol();
+        protocol.enableLockNotifications(viewID, true);
+      }
+
+      if (changeSubscriptionManager.hasSubscriptions())
+      {
+        changeSubscriptionManager.handleChangeSubcriptionPoliciesChanged();
+      }
+
+      // TODO unitManager.recoverView();
+    }
+
     @Override
     public CDOViewImpl getContainer()
     {