Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common')
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/lock/CDOLockChangeInfo.java62
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/lock/CDOLockOwner.java55
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/lock/CDOLockState.java56
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/lock/CDOLockUtil.java97
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/lock/IDurableLockingManager.java44
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/protocol/CDODataInput.java18
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/protocol/CDODataOutput.java18
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/protocol/CDOProtocolConstants.java25
8 files changed, 372 insertions, 3 deletions
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/lock/CDOLockChangeInfo.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/lock/CDOLockChangeInfo.java
new file mode 100644
index 0000000000..0307719d42
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/lock/CDOLockChangeInfo.java
@@ -0,0 +1,62 @@
+/**
+ * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Caspar De Groot - initial API and implementation
+ */
+package org.eclipse.emf.cdo.common.lock;
+
+import org.eclipse.emf.cdo.common.branch.CDOBranch;
+import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
+
+/**
+ * Represents a change in the lock state of a set of objects. Instances are meant to be sent from the server to the
+ * client for the purpose of notifying the latter.
+ *
+ * @author Caspar De Groot
+ * @since 4.1
+ * @noextend This interface is not intended to be extended by clients.
+ * @noimplement This interface is not intended to be implemented by clients.
+ */
+public interface CDOLockChangeInfo extends CDOBranchPoint
+{
+ /**
+ * @return The branch at which the lock changes took place, same as <code>getView().getBranch()</code>.
+ */
+ public CDOBranch getBranch();
+
+ /**
+ * @return The repository time at which the lock changes took place. This is only an informal indication; no formal
+ * relation (e.g. an ordering) with commit timestamps is guaranteed.
+ */
+ public long getTimeStamp();
+
+ /**
+ * @return The view, represented as a {@link CDOLockOwner}, that authored the lock changes.
+ */
+ public CDOLockOwner getLockOwner();
+
+ /**
+ * @return The new lock states of the objects that were affected by the change
+ */
+ public CDOLockState[] getLockStates();
+
+ /**
+ * @return the type of lock operation that caused the lock changes
+ */
+ public Operation getOperation();
+
+ /**
+ * Enumerates the possible locking operations.
+ *
+ * @author Caspar De Groot
+ */
+ public enum Operation
+ {
+ LOCK, UNLOCK
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/lock/CDOLockOwner.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/lock/CDOLockOwner.java
new file mode 100644
index 0000000000..012fc15117
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/lock/CDOLockOwner.java
@@ -0,0 +1,55 @@
+/**
+ * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Caspar De Groot - initial API and implementation
+ */
+package org.eclipse.emf.cdo.common.lock;
+
+/**
+ * A client-side representation of a view owning locks.
+ * <p>
+ *
+ * @author Caspar De Groot
+ * @since 4.1
+ * @noextend This interface is not intended to be extended by clients.
+ * @noimplement This interface is not intended to be implemented by clients.
+ */
+public interface CDOLockOwner
+{
+ /**
+ * @return the ID identifying the session that owns the view
+ */
+ public int getSessionID();
+
+ /**
+ * @return the ID identifying the view within the session
+ */
+ public int getViewID();
+
+ /**
+ * A constant to represent on the client-side that a lock's owner cannot be represented as a viewID-sessionID pair.
+ */
+ public static final CDOLockOwner UNKNOWN = new CDOLockOwner()
+ {
+ public int getViewID()
+ {
+ return 0;
+ }
+
+ public int getSessionID()
+ {
+ return 0;
+ }
+
+ @Override
+ public String toString()
+ {
+ return CDOLockOwner.class.getSimpleName() + ".UNKNOWN";
+ }
+ };
+}
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/lock/CDOLockState.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/lock/CDOLockState.java
new file mode 100644
index 0000000000..0e470b28c3
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/lock/CDOLockState.java
@@ -0,0 +1,56 @@
+/**
+ * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Caspar De Groot - initial API and implementation
+ */
+package org.eclipse.emf.cdo.common.lock;
+
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.revision.CDOIDAndBranch;
+
+import org.eclipse.net4j.util.concurrent.IRWLockManager.LockType;
+
+import java.util.Set;
+
+/**
+ * A client-side representation of <i>all</i> the locks on a single CDOObject.
+ * <p>
+ * As an individual lock is always owned by view, which in turn is owned by a session, the methods on this interface
+ * return instances of {@link CDOLockOwner} which carry that information.
+ * <p>
+ *
+ * @author Caspar De Groot
+ * @since 4.1
+ * @noextend This interface is not intended to be extended by clients.
+ * @noimplement This interface is not intended to be implemented by clients.
+ */
+public interface CDOLockState
+{
+ /**
+ * Gets a unique identifier for the object that is locked; typically a {@link CDOID} or a {@link CDOIDAndBranch},
+ * depending on whether branching support is enabled or not
+ *
+ * @return the identifier
+ */
+ public Object getLockedObject();
+
+ /**
+ * If the 'others' argument is <code>false</code>, this method returns <code>true</code> if this lock is currently
+ * held by the <i>requesting</i> CDOView, <code>false</code> otherwise.
+ * <p>
+ * If the 'others' argument is <code>true</code>, this method returns <code>true</code> if this lock is currently held
+ * by <i>another</i> view (i.e. any view different from the requesting one), <code>false</code> otherwise.
+ */
+ public boolean isLocked(LockType lockType, CDOLockOwner lockOwner, boolean others);
+
+ public Set<CDOLockOwner> getReadLockOwners();
+
+ public CDOLockOwner getWriteLockOwner();
+
+ public CDOLockOwner getWriteOptionOwner();
+}
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/lock/CDOLockUtil.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/lock/CDOLockUtil.java
new file mode 100644
index 0000000000..d36d9078b6
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/lock/CDOLockUtil.java
@@ -0,0 +1,97 @@
+/**
+ * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Caspar De Groot - initial API and implementation
+ */
+package org.eclipse.emf.cdo.common.lock;
+
+import org.eclipse.emf.cdo.common.CDOCommonSession;
+import org.eclipse.emf.cdo.common.CDOCommonView;
+import org.eclipse.emf.cdo.common.branch.CDOBranch;
+import org.eclipse.emf.cdo.common.lock.CDOLockChangeInfo.Operation;
+import org.eclipse.emf.cdo.internal.common.lock.CDOLockChangeInfoImpl;
+import org.eclipse.emf.cdo.internal.common.lock.CDOLockOwnerImpl;
+import org.eclipse.emf.cdo.internal.common.lock.CDOLockStateImpl;
+import org.eclipse.emf.cdo.spi.common.lock.InternalCDOLockState;
+
+import org.eclipse.net4j.util.CheckUtil;
+import org.eclipse.net4j.util.concurrent.RWOLockManager.LockState;
+
+/**
+ * Various static methods that may help with classes related to CDO locks.
+ *
+ * @author Caspar De Groot
+ * @since 4.1
+ */
+public final class CDOLockUtil
+{
+ private CDOLockUtil()
+ {
+ }
+
+ public static CDOLockState createLockState(Object target)
+ {
+ return new CDOLockStateImpl(target);
+ }
+
+ public static CDOLockState createLockState(LockState<Object, ? extends CDOCommonView> lockState)
+ {
+ CheckUtil.checkArg(lockState, "lockState");
+
+ InternalCDOLockState cdoLockState = new CDOLockStateImpl(lockState.getLockedObject());
+
+ for (CDOCommonView view : lockState.getReadLockOwners())
+ {
+ int sessionID = view.getSession().getSessionID();
+ int viewID = view.getViewID();
+ CDOLockOwner owner = new CDOLockOwnerImpl(sessionID, viewID);
+ cdoLockState.addReadLockOwner(owner);
+ }
+
+ CDOCommonView writeLockOwner = lockState.getWriteLockOwner();
+ if (writeLockOwner != null)
+ {
+ CDOLockOwner owner = createLockOwner(writeLockOwner);
+ cdoLockState.setWriteLockOwner(owner);
+ }
+
+ CDOCommonView writeOptionOwner = lockState.getWriteOptionOwner();
+ if (writeOptionOwner != null)
+ {
+ CDOLockOwner owner = createLockOwner(writeOptionOwner);
+ cdoLockState.setWriteOptionOwner(owner);
+ }
+
+ return cdoLockState;
+ }
+
+ public static CDOLockOwner createLockOwner(CDOCommonView view)
+ {
+ CDOCommonSession session = view.getSession();
+ if (session != null)
+ {
+ int sessionID = session.getSessionID();
+ int viewID = view.getViewID();
+ return new CDOLockOwnerImpl(sessionID, viewID);
+ }
+ return CDOLockOwner.UNKNOWN;
+ }
+
+ public static CDOLockChangeInfo createLockChangeInfo(long timestamp, CDOLockOwner lockOwner, CDOBranch branch,
+ Operation op, CDOLockState[] cdoLockStates)
+ {
+ return new CDOLockChangeInfoImpl(branch.getPoint(timestamp), lockOwner, cdoLockStates, op);
+ }
+
+ public static CDOLockChangeInfo createLockChangeInfo(long timestamp, CDOCommonView view, CDOBranch viewedBranch,
+ Operation op, CDOLockState[] cdoLockStates)
+ {
+ CDOLockOwner lockOwner = createLockOwner(view);
+ return createLockChangeInfo(timestamp, lockOwner, viewedBranch, op, cdoLockStates);
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/lock/IDurableLockingManager.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/lock/IDurableLockingManager.java
index 7d042af590..5343f8f91a 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/lock/IDurableLockingManager.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/lock/IDurableLockingManager.java
@@ -24,8 +24,6 @@ import java.util.Map;
*
* @author Eike Stepper
* @since 4.0
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
*/
public interface IDurableLockingManager
{
@@ -104,6 +102,28 @@ public interface IDurableLockingManager
}
/**
+ * @author Caspar De Groot
+ * @since 4.1
+ */
+ public static class LockAreaAlreadyExistsException extends IllegalStateException
+ {
+ private static final long serialVersionUID = 1L;
+
+ private String durableLockingID;
+
+ public LockAreaAlreadyExistsException(String durableLockingID)
+ {
+ super("A lock area with ID=" + durableLockingID + " already exists");
+ this.durableLockingID = durableLockingID;
+ }
+
+ public String getDurableLockingID()
+ {
+ return durableLockingID;
+ }
+ }
+
+ /**
* Enumerates the possible combinations of read and write locks on a single CDO object.
*
* @author Eike Stepper
@@ -165,7 +185,8 @@ public interface IDurableLockingManager
public LockGrade getUpdated(LockType type, boolean on)
{
- int mask = type == LockType.READ ? 1 : 2;
+ int mask = getMask(type);
+
if (on)
{
return get(value | mask);
@@ -174,6 +195,23 @@ public interface IDurableLockingManager
return get(value & ~mask);
}
+ private int getMask(LockType type)
+ {
+ switch (type)
+ {
+ case READ:
+ return 1;
+
+ case WRITE:
+ return 2;
+
+ case OPTION:
+ return 4;
+ }
+
+ return 0;
+ }
+
public static LockGrade get(LockType type)
{
if (type == LockType.READ)
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/protocol/CDODataInput.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/protocol/CDODataInput.java
index 2cbbde9d83..acab6ac3ea 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/protocol/CDODataInput.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/protocol/CDODataInput.java
@@ -19,6 +19,9 @@ import org.eclipse.emf.cdo.common.commit.CDOCommitData;
import org.eclipse.emf.cdo.common.commit.CDOCommitInfo;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.id.CDOIDReference;
+import org.eclipse.emf.cdo.common.lock.CDOLockChangeInfo;
+import org.eclipse.emf.cdo.common.lock.CDOLockOwner;
+import org.eclipse.emf.cdo.common.lock.CDOLockState;
import org.eclipse.emf.cdo.common.model.CDOClassifierRef;
import org.eclipse.emf.cdo.common.model.CDOPackageInfo;
import org.eclipse.emf.cdo.common.model.CDOPackageUnit;
@@ -135,4 +138,19 @@ public interface CDODataInput extends ExtendedDataInput
// /////////////////////////////////////////////////////////////////////////////////////////////////
public LockType readCDOLockType() throws IOException;
+
+ /**
+ * @since 4.1
+ */
+ public CDOLockChangeInfo readCDOLockChangeInfo() throws IOException;
+
+ /**
+ * @since 4.1
+ */
+ public CDOLockOwner readCDOLockOwner() throws IOException;
+
+ /**
+ * @since 4.1
+ */
+ public CDOLockState readCDOLockState() throws IOException;
}
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/protocol/CDODataOutput.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/protocol/CDODataOutput.java
index db036d7926..9c040d46fe 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/protocol/CDODataOutput.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/protocol/CDODataOutput.java
@@ -20,6 +20,9 @@ import org.eclipse.emf.cdo.common.commit.CDOCommitInfo;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.id.CDOIDProvider;
import org.eclipse.emf.cdo.common.id.CDOIDReference;
+import org.eclipse.emf.cdo.common.lock.CDOLockChangeInfo;
+import org.eclipse.emf.cdo.common.lock.CDOLockOwner;
+import org.eclipse.emf.cdo.common.lock.CDOLockState;
import org.eclipse.emf.cdo.common.model.CDOClassifierRef;
import org.eclipse.emf.cdo.common.model.CDOPackageInfo;
import org.eclipse.emf.cdo.common.model.CDOPackageRegistry;
@@ -141,4 +144,19 @@ public interface CDODataOutput extends ExtendedDataOutput
// /////////////////////////////////////////////////////////////////////////////////////////////////
public void writeCDOLockType(LockType lockType) throws IOException;
+
+ /**
+ * @since 4.1
+ */
+ public void writeCDOLockChangeInfo(CDOLockChangeInfo lockChangeInfo) throws IOException;
+
+ /**
+ * @since 4.1
+ */
+ public void writeCDOLockState(CDOLockState lockState) throws IOException;
+
+ /**
+ * @since 4.1
+ */
+ public void writeCDOLockOwner(CDOLockOwner lockOwner) throws IOException;
}
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/protocol/CDOProtocolConstants.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/protocol/CDOProtocolConstants.java
index ef2fbfee26..722b158ca9 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/protocol/CDOProtocolConstants.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/protocol/CDOProtocolConstants.java
@@ -217,6 +217,31 @@ public interface CDOProtocolConstants
*/
public static final short SIGNAL_HANDLE_REVISIONS = 48;
+ /**
+ * @since 4.1
+ */
+ public static final short SIGNAL_LOCK_DELEGATION = 49;
+
+ /**
+ * @since 4.1
+ */
+ public static final short SIGNAL_UNLOCK_DELEGATION = 50;
+
+ /**
+ * @since 4.1
+ */
+ public static final short SIGNAL_LOCK_NOTIFICATION = 51;
+
+ /**
+ * @since 4.1
+ */
+ public static final short SIGNAL_LOCK_STATE = 52;
+
+ /**
+ * @since 4.1
+ */
+ public static final short SIGNAL_ENABLE_LOCK_NOTIFICATION = 53;
+
// //////////////////////////////////////////////////////////////////////
// Session Refresh

Back to the top