Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/LockingManagerTest.java62
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/SavePointTest.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_273565_Test.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_294850_Test.java2
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOLock.java17
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLockImpl.java224
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java135
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectWrapper.java115
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/NOOPLockImpl.java83
9 files changed, 297 insertions, 352 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/LockingManagerTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/LockingManagerTest.java
index ce9986dbef..835781a2b4 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/LockingManagerTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/LockingManagerTest.java
@@ -152,7 +152,7 @@ public class LockingManagerTest extends AbstractCDOTest
transaction.commit();
CDOObject cdoCompany = CDOUtil.getCDOObject(company);
- cdoCompany.cdoWriteLock().lock();
+ writeLock(cdoCompany);
CDOTransaction transaction2 = session.openTransaction();
CDOObject company2 = transaction2.getObject(cdoCompany.cdoID());
@@ -177,7 +177,7 @@ public class LockingManagerTest extends AbstractCDOTest
transaction.commit();
CDOObject cdoCompany = CDOUtil.getCDOObject(company);
- cdoCompany.cdoReadLock().lock();
+ readLock(cdoCompany);
CDOTransaction transaction2 = session.openTransaction();
Company company2 = (Company)transaction2.getResource("/res1").getContents().get(0);
@@ -206,7 +206,7 @@ public class LockingManagerTest extends AbstractCDOTest
try
{
- cdoCompany2.cdoReadLock().lock();
+ readLock(cdoCompany2);
fail("IllegalArgumentException expected");
}
catch (IllegalArgumentException expected)
@@ -228,7 +228,7 @@ public class LockingManagerTest extends AbstractCDOTest
transaction.commit();
CDOObject cdoCompany = CDOUtil.getCDOObject(company);
- cdoCompany.cdoWriteLock().lock();
+ writeLock(cdoCompany);
CDOTransaction transaction2 = session.openTransaction();
Company company2 = (Company)transaction2.getResource("/res1").getContents().get(0);
@@ -293,7 +293,7 @@ public class LockingManagerTest extends AbstractCDOTest
CDOObject cdoCompany = CDOUtil.getCDOObject(company);
CDOObject cdoCompany2 = CDOUtil.getCDOObject(company2);
- cdoCompany.cdoWriteLock().lock();
+ writeLock(cdoCompany);
boolean acquired = cdoCompany2.cdoWriteLock().tryLock(1000L, TimeUnit.MILLISECONDS);
assertEquals(false, acquired);
@@ -404,7 +404,7 @@ public class LockingManagerTest extends AbstractCDOTest
transaction.commit();
CDOObject cdoCompany = CDOUtil.getCDOObject(company);
- cdoCompany.cdoReadLock().lock();
+ readLock(cdoCompany);
company.setCity("Ottawa");
transaction.commit();
@@ -421,7 +421,7 @@ public class LockingManagerTest extends AbstractCDOTest
transaction.commit();
CDOObject cdoCompany = CDOUtil.getCDOObject(company);
- cdoCompany.cdoWriteLock().lock();
+ writeLock(cdoCompany);
company.setCity("Ottawa");
assertEquals(true, cdoCompany.cdoWriteLock().isLocked());
@@ -444,7 +444,7 @@ public class LockingManagerTest extends AbstractCDOTest
transaction.commit();
CDOObject cdoCompany = CDOUtil.getCDOObject(company);
- cdoCompany.cdoWriteLock().lock();
+ writeLock(cdoCompany);
company.setCity("Ottawa");
transaction.rollback();
@@ -462,19 +462,19 @@ public class LockingManagerTest extends AbstractCDOTest
transaction.commit();
CDOObject cdoCompany = CDOUtil.getCDOObject(company);
- cdoCompany.cdoReadLock().lock();
+ readLock(cdoCompany);
assertEquals(true, cdoCompany.cdoReadLock().isLocked());
assertEquals(false, cdoCompany.cdoWriteLock().isLocked());
- cdoCompany.cdoWriteLock().lock();
+ writeLock(cdoCompany);
assertEquals(true, cdoCompany.cdoReadLock().isLocked());
assertEquals(true, cdoCompany.cdoWriteLock().isLocked());
- cdoCompany.cdoReadLock().lock();
+ readLock(cdoCompany);
assertEquals(true, cdoCompany.cdoReadLock().isLocked());
assertEquals(true, cdoCompany.cdoWriteLock().isLocked());
- cdoCompany.cdoWriteLock().lock();
+ writeLock(cdoCompany);
assertEquals(true, cdoCompany.cdoReadLock().isLocked());
assertEquals(true, cdoCompany.cdoWriteLock().isLocked());
@@ -496,19 +496,19 @@ public class LockingManagerTest extends AbstractCDOTest
/********************/
- cdoCompany.cdoReadLock().lock();
+ readLock(cdoCompany);
assertEquals(true, cdoCompany.cdoReadLock().isLocked());
assertEquals(false, cdoCompany.cdoWriteLock().isLocked());
- cdoCompany.cdoWriteLock().lock();
+ writeLock(cdoCompany);
assertEquals(true, cdoCompany.cdoReadLock().isLocked());
assertEquals(true, cdoCompany.cdoWriteLock().isLocked());
- cdoCompany.cdoReadLock().lock();
+ readLock(cdoCompany);
assertEquals(true, cdoCompany.cdoReadLock().isLocked());
assertEquals(true, cdoCompany.cdoWriteLock().isLocked());
- cdoCompany.cdoWriteLock().lock();
+ writeLock(cdoCompany);
assertEquals(true, cdoCompany.cdoReadLock().isLocked());
assertEquals(true, cdoCompany.cdoWriteLock().isLocked());
@@ -543,7 +543,7 @@ public class LockingManagerTest extends AbstractCDOTest
transaction.commit();
CDOObject cdoCompany = CDOUtil.getCDOObject(company);
- cdoCompany.cdoReadLock().lock();
+ readLock(cdoCompany);
transaction.close();
assertEquals(false, repo.getLockManager().hasLock(LockType.READ, view, cdoCompany.cdoID()));
}
@@ -562,7 +562,7 @@ public class LockingManagerTest extends AbstractCDOTest
transaction.commit();
CDOObject cdoCompany = CDOUtil.getCDOObject(company);
- cdoCompany.cdoReadLock().lock();
+ readLock(cdoCompany);
session.close();
sleep(100);
@@ -584,7 +584,7 @@ public class LockingManagerTest extends AbstractCDOTest
CDOObject cdoCompany1 = CDOUtil.getCDOObject(company1);
CDOObject cdoCompany2 = CDOUtil.getCDOObject(company2);
- cdoCompany1.cdoWriteLock().lock();
+ writeLock(cdoCompany1);
assertEquals(true, cdoCompany1.cdoWriteLock().isLocked());
Company companyFrom2 = (Company)CDOUtil.getEObject(transaction2.getObject(cdoCompany2.cdoID()));
companyFrom2.setCity("sss");
@@ -604,8 +604,8 @@ public class LockingManagerTest extends AbstractCDOTest
transaction.options().setAutoReleaseLocksEnabled(false);
CDOObject cdoCompany = CDOUtil.getCDOObject(company);
- cdoCompany.cdoWriteLock().lock();
- cdoCompany.cdoReadLock().lock();
+ writeLock(cdoCompany);
+ readLock(cdoCompany);
msg("Test with read/write lock");
assertEquals(true, cdoCompany.cdoWriteLock().isLocked());
@@ -620,7 +620,7 @@ public class LockingManagerTest extends AbstractCDOTest
transaction.unlockObjects(null, null);
msg("Test with read lock");
- cdoCompany.cdoReadLock().lock();
+ readLock(cdoCompany);
assertEquals(true, cdoCompany.cdoReadLock().isLocked());
company.setCity("Toronto");
@@ -644,8 +644,8 @@ public class LockingManagerTest extends AbstractCDOTest
transaction.options().setAutoReleaseLocksEnabled(false);
CDOObject cdoCompany = CDOUtil.getCDOObject(company);
- cdoCompany.cdoWriteLock().lock();
- cdoCompany.cdoReadLock().lock();
+ writeLock(cdoCompany);
+ readLock(cdoCompany);
msg("Test with read/write lock");
assertEquals(true, cdoCompany.cdoWriteLock().isLocked());
@@ -660,7 +660,7 @@ public class LockingManagerTest extends AbstractCDOTest
transaction.unlockObjects(null, null);
msg("Test with read lock");
- cdoCompany.cdoReadLock().lock();
+ readLock(cdoCompany);
assertEquals(true, cdoCompany.cdoReadLock().isLocked());
company.setCity("Toronto");
@@ -689,9 +689,19 @@ public class LockingManagerTest extends AbstractCDOTest
// 335-418 locks/sec
for (int i = 0; i < ITERATION; i++)
{
- cdoCompany.cdoWriteLock().lock();
+ writeLock(cdoCompany);
}
msg("Lock " + ITERATION / ((double)(System.currentTimeMillis() - start) / 1000) + " objects/sec");
}
+
+ private static void readLock(CDOObject object) throws InterruptedException
+ {
+ assertEquals(true, object.cdoReadLock().tryLock(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS));
+ }
+
+ private static void writeLock(CDOObject object) throws InterruptedException
+ {
+ assertEquals(true, object.cdoWriteLock().tryLock(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS));
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/SavePointTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/SavePointTest.java
index e9305aeeee..69fbb2b3ee 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/SavePointTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/SavePointTest.java
@@ -18,7 +18,6 @@ import org.eclipse.emf.cdo.tests.model1.Company;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.transaction.CDOUserSavepoint;
import org.eclipse.emf.cdo.util.CDOUtil;
-import org.eclipse.emf.cdo.util.CommitException;
import org.eclipse.emf.cdo.view.CDOView;
import org.eclipse.emf.spi.cdo.FSMUtil;
@@ -277,7 +276,7 @@ public class SavePointTest extends AbstractCDOTest
* client2: same as repository
* </pre>
*/
- public void _testScenario1() throws CommitException
+ public void _testScenario1() throws Exception
{
CDOSession client1 = openSession();
CDOTransaction transaction1 = client1.openTransaction();
@@ -289,7 +288,7 @@ public class SavePointTest extends AbstractCDOTest
CDOUserSavepoint savepoint = transaction1.setSavepoint();
// client1 write locks object1
- object1X.cdoWriteLock().lock();
+ object1X.cdoWriteLock().lock(DEFAULT_TIMEOUT);
// client1 modifies object1
object1X.getContents().add(getModel1Factory().createCompany());
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_273565_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_273565_Test.java
index fe93681815..36d9d585d6 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_273565_Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_273565_Test.java
@@ -10,7 +10,6 @@
*/
package org.eclipse.emf.cdo.tests.bugzilla;
-import org.eclipse.emf.cdo.CDOLock;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.session.CDOSession;
@@ -215,8 +214,7 @@ public class Bugzilla_273565_Test extends AbstractCDOTest
start.await(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS);
for (int i = 0; i < 5000 && exception[0] == null; i++)
{
- CDOLock writeLock = CDOUtil.getCDOObject(orderDetail).cdoWriteLock();
- writeLock.lock();
+ CDOUtil.getCDOObject(orderDetail).cdoWriteLock().lock(DEFAULT_TIMEOUT);
System.out.println("\nGot lock: " + price + " --> " + CDOUtil.getCDOObject(orderDetail).cdoRevision());
sleep(1L);
@@ -275,7 +273,7 @@ public class Bugzilla_273565_Test extends AbstractCDOTest
CDOTransaction transaction2 = session.openTransaction();
OrderDetail orderDetail2 = (OrderDetail)CDOUtil.getEObject(transaction2.getObject(orderDetail));
- CDOUtil.getCDOObject(orderDetail).cdoWriteLock().lock();
+ CDOUtil.getCDOObject(orderDetail).cdoWriteLock().lock(DEFAULT_TIMEOUT);
orderDetail.setPrice(2);
boolean locked = CDOUtil.getCDOObject(orderDetail2).cdoWriteLock()
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_294850_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_294850_Test.java
index 6474ed7ad4..27c4b0c15d 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_294850_Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_294850_Test.java
@@ -76,7 +76,7 @@ public class Bugzilla_294850_Test extends AbstractCDOTest
}.assertNoTimeOut();
// Lock company to trigger a refresh
- CDOUtil.getCDOObject(company).cdoWriteLock().lock();
+ CDOUtil.getCDOObject(company).cdoWriteLock().lock(DEFAULT_TIMEOUT);
// Object should be in conflict state now
assertSame(CDOState.CONFLICT, CDOUtil.getCDOObject(company).cdoState());
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOLock.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOLock.java
index 67c640839c..b4314f824f 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOLock.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOLock.java
@@ -16,6 +16,8 @@ import org.eclipse.emf.cdo.view.CDOView;
import org.eclipse.net4j.util.concurrent.IRWLockManager.LockType;
import org.eclipse.net4j.util.concurrent.RWLockManager;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
import java.util.concurrent.locks.Lock;
/**
@@ -44,6 +46,21 @@ public interface CDOLock extends Lock
public LockType getType();
/**
+ * @since 4.0
+ */
+ public void lock(long time, TimeUnit unit) throws TimeoutException;
+
+ /**
+ * @since 4.0
+ */
+ public void lock(long millis) throws TimeoutException;
+
+ /**
+ * @since 4.0
+ */
+ public boolean tryLock(long millis) throws InterruptedException;
+
+ /**
* Returns <code>true</code> if this lock is currently held by the requesting {@link CDOView view}, <code>false</code>
* otherwise.
*/
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLockImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLockImpl.java
new file mode 100644
index 0000000000..8ce567115e
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLockImpl.java
@@ -0,0 +1,224 @@
+/**
+ * Copyright (c) 2004 - 2010 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:
+ * Simon McDuff - initial API and implementation
+ * Eike Stepper - maintenance
+ */
+package org.eclipse.emf.internal.cdo;
+
+import org.eclipse.emf.cdo.CDOLock;
+
+import org.eclipse.net4j.util.WrappedException;
+import org.eclipse.net4j.util.concurrent.IRWLockManager.LockType;
+import org.eclipse.net4j.util.concurrent.TimeoutRuntimeException;
+
+import org.eclipse.emf.spi.cdo.InternalCDOObject;
+
+import java.text.MessageFormat;
+import java.util.Collections;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.locks.Condition;
+
+/**
+ * @author Simon McDuff
+ * @since 4.0
+ */
+public class CDOLockImpl implements CDOLock
+{
+ public static final CDOLock NOOP = new NOOPLockImpl();
+
+ private InternalCDOObject object;
+
+ private LockType type;
+
+ public CDOLockImpl(InternalCDOObject object, LockType type)
+ {
+ this.object = object;
+ this.type = type;
+ }
+
+ public LockType getType()
+ {
+ return type;
+ }
+
+ public boolean isLocked()
+ {
+ return object.cdoView().isObjectLocked(object, type, false);
+ }
+
+ /**
+ * @see org.eclipse.emf.cdo.CDOLock#isLockedByOthers()
+ */
+ public boolean isLockedByOthers()
+ {
+ return object.cdoView().isObjectLocked(object, type, true);
+ }
+
+ public void lock()
+ {
+ try
+ {
+ object.cdoView().lockObjects(Collections.singletonList(object), type, CDOLock.WAIT);
+ }
+ catch (InterruptedException ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ }
+
+ public void lock(long time, TimeUnit unit) throws TimeoutException
+ {
+ try
+ {
+ if (!tryLock(time, unit))
+ {
+ throw new TimeoutException();
+ }
+ }
+ catch (InterruptedException ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ }
+
+ public void lock(long millis) throws TimeoutException
+ {
+ lock(millis, TimeUnit.MILLISECONDS);
+ }
+
+ public boolean tryLock(long millis) throws InterruptedException
+ {
+ return tryLock(millis, TimeUnit.MILLISECONDS);
+ }
+
+ public void lockInterruptibly() throws InterruptedException
+ {
+ lock();
+ }
+
+ public Condition newCondition()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean tryLock()
+ {
+ try
+ {
+ object.cdoView().lockObjects(Collections.singletonList(object), type, CDOLock.NO_WAIT);
+ return true;
+ }
+ catch (TimeoutRuntimeException ex)
+ {
+ return false;
+ }
+ catch (InterruptedException ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ }
+
+ public boolean tryLock(long time, TimeUnit unit) throws InterruptedException
+ {
+ try
+ {
+ object.cdoView().lockObjects(Collections.singletonList(object), type, unit.toMillis(time));
+ return true;
+ }
+ catch (TimeoutRuntimeException ex)
+ {
+ return false;
+ }
+ }
+
+ public void unlock()
+ {
+ object.cdoView().unlockObjects(Collections.singletonList(object), type);
+ }
+
+ @Override
+ public String toString()
+ {
+ return MessageFormat.format("CDOLock[object={0}, type={1}]", object, type);
+ }
+
+ /**
+ * @author Simon McDuff
+ */
+ public static final class NOOPLockImpl implements CDOLock
+ {
+ private NOOPLockImpl()
+ {
+ }
+
+ public boolean isLocked()
+ {
+ return false;
+ }
+
+ /**
+ * @see org.eclipse.emf.cdo.CDOLock#isLockedByOthers()
+ */
+ public boolean isLockedByOthers()
+ {
+ return false;
+ }
+
+ public void lock()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void lockInterruptibly() throws InterruptedException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Condition newCondition()
+ {
+ return null;
+ }
+
+ public void lock(long time, TimeUnit unit) throws TimeoutException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void lock(long millis) throws TimeoutException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean tryLock(long millis) throws InterruptedException
+ {
+ return false;
+ }
+
+ public boolean tryLock()
+ {
+ return false;
+ }
+
+ public boolean tryLock(long time, TimeUnit unit) throws InterruptedException
+ {
+ return false;
+ }
+
+ public void unlock()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public LockType getType()
+ {
+ return null;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java
index d918d2e1f0..28a7487669 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java
@@ -27,9 +27,7 @@ import org.eclipse.emf.internal.cdo.messages.Messages;
import org.eclipse.net4j.util.ImplementationError;
import org.eclipse.net4j.util.ObjectUtil;
-import org.eclipse.net4j.util.WrappedException;
import org.eclipse.net4j.util.concurrent.IRWLockManager.LockType;
-import org.eclipse.net4j.util.concurrent.TimeoutRuntimeException;
import org.eclipse.net4j.util.om.trace.ContextTracer;
import org.eclipse.emf.common.notify.Adapter;
@@ -61,14 +59,10 @@ import org.eclipse.emf.spi.cdo.InternalCDOLoadable;
import org.eclipse.emf.spi.cdo.InternalCDOObject;
import org.eclipse.emf.spi.cdo.InternalCDOView;
-import java.text.MessageFormat;
import java.util.Collection;
-import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.locks.Condition;
/**
* @author Eike Stepper
@@ -187,11 +181,10 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
{
if (FSMUtil.isTransient(this) || FSMUtil.isNew(this))
{
- return NOOPLockImpl.INSTANCE;
+ return CDOLockImpl.NOOP;
}
- // Should we cache the locks ?
- return new CDOReadLock();
+ return new CDOLockImpl(this, LockType.READ);
}
/**
@@ -201,11 +194,10 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
{
if (FSMUtil.isTransient(this) || FSMUtil.isNew(this))
{
- return NOOPLockImpl.INSTANCE;
+ return CDOLockImpl.NOOP;
}
- // Should we cache the locks ?
- return new CDOWriteLock();
+ return new CDOLockImpl(this, LockType.WRITE);
}
public void cdoInternalSetID(CDOID id)
@@ -1161,125 +1153,6 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
/**
* @author Simon McDuff
- * @since 3.0
- */
- public abstract class AbstractCDOLock implements CDOLock
- {
- public AbstractCDOLock()
- {
- }
-
- public boolean isLocked()
- {
- return view.isObjectLocked(CDOObjectImpl.this, getType(), false);
- }
-
- /**
- * @see org.eclipse.emf.cdo.CDOLock#isLockedByOthers()
- */
- public boolean isLockedByOthers()
- {
- return view.isObjectLocked(CDOObjectImpl.this, getType(), true);
- }
-
- public void lock()
- {
- try
- {
- view.lockObjects(Collections.singletonList(CDOObjectImpl.this), getType(), CDOLock.WAIT);
- }
- catch (InterruptedException ex)
- {
- throw WrappedException.wrap(ex);
- }
- }
-
- public void lockInterruptibly() throws InterruptedException
- {
- lock();
- }
-
- public Condition newCondition()
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean tryLock()
- {
- try
- {
- view.lockObjects(Collections.singletonList(CDOObjectImpl.this), getType(), CDOLock.NO_WAIT);
- return true;
- }
- catch (TimeoutRuntimeException ex)
- {
- return false;
- }
- catch (InterruptedException ex)
- {
- throw WrappedException.wrap(ex);
- }
- }
-
- public boolean tryLock(long time, TimeUnit unit) throws InterruptedException
- {
- try
- {
- view.lockObjects(Collections.singletonList(CDOObjectImpl.this), getType(), unit.toMillis(time));
- return true;
- }
- catch (TimeoutRuntimeException ex)
- {
- return false;
- }
- }
-
- public void unlock()
- {
- view.unlockObjects(Collections.singletonList(CDOObjectImpl.this), getType());
- }
-
- @Override
- public String toString()
- {
- return MessageFormat.format("CDOLock[object={0}, type={1}]", CDOObjectImpl.this, getType());
- }
- }
-
- /**
- * @author Eike Stepper
- * @since 3.0
- */
- public final class CDOReadLock extends AbstractCDOLock
- {
- public CDOReadLock()
- {
- }
-
- public LockType getType()
- {
- return LockType.READ;
- }
- }
-
- /**
- * @author Eike Stepper
- * @since 3.0
- */
- public final class CDOWriteLock extends AbstractCDOLock
- {
- public CDOWriteLock()
- {
- }
-
- public LockType getType()
- {
- return LockType.WRITE;
- }
- }
-
- /**
- * @author Simon McDuff
* @since 2.0
*/
public static class CDOStoreSettingsImpl implements InternalEObject.EStore
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectWrapper.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectWrapper.java
index cced821873..2bbb64231c 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectWrapper.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectWrapper.java
@@ -17,9 +17,7 @@ import org.eclipse.emf.cdo.view.CDOView;
import org.eclipse.emf.internal.cdo.bundle.OM;
-import org.eclipse.net4j.util.WrappedException;
import org.eclipse.net4j.util.concurrent.IRWLockManager.LockType;
-import org.eclipse.net4j.util.concurrent.TimeoutRuntimeException;
import org.eclipse.net4j.util.om.trace.ContextTracer;
import org.eclipse.emf.common.notify.Adapter;
@@ -43,9 +41,6 @@ import org.eclipse.emf.spi.cdo.InternalCDOObject;
import org.eclipse.emf.spi.cdo.InternalCDOView;
import java.lang.reflect.InvocationTargetException;
-import java.util.Collections;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.locks.Condition;
/**
* @author Eike Stepper
@@ -185,11 +180,10 @@ public abstract class CDOObjectWrapper implements InternalCDOObject
{
if (FSMUtil.isTransient(this) || FSMUtil.isNew(this))
{
- return NOOPLockImpl.INSTANCE;
+ return CDOLockImpl.NOOP;
}
- // Should we cache the locks ?
- return new Lock(LockType.READ);
+ return new CDOLockImpl(this, LockType.READ);
}
/**
@@ -199,11 +193,10 @@ public abstract class CDOObjectWrapper implements InternalCDOObject
{
if (FSMUtil.isTransient(this) || FSMUtil.isNew(this))
{
- return NOOPLockImpl.INSTANCE;
+ return CDOLockImpl.NOOP;
}
- // Should we cache the locks ?
- return new Lock(LockType.WRITE);
+ return new CDOLockImpl(this, LockType.WRITE);
}
public EList<Adapter> eAdapters()
@@ -463,6 +456,13 @@ public abstract class CDOObjectWrapper implements InternalCDOObject
protected class AdapterListListener implements
org.eclipse.emf.common.notify.impl.BasicNotifierImpl.EObservableAdapterList.Listener
{
+ /**
+ * @since 4.0
+ */
+ public AdapterListListener()
+ {
+ }
+
public void added(Notifier notifier, Adapter adapter)
{
if (TRACER.isEnabled())
@@ -489,97 +489,4 @@ public abstract class CDOObjectWrapper implements InternalCDOObject
}
}
}
-
- /**
- * @author Martin Fluegge
- * @since 3.0
- */
- private final class Lock implements CDOLock
- {
- private LockType type;
-
- public Lock(LockType type)
- {
- this.type = type;
- }
-
- public LockType getType()
- {
- return type;
- }
-
- public boolean isLocked()
- {
- return cdoView().isObjectLocked(CDOObjectWrapper.this, type, false);
- }
-
- /**
- * @see org.eclipse.emf.cdo.CDOLock#isLockedByOthers()
- */
- public boolean isLockedByOthers()
- {
- return cdoView().isObjectLocked(CDOObjectWrapper.this, type, true);
- }
-
- public void lock()
- {
- try
- {
- cdoView().lockObjects(Collections.singletonList(CDOObjectWrapper.this), type, CDOLock.WAIT);
- }
- catch (InterruptedException ex)
- {
- throw WrappedException.wrap(ex);
- }
- }
-
- public void lockInterruptibly() throws InterruptedException
- {
- lock();
- }
-
- public Condition newCondition()
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean tryLock()
- {
- try
- {
- cdoView().lockObjects(Collections.singletonList(CDOObjectWrapper.this), type, CDOLock.NO_WAIT);
- return true;
- }
- catch (TimeoutRuntimeException ex)
- {
- return false;
- }
- catch (InterruptedException ex)
- {
- throw WrappedException.wrap(ex);
- }
- }
-
- /**
- * @throws InterruptedException
- * if timeout is reached.
- */
- public boolean tryLock(long time, TimeUnit unit) throws InterruptedException
- {
- try
- {
- cdoView().lockObjects(Collections.singletonList(CDOObjectWrapper.this), type, unit.toMillis(time));
- return true;
- }
- catch (TimeoutRuntimeException ex)
- {
- return false;
- }
- }
-
- public void unlock()
- {
- cdoView().unlockObjects(Collections.singletonList(CDOObjectWrapper.this), type);
- }
- }
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/NOOPLockImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/NOOPLockImpl.java
deleted file mode 100644
index 240188d3e5..0000000000
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/NOOPLockImpl.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/**
- * Copyright (c) 2004 - 2010 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:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.internal.cdo;
-
-import org.eclipse.emf.cdo.CDOLock;
-
-import org.eclipse.net4j.util.concurrent.IRWLockManager.LockType;
-
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.locks.Condition;
-
-/**
- * @author Simon McDuff
- * @since 2.0
- */
-public class NOOPLockImpl implements CDOLock
-{
- public static final NOOPLockImpl INSTANCE = new NOOPLockImpl();
-
- private NOOPLockImpl()
- {
- }
-
- public boolean isLocked()
- {
- return false;
- }
-
- /**
- * @see org.eclipse.emf.cdo.CDOLock#isLockedByOthers()
- */
- public boolean isLockedByOthers()
- {
- return false;
- }
-
- public void lock()
- {
- throw new UnsupportedOperationException();
- }
-
- public void lockInterruptibly() throws InterruptedException
- {
- throw new UnsupportedOperationException();
- }
-
- public Condition newCondition()
- {
- return null;
- }
-
- public boolean tryLock()
- {
- return false;
- }
-
- public boolean tryLock(long time, TimeUnit unit) throws InterruptedException
- {
- return false;
- }
-
- public void unlock()
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @since 3.0
- */
- public LockType getType()
- {
- return null;
- }
-}

Back to the top